rest_sanitize_boolean

函式
rest_sanitize_boolean ( $value )
引數
  • (bool|string|int) $value The value being evaluated.
    Required:
返回值
  • (bool) Returns the proper associated boolean value.
定義位置
相關方法
rest_sanitize_objectrest_is_booleanrest_sanitize_arrayrest_sanitize_request_argsanitize_bookmark
引入
4.7.0
棄用
-

rest_sanitize_boolean: 這是一個WordPress的函式,它對一個布林值進行淨化,確保它是真或假: 該函式用於確保傳遞給WordPress REST API的布林值可以安全使用。

將一個類似於布林值的值改變為適當的布林值。

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

常見問題

FAQs
檢視更多 >