Filter uncanny-automator

automator_action_complete_action_skipped

Filters if an Automator Action should be skipped.

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

Description

Filters the action array after an action has been determined to be skipped during recipe execution. Developers can modify the action array or the arguments passed to the action. This filter runs within the core recipe process, allowing for late-stage adjustments to skipped actions before they are logged as skipped.


Usage

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

Parameters

$action (mixed)
This parameter contains the action object being processed by the Automator.
$args (mixed)
This parameter contains the action object, which may have been modified by previous filters.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the automator_action_complete_action_skipped filter hook.
 *
 * This filter allows you to programmatically determine if an action should be skipped
 * after it has been processed but before it's considered complete.
 *
 * In this example, we'll skip the action if a specific meta key is present on the
 * user associated with the recipe.
 */
add_filter(
	'automator_action_complete_action_skipped',
	function ( $action, $args ) {
		// Check if the user object is available in the arguments.
		if ( isset( $args['user'] ) && $args['user'] instanceof WP_User ) {
			$user_id = $args['user']->ID;

			// Check if a specific meta key exists for this user.
			// Replace 'skip_automator_actions' with your actual meta key.
			if ( get_user_meta( $user_id, 'skip_automator_actions', true ) ) {
				// If the meta key exists and has a truthy value, skip the action.
				// You might want to add a custom error message or log here if needed.
				Automator()->wp_error->add_error(
					'custom_skip_logic',
					sprintf(
						'Action "%s" for user ID %d was skipped due to custom logic.',
						$action['ID'], // Assuming 'ID' is a key in $action
						$user_id
					)
				);
				return false; // Returning false signifies that the action should be skipped.
			}
		}

		// If the custom skip condition is not met, return the original $action.
		// This is crucial for the filter to not alter the intended behavior.
		return $action;
	},
	10, // Priority
	2   // Number of accepted arguments
);

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

$action = apply_filters( 'automator_before_action_executed', $action, $args );

			if ( isset( $action['process_further'] ) ) {

				do_action( 'automator_action_been_process_further', $action );

				if ( false === $action['process_further'] ) {
					$action = apply_filters( 'automator_action_complete_action_skipped', $action, $args );
					Automator()->wp_error->add_error( 'complete_action', 'Action was skipped by uap_before_action_executed filter' );

					return false;
				}

				unset( $action['process_further'] );


Scroll to Top