automator_after_trigger_run
Fires after a trigger has successfully completed its execution, passing all trigger arguments and passed arguments.
add_action( 'automator_after_trigger_run', $callback, 10, 4 );
Description
Fired after a trigger has been successfully processed and potentially added as a user entry. Developers can use this hook to perform additional actions based on the trigger's execution, such as logging, sending notifications, or modifying related data. It receives the original trigger arguments and the arguments passed to the processing function.
Usage
add_action( 'automator_after_trigger_run', 'your_function_name', 10, 4 );
Parameters
-
$check_trigger_code(mixed) - This parameter contains a boolean value indicating whether the trigger code check was successful.
-
$post_id(mixed) - This parameter holds the unique code that identifies the trigger that has just run.
-
$user_id(mixed) - This parameter represents the ID of the post associated with the trigger event.
-
$trigger_meta(mixed) - This parameter contains the ID of the user who triggered the action.
Examples
<?php
/**
* Logs details about a completed Automator trigger run.
*
* This function hooks into the 'automator_after_trigger_run' action to log
* information about the trigger that just ran, specifically when it's autocompleted.
* It accesses the user ID and the trigger's meta data from the provided arguments.
*
* @param mixed $args The arguments passed to the trigger run, potentially including trigger metadata.
* @param mixed $pass_args The arguments passed to the trigger run, typically including user ID and other contextual data.
*/
function my_automator_log_completed_trigger( $args, $pass_args ) {
// Check if $pass_args contains user ID and if $args contains trigger metadata
if ( isset( $pass_args['user_id'] ) && isset( $args['trigger_meta'] ) ) {
$user_id = absint( $pass_args['user_id'] );
$trigger_meta = $args['trigger_meta']; // Assuming trigger_meta is an array
// Sanitize and prepare data for logging
$trigger_title = isset( $trigger_meta['label'] ) ? sanitize_text_field( $trigger_meta['label'] ) : 'Unknown Trigger';
$recipe_id = isset( $trigger_meta['recipe_id'] ) ? absint( $trigger_meta['recipe_id'] ) : 0;
// Log the event (e.g., to a custom log file or a WordPress option for debugging)
// For demonstration, we'll use WP_Error to represent logging an event.
// In a real scenario, you might use error_log(), a dedicated logging class,
// or store this in a custom database table.
$log_message = sprintf(
'Automator Trigger Completed: User ID %1$d ran trigger "%2$s" for Recipe ID %3$d.',
$user_id,
$trigger_title,
$recipe_id
);
// You would typically use a more robust logging mechanism here.
// For example, to add to a transient for debugging:
// $current_logs = get_transient( 'my_automator_trigger_logs' );
// if ( ! is_array( $current_logs ) ) {
// $current_logs = [];
// }
// $current_logs[] = $log_message;
// set_transient( 'my_automator_trigger_logs', $current_logs, DAY_IN_SECONDS );
// Or simply use error_log for server-level logging:
error_log( $log_message );
}
}
// Add the action hook.
// We specify 10 as the priority (default) and 2 as the number of arguments accepted by the callback function.
add_action( 'automator_after_trigger_run', 'my_automator_log_completed_trigger', 10, 2 );
?>
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/process/class-automator-recipe-process-user.php:185
src/core/lib/recipe-parts/triggers/trait-triggers.php:226
src/core/lib/recipe-parts/triggers/trait-triggers.php:277
$post_id,
$user_id,
$trigger_meta,
),
'3.0',
'automator_after_trigger_run'
);
do_action( 'automator_after_trigger_run', $check_trigger_code, $post_id, $user_id, $trigger_meta );
if ( true === $trigger_steps_completed['result'] ) {
/**
* @version 3.0
* @deprecated $args['trigger_log_id'] Use $args['trigger_log_id'].
*/
$args['get_trigger_id'] = $get_trigger_log_id;