Action uncanny-automator

automator_recipe_process_user_trigger_num_times_insufficient

Fires when a user's trigger has not run the required number of times for an Automator recipe.

add_action( 'automator_recipe_process_user_trigger_num_times_insufficient', $callback, 10, 1 );

Description

Fires when a user fails to trigger a recipe's trigger the required number of times. Developers can use this hook to log this event or perform custom actions. It provides the trigger ID, recipe ID, and user ID. This hook is used internally by the logger service.


Usage

add_action( 'automator_recipe_process_user_trigger_num_times_insufficient', 'your_function_name', 10, 1 );

Parameters

$trigger_id (mixed)
This parameter holds the ID of the trigger that was being processed.

Examples

/**
 * Example of how to hook into the automator_recipe_process_user_trigger_num_times_insufficient action.
 * This function will be executed when a trigger's required number of occurrences has not been met.
 * In this example, we'll log a message to the WordPress debug log indicating that the trigger count was insufficient.
 */
add_action(
	'automator_recipe_process_user_trigger_num_times_insufficient',
	function ( $args ) {
		// Ensure the expected arguments are present.
		if ( ! is_array( $args ) || ! isset( $args['trigger_id'], $args['recipe_id'], $args['trigger_log_id'] ) ) {
			error_log( 'automator_recipe_process_user_trigger_num_times_insufficient received invalid arguments.' );
			return;
		}

		$trigger_id   = $args['trigger_id'];
		$recipe_id    = $args['recipe_id'];
		$trigger_log_id = $args['trigger_log_id'];

		// Log a custom message to the WordPress debug log.
		// In a real-world scenario, you might use this to send a notification,
		// perform a fallback action, or update custom meta.
		$message = sprintf(
			'Uncanny Automator: Trigger #%s for Recipe #%s did not meet the required number of occurrences. Trigger Log ID: %s',
			$trigger_id,
			$recipe_id,
			$trigger_log_id
		);
		error_log( $message );

	},
	10, // Priority: Lower numbers execute earlier.
	1  // Accepted arguments: This hook passes one argument (an array of 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

src/core/lib/process/class-automator-recipe-process-user.php:892

//change completed from -1 to 0
		$this->maybe_change_recipe_log_to_zero( $recipe_id, $user_id, $recipe_log_id, true );

		// Move on if the user didn't trigger the trigger enough times
		if ( $user_num_times < $num_times ) {

			// Used by fields logger.
			do_action(
				'automator_recipe_process_user_trigger_num_times_insufficient',
				array(
					'trigger_id'     => $trigger_id,
					'recipe_id'      => isset( $times_args['recipe_id'] ) ? $times_args['recipe_id'] : null,
					'trigger_log_id' => $trigger_log_id,
					'recipe_log_id'  => $recipe_log_id,
					'run_number'     => $run_number,

Scroll to Top