Filter
uncanny-automator
automator_recipe_children_data
Filters recipe children data before it is saved or displayed, allowing modification of child recipe information.
add_filter( 'automator_recipe_children_data', $callback, 10, 2 );
Description
Fires after recipe children data, including token information, has been gathered. Developers can filter this data to modify or add to the information provided for each recipe child, such as adding custom token renderable data. This hook is crucial for customizing how recipe child data is presented and utilized.
Usage
add_filter( 'automator_recipe_children_data', 'your_function_name', 10, 2 );
Parameters
-
$recipe_children_data(mixed) - This parameter contains an array of data related to the recipe's child items, specifically actions or triggers, that will be processed and potentially modified.
-
$type(mixed) - This parameter contains an array of data related to the recipe's child items (actions or triggers), including their metadata and tokens.
Return Value
The filtered value.
Examples
/**
* Modify the recipe children data to add custom information.
*
* This function demonstrates how to hook into the 'automator_recipe_children_data'
* filter to add or modify data associated with recipe children (triggers, actions, etc.).
* In this example, we're adding a custom 'custom_field_value' to action items
* if a specific meta key exists in their metadata.
*
* @param array $recipe_children_data The array of recipe children data.
* @param array $args An array containing 'type', 'recipe_id', and 'recipe_children'.
*
* @return array The modified $recipe_children_data.
*/
add_filter( 'automator_recipe_children_data', function( $recipe_children_data, $args ) {
// Ensure we have the expected arguments
if ( ! isset( $args['type'] ) || ! isset( $args['recipe_id'] ) || ! isset( $args['recipe_children'] ) ) {
return $recipe_children_data;
}
$type = $args['type'];
$recipe_id = $args['recipe_id'];
$recipe_children = $args['recipe_children'];
// Check if the current child type is an action
if ( AUTOMATOR_POST_TYPE_ACTION === $type ) {
foreach ( $recipe_children as $key => $child ) {
// Get the metadata for the current action
$child_meta = get_post_meta( $child['ID'] );
// Check if our custom meta key exists
if ( isset( $child_meta['_my_custom_action_setting'][0] ) ) {
// Add our custom data to the existing recipe_children_data array
// We are assuming $recipe_children_data[$key] already exists from the original function.
if ( isset( $recipe_children_data[ $key ] ) ) {
$recipe_children_data[ $key ]['custom_field_value'] = sanitize_text_field( $child_meta['_my_custom_action_setting'][0] );
} else {
// If for some reason it doesn't exist, create it.
$recipe_children_data[ $key ] = array(
'custom_field_value' => sanitize_text_field( $child_meta['_my_custom_action_setting'][0] ),
);
}
}
}
}
return $recipe_children_data;
}, 10, 2 ); // Priority 10, accepts 2 arguments
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/class-automator-functions.php:1626
if ( AUTOMATOR_POST_TYPE_ACTION === $type ) {
$recipe_children_data[ $key ]['tokens'] = $this->tokens->get_action_tokens_renderable( $child_meta_single, absint( $child['ID'] ), $recipe_id );
}
}
}
return apply_filters(
'automator_recipe_children_data',
$recipe_children_data,
array(
'type' => $type,
'recipe_id' => $recipe_id,
'recipe_children' => $recipe_children,
)