wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_validate_boolean › WordPress Function

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

Filters/validates a variable as a boolean.

Alternative to filter_var( $value, FILTER_VALIDATE_BOOLEAN ).


Source

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

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

	return (bool) $value;
}