WP_REST_Revisions_Controller::get_item()publicWP 4.7.0

Retrieves one revision from the collection.

Method of the class: WP_REST_Revisions_Controller{}

No Hooks.

Return

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

Usage

$WP_REST_Revisions_Controller = new WP_REST_Revisions_Controller();
$WP_REST_Revisions_Controller->get_item( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 4.7.0 Introduced.
Since 6.5.0 Added a condition to check that parent id matches revision parent id.

WP_REST_Revisions_Controller::get_item() code WP 6.5.2

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

	$revision = $this->get_revision( $request['id'] );
	if ( is_wp_error( $revision ) ) {
		return $revision;
	}

	if ( (int) $parent->ID !== (int) $revision->post_parent ) {
		return new WP_Error(
			'rest_revision_parent_id_mismatch',
			/* translators: %d: A post id. */
			sprintf( __( 'The revision does not belong to the specified parent with id of "%d"' ), $parent->ID ),
			array( 'status' => 404 )
		);
	}

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