Action
uncanny-automator
automator_before_maybe_trigger_num_times_completed
Fires before checking if a trigger has completed the maximum number of times, allowing modification of arguments.
add_action( 'automator_before_maybe_trigger_num_times_completed', $callback, 10, 1 );
Description
Fires before the number of times a trigger has completed is checked. Developers can use this hook to modify the `$times_args` array, which contains details like the recipe and trigger IDs, before the check is performed. This offers an opportunity to influence the trigger completion logic.
Usage
add_action( 'automator_before_maybe_trigger_num_times_completed', 'your_function_name', 10, 1 );
Parameters
-
$times_args(mixed) - This parameter contains an array of arguments related to the number of times a recipe has been completed, including the recipe ID and trigger ID.
Examples
add_action( 'automator_before_maybe_trigger_num_times_completed', function ( $times_args ) {
// This example shows how to log specific details before a trigger is potentially processed multiple times.
// It's useful for debugging or auditing complex automation flows.
// Ensure we have the necessary arguments
if ( ! isset( $times_args['recipe_id'] ) || ! isset( $times_args['trigger_id'] ) || ! isset( $times_args['user_id'] ) ) {
return; // Exit if essential data is missing
}
$recipe_id = $times_args['recipe_id'];
$trigger_id = $times_args['trigger_id'];
$user_id = $times_args['user_id'];
$recipe_log_id = isset( $times_args['recipe_log_id'] ) ? $times_args['recipe_log_id'] : 'N/A';
$trigger_log_id = isset( $times_args['trigger_log_id'] ) ? $times_args['trigger_log_id'] : 'N/A';
$trigger_data = isset( $times_args['trigger'] ) ? $times_args['trigger'] : [];
// Log the event using WordPress's error logging system for clarity.
// In a real-world scenario, you might integrate with a custom logging plugin or service.
error_log( sprintf(
'automator_before_maybe_trigger_num_times_completed Hook Fired: Recipe ID: %d, Trigger ID: %d, User ID: %d, Recipe Log ID: %s, Trigger Log ID: %s. Trigger details: %s',
$recipe_id,
$trigger_id,
$user_id,
$recipe_log_id,
$trigger_log_id,
print_r( $trigger_data, true ) // Log trigger data in a readable format
) );
// You could also potentially perform other actions here, such as:
// - Adding a meta entry to the user or recipe log for auditing.
// - Incrementing a counter for monitoring purposes.
// - Preparing data that will be used by subsequent actions in the same process.
}, 10, 1 ); // Priority 10, accepting 1 argument.
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:790
*
* @param $times_args
*
* @return array
*/
public function maybe_trigger_num_times_completed( $times_args ) {
do_action( 'automator_before_maybe_trigger_num_times_completed', $times_args );
$recipe_id = key_exists( 'recipe_id', $times_args ) ? $times_args['recipe_id'] : null;
$trigger_id = key_exists( 'trigger_id', $times_args ) ? $times_args['trigger_id'] : null;
$trigger = key_exists( 'trigger', $times_args ) ? $times_args['trigger'] : null;
$user_id = key_exists( 'user_id', $times_args ) ? $times_args['user_id'] : null;
$recipe_log_id = key_exists( 'recipe_log_id', $times_args ) ? $times_args['recipe_log_id'] : null;
$trigger_log_id = key_exists( 'trigger_log_id', $times_args ) ? $times_args['trigger_log_id'] : null;