Filter uncanny-automator

automator_skip_cslashing_value

Filters the value before it's escaped to prevent extra slashes, useful for controlling output.

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

Description

Filters whether `stripslashes()` should be skipped for specific token values. Use this filter to prevent automatic slashes from being removed from token values within certain actions, like CREATEPOST or BULKUPDATE_CODE, when needed for maintaining data integrity.


Usage

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

Parameters

$field_text (mixed)
This parameter represents an array of action codes that should be skipped when parsing shortcodes in fields.
$action_meta_code (mixed)
This parameter contains the text of the field that might contain shortcodes.
$recipe_id (mixed)
This parameter is used to pass an array of action meta codes that should be skipped when parsing shortcodes in fields.
$args (mixed)
This parameter contains an array of action meta codes that should be skipped during shortcode parsing in fields.

Return Value

The filtered value.


Examples

add_filter(
	'automator_skip_cslashing_value',
	'my_automator_skip_cslashing_logic',
	10,
	5
);

/**
 * Conditionally skips the stripcslashes() function for specific scenarios.
 *
 * This filter allows developers to prevent stripcslashes() from being applied
 * to a value under certain conditions, which might be necessary for specific
 * actions or fields where escaped characters need to be preserved.
 *
 * For example, if you are dealing with a custom field that explicitly expects
 * escaped characters for its processing, you might want to use this filter
 * to bypass the default stripping.
 *
 * @param bool   $skip             The default value, indicating whether to skip stripcslashes().
 * @param mixed  $field_text       The text value being processed.
 * @param string $action_meta_code The code of the action meta.
 * @param int    $recipe_id        The ID of the current recipe.
 * @param array  $args             Additional arguments passed to the filter.
 *
 * @return bool True if stripcslashes() should be skipped, false otherwise.
 */
function my_automator_skip_cslashing_logic( $skip, $field_text, $action_meta_code, $recipe_id, $args ) {
	// Example: Skip stripcslashes for a specific custom action code if the field text contains a specific placeholder.
	$custom_action_to_prevent_slashes = 'MY_SPECIAL_ACTION';
	$placeholder_to_preserve_slashes  = '%%PRESERVE_SLASHES%%';

	if (
		$action_meta_code === $custom_action_to_prevent_slashes &&
		strpos( $field_text, $placeholder_to_preserve_slashes ) !== false
	) {
		// If it's our special action and the placeholder is present, skip stripcslashes.
		return true;
	}

	// Otherwise, rely on the default behavior.
	return $skip;
}

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

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