Action uncanny-automator-pro

automator_pro_before_anon_user_action_completed

Fires before an anonymous user action is completed, allowing for modifications to the process.

add_action( 'automator_pro_before_anon_user_action_completed', $callback, 10, 5 );

Description

Fires before an anonymous user action is completed. This hook allows developers to intercept and modify the action process, access user, recipe, and log data, and perform custom logic before the action is finalized. It's useful for advanced logging or custom integrations triggered by anonymous user actions.


Usage

add_action( 'automator_pro_before_anon_user_action_completed', 'your_function_name', 10, 5 );

Parameters

$user_id (mixed)
This parameter contains the ID of the user performing the action, or `0` if the user is anonymous.
$recipe_id (mixed)
This parameter represents the ID of the user performing the action, which could be a logged-in user ID or null for anonymous users.
$trigger_log_id (mixed)
This parameter contains the ID of the recipe that is being processed.
$args (mixed)
This parameter holds the ID of the log entry for the trigger that initiated this action.
$attributes (mixed)
This parameter holds any additional arguments passed to the action completion process.

Examples

<?php
/**
 * Example function to hook into `automator_pro_before_anon_user_action_completed`.
 *
 * This function demonstrates how to access the parameters passed to the hook
 * and perform a custom action before the anonymous user action is marked as completed.
 * For instance, we might want to log additional details about the action or
 * modify the $args before they are processed further.
 *
 * @param mixed $user_id        The ID of the user (can be null for anonymous users).
 * @param mixed $recipe_id      The ID of the Uncanny Automator recipe.
 * @param mixed $trigger_log_id The ID of the trigger log entry.
 * @param mixed $args           An array of arguments passed to the action.
 * @param mixed $attributes     An array of attributes associated with the action.
 */
add_action( 'automator_pro_before_anon_user_action_completed', function ( $user_id, $recipe_id, $trigger_log_id, $args, $attributes ) {

	// Example: Log additional information about the anonymous user action.
	// We can check if the user_id is null to confirm it's an anonymous action.
	if ( null === $user_id ) {
		error_log( sprintf(
			'Automator Pro: Before anonymous user action completion. Recipe ID: %d, Trigger Log ID: %d. Args: %s, Attributes: %s',
			$recipe_id,
			$trigger_log_id,
			print_r( $args, true ),
			print_r( $attributes, true )
		) );
	}

	// Example: Potentially modify $args before they are processed.
	// Be cautious when modifying arguments as it can lead to unexpected behavior.
	// For instance, if you wanted to add a default value to an argument if it's missing.
	if ( isset( $args['some_specific_argument'] ) && empty( $args['some_specific_argument'] ) ) {
		$args['some_specific_argument'] = 'default_value';
		// Note: To ensure this modification is used, you might need to re-add it to $args
		// or ensure the system that processes $args later respects these changes.
		// However, for 'before' hooks, direct modification of passed by reference variables
		// is often the intended use. In this case, $args is passed by value, so
		// this modification would only affect subsequent code *within this callback*,
		// not the original $args in the calling function unless it was passed by reference.
		// For this specific hook, assume $args is treated as a copy for modification.
	}

	// If this was a filter, you would need to return the modified value:
	// return $modified_value;

}, 10, 5 ); // Priority 10, accepts 5 arguments.

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-complete.php:281

$args,
				$attributes,
			),
			'4.3',
			'automator_pro_before_anon_user_action_completed'
		);

		do_action( 'automator_pro_before_anon_user_action_completed', $user_id, $recipe_id, $trigger_log_id, $args, $attributes );

		$user_action_result       = $this->maybe_run_anonymous_recipe_user_actions( $recipe_id, $user_id, $recipe_log_id, $trigger_data, $args );
		$this->user_action_result = $user_action_result;
		$user_action_status       = isset( $user_action_result['status'] ) ? $user_action_result['status'] : false;
		$user_action_data         = isset( $user_action_result['data'] ) ? $user_action_result['data'] : array();
		$user_id                  = array_key_exists( 'user_id', $user_action_data ) ? $user_action_data['user_id'] : false;


Scroll to Top