WP_REST_Revisions_Controller::get_revision() WordPress Method

The WP_REST_Revisions_Controller::get_revision() method is used to retrieve a specific revision for a post. The method takes the post ID as a parameter and returns the revision object.

WP_REST_Revisions_Controller::get_revision( int $id ) #

Get the revision, if the ID is valid.


Parameters

$id

(int)(Required)Supplied ID.


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-revisions-controller.php

	protected function get_revision( $id ) {
		$error = new WP_Error(
			'rest_post_invalid_id',
			__( 'Invalid revision ID.' ),
			array( 'status' => 404 )
		);

		if ( (int) $id <= 0 ) {
			return $error;
		}

		$revision = get_post( (int) $id );
		if ( empty( $revision ) || empty( $revision->ID ) || 'revision' !== $revision->post_type ) {
			return $error;
		}

		return $revision;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.2Introduced.

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.