WP_REST_Template_Autosaves_Controller::get_item( WP_REST_Request $request ): WP_Post|WP_Error

In this article

Gets the autosave, if the ID is valid.

Parameters

$requestWP_REST_Requestrequired
Full details about the request.

Return

WP_Post|WP_Error Autosave post object if ID is valid, WP_Error otherwise.

Source

public function get_item( $request ) {
	$parent = $this->get_parent( $request['parent'] );
	if ( is_wp_error( $parent ) ) {
		return $parent;
	}

	$autosave = wp_get_post_autosave( $parent->ID );

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

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

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.