automator_loopable_token_hydrate
Fires when a loopable token needs to be hydrated with its actual data.
add_action( 'automator_loopable_token_hydrate', $callback, 10, 2 );
Description
Fires before loopable tokens are hydrated for a trigger. Developers can use this hook to modify or add to the data available within loopable tokens, enabling dynamic content manipulation for trigger outcomes. This hook is primarily for internal use and advanced customization.
Usage
add_action( 'automator_loopable_token_hydrate', 'your_function_name', 10, 2 );
Parameters
-
$do_action(mixed) - This parameter contains the dynamic data that needs to be processed or made available within the loop.
-
$do_action(mixed) - This parameter represents the data from the action that is being processed.
Examples
<?php
/**
* Example callback for the automator_loopable_token_hydrate action hook.
*
* This function demonstrates how to access and potentially modify trigger arguments
* before they are used to hydrate loopable tokens.
*
* @param array $entry_args Arguments related to the trigger entry.
* @param array $trigger_args Arguments specific to the trigger execution.
*/
function my_automator_hydrate_loopable_tokens( $entry_args, $trigger_args ) {
// Example: Check if a specific post ID is present and log it.
if ( ! empty( $trigger_args['post_id'] ) ) {
$post_id = absint( $trigger_args['post_id'] );
error_log( "Automator: Hydrating loopable tokens for post ID: {$post_id}" );
// Example: Add a custom key to the entry arguments if a condition is met.
if ( isset( $trigger_args['user_id'] ) && absint( $trigger_args['user_id'] ) > 0 ) {
$entry_args['custom_context'] = 'user_triggered';
error_log( "Automator: Added 'custom_context' to entry arguments for user ID: " . absint( $trigger_args['user_id'] ) );
}
}
// Note: This is an action hook, so no return value is expected.
// If this were a filter, you would typically return the modified arguments.
}
add_action( 'automator_loopable_token_hydrate', 'my_automator_hydrate_loopable_tokens', 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/recipe-parts/triggers/abstract-trigger.php:550
src/core/lib/recipe-parts/triggers/trait-triggers.php:259
src/integrations/woocommerce/triggers/wc-purchasesproduct.php:219
src/integrations/wp/triggers/anon-wp-post-published-in-taxonomy.php:338
src/integrations/wp/triggers/anon-wp-viewposttype.php:163
src/integrations/wp/triggers/anon-wp-updates-post-in-taxonomy.php:368
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-orderrefunded.php:118
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-orderstatuschange.php:133
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-order-payment-fail.php:100
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-shipstation-ordertotal-shipped.php:199
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-shipstation-product-shipped.php:192
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-purchprod-payment-gateway.php:229
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-quantity-purchprod.php:235
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-orderpartrefunded.php:119
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-ordercomplete.php:208
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-purchvarprod.php:219
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-orderrefundedasscproduct.php:226
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-orderwithcoupon.php:188
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-orderproductqty.php:258
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-purchprod-category.php:235
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-purchprod-category.php:204
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-purchprod-tag.php:231
uncanny-automator-pro/src/integrations/woocommerce/triggers/wc-purchvariableprod.php:229
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-orderstatuschange.php:137
uncanny-automator-pro/src/integrations/woocommerce/triggers/anon-wc-purchprod.php:189
uncanny-automator-pro/src/integrations/wp/triggers/wp-postinstatusupdated.php:208
uncanny-automator-pro/src/integrations/wp/triggers/wp-userpoststatus.php:223
uncanny-automator-pro/src/integrations/wp/triggers/wp-postintaxonomyupdated.php:369
uncanny-automator-pro/src/integrations/wp/triggers/wp-postupdated.php:251
protected function process( $recipe_id, $trigger, $hook_args ) {
if ( Automator()->is_recipe_throttled( absint( $recipe_id ), absint( $this->user_id ) ) ) {
return;
}
$this->recipe_log_id = $this->maybe_create_recipe_log_entry( $this->recipe_id );
$this->trigger_log_entry = $this->maybe_create_trigger_log_entry( $this->recipe_id, $this->recipe_log_id, $this->trigger );
$this->trigger_records = array(
'code' => $this->get_code(),
'user_id' => $this->user_id,
'trigger_id' => (int) $this->trigger['ID'],
'recipe_id' => $this->recipe_id,
'trigger_log_id' => $this->trigger_log_entry,
'recipe_log_id' => $this->recipe_log_id,
'run_number' => (int) Automator()->get->next_run_number( $this->recipe_id, $this->user_id, true ),
'meta' => $this->get_trigger_meta(),
'get_trigger_id' => $this->trigger_log_entry,
);
$this->token_values = $this->hydrate_tokens( $this->trigger, $this->hook_args );
$this->save_tokens( $this->get_code(), $this->token_values );
$do_action = array(
'trigger_entry' => $this->trigger,
'entry_args' => $this->trigger_records,
'trigger_args' => $this->hook_args,
);
do_action( 'automator_before_trigger_completed', $do_action, $this );
$process_further = apply_filters( 'automator_trigger_should_complete', true, $do_action, $this );
if ( $process_further ) {
// Register the hook.
$this->register_loopable_trigger_tokens_hooks( $do_action );
// Fire the hook.
do_action( 'automator_loopable_token_hydrate', $do_action['entry_args'], $do_action['trigger_args'] );
// Complete the trigger.
Automator()->complete->trigger( $this->trigger_records );
}
do_action( 'automator_after_maybe_trigger_complete', $do_action, $this );
}
Internal Usage
Found in src/core/services/loopable/trigger-loopable-token.php:64:
add_action( 'automator_loopable_token_hydrate', array( $this, 'on_before_trigger_complete' ), 10, 2 );