Filter
uncanny-automator
automator_action_tokens_interpolate_tokens_with_values_max_iteration
Filters the maximum number of iterations allowed during token interpolation for automator actions.
add_filter( 'automator_action_tokens_interpolate_tokens_with_values_max_iteration', $callback, 10, 1 );
Description
Filters the maximum number of iterations for interpolating tokens with values. Developers can use this to prevent infinite loops by adjusting the default limit of 5, ensuring token replacement processes complete efficiently.
Usage
add_filter( 'automator_action_tokens_interpolate_tokens_with_values_max_iteration', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
// Increase the maximum iteration limit for token interpolation to 10.
// This might be useful if you have deeply nested or complex token structures
// that require more iterations to fully resolve.
add_filter(
'automator_action_tokens_interpolate_tokens_with_values_max_iteration',
function ( $max_iterations ) {
// The default is 5. Let's increase it to 10.
return 10;
},
10, // Priority: Higher priority means it runs later.
1 // Accepted args: The filter callback accepts only one argument.
);
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/parser.php:116
public function parse( $field_text, $args, $trigger_args ) {
// Max depth depth of 5.
$max_iteration = apply_filters( 'automator_action_tokens_interpolate_tokens_with_values_max_iteration', 5 );
// Initiate to 0.
$count_iteration = 0;
$replaceables = $this->get_replace_pairs( $field_text, $trigger_args, $args );
if ( false === $replaceables ) {
return $field_text;
}
if ( ! empty( $replaceables ) ) {
// The strtr array format is '[ {{{ACTION_FIELD: % d: % s}}} ] => $actual_value'.
$field_text = strtr( $args['field_text'], $replaceables );
// Do recursive magic ➰ for either of these action tokens.
$do_iterate = true;
while ( $do_iterate && ( strpos( $field_text, '{{ACTION_FIELD' ) || strpos( $field_text, '{{ACTION_META' ) ) ) {
++$count_iteration;
// Terminate safely, in case for some reason, unexpected input turns into infinite loop.
if ( $count_iteration >= $max_iteration ) {
$do_iterate = false;
}
$field_text = strtr( $field_text, $this->get_replace_pairs( $field_text, $trigger_args, $args ) );
}
}
return $field_text;
}