Action
uncanny-automator
automator_recipe_copy_action_conditions
Fires after a recipe's actions and conditions are copied to a new recipe.
add_action( 'automator_recipe_copy_action_conditions', $callback, 10, 3 );
Description
Fires after an action's conditions have been copied and modified when duplicating a recipe. Developers can use this hook to further process or alter the copied conditions before they are saved to the new recipe's metadata. The hook provides access to the conditions, the original recipe ID, and the new recipe ID.
Usage
add_action( 'automator_recipe_copy_action_conditions', 'your_function_name', 10, 3 );
Parameters
-
$conditions(mixed) - This parameter contains the action conditions for the recipe being copied.
-
$post_id(mixed) - This parameter contains the conditions associated with the action being copied.
-
$new_post_id(mixed) - The `$post_id` parameter contains the ID of the original recipe being copied.
Examples
<?php
/**
* Example of how to hook into the 'automator_recipe_copy_action_conditions' action.
* This function will be triggered when a recipe's action conditions are copied.
* It can be used to modify or log the conditions being copied.
*
* @param mixed $conditions The action conditions being copied. The structure depends on the specific condition.
* @param int $post_id The ID of the original recipe post.
* @param int $new_post_id The ID of the newly created recipe post.
*/
add_action( 'automator_recipe_copy_action_conditions', function( $conditions, $post_id, $new_post_id ) {
// Log the action condition copying for debugging or auditing purposes.
error_log( sprintf(
'Automator: Action conditions copied for recipe %1$d to new recipe %2$d. Conditions: %3$s',
$post_id,
$new_post_id,
print_r( $conditions, true ) // Use print_r for a readable representation of the conditions array.
) );
// You could also potentially modify the conditions here, though the hook
// 'automator_recipe_copy_action_conditions_meta' before the action is
// generally the better place for direct modification.
// For instance, if you wanted to append a note to a specific type of condition:
/*
if ( is_array( $conditions ) ) {
foreach ( $conditions as $key => $condition ) {
if ( isset( $condition['type'] ) && 'specific_condition_type' === $condition['type'] ) {
$conditions[ $key ]['notes'] = 'Copied from recipe ' . $post_id;
}
}
}
*/
}, 10, 3 );
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:419
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 );
}