Filter uncanny-automator

automator_option_updated

Filters the updated option data before it's saved, allowing modifications to the item, key, or value.

add_filter( 'automator_option_updated', $callback, 10, 4 );

Description

Fires after a recipe option has been successfully updated. Developers can use this filter to modify the return value or perform additional actions based on the updated option and its meta data. It's applied after the option is saved and before the REST API response is sent.


Usage

add_filter( 'automator_option_updated', 'your_function_name', 10, 4 );

Parameters

$return (mixed)
This parameter contains the value returned by the filter, which can be used to modify the behavior of the `automator_option_updated` filter.
$item (mixed)
This parameter represents the value that will be returned by the filter, which can be modified by the hooked function.
$meta_key (mixed)
This parameter contains the item related to the option being updated, such as the recipe or automation it belongs to.
$meta_value (mixed)
This parameter contains the meta key of the option being updated.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into the 'automator_option_updated' filter.
 *
 * This function demonstrates how to intercept an option update for a recipe
 * and potentially modify the return value or perform additional actions.
 * In this example, we'll check if a specific meta key is being updated and
 * log a message if it is, then return the original value.
 *
 * @param mixed $return     The original return value from the filter.
 * @param mixed $item       The item being updated (likely an array or object representing the recipe part).
 * @param mixed $meta_key   The meta key that was updated.
 * @param mixed $meta_value The new meta value.
 * @return mixed The modified or original return value.
 */
add_filter( 'automator_option_updated', function( $return, $item, $meta_key, $meta_value ) {

    // Check if we are interested in a specific meta key, for example, a trigger configuration.
    if ( 'your_trigger_meta_key' === $meta_key ) {

        // Log that a specific trigger meta was updated for debugging or auditing.
        // In a real scenario, you might want to use WP_Error or more sophisticated logging.
        error_log( sprintf(
            'Automator: Trigger meta "%s" updated for item: %s. New value: %s',
            $meta_key,
            is_array( $item ) ? implode( ',', $item ) : ( is_object( $item ) ? $item->ID : $item ),
            print_r( $meta_value, true )
        ) );

        // You could also modify the $return value here if needed.
        // For example, to prepend a message to the success response.
        // if ( is_array( $return ) && isset( $return['message'] ) ) {
        //     $return['message'] = 'Custom message: ' . $return['message'];
        // }
    }

    // Always return the $return value, whether modified or not.
    return $return;

}, 10, 4 ); // Priority 10, accepts 4 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/automator-post-types/uo-recipe/class-recipe-post-rest-api.php:757

/**
				 * 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;
			$return['data']    = $request;
			$return['post']    = '';


Scroll to Top