_wp_get_allowed_postdata

函式
_wp_get_allowed_postdata ( $post_data = null )
引數
  • (array|WP_Error|null) $post_data The array of post data to process, or an error object. Defaults to the `$_POST` superglobal.
    Required:
    Default: null
返回值
  • (array|WP_Error) Array of post data on success, WP_Error on failure.
定義位置
相關方法
_wp_translate_postdatawp_reset_postdataget_postdatawp_get_single_postwp_get_post_cats
引入
5.0.1
棄用
-

_wp_get_allowed_postdata: 這是一個WordPress的函式,用來檢索一個文章的允許文章資料,其中包括post_title、post_content、post_excerpt等欄位: 這個函式可以用來驗證和淨化通過表單提交的資料,然後再儲存到資料庫中。

只返回允許的文章資料欄位。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _wp_get_allowed_postdata( $post_data = null ) {
if ( empty( $post_data ) ) {
$post_data = $_POST;
}
// Pass through errors.
if ( is_wp_error( $post_data ) ) {
return $post_data;
}
return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
}
function _wp_get_allowed_postdata( $post_data = null ) { if ( empty( $post_data ) ) { $post_data = $_POST; } // Pass through errors. if ( is_wp_error( $post_data ) ) { return $post_data; } return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) ); }
function _wp_get_allowed_postdata( $post_data = null ) {
	if ( empty( $post_data ) ) {
		$post_data = $_POST;
	}

	// Pass through errors.
	if ( is_wp_error( $post_data ) ) {
		return $post_data;
	}

	return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
}

常見問題

FAQs
檢視更多 >