Action Since 5.7 uncanny-automator

automator_recipe_all_or_any_trigger_option_updated

Fires when a recipe all or any trigger option is updated. Fires when a recipe's all or any trigger option is updated, passing the recipe ID and new setting.

add_action( 'automator_recipe_all_or_any_trigger_option_updated', $callback, 10, 2 );

Description

Fired after a recipe's "all or any" trigger option is updated via the REST API. Developers can access the updated recipe ID, the new "all or any" value, and the response data to perform follow-up actions or log changes. This hook ensures post-update logic executes reliably.


Usage

add_action( 'automator_recipe_all_or_any_trigger_option_updated', 'your_function_name', 10, 2 );

Parameters

$recipe_id (mixed)
- **$all_or_any** `mixed`
$return (mixed)

Examples

/**
 * Example function to handle the automator_recipe_all_or_any_trigger_option_updated hook.
 * This function logs the updated recipe ID and the new all_or_any setting.
 *
 * @param int   $recipe_id    The ID of the updated recipe.
 * @param string $all_or_any The new 'all or any' trigger option ('all' or 'any').
 * @param array  $return     The response array from the REST API.
 */
function my_automator_log_all_or_any_update( $recipe_id, $all_or_any, $return ) {
	// Check if the update was successful based on the $return array.
	if ( isset( $return['success'] ) && true === $return['success'] ) {
		// Log the update to the WordPress debug log for auditing.
		error_log(
			sprintf(
				'Automator Recipe %d: "All or Any" trigger option updated to "%s". Response data: %s',
				$recipe_id,
				$all_or_any,
				wp_json_encode( $return )
			)
		);
	} else {
		// Log a warning if the update seemed to fail.
		error_log(
			sprintf(
				'Automator Recipe %d: Failed to update "All or Any" trigger option. Response data: %s',
				$recipe_id,
				wp_json_encode( $return )
			),
			E_USER_WARNING
		);
	}
}

// Add the action hook with the correct number of accepted arguments.
add_action( 'automator_recipe_all_or_any_trigger_option_updated', 'my_automator_log_all_or_any_update', 10, 3 );

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:1628

public function set_any_or_all_trigger_option( WP_REST_Request $request ) {

		// Make sure we have a recipe ID and the newOrder
		if ( $request->has_param( 'recipeID' ) ) {

			$recipe_id  = absint( $request->get_param( 'recipeID' ) );
			$all_or_any = $request->get_param( 'allOrAnyOption' );

			update_post_meta( $recipe_id, 'run_when_any_trigger_complete', $all_or_any );

			$return['message'] = 'Updated!';
			$return['success'] = true;
			$return['action']  = 'set_any_trigger_option';

			Automator()->cache->clear_automator_recipe_part_cache( $recipe_id );

			$return['recipes_object'] = Automator()->get_recipes_data( true, $recipe_id );

			/**
			 * Fires when a recipe all or any trigger option is updated.
			 *
			 * @since 5.7
			 */
			do_action( 'automator_recipe_all_or_any_trigger_option_updated', $recipe_id, $all_or_any, $return );

			return new WP_REST_Response( $return, 200 );
		}

		$return['message'] = 'Failed to update';
		$return['success'] = false;
		$return['action']  = 'show_error';

		return new WP_REST_Response( $return, 200 );
	}

Scroll to Top