stripslashes_deep()WP 2.0.0

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

Used By: wp_unslash()

No Hooks.

Return

Mixed. Stripped value.

Usage

stripslashes_deep( $value );
$value(mixed) (required)
The value to be stripped.

Examples

0

#1 Remove slashes from global arrays

Suppose we need to clear the global arrays $_POST, $_GET, $_COOKIE, or $_REQUEST from slashes while developing our application in the WordPress environment.

For example, we create a contact page in which we use a form to send a message. To get data without slashes sent through this form, we can pass the entire $_POST array through the function:

$_POST = stripslashes_deep( $_POST );

The function will go through all data, even if the array is multidimensional, and remove \ from all array values and sub-arrays.

0

#2 Good code practice

WordPress adds slashes to $_POST/$_GET/$_REQUEST/$_COOKIE regardless of what get_magic_quotes_gpc() returns. Therefore, in the context of WordPress, you should always remove escaped slashes when using these global variables.

Example:

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

Or:

$my_value = stripslashes( $_POST['value'] );

Changelog

Since 2.0.0 Introduced.

Code of stripslashes_deep() WP 5.9.3

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