WP_REST_Revisions_Controller::get_item()publicWP 4.7.0

Retrieves one revision from the collection.

Метод класса: WP_REST_Revisions_Controller{}

Хуков нет.

Возвращает

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

Использование

$WP_REST_Revisions_Controller = new WP_REST_Revisions_Controller();
$WP_REST_Revisions_Controller->get_item( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Список изменений

С версии 4.7.0 Введена.
С версии 6.5.0 Added a condition to check that parent id matches revision parent id.

Код WP_REST_Revisions_Controller::get_item() WP 6.6.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 );
}