Action uncanny-automator

automator_enqueue_trigger_before_process_queue_item

Fires before an Automator queue item is processed, allowing for pre-processing modifications or checks.

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

Description

Fires before a trigger queue item is processed. This hook allows developers to modify the queue item or perform actions before processing begins. Use it to customize trigger execution or log data. The `$hook_args` array contains the queue item.


Usage

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

Parameters

$hook_args (mixed)
This parameter contains an array where the 'item' key holds the specific trigger queue item being processed.

Examples

<?php
/**
 * Example: Log the queue item before it's processed.
 *
 * This example demonstrates how to hook into the
 * 'automator_enqueue_trigger_before_process_queue_item' action
 * to inspect and log the queue item data before it proceeds with processing.
 */
add_action( 'automator_enqueue_trigger_before_process_queue_item', function( $hook_args ) {

	// Ensure we have the expected 'item' key in the hook arguments.
	if ( isset( $hook_args['item'] ) && is_array( $hook_args['item'] ) ) {

		$queue_item = $hook_args['item'];

		// For demonstration, let's log some details about the queue item.
		// In a real-world scenario, you might want to perform more complex logic,
		// like conditionally modifying the item, aborting the process, or
		// triggering other related actions.

		$log_message = sprintf(
			'Automator Queue Item: Trigger ID - %s, User ID - %s, Timestamp - %s',
			isset( $queue_item['trigger_id'] ) ? esc_html( $queue_item['trigger_id'] ) : 'N/A',
			isset( $queue_item['user_id'] ) ? esc_html( $queue_item['user_id'] ) : 'N/A',
			current_time( 'mysql' )
		);

		// Using WordPress's error_log for logging.
		error_log( $log_message );

		// You could also check for specific conditions.
		// For example, if a particular trigger ID should be handled differently:
		/*
		if ( isset( $queue_item['trigger_id'] ) && $queue_item['trigger_id'] === 123 ) {
			error_log( 'Special handling for Trigger ID 123 detected.' );
			// Potentially add more logic here.
		}
		*/

	} else {
		error_log( 'Automator Queue Item: Invalid hook_args received.' );
	}

}, 10, 1 ); // Priority 10, accepts 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/actionify-triggers/class-trigger-queue.php:242

private function process_queue_item( $item ) {

		$hook_args = array( 'item' => $item );
		do_action( 'automator_enqueue_trigger_before_process_queue_item', $hook_args );

		// If recipe parts haven't loaded yet (e.g., exit() was called before init:30),
		// delegate to the AJAX fallback where the full WordPress lifecycle runs.
		if ( ! did_action( 'automator_add_integration_recipe_parts' ) ) {
			$this->safe_process( $item );
			return;
		}

		$trigger_obj = Automator()->get_trigger( $item['trigger_code'] );

		// If trigger object doesn't exist, use redundancy fallback.
		if ( ! $trigger_obj ) {
			$this->safe_process( $item );
			return;
		}

		$this->execute_trigger( $trigger_obj, $item );
	}

Scroll to Top