wp_validate_boolean() WordPress Function

The wp_validate_boolean() function is used to validate a boolean value passed to a Wordpress function. This function ensures that the value passed is either true or false.

wp_validate_boolean( mixed $var ) #

Filter/validate a variable as a boolean.


Description

Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).


Top ↑

Parameters

$var

(mixed)(Required)Boolean value to validate.


Top ↑

Return

(bool) Whether the value is validated.


Top ↑

Source

File: wp-includes/functions.php

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

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

	return (bool) $var;
}


Top ↑

Changelog

Changelog
VersionDescription
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More