WordPress at a glance

wp_validate_boolean() WP 1.0

Filter/validate a variable as a boolean.

Alternative to filter_var($var, FILTER_VALIDATE_BOOLEAN ).

No Hooks.

Return

true/false. Whether the value is validated.

Usage

wp_validate_boolean( $var );
$var(mixed) (required)
Boolean value to validate.

Code of wp_validate_boolean: wp-includes/functions.php VER 4.9.8

<?php
function wp_validate_boolean( $var ) {
	if ( is_bool( $var ) ) {
		return $var;
	}

	if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
		return false;
	}

	return (bool) $var;
}

Related Functions

From category: Helper Functions

No comments
    Hello, !     Log In . Register