Filters/validates a variable as a boolean.
Description
Alternative to filter_var( $value, FILTER_VALIDATE_BOOLEAN )
.
Parameters
$value
mixedrequired- Boolean value to validate.
Source
function wp_validate_boolean( $value ) {
if ( is_bool( $value ) ) {
return $value;
}
if ( is_string( $value ) && 'false' === strtolower( $value ) ) {
return false;
}
return (bool) $value;
}
Changelog
Version | Description |
---|---|
4.0.0 | Introduced. |
wp_validate_boolean() tests: