Filter uncanny-automator

automator_skip_do_shortcode_parse_in_fields

Filters whether to skip shortcode parsing for specific automator fields, allowing for custom control.

add_filter( 'automator_skip_do_shortcode_parse_in_fields', $callback, 10, 1 );

Description

This filter allows developers to control which Automator action types should skip shortcode parsing within their field values. By returning an array of action codes, you can prevent shortcodes from being processed for specific actions, ensuring the literal shortcode remains intact. This is useful for actions that rely on the raw shortcode for their functionality.


Usage

add_filter( 'automator_skip_do_shortcode_parse_in_fields', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Disable shortcode parsing for specific action types.
 *
 * This example shows how to prevent shortcodes from being parsed within the fields
 * of certain Uncanny Automator actions. This might be useful if the action's
 * content is intended to be plain text or is handled by a different parsing mechanism.
 *
 * @param array $skip_actions An array of action codes that should skip shortcode parsing.
 *
 * @return array The modified array of action codes.
 */
function my_automator_disable_shortcode_parsing_for_certain_actions( $skip_actions ) {
	// Add a custom action code to the list of actions that should skip shortcode parsing.
	// For instance, if we had a custom action like 'SEND_EMAIL_HTML' that uses its own
	// templating engine and we don't want WordPress shortcodes to interfere.
	$skip_actions[] = 'SEND_EMAIL_HTML';

	// In this specific scenario, the original example already includes 'CREATEPOST' and 'BULKUPDATE_CODE'.
	// We're demonstrating adding another one. If you wanted to *remove* existing ones,
	// you'd need to use array_diff or unset.

	return $skip_actions;
}
// Add the filter with a priority of 10 and expecting 1 argument (the $skip_actions array).
add_filter( 'automator_skip_do_shortcode_parse_in_fields', 'my_automator_disable_shortcode_parsing_for_certain_actions', 10, 1 );

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

public function maybe_parse_shortcodes_in_fields( $field_text, $recipe_id = null, $user_id = null, $args = array() ) {

		$skip_do_shortcode_actions = apply_filters(
			'automator_skip_do_shortcode_parse_in_fields',
			array(
				'CREATEPOST',
				'BULKUPDATE_CODE',
			)
		);

		$action_meta_code = isset( $args['action_meta'] ) && isset( $args['action_meta']['code'] ) ? $args['action_meta']['code'] : '';
		if ( true === apply_filters( 'automator_skip_cslashing_value', false, $field_text, $action_meta_code, $recipe_id, $args ) ) {
			return $field_text;
		}

		// If filter is set to true OR action meta matches
		if ( in_array( $action_meta_code, $skip_do_shortcode_actions, true ) || true === apply_filters( 'automator_skip_do_action_field_parsing', $field_text, $recipe_id, $user_id, $args ) ) {
			// The function stripcslashes preserves the a, b, f, n, r, t and v characters.
			return apply_filters( 'automator_parse_token_parse_text', stripcslashes( $field_text ), $field_text, $args );
		}

		/**
		 * May be run a do_shortcode on the field itself if it contains a shortcode?
		 * Ticket# 22255
		 *
		 * @since 3.0
		 */
		return do_shortcode( apply_filters( 'automator_parse_token_parse_text', stripcslashes( $field_text ), $field_text, $args ) );
	}


Internal Usage

Found in uncanny-automator-pro/src/integrations/wp/actions/wp-setpostcontent.php:74:

add_filter( 'automator_skip_do_shortcode_parse_in_fields', array( $this, 'disable_input_parser_do_shortcode' ) );
Scroll to Top