W3cubDocs

/WordPress

wp_validate_boolean( mixed $value ): bool

Filters/validates a variable as a boolean.

Description

Alternative to filter_var( $value, FILTER_VALIDATE_BOOLEAN ).

Parameters

$valuemixedrequired
Boolean value to validate.

Return

bool Whether the value is validated.

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.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_validate_boolean