Action
Since 7.0
uncanny-automator
automator_recipe_{$type}_update_before
Fires before a specific recipe item type is updated. Fires before a specific Automator recipe item type is updated via the API.
add_action( 'automator_recipe_{$type}_update_before', $callback, 10, 1 );
Description
This hook fires just before a specific recipe item type is updated via the API, providing access to the `$request` object. Developers can use this to perform pre-update validations or modifications. Be aware that the item's data may not yet reflect the full update at this stage.
Usage
add_action( 'automator_recipe_{$type}_update_before', 'your_function_name', 10, 1 );
Parameters
-
$request(WP_REST_Request) - The REST request object.
Examples
/**
* Example of using the 'automator_recipe_action_update_before' hook.
*
* This function demonstrates how to intercept an action item update
* before it's fully processed. It checks if a specific meta key is being updated
* and logs a message if it is.
*/
add_action( 'automator_recipe_action_update_before', function ( WP_REST_Request $request ) {
// Get the data being updated from the request.
$update_data = $request->get_params();
// Check if we're updating a specific meta field, for example, 'my_custom_setting'.
if ( isset( $update_data['meta']['my_custom_setting'] ) ) {
// Get the recipe ID from the request.
$recipe_id = $request->get_param( 'recipe_id' );
// Log a message indicating that a specific setting is being updated for a recipe.
error_log( sprintf(
'Automator: User is attempting to update "my_custom_setting" for recipe ID %d.',
$recipe_id
) );
// You could also perform validation or modify $update_data here before it's saved.
// For instance, if you wanted to prevent the update:
// $request->set_param( 'meta', [ 'my_custom_setting' => 'original_value' ] );
}
// Note: This is an action hook, so no return value is expected.
}, 10, 1 );
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/api/transports/restful/recipe/items/traits/hooks/trait-hook-update-operations.php:40
protected function dispatch_update_before_hooks(): void {
$type = $this->get_item_type();
/**
* Fires before a recipe item is updated.
*
* @since 7.0
*
* @param WP_REST_Request $request The REST request object.
* @param string $type The item type.
*/
do_action( 'automator_recipe_item_update_before', $this->get_request(), $type );
/**
* Fires before a specific recipe item type is updated.
*
* @since 7.0
*
* @param WP_REST_Request $request The REST request object.
*/
do_action( "automator_recipe_{$type}_update_before", $this->get_request() );
}