Filter uncanny-automator

automator_before_action_executed

Filters the action object and arguments before an Automator action is executed, allowing for modification or cancellation.

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

Description

Fires before an action is executed within an Uncanny Automator recipe. Developers can modify the action data, arguments, or even prevent the action from running by returning `false` in the `process_further` key of the `$action` array. This hook is crucial for custom logic and conditional execution of actions.


Usage

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

Parameters

$action (mixed)
This parameter contains an array of data related to the action that is about to be executed, including the user ID, action data, recipe ID, and arguments.
$args (mixed)
This parameter contains an array representing the action being executed, including its user ID, action data, recipe ID, and arguments.

Return Value

The filtered value.


Examples

<?php

/**
 * Example function to potentially modify the action data before it's executed.
 *
 * This function demonstrates how to access and modify the $action array,
 * and also how to conditionally stop further processing by returning false
 * in the 'process_further' key.
 *
 * @param array $action  The action array, containing user_id, action_data, recipe_id, and args.
 * @param mixed $args    Additional arguments passed to the filter.
 *
 * @return array The modified or original $action array.
 */
function my_automator_modify_action_data( $action, $args ) {

	// Example: Add a custom tag to the action if a specific condition is met.
	if ( isset( $action['action_data']['trigger_type'] ) && $action['action_data']['trigger_type'] === 'form_submission' ) {
		$action['action_data']['custom_tags'][] = 'form_submitted_entry';
	}

	// Example: Conditionally prevent the action from processing further.
	// This simulates a scenario where an action might be deferred or skipped based on specific logic.
	if ( ! empty( $action['action_data']['email_address'] ) && ! filter_var( $action['action_data']['email_address'], FILTER_VALIDATE_EMAIL ) ) {
		// If the email address is invalid, we might want to skip this action.
		$action['process_further'] = false;
	}

	// Return the potentially modified action array.
	return $action;
}

// Add the filter to the 'automator_before_action_executed' hook.
// We are accepting 2 arguments: $action and $args.
add_filter( 'automator_before_action_executed', 'my_automator_modify_action_data', 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:429

$action = array(
				'user_id'     => $user_id,
				'action_data' => $action_data,
				'recipe_id'   => $recipe_id,
				'args'        => $action_args,
			);

			$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 );


Internal Usage

Found in src/core/classes/class-background-actions.php:51:

add_filter( 'automator_before_action_executed', array( $this, 'maybe_send_to_background' ), 200, 1 );

Found in uncanny-automator-pro/src/core/includes/automator-pro-recipe-process-complete.php:47:

add_filter( 'automator_before_action_executed', array( $this, 'maybe_user_actions_failed' ), 1 );

Found in uncanny-automator-pro/src/core/classes/actions-conditions.php:73:

add_filter( 'automator_before_action_executed', array( $this, 'maybe_skip_action' ), 5, 2 );

Found in uncanny-automator-pro/src/core/classes/async-actions.php:30:

add_filter( 'automator_before_action_executed', array( $this, 'maybe_postpone_action' ), 10, 2 );
Scroll to Top