Action
uncanny-automator
automator_recipe_before_options_update
Fires before Automator recipe options are updated, providing access to the incoming request data.
add_action( 'automator_recipe_before_options_update', $callback, 10, 1 );
Description
Fires just before a recipe's options are updated via the REST API. Allows developers to intercept and modify recipe option data or perform custom validation before saving. Useful for ensuring data integrity or implementing custom option logic. The `$request` object contains all submitted data.
Usage
add_action( 'automator_recipe_before_options_update', 'your_function_name', 10, 1 );
Parameters
-
$request(mixed) - The `$request` parameter contains the data sent in the REST API request for updating recipe options.
Examples
// Example: Prevent saving a recipe if a specific email integration is configured with an invalid sender address.
add_action( 'automator_recipe_before_options_update', function( $request ) {
// Check if we are updating recipe options and if the request contains relevant data.
if ( ! $request->has_param( 'itemId' ) || ! $request->has_param( 'optionCode' ) || ! $request->has_param( 'optionValue' ) ) {
return; // Not relevant to this specific update scenario.
}
$recipe_id = absint( $request->get_param( 'recipe_id' ) );
$option_code = sanitize_text_field( $request->get_param( 'optionCode' ) );
$option_value = $request->get_param( 'optionValue' );
// Target a specific integration, for example, the 'EMAIL' integration.
// We are looking for an option related to sender email within this integration.
if ( 'EMAIL' === $option_code && is_array( $option_value ) && isset( $option_value['from_email'] ) ) {
$sender_email = sanitize_email( $option_value['from_email'] );
// Basic check for a valid email format. WordPress core's sanitize_email() handles a lot,
// but we might have custom validation needs.
if ( ! filter_var( $sender_email, FILTER_VALIDATE_EMAIL ) ) {
// In a real scenario, you'd likely want to return a WP_Error
// or set an error message on the request object to be displayed to the user.
// For this example, we'll just log a warning.
error_log( "Automator: Invalid sender email address detected for recipe ID {$recipe_id}: {$sender_email}" );
// If you were to prevent saving, you would need to interact with
// the REST API response mechanism, which is more complex within a hook like this.
// This example focuses on the action hook itself.
}
}
}, 10, 1 ); // Priority 10, accepts 1 argument ($request).
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:661
*
* @param $request
*
* @return WP_REST_Response
*/
public function update( WP_REST_Request $request ) {
do_action( 'automator_recipe_before_options_update', $request );
if ( $request->has_param( 'itemId' ) && is_numeric( $request->get_param( 'itemId' ) ) && $request->has_param( 'optionCode' ) && $request->has_param( 'optionValue' ) ) {
$item_id = absint( $request->get_param( 'itemId' ) );
$recipe_id = absint( $request->get_param( 'recipe_id' ) );
$meta_key = (string) Automator()->utilities->automator_sanitize( $request->get_param( 'optionCode' ) );
$meta_value = $request->get_param( 'optionValue' );
$meta_value = Automator()->utilities->automator_sanitize( $meta_value, 'mixed', $meta_key, $request->get_param( 'options' ) );
Internal Usage
Found in src/integrations/emails/helpers/emails-helpers.php:15:
# Disable recipe builder validation: add_action( 'automator_recipe_before_options_update', array( $this, 'file_attachments_validate' ) );