rest_sanitize_object

函式
rest_sanitize_object ( $maybe_object )
引數
  • (mixed) $maybe_object The value being evaluated.
    Required:
返回值
  • (array) Returns the object extracted from the value.
定義位置
相關方法
rest_sanitize_booleanrest_is_objectsanitize_user_objectrest_sanitize_arrayrest_sanitize_request_arg
引入
5.5.0
棄用
-

rest_sanitize_object: 這是一個WordPress的函式,它對一個物件進行淨化,對物件中的每個屬性應用適當的淨化過濾器: 這個函式用來確保傳遞給WordPress REST API的物件可以安全使用。

將一個類似物件的值轉換為一個物件。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_sanitize_object( $maybe_object ) {
if ( '' === $maybe_object ) {
return array();
}
if ( $maybe_object instanceof stdClass ) {
return (array) $maybe_object;
}
if ( $maybe_object instanceof JsonSerializable ) {
$maybe_object = $maybe_object->jsonSerialize();
}
if ( ! is_array( $maybe_object ) ) {
return array();
}
return $maybe_object;
}
function rest_sanitize_object( $maybe_object ) { if ( '' === $maybe_object ) { return array(); } if ( $maybe_object instanceof stdClass ) { return (array) $maybe_object; } if ( $maybe_object instanceof JsonSerializable ) { $maybe_object = $maybe_object->jsonSerialize(); } if ( ! is_array( $maybe_object ) ) { return array(); } return $maybe_object; }
function rest_sanitize_object( $maybe_object ) {
	if ( '' === $maybe_object ) {
		return array();
	}

	if ( $maybe_object instanceof stdClass ) {
		return (array) $maybe_object;
	}

	if ( $maybe_object instanceof JsonSerializable ) {
		$maybe_object = $maybe_object->jsonSerialize();
	}

	if ( ! is_array( $maybe_object ) ) {
		return array();
	}

	return $maybe_object;
}

常見問題

FAQs
檢視更多 >