Filter uncanny-automator

automator_recipe_process_complete_status

Filters the completion status of an Automator recipe process after it has finished running.

add_filter( 'automator_recipe_process_complete_status', $callback, 10, 2 );

Description

Filters the completion status of a recipe process before it's marked as complete in the database. Developers can modify the $completed status based on the recipe's arguments. This hook is crucial for custom logic that might override the default completion status.


Usage

add_filter( 'automator_recipe_process_complete_status', 'your_function_name', 10, 2 );

Parameters

$completed (mixed)
This parameter indicates whether the recipe execution was completed successfully.
$args (mixed)
This parameter represents the completion status of the recipe process.

Return Value

The filtered value.


Examples

/**
 * Example of using the automator_recipe_process_complete_status filter.
 * This function demonstrates how to modify the completion status of a recipe process.
 * In this example, we'll check if the completion status indicates an error
 * and if so, append a custom note to the completion status.
 *
 * @param mixed $completed The current completion status of the recipe process.
 * @param array $args      An array of arguments passed to the process.
 *
 * @return mixed The modified completion status.
 */
function my_custom_automator_recipe_completion_status( $completed, $args ) {
	// Assuming $completed can be a boolean or a string indicating an error.
	// Let's say 'error' is a string that signifies a failure.
	if ( is_string( $completed ) && strtolower( $completed ) === 'error' ) {
		// Check if there's a user ID and recipe ID in the arguments to make the note more specific.
		$user_id   = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : 0;
		$recipe_id = isset( $args['recipe_id'] ) ? absint( $args['recipe_id'] ) : 0;

		// Append a custom note to the error status.
		$completed .= " - Custom Note: User ID {$user_id} encountered an error with Recipe ID {$recipe_id}.";
	}

	// Return the potentially modified completion status.
	return $completed;
}
add_filter( 'automator_recipe_process_complete_status', 'my_custom_automator_recipe_completion_status', 10, 2 );

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/lib/process/class-automator-recipe-process-complete.php:948

return null;
			}

			$recipe_log_id = Automator()->db->recipe->add( $user_id, $recipe_id, $completed, $run_number );

		} else {

			$completed = apply_filters( 'automator_recipe_process_complete_status', $completed, $args );

			Automator()->db->recipe->mark_complete( $recipe_log_id, $completed );

		}

		// Check all actions for errors that should update the recipe status.
		$actionable_error = self::find_actionable_error( $recipe_log_id );


Internal Usage

Found in src/integrations/linkedin/helpers/linkedin-scheduled-posts-manager.php:98:

add_filter( 'automator_recipe_process_complete_status', array( $this, 'filter_recipe_status' ), 10, 2 );

Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:65:

add_filter( 'automator_recipe_process_complete_status', array( $this, 'intercept_recipe_process_complete_status' ), 10, 2 );
Scroll to Top