rest_sanitize_array

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

rest_sanitize_array: 這是一個WordPress的函式,對一個陣列的值進行淨化,對陣列中的每個值應用適當的淨化過濾器: 這個函式用來確保傳遞給WordPress REST API的陣列可以安全使用。

將一個類似陣列的值轉換為陣列。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_sanitize_array( $maybe_array ) {
if ( is_scalar( $maybe_array ) ) {
return wp_parse_list( $maybe_array );
}
if ( ! is_array( $maybe_array ) ) {
return array();
}
// Normalize to numeric array so nothing unexpected is in the keys.
return array_values( $maybe_array );
}
function rest_sanitize_array( $maybe_array ) { if ( is_scalar( $maybe_array ) ) { return wp_parse_list( $maybe_array ); } if ( ! is_array( $maybe_array ) ) { return array(); } // Normalize to numeric array so nothing unexpected is in the keys. return array_values( $maybe_array ); }
function rest_sanitize_array( $maybe_array ) {
	if ( is_scalar( $maybe_array ) ) {
		return wp_parse_list( $maybe_array );
	}

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

	// Normalize to numeric array so nothing unexpected is in the keys.
	return array_values( $maybe_array );
}

常見問題

FAQs
檢視更多 >