Filter
uncanny-automator
automator_recipe_copy_action_conditions_meta
Filters the conditions metadata when a recipe action is copied.
add_filter( 'automator_recipe_copy_action_conditions_meta', $callback, 10, 3 );
Description
Filters the conditions meta data when copying a recipe action. Allows modification of action conditions before they are saved to the new recipe. Use this to customize or manipulate conditions during recipe duplication.
Usage
add_filter( 'automator_recipe_copy_action_conditions_meta', 'your_function_name', 10, 3 );
Parameters
-
$conditions(mixed) - This parameter contains the conditions for an action that are being copied.
-
$post_id(mixed) - This parameter contains the action conditions that are being copied for the recipe.
-
$new_post_id(mixed) - This parameter contains the ID of the original recipe item that is being copied.
Return Value
The filtered value.
Examples
// Example: Add a specific condition to a duplicated recipe's actions
add_filter(
'automator_recipe_copy_action_conditions_meta',
function ( $conditions, $post_id, $new_post_id ) {
// Check if we are copying a specific recipe (replace with actual recipe ID if known)
if ( $post_id === 123 ) {
// Assume $conditions is an array of condition arrays.
// Let's add a new condition if it doesn't exist.
$new_condition = array(
'id' => 'new_custom_condition',
'label' => 'Custom Condition Added',
'value' => 'some_value',
'type' => 'custom',
'is_active' => true,
'operator' => '==',
'order' => count( $conditions ) + 1,
);
// Avoid adding duplicates if the condition already exists for some reason
$condition_exists = false;
foreach ( $conditions as $condition ) {
if ( isset( $condition['id'] ) && $condition['id'] === 'new_custom_condition' ) {
$condition_exists = true;
break;
}
}
if ( ! $condition_exists ) {
$conditions[] = $new_condition;
}
}
// Always return the modified conditions array
return $conditions;
},
10, // Priority
3 // Number of arguments accepted
);
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/admin/class-copy-recipe-parts.php:415
public function copy_action_conditions( $post_id = 0, $new_post_id = 0, $conditions = '' ) {
if ( empty( $conditions ) ) {
if ( ! empty( $this->action_conditions ) && isset( $this->action_conditions[ $new_post_id ] ) ) {
$conditions = $this->action_conditions[ $new_post_id ];
unset( $this->action_conditions[ $new_post_id ] );
}
}
if ( empty( $conditions ) ) {
return;
}
$conditions = $this->modify_conditions( $conditions, $post_id, $new_post_id );
$conditions = apply_filters( 'automator_recipe_copy_action_conditions_meta', $conditions, $post_id, $new_post_id );
update_post_meta( $new_post_id, self::ACTION_CONDITIONS_META_KEY, $conditions );
do_action( 'automator_recipe_copy_action_conditions', $conditions, $post_id, $new_post_id );
}