Action uncanny-automator

automator_pro_run_now_recipe

Fires when a recipe is manually triggered to run immediately.

add_action( 'automator_pro_run_now_recipe', $callback, 10, 1 );

Description

Fires when a recipe is manually triggered to run. Developers can use this hook to add custom logic, such as logging the event, performing pre-execution checks, or modifying the recipe ID before it's processed. This hook fires within the Uncanny Automator Pro REST API endpoint for running recipes immediately.


Usage

add_action( 'automator_pro_run_now_recipe', 'your_function_name', 10, 1 );

Parameters

$recipe_id (mixed)
This parameter contains the unique identifier of the recipe to be executed.

Examples

add_action( 'automator_pro_run_now_recipe', 'my_custom_automator_run_now_logic', 10, 1 );

/**
 * Example function to hook into the 'automator_pro_run_now_recipe' action.
 * This function demonstrates how to perform custom actions when a recipe is triggered to run now.
 *
 * @param int $recipe_id The ID of the recipe that is being run now.
 */
function my_custom_automator_run_now_logic( $recipe_id ) {
	// Ensure the recipe ID is a valid integer before proceeding.
	if ( ! is_numeric( $recipe_id ) || absint( $recipe_id ) !== intval( $recipe_id ) ) {
		error_log( "Invalid recipe ID received for automator_pro_run_now_recipe hook: " . print_r( $recipe_id, true ) );
		return;
	}

	// Convert the recipe ID to an integer.
	$recipe_id = absint( $recipe_id );

	// Example: Log that a specific recipe is about to run.
	// In a real-world scenario, you might perform custom logging,
	// trigger an external service, or modify data before the recipe execution.
	error_log( "Automator Pro recipe with ID {$recipe_id} is being triggered to run now." );

	// You could potentially add further logic here, such as:
	// - Checking specific conditions before allowing the recipe to proceed.
	// - Modifying parameters that will be passed to the recipe's actions.
	// - Sending a notification to an administrator.

	// For demonstration purposes, we'll just log the event.
}

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/services/recipe/services/class-recipe-execution-service.php:93
uncanny-automator-pro/src/integrations/run-now/rest/rest.php:56

public function execute_recipe( int $recipe_id ) {

		// Validate recipe exists.
		$recipe_post = get_post( $recipe_id );
		if ( ! $recipe_post || AUTOMATOR_POST_TYPE_RECIPE !== $recipe_post->post_type ) {
			return new WP_Error( 'recipe_not_found', 'Recipe not found or invalid type.' );
		}

		// Check for manual trigger.
		$recipe_id_vo = new Recipe_Id( $recipe_id );

		if ( ! $this->trigger_store->recipe_has_manual_trigger( $recipe_id_vo ) ) {
			return new WP_Error(
				'no_manual_trigger',
				'Recipe lacks a manual trigger. Add one with save_trigger using trigger_code "RECIPE_MANUAL_TRIGGER_ANON".'
			);
		}

		do_action( 'automator_pro_run_now_recipe', $recipe_id );

		return array(
			'recipe_id'     => $recipe_id,
			'recipe_title'  => get_the_title( $recipe_id ),
			'recipe_status' => 'initiated',
		);
	}

Internal Usage

Found in uncanny-automator-pro/src/integrations/loopable-rss/triggers/loopable-rss-trigger.php:62:

$this->add_action( 'automator_pro_run_now_recipe', 10, 1 );

Found in uncanny-automator-pro/src/integrations/loopable-json/triggers/loopable-json-trigger.php:62:

$this->add_action( 'automator_pro_run_now_recipe', 10, 1 );

Found in uncanny-automator-pro/src/integrations/loopable-csv/triggers/loopable-csv-trigger.php:62:

$this->add_action( 'automator_pro_run_now_recipe', 10, 1 );

Found in uncanny-automator-pro/src/integrations/loopable-xml/triggers/loopable-xml-trigger.php:62:

$this->add_action( 'automator_pro_run_now_recipe', 10, 1 );

Found in uncanny-automator-pro/src/integrations/run-now/triggers/recipe-manual-trigger-anon.php:28:

$this->add_action( 'automator_pro_run_now_recipe', 10, 1 );
Scroll to Top