On this page
rest_is_boolean( bool|string $maybe_bool ): bool
Determines if a given value is boolean-like.
Parameters
$maybe_boolbool|string Required-
The value being evaluated.
Return
bool True if a boolean, otherwise false.
Source
File: wp-includes/rest-api.php. View all references
function rest_is_boolean( $maybe_bool ) {
if ( is_bool( $maybe_bool ) ) {
return true;
}
if ( is_string( $maybe_bool ) ) {
$maybe_bool = strtolower( $maybe_bool );
$valid_boolean_values = array(
'false',
'true',
'0',
'1',
);
return in_array( $maybe_bool, $valid_boolean_values, true );
}
if ( is_int( $maybe_bool ) ) {
return in_array( $maybe_bool, array( 0, 1 ), true );
}
return false;
}
Related
Used By
| Used By | Description |
|---|---|
| rest_validate_boolean_value_from_schema() wp-includes/rest-api.php | Validates a boolean value based on a schema. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_is_boolean