Filter Since 3.0 uncanny-automator

automator_replace_recipe_variables_do_shortcode

Maybe run a do_shortcode on the field itself if it contains a shortcode? Filters after recipe variables are replaced, optionally running `do_shortcode` on the resulting field content.

add_filter( 'automator_replace_recipe_variables_do_shortcode', $callback, 10, 3 );

Description

Fires after variable replacement within a recipe, allowing developers to conditionally process shortcodes within the replaced content. This filter controls whether `do_shortcode` is executed on the field value. Developers can return `false` to prevent shortcode execution or modify the shortcode output by returning a custom string.


Usage

add_filter( 'automator_replace_recipe_variables_do_shortcode', 'your_function_name', 10, 3 );

Parameters

$return (mixed)
- **$pieces** `mixed`
$recipe_id (mixed)
- **$trigger_data** `mixed`
$user_id (mixed)
- **$replace_args** `mixed`

Return Value

The filtered value.


Examples

/**
 * Processes shortcodes within a recipe variable before it's returned.
 *
 * This filter allows developers to control whether shortcodes embedded within
 * recipe variables (like from form submissions or post content) are parsed
 * and rendered.
 *
 * @param bool   $should_process_shortcodes Whether to process shortcodes. Defaults to true.
 * @param mixed  $return                  The current return value before this filter.
 * @param mixed  $pieces                  An array of pieces parsed from the token.
 * @param int    $recipe_id               The ID of the current Automator recipe.
 * @param array  $trigger_data            An array containing data from the trigger.
 * @param int    $user_id                 The ID of the user associated with the recipe.
 * @param array  $replace_args            An array of arguments used for replacement.
 *
 * @return bool The modified value to determine if shortcodes should be processed.
 */
add_filter(
	'automator_replace_recipe_variables_do_shortcode',
	function (
		$should_process_shortcodes,
		$return,
		$pieces,
		$recipe_id,
		$trigger_data,
		$user_id,
		$replace_args
	) {
		// Example: Conditionally disable shortcode processing if the user is
		// a specific role or if the recipe is for a certain action.
		$current_user = wp_get_current_user();
		if ( in_array( 'administrator', $current_user->roles, true ) ) {
			// Admins can always see rendered shortcodes.
			return true;
		}

		// Example: If the 'pieces' array indicates it's a specific type of
		// input where shortcodes might cause issues or are not intended,
		// disable processing.
		if ( isset( $pieces['type'] ) && 'plain_text_email_body' === $pieces['type'] ) {
			return false;
		}

		// Otherwise, respect the original decision or further modifications.
		return $should_process_shortcodes;
	},
	10, // Priority
	7  // Number of accepted arguments
);

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

/**
			 * Maybe run a do_shortcode on the field itself if it contains a shortcode?
			 *
			 * @ticket #2255
			 * @since 3.0
			 */

			if ( apply_filters(
				'automator_replace_recipe_variables_do_shortcode',
				true,
				$return,
				$pieces,
				$recipe_id,
				$trigger_data,
				$user_id,


Scroll to Top