Action uncanny-automator

automator_before_trigger_completed

Fires before a trigger is marked as completed, allowing for custom actions before finalization.

add_action( 'automator_before_trigger_completed', $callback, 10, 2 );

Description

Fires just before a trigger is marked as completed. Developers can use this hook to perform custom actions, such as saving trigger data or logging events, before the trigger's completion status is finalized. It provides access to trigger entry details, records, and hook arguments.


Usage

add_action( 'automator_before_trigger_completed', 'your_function_name', 10, 2 );

Parameters

$do_action (mixed)
This parameter contains the result of the action execution or a boolean indicating if the action was performed.
$this (mixed)
This parameter contains the value that determines whether the subsequent actions should be executed or not.

Examples

// This function intercepts the trigger completion process to log relevant data
// before further processing. It's useful for debugging or custom logging needs.
add_action( 'automator_before_trigger_completed', 'my_custom_trigger_log', 15, 2 );

function my_custom_trigger_log( $do_action_data, $trigger_object ) {
    // Ensure we have the necessary data before logging.
    if ( is_array( $do_action_data ) && isset( $do_action_data['trigger_entry'] ) && isset( $do_action_data['entry_args'] ) ) {
        $trigger_id = $do_action_data['trigger_entry'];
        $entry_args = $do_action_data['entry_args'];

        // You can access the trigger object itself for more context if needed.
        // For example, $trigger_object->get_trigger_meta()

        // Log the trigger ID and its arguments to the WordPress debug log.
        // In a real-world scenario, you might want more sophisticated logging
        // or error handling.
        error_log( "automator_before_trigger_completed Hook Fired: Trigger ID = {$trigger_id}" );
        error_log( "Entry Arguments: " . print_r( $entry_args, true ) );

        // If the trigger object has specific methods or properties you need to access,
        // you can do so here. For instance, if $trigger_object is an instance of a
        // specific trigger class with a method like get_trigger_name().
        // if ( method_exists( $trigger_object, 'get_trigger_name' ) ) {
        //     error_log( "Trigger Name: " . $trigger_object->get_trigger_name() );
        // }
    }
}

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/abstract-trigger.php:542
src/core/lib/recipe-parts/triggers/trait-triggers.php:252

protected function process( $recipe_id, $trigger, $hook_args ) {

		if ( Automator()->is_recipe_throttled( absint( $recipe_id ), absint( $this->user_id ) ) ) {
			return;
		}

		$this->recipe_log_id = $this->maybe_create_recipe_log_entry( $this->recipe_id );

		$this->trigger_log_entry = $this->maybe_create_trigger_log_entry( $this->recipe_id, $this->recipe_log_id, $this->trigger );

		$this->trigger_records = array(
			'code'           => $this->get_code(),
			'user_id'        => $this->user_id,
			'trigger_id'     => (int) $this->trigger['ID'],
			'recipe_id'      => $this->recipe_id,
			'trigger_log_id' => $this->trigger_log_entry,
			'recipe_log_id'  => $this->recipe_log_id,
			'run_number'     => (int) Automator()->get->next_run_number( $this->recipe_id, $this->user_id, true ),
			'meta'           => $this->get_trigger_meta(),
			'get_trigger_id' => $this->trigger_log_entry,
		);

		$this->token_values = $this->hydrate_tokens( $this->trigger, $this->hook_args );
		$this->save_tokens( $this->get_code(), $this->token_values );

		$do_action = array(
			'trigger_entry' => $this->trigger,
			'entry_args'    => $this->trigger_records,
			'trigger_args'  => $this->hook_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 ) {
			// Register the hook.
			$this->register_loopable_trigger_tokens_hooks( $do_action );
			// Fire the hook.
			do_action( 'automator_loopable_token_hydrate', $do_action['entry_args'], $do_action['trigger_args'] );
			// Complete the trigger.
			Automator()->complete->trigger( $this->trigger_records );
		}

		do_action( 'automator_after_maybe_trigger_complete', $do_action, $this );
	}


Internal Usage

Found in src/integrations/autonami/tokens/autonami-tokens.php:16:

add_filter( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/thrive-ovation/tokens/thrive-ovation-tokens.php:18:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/mailpoet/tokens/mailpoet-tokens.php:29:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/wp-download-manager/tokens/wpdm-tokens.php:18:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/whatsapp/tokens/wa-message-delivery-tokens.php:31:

add_filter( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/ws-form-lite/tokens/ws-form-lite-tokens.php:17:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/armember/tokens/armember-tokens.php:37:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/advanced-ads/tokens/advanced-ads-tokens.php:15:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/jet-crm/tokens/jetcrm-tokens.php:19:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/ameliabooking/tokens/ameliabooking-tokens.php:34:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/ameliabooking/tokens/ameliabooking-tokens.php:37:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data_reservation' ), 30, 2 );

Found in src/integrations/wp/tokens/wp-post-tokens.php:64:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/easy-affiliate/tokens/esaf-tokens.php:22:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/mailchimp/tokens/mailchimp-tokens.php:20:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/wp-all-import/tokens/wpai-tokens.php:18:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/wp-mail-smtp-pro/tokens/wpmsmtp-tokens.php:17:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/edd/tokens/edd-tokens.php:32:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/uncanny-automator/tokens/uoa-tokens.php:59:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/memberpress/tokens/mp-tokens.php:20:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/integrations/wholesale-suite/tokens/wss-tokens.php:13:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in src/core/lib/recipe-parts/trait-trigger-tokens.php:112:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/armember/tokens/armember-pro-tokens.php:22:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/ameliabooking/tokens/ameliabooking-pro-service-tokens.php:52:

add_filter( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/ameliabooking/tokens/ameliabooking-pro-custom-fields-tokens.php:41:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/ameliabooking/tokens/ameliabooking-pro-tokens.php:26:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/groundhogg/tokens/groundhogg-anon-tokens.php:23:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 22, 2 );

Found in uncanny-automator-pro/src/integrations/memberpress-courses/tokens/mpc-pro-tokens.php:13:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 22, 2 );

Found in uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:400:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/paid-memberships-pro/tokens/pmp-pro-tokens.php:16:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/acf/tokens/acf-tokens.php:29:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data_user_form' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/jet-crm/tokens/jetcrm-pro-tokens.php:130:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/learndash/tokens/ld-pro-tokens.php:17:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/advanced-ads/tokens/advads-pro-tokens.php:20:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 22, 2 );

Found in uncanny-automator-pro/src/integrations/event-tickets/tokens/et-anon-tokens.php:27:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/wp/tokens/wp-pro-tokens.php:112:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/memberpress/tokens/memberpress-pro-tokens.php:20:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );

Found in uncanny-automator-pro/src/integrations/wishlist-member/tokens/wm-pro-tokens.php:26:

add_action( 'automator_before_trigger_completed', array( $this, 'save_token_data' ), 20, 2 );
Scroll to Top