Filter uncanny-automator

automator_parse_token_parse_text_autostripcslashes

Filters the parsed text, automatically removing backslashes before processing to clean up token data.

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

Description

Fires before stripcslashes() is applied to parsed text. Allows developers to prevent automatic backslash stripping by returning false, or to modify the text before stripping occurs. Defaults to true, enabling stripping.


Usage

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

Parameters

$text (mixed)
This parameter determines whether `stripcslashes()` should be automatically applied to the provided text.

Return Value

The filtered value.


Examples

add_filter( 'automator_parse_token_parse_text_autostripcslashes', 'my_custom_automator_autostripcslashes', 10, 2 );

/**
 * Custom logic to conditionally disable or modify the stripcslashes behavior
 * for automator parsed text.
 *
 * This example demonstrates how to prevent stripcslashes from running if the
 * text contains a specific placeholder or if it's a particular type of input
 * that shouldn't be stripped.
 *
 * @param mixed $autostripcslashes Whether to perform stripcslashes. Default is true.
 * @param mixed $text              The text being processed.
 *
 * @return mixed Returns true to continue with stripcslashes, false or other value to prevent it.
 */
function my_custom_automator_autostripcslashes( $autostripcslashes, $text ) {

	// Do not strip slashes if the text contains a specific placeholder,
	// for instance, if it's a dynamic shortcode that might have escaped characters
	// that should be preserved.
	if ( is_string( $text ) && str_contains( $text, '[automator_preserve_slashes]' ) ) {
		return false; // Prevent stripcslashes
	}

	// Example: Only allow stripcslashes for specific user roles or contexts.
	// This is a simplified check, in a real scenario you might check user capabilities.
	// if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
	//     return true; // Allow stripcslashes for administrators
	// } else {
	//     return false; // Prevent stripcslashes for other users
	// }

	// If none of the specific conditions are met, return the original value
	// to let the default logic decide.
	return $autostripcslashes;
}

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/utilities/class-automator-input-parser.php:898

public function stripcslashes( $text ) {

		if ( ! is_string( $text ) ) {
			return $text;
		}

		$autostripcslashes = apply_filters( 'automator_parse_token_parse_text_autostripcslashes', true, $text );

		if ( true === $autostripcslashes ) {
			return stripcslashes( $text );
		}

		return $text;
	}


Scroll to Top