_wp_get_allowed_postdata() WordPress Function

The wp_get_allowed_postdata() function is used to retrieve data from a post that is allowed by the current user. This function is used to limit the data that is returned from a post to what the current user is allowed to see.

_wp_get_allowed_postdata( array|WP_Error|null $post_data = null ) #

Returns only allowed post data fields.


Parameters

$post_data

(array|WP_Error|null)(Optional)The array of post data to process, or an error object. Defaults to the $_POST superglobal.

Default value: null


Top ↑

Return

(array|WP_Error) Array of post data on success, WP_Error on failure.


Top ↑

Source

File: wp-admin/includes/post.php

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' ) ) );
}


Top ↑

Changelog

Changelog
VersionDescription
5.0.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.