Action Since 5.7 uncanny-automator

automator_recipe_option_updated

Fires when a recipe option is updated. Fires after any option within an Automator recipe is successfully updated, providing access to the updated values and recipe context.

add_action( 'automator_recipe_option_updated', $callback, 10, 3 );

Description

Fires after a specific recipe option is successfully updated via the REST API. This hook provides access to the updated item, meta key and value, the value before the update, the recipe ID, and the REST API response data. Developers can use this to react to option changes, clear caches, or perform other post-update actions for a specific recipe.


Usage

add_action( 'automator_recipe_option_updated', 'your_function_name', 10, 3 );

Parameters

$item (mixed)
- **$meta_key** `mixed`
$meta_value (mixed)
- **$before_update_value** `mixed`
$recipe_id (mixed)
- **$return** `mixed`

Examples

<?php
/**
 * Example function to log changes to recipe options.
 *
 * This function hooks into the 'automator_recipe_option_updated' action and logs
 * details about the updated option, including the recipe ID, the key being updated,
 * the new value, and the value before the update. This can be useful for debugging
 * or auditing changes to recipe configurations.
 *
 * @param mixed $item The item related to the update (e.g., trigger, action).
 * @param string $meta_key The meta key of the option being updated.
 * @param mixed $meta_value The new value of the meta key.
 * @param mixed $before_update_value The value of the meta key before the update.
 * @param int $recipe_id The ID of the recipe being updated.
 * @param array $return The return data from the REST API response.
 */
function my_automator_log_recipe_option_update( $item, $meta_key, $meta_value, $before_update_value, $recipe_id, $return ) {
    // Ensure we are in an environment where logging is appropriate, e.g., not during AJAX save
    // or specific admin pages if not desired. For this example, we'll always log.

    $log_message = sprintf(
        'Recipe Option Updated - Recipe ID: %d, Meta Key: %s, New Value: %s, Old Value: %s',
        $recipe_id,
        $meta_key,
        is_array( $meta_value ) ? json_encode( $meta_value ) : (string) $meta_value,
        is_array( $before_update_value ) ? json_encode( $before_update_value ) : (string) $before_update_value
    );

    // Use WordPress's built-in error log or a custom logging function.
    // For simplicity, we'll use error_log here.
    error_log( $log_message );

    // Optionally, you could also add more specific logic here, like:
    // - If a specific meta_key is updated, trigger another action.
    // - If a value changes to something critical, send a notification.

    // Example: If a trigger's 'run_count' is reset, perhaps notify an admin.
    if ( 'run_count' === $meta_key && $meta_value === 0 && $before_update_value > 0 ) {
        error_log( sprintf( 'Recipe %d trigger run count has been reset.', $recipe_id ) );
        // You could also call wp_mail() or another notification system here.
    }
}
add_action( 'automator_recipe_option_updated', 'my_automator_log_recipe_option_update', 10, 6 );

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/automator-post-types/uo-recipe/class-recipe-post-rest-api.php:755

$return['_recipe']        = Automator()->get_recipe_object( $recipe_id );

				/**
				 * Fires when a recipe option is updated.
				 *
				 * @since 5.7
				 */
				do_action( 'automator_recipe_option_updated', $item, $meta_key, $meta_value, $before_update_value, $recipe_id, $return );

				$return = apply_filters( 'automator_option_updated', $return, $item, $meta_key, $meta_value );

				return new WP_REST_Response( $return, 200 );
			}
			$return['message'] = 'You are trying to update trigger meta for a trigger that does not exist. Please reload the page and trying again.';
			$return['success'] = false;


Internal Usage

Found in src/core/lib/recipe-parts/class-recipe-manifest.php:105:

add_action( 'automator_recipe_option_updated', array( $this, 'on_recipe_option_updated' ) );

Found in src/core/admin/class-import-recipe.php:89:

add_action( 'automator_recipe_option_updated', array( $this, 'clear_imported_recipe_warning' ), 10, 6 );

Found in uncanny-automator-pro/src/core/webhook/class-webhook-index.php:67:

add_action( 'automator_recipe_option_updated', array( $this, 'rebuild' ) );
Scroll to Top