Action uncanny-automator-pro

uap_after_trigger_run

Fires after a trigger has been successfully run, providing access to trigger details and related data.

add_action( 'uap_after_trigger_run', $callback, 10, 4 );

Description

Fires after a trigger's meta data has been processed and potentially added. Developers can use this hook to perform additional actions based on the trigger's code, associated post, user ID, and meta data. This is useful for custom logging or triggering further automations.


Usage

add_action( 'uap_after_trigger_run', 'your_function_name', 10, 4 );

Parameters

$check_trigger_code (mixed)
This parameter contains a unique code that identifies the specific trigger that has just been executed.
$post_id (mixed)
This parameter contains the unique code identifier for the trigger that has just run.
$user_id (mixed)
This parameter contains the ID of the post associated with the trigger.
$trigger_meta (mixed)
This parameter holds the ID of the user associated with the trigger's execution.

Examples

<?php

/**
 * Example function to hook into 'uap_after_trigger_run'.
 * This function logs the trigger details and potentially updates user meta.
 *
 * @param mixed $check_trigger_code The code that was checked for the trigger.
 * @param mixed $post_id The ID of the post associated with the trigger.
 * @param mixed $user_id The ID of the user associated with the trigger.
 * @param mixed $trigger_meta Additional meta data for the trigger.
 */
function my_uncanny_automator_after_trigger_run_handler( $check_trigger_code, $post_id, $user_id, $trigger_meta ) {
	// Log that the trigger has run.
	error_log( sprintf(
		'Uncanny Automator Trigger Ran: Code: %s, Post ID: %d, User ID: %d, Meta: %s',
		esc_html( (string) $check_trigger_code ),
		absint( $post_id ),
		absint( $user_id ),
		print_r( $trigger_meta, true ) // Log trigger meta for debugging.
	) );

	// Example: If the trigger is for a specific post type and the user is logged in,
	// you might want to update a piece of user meta to indicate they've completed this.
	// This is a simplified example. Real-world logic would be more complex.
	if ( 'recipe_completed' === $check_trigger_code && $post_id && $user_id && is_user_logged_in() ) {
		// Let's assume $trigger_meta might contain information about which recipe was completed.
		// For this example, we'll just mark a generic "last recipe completed" timestamp.
		$recipe_meta_slug = isset( $trigger_meta['recipe_slug'] ) ? sanitize_key( $trigger_meta['recipe_slug'] ) : 'general_recipe_completion';
		$meta_key = 'uap_last_completed_recipe_' . $recipe_meta_slug;
		$meta_value = current_time( 'mysql' );

		update_user_meta( $user_id, $meta_key, $meta_value );

		error_log( sprintf(
			'Uncanny Automator: Updated user meta "%s" for user ID %d to "%s"',
			$meta_key,
			absint( $user_id ),
			esc_html( $meta_value )
		) );
	}
}

// Add the action hook.
// The 'uap_after_trigger_run' hook provides 4 arguments: $check_trigger_code, $post_id, $user_id, $trigger_meta.
add_action( 'uap_after_trigger_run', 'my_uncanny_automator_after_trigger_run_handler', 10, 4 );
?>

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/includes/automator-pro-recipe-process-anon.php:150

$meta_results = $this->maybe_trigger_add_any_option_meta( $meta_arg, $trigger_meta );
					if ( false === $meta_results['result'] ) {
						Utilities::log( 'ERROR: You are trying to add entry ' . $trigger['meta'][ $trigger_meta ] . ' and post_id = ' . $post_id . '.', 'uap_maybe_add_meta_entry ERROR', false, 'uap-errors' );
					}
				}

				do_action( 'uap_after_trigger_run', $check_trigger_code, $post_id, $user_id, $trigger_meta );

				if ( true === $trigger_steps_completed['result'] ) {
					$args['trigger_log_id'] = $get_trigger_id;
					$args['recipe_id']      = $recipe_id;
					$args['trigger_id']     = $trigger_id;
					$args['recipe_log_id']  = $recipe_log_id;
					$args['post_id']        = $post_id;

Scroll to Top