automator_action_token_input_parser_text_field_text
Filters the arguments for the text field input parser to customize token handling in automator actions.
add_filter( 'automator_action_token_input_parser_text_field_text', $callback, 10, 3 );
Description
Filters the text content of a text field used for action tokens within the Uncanny Automator core. This hook allows developers to modify or augment token text before it's parsed, offering control over how dynamic data is displayed in action configurations. It's useful for custom token formatting or conditional text generation.
Usage
add_filter( 'automator_action_token_input_parser_text_field_text', 'your_function_name', 10, 3 );
Parameters
-
$args(mixed) - The `$field_text` parameter contains the text value entered by the user into the text field.
-
$args(mixed) - This parameter contains the text value from the input field that needs to be parsed.
-
$trigger_args(mixed) - This parameter contains the ID of the recipe that the current action belongs to.
Return Value
The filtered value.
Examples
/**
* Example function to modify the text field content for action tokens.
* This could be used to append a specific suffix to a token's value.
*
* @param string $field_text The original text field value.
* @param array $args An array of arguments passed to the filter. Includes recipe_id, user_id, action_data, etc.
* @param array $trigger_args An array of arguments related to the trigger.
*
* @return string The modified text field value.
*/
function my_automator_modify_action_token_text( $field_text, $args, $trigger_args ) {
// Only modify if a specific action_data key is present, for example.
if ( isset( $args['action_data']['some_specific_key'] ) && $args['action_data']['some_specific_key'] === 'special_value' ) {
// Append a custom string to the existing field text.
$field_text .= ' (Processed by custom function)';
}
// You could also conditionally remove or replace parts of the text.
// For instance, if the field_text is a URL, you might want to ensure it starts with 'https://'.
if ( strpos( $field_text, 'http://' ) === 0 ) {
$field_text = str_replace( 'http://', 'https://', $field_text );
}
return $field_text;
}
add_filter( 'automator_action_token_input_parser_text_field_text', 'my_automator_modify_action_token_text', 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:855
src/core/lib/utilities/class-automator-input-parser.php:813
public function text( $field_text = null, $recipe_id = null, $user_id = null, $trigger_args = null ) {
// Sanity check that there was a $field_text passed
if ( null === $field_text ) {
return null;
}
$args = array(
'field_text' => $field_text,
'meta_key' => null,
'user_id' => $user_id,
'action_data' => isset( $trigger_args['action_meta'] ) ? $trigger_args['action_meta'] : null,
'recipe_id' => $recipe_id,
);
// Action tokens hook.
$args['field_text'] = apply_filters( 'automator_action_token_input_parser_text_field_text', $args['field_text'], $args, $trigger_args );
if ( ! empty( $trigger_args['trigger_log_id'] ) ) {
$args['trigger_log_id'] = $trigger_args['trigger_log_id'];
}
if ( ! empty( $trigger_args['run_number'] ) ) {
$args['run_number'] = $trigger_args['run_number'];
}
if ( ! empty( $trigger_args['recipe_log_id'] ) ) {
$args['recipe_log_id'] = $trigger_args['recipe_log_id'];
}
if ( ! empty( $trigger_args['trigger_id'] ) ) {
$args['trigger_id'] = $trigger_args['trigger_id'];
}
if ( isset( $trigger_args['recipe_triggers'] ) ) {
$args['recipe_triggers'] = $trigger_args['recipe_triggers'];
}
if ( isset( $trigger_args['action_meta'] ) ) {
$args['action_meta'] = $trigger_args['action_meta'];
}
$field_text = apply_filters( 'automator_text_field_parsed', $this->parse_vars( $args, $trigger_args ), $args );
return $this->maybe_parse_shortcodes_in_fields( $field_text, $recipe_id, $user_id, $args );
}
Internal Usage
Found in src/core/services/loopable/action-loopable-token.php:73:
add_filter( 'automator_action_token_input_parser_text_field_text', array( $this, 'hydrate_loopable_parent_action_token' ), 10, 3 );
Found in src/core/services/recipe/action/token/registry.php:42:
add_filter( 'automator_action_token_input_parser_text_field_text', array( new Parser(), 'replace_key_value_pairs' ), 10, 3 );