Filter uncanny-automator

automator_maybe_continue_recipe_process

Filters whether to continue processing a recipe step, allowing modification of the decision.

add_filter( 'automator_maybe_continue_recipe_process', $callback, 10, 1 );

Description

Allows developers to conditionally stop or continue a recipe's process. By returning `false`, the recipe execution will halt. Use this filter to implement custom logic that might prevent a recipe from proceeding based on specific conditions or data. This filter fires after a step completes and before the next step is initiated.


Usage

add_filter( 'automator_maybe_continue_recipe_process', 'your_function_name', 10, 1 );

Parameters

$process_further (mixed)
This parameter determines whether the recipe process should continue to the next step, defaulting to `true`.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'automator_maybe_continue_recipe_process' filter hook.
 * This filter allows you to conditionally stop a recipe process from continuing
 * based on specific criteria.
 *
 * @param array $process_further An array containing details about the current recipe process,
 *                               including 'trigger_log_id', 'trigger_id', and 'args'.
 *
 * @return array The modified $process_further array. If you want to stop the process,
 *               you can modify this array to signal that. For example, by setting a specific flag.
 */
add_filter( 'automator_maybe_continue_recipe_process', function( $process_further ) {

	// In a real-world scenario, you would check conditions related to the trigger or arguments.
	// For this example, let's imagine we want to stop the process if a specific user ID
	// is present in the trigger arguments, preventing it from proceeding for that user.

	$trigger_log_id = $process_further['trigger_log_id'] ?? 0;
	$trigger_id     = $process_further['trigger_id'] ?? 0;
	$args           = $process_further['args'] ?? array();

	// Let's assume our trigger arguments might contain a 'user_id' key.
	$blocked_user_id = 123; // Example of a user ID we want to block.

	if ( isset( $args['user_id'] ) && $args['user_id'] == $blocked_user_id ) {
		// Log this event if needed for debugging or auditing.
		// Automator's logging system would likely be used here in a real plugin.
		error_log( sprintf(
			'Automator: Recipe process %d (Trigger ID: %d) halted due to blocked user ID %d.',
			$trigger_log_id,
			$trigger_id,
			$blocked_user_id
		) );

		// To stop the process further, we can add a specific flag to the array.
		// The Automator core would need to be designed to interpret this flag.
		// For this example, let's imagine adding a 'stop_process' key.
		$process_further['stop_process'] = true;
	}

	// Always return the $process_further array, even if modified.
	return $process_further;

}, 10, 1 ); // Priority 10, accepts 1 argument.

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

'trigger_log_id'                => $trigger_log_id,
			'trigger_id'                    => $trigger_id,
			'args'                          => $args,
		);

		//New filter.. see usage in pro
		$process_further = apply_filters_deprecated( 'uap_maybe_continue_recipe_process', array( $process_further ), '3.0', 'automator_maybe_continue_recipe_process' );
		$process_further = apply_filters( 'automator_maybe_continue_recipe_process', $process_further );

		extract( $process_further, EXTR_OVERWRITE ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract

		// The trigger is now completed
		do_action_deprecated( 'uap_trigger_completed', array( $process_further ), '3.0', 'automator_trigger_completed' );

		do_action( 'automator_trigger_completed', $process_further );


Scroll to Top