stripslashes_deep( mixed $value )

Navigates through an array, object, or scalar, and removes slashes from the values.


Parameters Parameters

$value

(mixed) (Required) The value to be stripped.


Top ↑

Return Return

(mixed) Stripped value.


Top ↑

More Information More Information

If an array is passed, the array_map() function causes a callback to pass the value back to the function. The slashes from each value will be removed using the stripslashes() function.

SeeĀ Disabling Magic Quotes

WordPress ignores the built-in PHP magic quotes setting and the value of get_magic_quotes_gpc() and will always add magic quotes (even after the feature is removed from PHP in 5.4).

WordPress does this because too much core and plugin code have come to rely on the quotes being there, so disabling quotes on the superglobals (as is done in both the “Basic Example” and “Good Coding Practice” examples above) is likely to cause security holes.


Top ↑

Source Source

File: wp-includes/formatting.php

function stripslashes_deep( $value ) {
	return map_deep( $value, 'stripslashes_from_strings_only' );
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Good Coding Practice
    WordPress adds slashes to $_POST/$_GET/$_REQUEST/$_COOKIE regardless of what get_magic_quotes_gpc() returns. So in the context of WordPress, stripslashes() or stipslashes_deep() should always be used when using those variables.

    Example:

    $my_post = stripslashes_deep($_POST);
    $my_value = $my_post['value'];
    

    Or:

    $my_value = stripslashes($_POST['value']);
    
  2. Skip to note 2 content
    Contributed by Codex

    Basic Example
    You may want this function when developing your own PHP application intended to run within the WordPress environment. Specifically, your program needs to strip slashes when data arrives via $_POST, $_GET, $_COOKIE, and $_REQUEST arrays.

    An example would be a “Contact Me” page and the ancillary program that sanitizes the user-supplied text. Such user inputs typically travel from an HTML to your program by way of the $_POST array. stripslashes_deep(), in that case, could be used thus (caution, see notes below):

    $_POST = stripslashes_deep( $_POST );
    

    The stripslashes_deep() function is recursive and will walk through the $_POST array even when some of the elements are themselves an array.

    Please note: WordPress Core and most plugins will still be expecting slashes, and the above code will confuse and break them. If you must unslash, consider only doing it to your own data which isn’t used by others:

    $your_own_data = stripslashes_deep( $_POST['your_own_data'] );
    

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