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

  1. if ( !function_exists( 'wp_slash' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // String or array of strings to slash. 
  5. $value = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_slash($value); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function wp_slash( $value ) { 
  2. if ( is_array( $value ) ) { 
  3. foreach ( $value as $k => $v ) { 
  4. if ( is_array( $v ) ) { 
  5. $value[$k] = wp_slash( $v ); 
  6. } else { 
  7. $value[$k] = addslashes( $v ); 
  8. } else { 
  9. $value = addslashes( $value ); 
  10.  
  11. return $value;