Filter uncanny-automator

automator_skip_do_action_field_parsing

Filters whether to skip parsing of action fields for a given recipe and user.

add_filter( 'automator_skip_do_action_field_parsing', $callback, 10, 4 );

Description

Use this filter to bypass the default parsing of field text within Automator recipes. Developers can return `true` to prevent parsing, allowing custom handling of recipe field values based on the field text, recipe ID, user ID, and additional arguments. This offers granular control over how recipe data is processed.


Usage

add_filter( 'automator_skip_do_action_field_parsing', 'your_function_name', 10, 4 );

Parameters

$field_text (mixed)
This parameter contains the raw text of a field that might include shortcodes.
$recipe_id (mixed)
This parameter contains the text or value of a field that might need shortcode parsing.
$user_id (mixed)
This parameter is used to pass the ID of the current recipe being processed.
$args (mixed)
This parameter contains the ID of the user who is triggering the recipe.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'automator_skip_do_action_field_parsing' filter.
 *
 * This filter allows you to conditionally prevent the Automator plugin
 * from parsing specific fields for shortcodes or tokens. In this example,
 * we'll skip parsing if the $field_text contains the string "DEBUG_SKIP_PARSE".
 * This could be useful for debugging or for fields that should never be processed.
 *
 * @param mixed $field_text The current field text being processed.
 * @param mixed $recipe_id  The ID of the current recipe.
 * @param mixed $user_id    The ID of the user associated with the recipe.
 * @param mixed $args       Additional arguments passed to the filter.
 *
 * @return mixed The original $field_text if the condition is met, otherwise the default value (usually false).
 */
add_filter( 'automator_skip_do_action_field_parsing', function( $field_text, $recipe_id, $user_id, $args ) {

	// Check if the field text contains a specific debug string.
	if ( is_string( $field_text ) && strpos( $field_text, 'DEBUG_SKIP_PARSE' ) !== false ) {
		// If it does, return true to skip parsing.
		return true;
	}

	// Otherwise, return the default value (false) to allow parsing.
	return false;
}, 10, 4 );

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

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 ) );
	}


Scroll to Top