WP_REST_Post_Statuses_Controller::get_items() WordPress Method

The WP_REST_Post_Statuses_Controller::get_items() method is used to retrieve a list of post statuses. This is useful for finding out which statuses are available for posts, and for creating custom endpoints that return a specific status.

WP_REST_Post_Statuses_Controller::get_items( WP_REST_Request $request ) #

Retrieves all post statuses, depending on user context.


Parameters

$request

(WP_REST_Request)(Required)Full details about the request.


Top ↑

Return

(WP_REST_Response|WP_Error) Response object on success, or WP_Error object on failure.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php

	public function get_items( $request ) {
		$data              = array();
		$statuses          = get_post_stati( array( 'internal' => false ), 'object' );
		$statuses['trash'] = get_post_status_object( 'trash' );

		foreach ( $statuses as $slug => $obj ) {
			$ret = $this->check_read_permission( $obj );

			if ( ! $ret ) {
				continue;
			}

			$status             = $this->prepare_item_for_response( $obj, $request );
			$data[ $obj->name ] = $this->prepare_response_for_collection( $status );
		}

		return rest_ensure_response( $data );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

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.