stripslashes_deep()
Navigates through an array, object, or scalar, and removes slashes from the values.
No Hooks.
Return
Mixed
. Stripped value.
Usage
stripslashes_deep( $value );
- $value(mixed) (required)
- The value to be stripped.
Examples
#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.
#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. |
stripslashes_deep() stripslashes deep code WP 6.7.2
function stripslashes_deep( $value ) { return map_deep( $value, 'stripslashes_from_strings_only' ); }