Filter
uncanny-automator-pro
automator_action_tokens_hydrate_tokens
Filters tokens before they are added to an action, allowing for modification of their values.
add_filter( 'automator_action_tokens_hydrate_tokens', $callback, 10, 1 );
Description
Filters the processed action tokens before they are saved to the database. This hook allows developers to modify or augment the token values, enabling custom token handling or transformations within the Uncanny Automator core. Use this to dynamically adjust token output for specific actions or integrations.
Usage
add_filter( 'automator_action_tokens_hydrate_tokens', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter is the array of action data being processed.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify action token values before they are saved to the database.
*
* This example demonstrates how to intercept and modify the 'action_tokens' meta value
* for an action log entry. It's useful for sanitizing or transforming token data
* before it's permanently stored.
*
* In this specific example, we'll simulate adding a prefix to any token values
* that are strings.
*
* @param mixed $meta_value The current meta value being filtered.
* @param object $action_tokens_helper The instance of the Action_Tokens class.
* @return mixed The modified meta value.
*/
add_filter( 'automator_action_tokens_hydrate_tokens', function( $meta_value, $action_tokens_helper ) {
// In a real scenario, $meta_value would likely be an array of tokens.
// We're assuming it's an array for this example, even though the hook
// signature shows '' as the initial value. The internal logic of
// Uncanny Automator will likely pass an array here.
if ( ! is_array( $meta_value ) ) {
// If it's not an array, return it as is, or handle it based on expected structure.
// For this example, we'll just return if it's not an array.
return $meta_value;
}
// Iterate through each token and modify if it's a string.
foreach ( $meta_value as $key => &$token_value ) {
if ( is_string( $token_value ) ) {
// Add a custom prefix to string token values.
$token_value = 'MODIFIED_' . $token_value;
}
}
unset( $token_value ); // Unset the reference to avoid potential issues.
return $meta_value;
}, 10, 2 ); // Priority 10, accepting 2 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
uncanny-automator-pro/src/core/classes/action-tokens-helpers.php:59
public function update_action_token_record( $action = array() ) {
// Bail if empty.
if ( empty( $action ) ) {
return false;
}
$action_id = isset( $action['action_data']['ID'] ) ? $action['action_data']['ID'] : null;
$action_log_id = isset( $action['action_data']['action_log_id'] ) ? $action['action_data']['action_log_id'] : null;
// Bail if either of $action_id or $action_log_id has a falsy value.
if ( empty( $action_id ) || empty( $action_log_id ) ) {
return false;
}
global $wpdb;
return Automator()->db->update(
$wpdb->prefix . 'uap_action_log_meta',
array(
// @see Uncanny_AutomatorRecipeAction_Tokens::hydrate_tokens.
'meta_value' => apply_filters( 'automator_action_tokens_hydrate_tokens', '', $this ),
),
array(
'meta_key' => 'action_tokens',
'automator_action_id' => $action_id,
'automator_action_log_id' => $action_log_id,
'user_id' => $action['user_id'],
),
array(
'%s', // Update format.
),
array(
'%s', // String 'meta_key'.
'%d', // Integer 'automator_action_id'.
'%d', // Integer 'automator_action_log_id'.
'%d', // Integer 'user_id'
)
);
}