rest_sanitize_boolean( bool|string|int $value )

Changes a boolean-like value into the proper boolean value.


Parameters Parameters

$value

(bool|string|int) (Required) The value being evaluated.


Top ↑

Return Return

(boolean) Returns the proper associated boolean value.


Top ↑

Source Source

File: wp-includes/rest-api.php

function rest_sanitize_boolean( $value ) {
	// String values are translated to `true`; make sure 'false' is false.
	if ( is_string( $value ) ) {
		$value = strtolower( $value );
		if ( in_array( $value, array( 'false', '0' ), true ) ) {
			$value = false;
		}
	}

	// Everything else will map nicely to boolean.
	return (bool) $value;
}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.