A WordPress-centric search engine for devs and theme authors



wp_validate_boolean ›

Since4.0.0
Deprecatedn/a
wp_validate_boolean ( $var )
Parameters:
  • (mixed) $var Boolean value to validate.
    Required: Yes
Returns:
  • (bool) Whether the value is validated.
Defined at:
Codex:

Filter/validate a variable as a boolean.

Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).



Source

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

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

	return (bool) $var;
}