rest_sanitize_boolean

Changes a boolean-like value into the proper boolean value.

Description

rest_sanitize_boolean( $value ); 

Parameters (1)

0. $value
The value.

Usage

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

Defined (1)

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

/includes/vendor/wp-rest-functions.php  
  1. function rest_sanitize_boolean( $value ) { 
  2. // String values are translated to `true`; make sure 'false' is false. 
  3. if ( is_string( $value ) ) { 
  4. $value = strtolower( $value ); 
  5. if ( in_array( $value, array( 'false', '0' ), true ) ) { 
  6. $value = false; 
  7.  
  8. // Everything else will map nicely to boolean. 
  9. return (boolean) $value;