Action
uncanny-automator
automator_enqueue_trigger_before_enqueue_trigger
Fires before a trigger is enqueued, allowing for pre-enqueue modifications to trigger arguments.
add_action( 'automator_enqueue_trigger_before_enqueue_trigger', $callback, 10, 1 );
Description
Fires before a trigger is added to the queue for processing. Developers can use this hook to modify trigger arguments, perform pre-enqueue checks, or log trigger events. The `$hook_args` parameter contains `trigger_code`, `action_hook`, and `trigger_hash`.
Usage
add_action( 'automator_enqueue_trigger_before_enqueue_trigger', 'your_function_name', 10, 1 );
Parameters
-
$hook_args(mixed) - This parameter contains an array of arguments that will be passed to the trigger hook, including the trigger code and any associated action hook data.
Examples
<?php
/**
* Example function to hook into 'automator_enqueue_trigger_before_enqueue_trigger'.
* This example logs the trigger details before it's enqueued.
*
* @param array $hook_args An array containing trigger details.
* - 'trigger_code' (string): The unique code identifying the trigger.
* - 'action_hook' (string): The WordPress action hook associated with the trigger.
* - 'trigger_hash' (string): A unique hash for the trigger instance.
*/
function my_automator_log_trigger_enqueue_details( $hook_args ) {
// Ensure $hook_args is an array and has the expected keys.
if ( ! is_array( $hook_args ) || ! isset( $hook_args['trigger_code'], $hook_args['action_hook'], $hook_args['trigger_hash'] ) ) {
error_log( 'my_automator_log_trigger_enqueue_details: Invalid $hook_args received.' );
return;
}
$trigger_code = $hook_args['trigger_code'];
$action_hook = $hook_args['action_hook'];
$trigger_hash = $hook_args['trigger_hash'];
// Log the details to the WordPress debug log.
// This can be helpful for debugging when triggers are being processed.
$log_message = sprintf(
'Automator enqueueing trigger: Code="%s", Action Hook="%s", Hash="%s"',
$trigger_code,
$action_hook,
$trigger_hash
);
error_log( $log_message );
// In a real-world scenario, you might perform other actions here,
// such as adding custom data to the trigger's processing or
// conditionally preventing a trigger from being enqueued based on certain criteria.
// For instance, you could check if a specific user role is allowed to enqueue this trigger.
// Example:
// if ( ! current_user_can( 'manage_automator_triggers' ) && $trigger_code === 'specific_sensitive_trigger' ) {
// error_log( "User not permitted to enqueue sensitive trigger: {$trigger_hash}" );
// // You might need a way to signal back to the caller to stop processing.
// // This hook is 'before_enqueue', so if we want to prevent it, we'd need
// // to rely on the calling function's logic or a filter hook if available.
// }
}
// Add the action hook to WordPress.
// The '10' is the default priority, and '1' indicates that our function accepts one argument ($hook_args).
add_action( 'automator_enqueue_trigger_before_enqueue_trigger', 'my_automator_log_trigger_enqueue_details', 10, 1 );
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:156
public function enqueue( $trigger_code, $action_hook, $args ) {
$trigger_hash = $this->generate_trigger_hash( $trigger_code, $args );
// Skip if already processed in this request.
if ( isset( $this->processed_hashes[ $trigger_hash ] ) ) {
return false;
}
$hook_args = array(
'trigger_code' => $trigger_code,
'action_hook' => $action_hook,
'trigger_hash' => $trigger_hash,
);
do_action( 'automator_enqueue_trigger_before_enqueue_trigger', $hook_args );
$this->processed_hashes[ $trigger_hash ] = true;
$this->memory_queue[] = array(
'hash' => $trigger_hash,
'trigger_code' => $trigger_code,
'action_hook' => $action_hook,
'args' => $args,
'user_id' => get_current_user_id(),
'post_id' => get_the_ID(),
'timestamp' => time(),
);
$this->ensure_shutdown_hooks();
return true;
}