WordPress开发者和主题制作者的搜索引擎



rest_sanitize_boolean ›

Since4.7.0
已弃用n/a
rest_sanitize_boolean ( $value )
参数:
  • (bool|string|int) $value The value being evaluated.
    Required: Yes
返回:
  • (boolean) Returns the proper associated boolean value.
定义在:
文档:

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



源码

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;
}