addslashes_strings_only( mixed $value ): mixed

This function has been deprecated. Use wp_slash() instead.

Adds slashes only if the provided value is a string.

Description

See also

Parameters

$valuemixedrequired

Return

mixed

Source

function addslashes_strings_only( $value ) {
	return is_string( $value ) ? addslashes( $value ) : $value;
}

Changelog

VersionDescription
5.6.0This function has been deprecated. Use wp_slash() instead.
5.3.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    /* Example usage of addslashes_strings_only() */ 
    $string     = "This is a string with 'quotes'";
    $non_string = 12345;
    
    $escaped_string     = addslashes_strings_only( $string );
    $escaped_non_string = addslashes_strings_only( $non_string );
    
    echo "Original String: $string";
    echo "Escaped String: $escaped_string";
    
    echo "Original Non-string: $non_string";
    echo "Escaped Non-string: $escaped_non_string";

You must log in before being able to contribute a note or feedback.