rest_is_boolean

函数
rest_is_boolean ( $maybe_bool )
参数
  • (bool|string) $maybe_bool The value being evaluated.
    Required:
返回值
  • (bool) True if a boolean, otherwise false.
定义位置
相关方法
rest_sanitize_booleanrest_is_objectrest_is_arrayrest_is_integerwp_validate_boolean
引入
4.7.0
弃用
-

rest_is_boolean: 这是一个WordPress的函数,用来检查一个值是否是布尔值。如果该值是布尔值,该函数返回真,否则返回假: 这个函数是用来验证和净化WordPress REST API的输入数据的。

确定一个给定的值是否是类布尔值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常见问题

FAQs
查看更多 >