wc_clean

Clean variables using sanitize_text_field.

Description

(string|array) wc_clean( (string|array) $var ); 

Arrays are cleaned recursively. Non-scalar values are ignored.

Returns (string|array)

Parameters (1)

0. $var (string|array)
The var.

Usage

  1. if ( !function_exists( 'wc_clean' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
  3.  
  4. // The var. 
  5. $var = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_clean($var); 
  9.  

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_clean( $var ) { 
  2. if ( is_array( $var ) ) { 
  3. return array_map( 'wc_clean', $var ); 
  4. } else { 
  5. return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;