Action uncanny-automator-pro

automator_pro_after_user_action_completed

Fires after a user's action within a recipe has been successfully completed.

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

Description

Fires after a user action within an Uncanny Automator recipe completes. Developers can hook into this action to perform custom tasks, process the user action result, or modify subsequent recipe steps based on the outcome. It provides the action result, user ID, recipe ID, trigger log ID, and additional arguments.


Usage

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

Parameters

$user_action_result (mixed)
This parameter contains the result of the executed user action.
$user_id (mixed)
This parameter contains the result of the completed user action, which can be anything from a boolean `true` or `false` to a more complex object or array depending on the specific action.
$recipe_id (mixed)
This parameter holds the unique identifier of the user who performed the action.
$trigger_log_id (mixed)
This parameter contains the ID of the recipe that the user action is a part of.
$args (mixed)
This parameter contains the ID of the log entry for the trigger that initiated this recipe execution.

Examples

<?php
/**
 * Example function to hook into automator_pro_after_user_action_completed.
 * This function demonstrates how to access and process the data passed
 * when a user action within Uncanny Automator Pro is completed.
 *
 * @param mixed $user_action_result The result of the user action.
 * @param int   $user_id            The ID of the user for whom the action was performed.
 * @param int   $recipe_id          The ID of the Uncanny Automator recipe.
 * @param int   $trigger_log_id     The ID of the log entry for the trigger that initiated this action.
 * @param array $args               Additional arguments passed with the action.
 */
function my_automator_pro_user_action_completed_handler( $user_action_result, $user_id, $recipe_id, $trigger_log_id, $args ) {
	// Log the completion of the user action for debugging or auditing purposes.
	// In a real-world scenario, you might check $user_action_result to see if the action was successful.
	if ( $user_action_result && is_array( $user_action_result ) && isset( $user_action_result['success'] ) && true === $user_action_result['success'] ) {
		error_log(
			sprintf(
				'User action completed successfully for User ID: %d, Recipe ID: %d, Trigger Log ID: %d. Action details: %s',
				$user_id,
				$recipe_id,
				$trigger_log_id,
				print_r( $user_action_result, true )
			)
		);

		// Example: If the action was to award points, you might fetch the user's current points
		// and potentially perform further actions based on the updated points.
		// This is a hypothetical example, actual logic would depend on the specific action.
		if ( isset( $args['action_type'] ) && 'award_points' === $args['action_type'] ) {
			$points_awarded = isset( $args['points_to_award'] ) ? intval( $args['points_to_award'] ) : 0;
			if ( $points_awarded > 0 ) {
				$user_points = get_user_meta( $user_id, 'user_total_points', true );
				$user_points = $user_points ? intval( $user_points ) : 0;
				$new_total_points = $user_points + $points_awarded;
				update_user_meta( $user_id, 'user_total_points', $new_total_points );

				error_log(
					sprintf(
						'User ID: %d awarded %d points. New total points: %d.',
						$user_id,
						$points_awarded,
						$new_total_points
					)
				);

				// You could potentially trigger another Automator recipe here if needed,
				// though direct integration with Automator's internal functions might be complex.
				// For simplicity, we're just logging.
			}
		}
	} else {
		error_log(
			sprintf(
				'User action failed or had no success indicator for User ID: %d, Recipe ID: %d, Trigger Log ID: %d. Result: %s',
				$user_id,
				$recipe_id,
				$trigger_log_id,
				print_r( $user_action_result, true )
			)
		);
	}
}

// Add the action hook with the correct number of accepted arguments.
// The 'automator_pro_after_user_action_completed' hook passes 5 arguments.
add_action( 'automator_pro_after_user_action_completed', 'my_automator_pro_user_action_completed_handler', 10, 5 );
?>

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:316

$trigger_log_id,
					$args,
				),
				'4.3',
				'automator_pro_after_user_action_completed'
			);

			do_action( 'automator_pro_after_user_action_completed', $user_action_result, $user_id, $recipe_id, $trigger_log_id, $args );
		}

		$attributes = array(
			'maybe_continue_recipe_process' => $cont_recipe_process,
			'recipe_id'                     => $recipe_id,
			'user_id'                       => $user_id,
			'recipe_log_id'                 => $recipe_log_id,

Scroll to Top