Filter uncanny-automator

automator_token_parser_extended_{$extension_identifier}

Filters token parsing for specific extension identifiers, allowing modification of parsed token output.

add_filter( 'automator_token_parser_extended_{$extension_identifier}', $callback, 10, 4 );

Description

Extends the functionality of the Automator token parser for specific integrations. Developers can use this filter to modify how extended tokens, identified by `$extension_identifier`, are parsed and processed, allowing for custom token handling beyond the core logic.


Usage

add_filter( 'automator_token_parser_extended_{$extension_identifier}', 'your_function_name', 10, 4 );

Parameters

$field_text (mixed)
This parameter contains the raw text of the token that is being processed.
$match (mixed)
The `$field_text` parameter contains the raw text of the token that is being processed.
$args (mixed)
This parameter holds the matched token string, which is then further processed to extract its components.
$trigger_args (mixed)
This parameter contains additional arguments passed to the token parser.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the 'automator_token_parser_extended_example_extension' filter.
 * This filter allows you to modify or process extended tokens specific to an extension.
 * In this example, we'll assume the 'example_extension' is processing a token
 * that represents a user's first name, and we want to ensure it's capitalized.
 *
 * @param mixed $field_text   The original text of the field.
 * @param mixed $match        The full matched token string (e.g., 'TOKEN_EXTENDED:example_extension:user_first_name').
 * @param mixed $args         Additional arguments passed to the token parser.
 * @param mixed $trigger_args Arguments from the trigger.
 *
 * @return string The modified field text.
 */
add_filter( 'automator_token_parser_extended_example_extension', function ( $field_text, $match, $args, $trigger_args ) {

	// Let's assume the token is like TOKEN_EXTENDED:example_extension:user_first_name
	// We can parse the $match to get more specific information if needed, but for this example
	// we'll focus on a generic transformation.

	// If the field_text is a string, we can try to capitalize it.
	if ( is_string( $field_text ) && ! empty( $field_text ) ) {
		// Let's say the $args might contain information about how to format the output.
		// For simplicity here, we'll just capitalize the first letter.
		$field_text = ucfirst( $field_text );
	}

	// It's crucial to always return the $field_text, whether modified or not.
	return $field_text;

}, 10, 4 );
?>

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:443
src/core/lib/utilities/class-automator-input-parser.php:247

*/
			if ( str_starts_with( $match, 'TOKEN_EXTENDED' ) ) {
				// Each token parts is separated by a ':' colon.
				$token_parts = (array) explode( ':', strtolower( $match ) );
				// We need to extract the first and second argument.
				list( $extended_flag, $extension_identifier ) = $token_parts;
				// Then use it as a filter so we dont have to check it. It is also safer.
				$field_text = apply_filters( "automator_token_parser_extended_{$extension_identifier}", $field_text, $match, $args, $trigger_args );
			}

			// Fix deprecated issue.
			if ( null === $field_text ) {
				$field_text = '';
			}


Scroll to Top