Filter
uncanny-automator
automator_recipe_do_not_modify_meta_keys
Filters the meta keys that are explicitly excluded from being modified during recipe execution.
add_filter( 'automator_recipe_do_not_modify_meta_keys', $callback, 10, 2 );
Description
Filters the array of meta keys that should not be modified when copying a recipe. Developers can use this hook to prevent specific meta data from being duplicated or altered during the recipe copying process, ensuring data integrity for critical settings. This filter fires before the recipe post is copied.
Usage
add_filter( 'automator_recipe_do_not_modify_meta_keys', 'your_function_name', 10, 2 );
Parameters
-
$this(mixed) - This parameter likely holds an array or a value that determines which meta keys associated with a recipe should not be copied or modified during the recipe duplication process.
-
$recipe_id(mixed) - This parameter represents the current list of meta keys that should not be modified during the recipe copying process.
Return Value
The filtered value.
Examples
/**
* Prevent specific meta keys from being copied when duplicating a recipe.
*
* This example demonstrates how to prevent meta keys that store
* dynamically generated or sensitive information from being copied
* along with the core recipe data.
*
* @param array $meta_keys_to_exclude An array of meta keys that should not be copied.
* @param int $recipe_id The ID of the recipe being copied.
* @return array The modified array of meta keys to exclude.
*/
function my_automator_exclude_sensitive_recipe_meta( $meta_keys_to_exclude, $recipe_id ) {
// Add a meta key that stores the last execution timestamp,
// as we don't want to copy this to a new recipe.
$meta_keys_to_exclude[] = '_automator_recipe_last_run';
// Add another meta key that might store a generated API token,
// which should not be duplicated.
$meta_keys_to_exclude[] = '_automator_generated_api_token';
return $meta_keys_to_exclude;
}
add_filter( 'automator_recipe_do_not_modify_meta_keys', 'my_automator_exclude_recipe_meta', 10, 2 );
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:145
public function copy_this_recipe( $recipe_id ) {
global $wpdb;
$this->do_not_modify_meta_keys = apply_filters( 'automator_recipe_do_not_modify_meta_keys', $this->do_not_modify_meta_keys, $recipe_id );
// Copy recipe post
$new_recipe_id = $this->copy( $recipe_id );
if ( is_wp_error( $new_recipe_id ) ) {
return false;
}
// Copy triggers
$this->copy_recipe_part( $recipe_id, $new_recipe_id, AUTOMATOR_POST_TYPE_TRIGGER );
// Copy actions
$this->copy_recipe_part( $recipe_id, $new_recipe_id, AUTOMATOR_POST_TYPE_ACTION );
// Copy loops
$this->copy_recipe_loops( $recipe_id, $new_recipe_id );
// Copy closures
$this->copy_recipe_part( $recipe_id, $new_recipe_id, AUTOMATOR_POST_TYPE_CLOSURE );
// Fallback to update tokens for Anonymous recipes that is stored in recipe's post meta itself
$this->copy_recipe_metas( $recipe_id, $new_recipe_id );
// Copy recipe conditions
$this->copy_action_conditions( $recipe_id, $new_recipe_id );
$recipe_tax = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(object_id) AS total FROM $wpdb->term_relationships WHERE object_id = %d", $recipe_id ) );
if ( $recipe_tax > 0 ) {
//Clone tags and categories
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id=%d;", $new_recipe_id ) );
$wpdb->query( $wpdb->prepare( "CREATE TEMPORARY TABLE tmpCopyCats SELECT * FROM $wpdb->term_relationships WHERE object_id=%d;", $recipe_id ) );
$wpdb->query( $wpdb->prepare( 'UPDATE tmpCopyCats SET object_id=%d WHERE object_id=%d;', $new_recipe_id, $recipe_id ) );
$wpdb->query( "INSERT INTO $wpdb->term_relationships SELECT * FROM tmpCopyCats;" );
$wpdb->query( 'DROP TEMPORARY TABLE IF EXISTS tmpCopyCats;' );
}
return $new_recipe_id;
}