wp_slash
Add slashes to a string or array of strings.
Description
(string|array) wp_slash( (string|array) $value );
This should be used when preparing data for core API that expects slashed data. This should not be used to escape data going directly into an SQL query.
Returns (string|array)
Slashed $value
Parameters (1)
- 0. $value (string|array)
- String or array of strings to slash.
Usage
if ( !function_exists( 'wp_slash' ) ) { require_once ABSPATH . WPINC . '/formatting.php'; } // String or array of strings to slash. $value = null; // NOTICE! Understand what this does before running. $result = wp_slash($value);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/formatting.php
- function wp_slash( $value ) {
- if ( is_array( $value ) ) {
- foreach ( $value as $k => $v ) {
- if ( is_array( $v ) ) {
- $value[$k] = wp_slash( $v );
- } else {
- $value[$k] = addslashes( $v );
- }
- }
- } else {
- $value = addslashes( $value );
- }
- return $value;
- }