wp_validate_boolean

Filter/validate a variable as a boolean.

Description

wp_validate_boolean( (mixed) $var ); 

Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN )..

Parameters (1)

0. $var (mixed)
Boolean value to validate.

Usage

  1. if ( !function_exists( 'wp_validate_boolean' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Boolean value to validate. 
  5. $var = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_validate_boolean($var); 
  9.  

Defined (1)

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

/wp-includes/functions.php  
  1. function wp_validate_boolean( $var ) { 
  2. if ( is_bool( $var ) ) { 
  3. return $var; 
  4.  
  5. if ( is_string( $var ) && 'false' === strtolower( $var ) ) { 
  6. return false; 
  7.  
  8. return (bool) $var;