Filter uncanny-automator-pro

automator_pro_before_async_action_executed

Filters the action object before it's asynchronously executed, allowing modification or cancellation.

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

Description

Fires just before an asynchronous action is executed. Developers can modify the `$action` array to alter the action's data, prevent it from processing further by returning `false` in a `process_further` key, or adjust tokens before execution.


Usage

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

Parameters

$action (mixed)
This parameter contains the data associated with the asynchronous action that is about to be executed.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the automator_pro_before_async_action_executed filter.
 * This example conditionally skips an action if a specific meta key is set on the user.
 *
 * @param array $action The action data array.
 * @return array The modified action data array, or the original if no changes are made.
 */
function my_automator_skip_action_based_on_user_meta( $action ) {
	// Ensure we have the necessary data to proceed.
	if ( ! is_array( $action ) || ! isset( $action['user_id'] ) ) {
		return $action;
	}

	$user_id = $action['user_id'];
	$skip_action_meta_key = 'automator_skip_this_action';

	// Check if the user has the specific meta key set.
	$user_meta_value = get_user_meta( $user_id, $skip_action_meta_key, true );

	if ( ! empty( $user_meta_value ) && 'yes' === $user_meta_value ) {
		// Add a flag to indicate that the action should be skipped.
		$action['process_further'] = false;
		automator_log( "Skipping async action for user ID {$user_id} because meta key '{$skip_action_meta_key}' is set to 'yes'." );
	}

	return $action;
}
add_filter( 'automator_pro_before_async_action_executed', 'my_automator_skip_action_based_on_user_meta', 10, 1 );

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

uncanny-automator-pro/src/core/classes/async-actions.php:609

private function run_execution( $action ) {

		if ( ! is_array( $action ) || empty( $action['action_data'] ) || empty( $action['recipe_id'] ) ) {
			automator_log( 'Async action skipped — action data is missing or invalid.' );
			return;
		}

		$action = apply_filters( 'automator_pro_before_async_action_executed', $action );

		if ( isset( $action['process_further'] ) && false === $action['process_further'] ) {

			automator_log( 'Action was skipped by automator_pro_before_async_action_executed filter.' );

			return;
		}

		$action_id   = $action['action_data']['ID'];
		$recipe_id   = $action['recipe_id'];
		$action_post = get_post( $action_id );
		$recipe_post = get_post( $recipe_id );

		// If action or recipe no longer exists
		if ( empty( $action_post ) || empty( $recipe_post ) || ! $action_post instanceof WP_Post || ! $recipe_post instanceof WP_Post ) {
			$this->recipe_or_action_no_longer_exists( $action );

			return;
		}

		// If action or recipe is set to draft
		if ( 'publish' !== $action_post->post_status || 'publish' !== $recipe_post->post_status ) {
			$this->recipe_or_action_is_not_live( $action );

			return;
		}

		$action_code = $action['action_data']['meta']['code'];

		$action_execution_function = Automator()->get->action_execution_function_from_action_code( $action_code );

		$action['action_data']['async']['status']       = 'completed';
		$action['action_data']['async']['completed_at'] = current_time( 'timestamp' ); //phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested

		if ( isset( $action['process_further'] ) ) {
			unset( $action['process_further'] );
		}

		if ( empty( $action_execution_function ) ) {
			$this->missing_execution_function( $action );
			return;
		}

		try {

			call_user_func_array( $action_execution_function, $action );

			do_action( 'automator_pro_async_action_after_run_execution', $action );
		} catch ( Error $e ) {
			$this->complete_with_error( $action, $e->getMessage() );
		} catch ( Exception $e ) {
			$this->complete_with_error( $action, $e->getMessage() );
		}
	}

Internal Usage

Found in src/core/deprecated/legacy-token-parser.php:41:

add_filter( 'automator_pro_before_async_action_executed', array( $this, 'attach_trigger_tokens_hook' ), 10, 1 );

Found in src/core/lib/utilities/class-automator-input-parser.php:92:

add_filter( 'automator_pro_before_async_action_executed', array( $this, 'attach_trigger_tokens_hook' ), 10, 1 );

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

add_filter( 'automator_pro_before_async_action_executed', array( $this, 'maybe_skip_action' ), 10, 1 );
Scroll to Top