WP_REST_Autosaves_Controller::get_item() WordPress Method

The WP_REST_Autosaves_Controller::get_item() method is used to retrieve an autosave for a post.

WP_REST_Autosaves_Controller::get_item( WP_REST_Request $request ) #

Get the autosave, if the ID is valid.


Parameters

$request

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


Top ↑

Return

(WP_Post|WP_Error) Revision post object if ID is valid, WP_Error otherwise.


Top ↑

Source

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

	public function get_item( $request ) {
		$parent_id = (int) $request->get_param( 'parent' );

		if ( $parent_id <= 0 ) {
			return new WP_Error(
				'rest_post_invalid_id',
				__( 'Invalid post parent ID.' ),
				array( 'status' => 404 )
			);
		}

		$autosave = wp_get_post_autosave( $parent_id );

		if ( ! $autosave ) {
			return new WP_Error(
				'rest_post_no_autosave',
				__( 'There is no autosave revision for this post.' ),
				array( 'status' => 404 )
			);
		}

		$response = $this->prepare_item_for_response( $autosave, $request );
		return $response;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.0.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.