Purpose
Determine programmatically whether child objects should be added to a TemplateObject. This filter allows external plugins or custom logic to decide if the creation of child objects should occur.
Usage
add_filters( "wr_tb_add_children_to_template_object_flag", "my_function", 10, 3);
Parameters
$add_children (bool)
: A boolean flag indicating whether child objects should be added. Defaults to true.$object_settings (TemplateObjectDTO)
: The settings object containing configuration for the parent TemplateObject.$object_data (array)
: The data associated with the parent TemplateObject.
Use Case
This functionality is useful when:
- You want to enable or disable the addition of child objects dynamically based on specific criteria.
- External plugins or logic should have control over the behavior of child object creation.
Implementation Example
add_filter("wr_tb_add_children_to_template_object_flag", array( $this, "dont_add_children_if_query_result_is_empty" ), 20, 3);
public function dont_add_children_if_query_result_is_empty(
bool $flag,
TemplateObjectDTO $settings,
array $data
): bool {
$options = $settings->options->get_all_options_as_array();
if ( ! empty( $options["identifier"] )
&& ( $options["identifier"] === "template_object_example"
|| $options["identifier"] === "template_object_sample" )
&& empty( $data ) ) {
return false;
}
return $flag;
}