Filter uncanny-automator

automator_maybe_parse_field_text

Filters the text of a field before it's parsed for potential replacements during automation.

add_filter( 'automator_maybe_parse_field_text', $callback, 10, 3 );

Description

Filters field text for token replacement. Developers can modify the field text, match placeholder, or replacement value before they are processed. This hook is useful for customizing how recipe variables are displayed or manipulated.


Usage

add_filter( 'automator_maybe_parse_field_text', 'your_function_name', 10, 3 );

Parameters

$field_text (mixed)
This parameter contains the raw text of the field that may need parsing.
$match (mixed)
This parameter contains the text content of the field that might need to have its tokens parsed.
$replaceable (mixed)
This parameter contains the matched string that is being processed for replacement.

Return Value

The filtered value.


Examples

add_filter( 'automator_maybe_parse_field_text', function ( $field_text, $match, $replaceable ) {

	// Example: If the matched token is 'site_title' and the site title is longer than 20 characters,
	// truncate it and add an ellipsis.
	if ( 'site_title' === $match && is_string( $replaceable ) && strlen( $replaceable ) > 20 ) {
		$replaceable = substr( $replaceable, 0, 20 ) . '...';
	}

	// Example: If the matched token is 'user_email' and the user email contains 'test',
	// replace it with a placeholder for privacy.
	if ( 'user_email' === $match && is_string( $replaceable ) && strpos( $replaceable, 'test' ) !== false ) {
		$replaceable = '[email protected]';
	}

	return $replaceable;
}, 10, 3 );

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:330
src/core/deprecated/legacy-token-parser.php:432
src/core/lib/utilities/class-automator-input-parser.php:238

$replaceable = $this->replace_recipe_variables( $replace_args, $trigger_args, $trigger_id );

								break;

						}
					}
					$field_text = apply_filters( 'automator_maybe_parse_field_text', $field_text, $match, $replaceable );
					$field_text = str_replace( '{{' . $match . '}}', $replaceable, $field_text );
				} else {
					/**
					 * This section is for non-usermeta via "else". However, this is actually the Trigger tokens section.
					 *
					 * @todo Refactor this condition to not rely on "else" it should have its own condition. Or should be the default one.
					 */


Scroll to Top