Filter uncanny-automator

automator_usermeta_token_parsed

Filters the parsed user meta token before it's used in an automation.

add_filter( 'automator_usermeta_token_parsed', $callback, 10, 6 );

Description

Filters the parsed user meta token value before it's replaced. This hook allows developers to modify the value to be inserted, the user meta UID, key, trigger meta key, and related arguments. Use it to dynamically alter or validate user meta token replacements.


Usage

add_filter( 'automator_usermeta_token_parsed', 'your_function_name', 10, 6 );

Parameters

$replaceable (mixed)
This parameter contains the value that will be replaced in the token, potentially modified from its original form.
$user_meta_uid (mixed)
This parameter contains the value that will replace the token in the content.
$user_meta_key (mixed)
This parameter contains the unique identifier for the user meta being processed.
$trigger_meta_key (mixed)
This parameter contains the key of the user meta field whose value is being processed.
$args (mixed)
This parameter contains the meta key associated with the trigger.
$trigger_args (mixed)
This parameter contains an array of arguments passed to the trigger.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the parsed user meta token value.
 *
 * This function demonstrates how to hook into the 'automator_usermeta_token_parsed'
 * filter to alter the value before it's used. In this example, we'll
 * prepend a prefix to the user meta value if it's a string, and
 * conditionally return an empty string if the user meta key is 'custom_secret_code'.
 *
 * @param mixed $replaceable The value to be replaced (the user meta value).
 * @param mixed $user_meta_uid The unique ID of the user meta entry.
 * @param mixed $user_meta_key The key of the user meta being processed.
 * @param mixed $trigger_meta_key The meta key associated with the trigger.
 * @param mixed $args Additional arguments passed to the token parser.
 * @param mixed $trigger_args Arguments specific to the trigger.
 * @return mixed The modified or original $replaceable value.
 */
add_filter(
	'automator_usermeta_token_parsed',
	function( $replaceable, $user_meta_uid, $user_meta_key, $trigger_meta_key, $args, $trigger_args ) {
		// Prevent modification if the user meta key is a sensitive one.
		if ( 'custom_secret_code' === $user_meta_key ) {
			return ''; // Hide or clear sensitive data.
		}

		// If the replaceable value is a string, prepend a custom prefix.
		if ( is_string( $replaceable ) && ! empty( $replaceable ) ) {
			$replaceable = '[USER_META] ' . sanitize_text_field( $replaceable );
		}

		// You could also conditionally modify based on other parameters, e.g.:
		// if ( isset( $trigger_args['trigger_type'] ) && 'specific_trigger_type' === $trigger_args['trigger_type'] ) {
		//     // Perform a different modification for a specific trigger.
		// }

		return $replaceable;
	},
	10, // Priority
	6  // Number of accepted 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

src/core/deprecated/legacy-token-parser.php:296
src/integrations/advanced/tokens/usermeta-token.php:80

if ( is_array( $replaceable ) ) {
									$replaceable = join( ', ', $replaceable );
								}

								$trigger_meta_key = $meta_key;
								$user_meta_key    = $pieces[1];

								$replaceable = apply_filters(
									'automator_usermeta_token_parsed',
									$replaceable,
									$user_meta_uid,
									$user_meta_key,
									$trigger_meta_key,
									$args,
									$trigger_args

Scroll to Top