automator_action_tokens_hydrated_tokens
Filters action tokens properties before they are hydrated, allowing modification of token data.
add_filter( 'automator_action_tokens_hydrated_tokens', $callback, 10, 2 );
Description
Fires after an action token's value has been hydrated but before it's stored. Developers can use this hook to modify the token's properties, such as its value or whether to skip adding metadata. This is an internal hook, primarily for modifying how tokens are processed and stored within Uncanny Automator.
Usage
add_filter( 'automator_action_tokens_hydrated_tokens', 'your_function_name', 10, 2 );
Parameters
-
$action_token_props(mixed) - This parameter contains an array of properties related to the action token being hydrated, including whether to skip adding metadata and the encoded or raw value.
-
$this(mixed) - This parameter contains an array of properties for the action token being hydrated, including whether to skip adding meta and the encoded or original value.
Return Value
The filtered value.
Examples
add_filter( 'automator_action_tokens_hydrated_tokens', 'my_custom_automator_token_modification', 10, 3 );
/**
* Example function to modify action token properties.
* This function demonstrates how to conditionally alter the 'value'
* of an action token before it's stored, for example, to always
* ensure a specific token is JSON encoded regardless of the initial flag.
*
* @param array $action_token_props The current properties of the action token.
* Expected keys: 'should_skip_add_meta', 'value'.
* @param mixed $process_args Arguments passed during the process.
* @param Store $store An instance of the Store class.
*
* @return array The modified action token properties.
*/
function my_custom_automator_token_modification( $action_token_props, $process_args, $store ) {
// Let's assume we want to ensure a specific token (e.g., an email address)
// is always stored as a JSON encoded string, even if it wasn't initially.
// This is a hypothetical scenario for demonstration.
$target_token_key = 'user_email'; // This would ideally be determined more dynamically.
$token_value_to_modify = null;
// In a real-world scenario, you'd need to figure out which token's value
// you are modifying based on $process_args or by inspecting the structure of $action_token_props
// if it contained more identifying information. For this example, we'll simplify.
// We'll pretend $action_token_props['value'] is the actual token value we want to check.
// A more robust check would involve inspecting $process_args or other contextual data
// to identify *which* token's value we are dealing with.
// For this simple example, we'll just modify if a certain condition is met,
// assuming the current value is the one we are interested in.
// Let's say we want to always JSON encode if the value looks like an email.
if ( is_string( $action_token_props['value'] ) && is_email( $action_token_props['value'] ) ) {
$action_token_props['value'] = wp_json_encode( $action_token_props['value'] );
}
// You could also conditionally change 'should_skip_add_meta'
// if ( 'some_condition_met' === $process_args['some_flag'] ) {
// $action_token_props['should_skip_add_meta'] = true;
// }
return $action_token_props;
}
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/services/recipe/action/token/hydrator.php:95
src/core/services/recipe/action/token/store.php:74
public function hydrate( $value = '', $should_encode = true ) {
if ( empty( $value ) ) {
return false;
}
$action_token_props = array(
'should_skip_add_meta' => false,
'value' => $should_encode ? wp_json_encode( $value ) : $value,
);
// Allow other processes to modify the action token properties before storing.
$action_token_props = apply_filters(
'automator_action_tokens_hydrated_tokens',
$action_token_props,
$this->process_args,
new Store()
);
return $this->insert_token( $action_token_props['value'] );
}
Internal Usage
Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:56:
add_filter( 'automator_action_tokens_hydrated_tokens', array( $this, 'hydrate_action_tokens' ), 10, 3 );