Filter
uncanny-automator
automator_trait_action_parser_maybe_parse_tokens_should_process_shortcode
Filters whether shortcodes should be processed when parsing action tokens.
add_filter( 'automator_trait_action_parser_maybe_parse_tokens_should_process_shortcode', $callback, 10, 1 );
Description
Allows developers to conditionally prevent shortcode processing for token parsing. By default, shortcodes are processed. Return `false` to disable shortcode parsing for tokens, useful in specific scenarios where shortcode expansion might interfere with intended token resolution.
Usage
add_filter( 'automator_trait_action_parser_maybe_parse_tokens_should_process_shortcode', 'your_function_name', 10, 1 );
Parameters
-
$token_args(mixed) - This parameter is a boolean value that determines whether shortcodes should be processed by the token parser.
Return Value
The filtered value.
Examples
/**
* Prevent shortcode processing for specific tokens based on their arguments.
*
* For example, if a token's arguments indicate it's a sensitive piece of data
* that shouldn't be rendered as a shortcode, we can prevent it.
*
* @param bool $should_process_shortcode The current decision to process shortcodes.
* @param array $token_args The arguments passed to the token.
* @return bool Modified decision to process shortcodes.
*/
add_filter( 'automator_trait_action_parser_maybe_parse_tokens_should_process_shortcode', function( $should_process_shortcode, $token_args ) {
// If the token_args contain a key 'prevent_shortcode_processing' and it's set to true,
// then we should not process shortcodes for this token.
if ( isset( $token_args['prevent_shortcode_processing'] ) && true === $token_args['prevent_shortcode_processing'] ) {
return false;
}
// Otherwise, return the original decision.
return $should_process_shortcode;
}, 10, 2 );
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/lib/recipe-parts/actions/trait-action-parser.php:185
public function maybe_parse_tokens( $user_id, $action_data, $recipe_id, $args ) {
// Allows the parser to know that this action is under a loop.
if ( isset( $action_data['loop'] ) ) {
$args['loop'] = $action_data['loop'];
}
if ( ! array_key_exists( 'meta', $action_data ) ) {
return $this->get_parsed();
}
$metas = $action_data['meta'];
if ( empty( $metas ) ) {
return $this->get_parsed();
}
$this->pre_parse();
// Pass the 'should_apply_extra_formatting_property' to the $args['action_meta'] key.
$args['action_meta']['should_apply_extra_formatting'] = $this->get_should_apply_extra_formatting();
foreach ( $metas as $meta_key => $meta_value ) {
$is_json_string = Automator()->utilities->is_json_string( $meta_value );
// Parse the json string.
if ( true === $is_json_string ) {
// @added 5.9
$parser_args = array(
'recipe_id' => $recipe_id,
'user_id' => $user_id,
'args' => $args,
);
$json_parsed_string = $this->parse_json_string( $meta_value, $parser_args );
// Only skip if self::parse_json_string is successful.
if ( ! is_wp_error( $json_parsed_string ) ) {
$this->set_parsed( $meta_key, $json_parsed_string );
continue;
}
}
// Prevents autop when text only contains a single line.
if ( ! Automator()->utilities->has_multiple_lines( $meta_value ) ) {
$this->set_parsed( $meta_key, Automator()->parse->text( $meta_value, $recipe_id, $user_id, $args ) );
continue;
}
if ( ! $this->is_valid_token( $meta_key, $meta_value ) ) {
$parsed = Automator()->parse->text( $meta_value, $recipe_id, $user_id, $args );
$this->set_parsed( $meta_key, $this->should_wpautop( $parsed, $meta_key ) );
continue;
}
$parsed = Automator()->parse->text( $meta_value, $recipe_id, $user_id, $args );
$token_args = array(
'user_id' => $user_id,
'action_data' => $action_data,
'recipe_id' => $recipe_id,
'args' => $args,
);
$parsed = apply_filters( 'automator_pre_token_parsed', $parsed, $meta_key, $token_args );
$should_process_shortcode = apply_filters( 'automator_trait_action_parser_maybe_parse_tokens_should_process_shortcode', true, $token_args );
if ( true === $should_process_shortcode && $this->is_do_shortcode() ) {
$parsed = do_shortcode( $parsed );
}
$parsed = apply_filters( 'automator_post_token_parsed', $this->should_wpautop( $parsed, $meta_key ), $meta_key, $token_args );
$this->set_parsed( $meta_key, $parsed );
}
return $this->get_parsed();
}