Filter uncanny-automator

automator_auto_complete_trigger

Should the trigger be autocompleted and continue running trigger? Filters whether a trigger should be autocompleted and continue running.

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

Description

Fires after trigger arguments are prepared. Developers can use this filter to control whether a trigger should automatically complete and continue running. Return `true` to allow auto-completion; return `false` to prevent it. This is useful for custom trigger logic or integrations that require manual completion.


Usage

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

Parameters

$this (mixed)
- **$pass_args** `mixed`
$args (mixed)

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Conditionally skip auto-completion for a specific trigger based on user role.
 *
 * This filter allows developers to control whether a trigger should be "auto-completed"
 * and proceed with the rest of the automation, or if it should be halted.
 * In this example, we'll prevent auto-completion if the current user is an 'editor'
 * to simulate a scenario where manual review might be needed for certain triggers.
 *
 * The original value of the filter is determined by $this->do_trigger_autocomplete()
 * which is typically a boolean indicating if auto-completion is enabled by default.
 *
 * @param bool   $complete_trigger The current value of whether to auto-complete the trigger.
 * @param array  $pass_args        Arguments prepared for the trigger entry.
 * @param array  $args             Original arguments passed to the trigger.
 * @return bool                    Returns true to auto-complete, false to stop.
 */
add_filter( 'automator_auto_complete_trigger', function( $complete_trigger, $pass_args, $args ) {

	// Check if the current user is logged in and has the 'editor' role.
	if ( is_user_logged_in() ) {
		$current_user = wp_get_current_user();
		if ( in_array( 'editor', (array) $current_user->roles ) ) {
			// If the user is an editor, we want to prevent auto-completion for this trigger.
			// This might be useful for triggers that require manual verification by an editor.
			return false;
		}
	}

	// For all other users or if the default auto-completion is true,
	// return the original value or explicitly true.
	return $complete_trigger;

}, 10, 3 );

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/recipe-parts/triggers/trait-triggers.php:216

protected function process_trigger( $args ) {

		// Enqueuing do_actions
		$this->enqueue_token_action_and_filter();
		/**
		 * Allow developers to manipulate $pass_args with custom arguments. For example, ignore_post_id.
		 */
		$pass_args = $this->prepare_entry_args( $args );

		/**
		 * Should the trigger be autocompleted and continue running trigger?
		 */
		$complete_trigger = apply_filters( 'automator_auto_complete_trigger', $this->do_trigger_autocomplete(), $pass_args, $args );

		/**
		 * Attempt to add trigger entry and autocomplete it if autocomplete is set to true.
		 */
		do_action( 'automator_before_trigger_run', $args, $pass_args );

		if ( true === $this->do_trigger_autocomplete() ) {
			Automator()->process->user->maybe_add_trigger_entry( $pass_args, $complete_trigger );

			do_action( 'automator_after_trigger_run', $args, $pass_args );

			return;
		}
		$entry_args = Automator()->process->user->maybe_add_trigger_entry( $pass_args, $complete_trigger, $args );
		/**
		 * If trigger is not autocompleted, an array is returned which should be handled manually.
		 */
		if ( empty( $entry_args ) ) {
			return;
		}

		foreach ( $entry_args as $result ) {
			if ( true === $result['result'] ) {
				$result_args = $result['args'];
				/**
				 * @var array $args | All the arguments passed to this function
				 * @var array $pass_args | All the arguments passed to run mark a trigger complete
				 * @var array $result_args | All the arguments returned after marking trigger complete
				 */
				$do_action = array(
					'trigger_entry' => $result_args,
					'entry_args'    => $pass_args,
					'trigger_args'  => $args,
				);

				do_action( 'automator_before_trigger_completed', $do_action, $this );

				$process_further = apply_filters( 'automator_trigger_should_complete', true, $do_action, $this );

				if ( $process_further ) {

					// @since 5.10 - Added a way for a trigger loopable tokens to be processed at this point.
					do_action( 'automator_loopable_token_hydrate', $result_args, func_get_args() );

					Automator()->process->user->maybe_trigger_complete( $result_args );
				}

				do_action_deprecated(
					'automator_after_trigger_completed',
					array(
						$do_action,
						$this,
					),
					'4.1',
					'automator_after_maybe_trigger_complete'
				);
				do_action( 'automator_after_maybe_trigger_complete', $do_action, $this );
			}
		}

		do_action( 'automator_after_trigger_run', $args, $pass_args );
	}


Internal Usage

Found in uncanny-automator-pro/src/integrations/gamipress/triggers/gp-achievements-revoked.php:13:

add_filter( 'automator_auto_complete_trigger', '__return_false' );
Scroll to Top