Action
uncanny-automator-pro
uap_action_completed
Fires when a user completes an action, providing details about the user, action, and recipe.
add_action( 'uap_action_completed', $callback, 10, 5 );
Description
Fires after an action is marked as completed within Uncanny Automator. Developers can use this hook to trigger custom logic or integrations when a specific action in a recipe finishes. It provides access to the user ID, action ID, recipe ID, and additional arguments passed during completion.
Usage
add_action( 'uap_action_completed', 'your_function_name', 10, 5 );
Parameters
-
$user_id(mixed) - The ID of the user who triggered the action.
-
$action_data(mixed) - The ID of the user for whom the action was completed.
-
$recipe_id(mixed) - This parameter contains an array of data related to the completed action, including its ID and the ID of the associated recipe log.
-
$args(mixed) - This parameter contains the ID of the recipe that triggered the action.
-
$args(mixed) - This parameter contains any additional arguments passed to the action, which can be used for custom logic or data retrieval.
Examples
<?php
/**
* Example of how to hook into the 'uap_action_completed' action.
*
* This function demonstrates how to log details when an Uncanny Automator action is completed.
* It retrieves the user ID, action ID, recipe ID, and a custom message, then logs them
* to a custom log file or a database table for later analysis.
*
* @param int $user_id The ID of the user for whom the action was completed.
* @param int $action_id The ID of the specific Uncanny Automator action that was completed.
* @param int $recipe_id The ID of the Uncanny Automator recipe associated with this action.
* @param string $user_action_message A custom message associated with the action's completion, if any.
* @param array $args An array of additional arguments passed with the action.
*/
function my_uncanny_automator_action_completed_logger( $user_id, $action_id, $recipe_id, $user_action_message, $args ) {
// Ensure we have a user ID to log against.
if ( ! $user_id ) {
error_log( 'Uncanny Automator: uap_action_completed hook called without a valid user ID.' );
return;
}
// Retrieve user's display name for more context.
$user = get_user_by( 'id', $user_id );
$user_display_name = $user ? $user->display_name : 'Unknown User';
// Prepare log message.
$log_message = sprintf(
'[Uncanny Automator] Action Completed: User "%s" (ID: %d) completed Action ID %d for Recipe ID %d.',
$user_display_name,
$user_id,
$action_id,
$recipe_id
);
// Append custom message if available.
if ( ! empty( $user_action_message ) ) {
$log_message .= ' Message: "' . esc_html( $user_action_message ) . '"';
}
// Append any other relevant arguments from the $args array.
if ( ! empty( $args ) ) {
$log_message .= ' Additional Args: ' . json_encode( $args );
}
// Log the information. For a real-world scenario, you might want to
// log to a custom database table for easier querying and management.
error_log( $log_message );
// Example: Save to a custom database table (assuming you have one set up).
// global $wpdb;
// $table_name = $wpdb->prefix . 'my_automator_logs';
// $wpdb->insert( $table_name, array(
// 'user_id' => $user_id,
// 'action_id' => $action_id,
// 'recipe_id' => $recipe_id,
// 'message' => $user_action_message,
// 'args' => json_encode( $args ),
// 'timestamp' => current_time( 'mysql' ),
// ) );
}
// Add the action hook. The 'uap_action_completed' hook passes 5 arguments.
// We use a priority of 10 (default) and accept all 5 arguments.
add_action( 'uap_action_completed', 'my_uncanny_automator_action_completed_logger', 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/classes/actions-conditions.php:1117
uncanny-automator-pro/src/core/classes/async-actions.php:790
public function mark_existing_action_skipped( $action ) {
extract( $action ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$recipe_log_id = $action_data['recipe_log_id'];
Automator()->db->action->mark_complete( (int) $action_data['ID'], $recipe_log_id, self::SKIPPED_STATUS, $args['user_action_message'] );
do_action( 'uap_action_completed', $user_id, (int) $action_data['ID'], $recipe_id, $args['user_action_message'], $args );
Automator()->complete->recipe( $recipe_id, $user_id, $recipe_log_id, $args );
}