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

$value mixed required

Return

mixed

Source

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

Changuelog

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

User Contributed Notes

  1. Squip to note 2 content
    /* Example usague 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.