WP_REST_Revisions_Controller::get_parent() WordPress Method

The WP_REST_Revisions_Controller::get_parent() method is used to get the parent of a revision. This is useful for getting the post that a revision is for.

WP_REST_Revisions_Controller::get_parent( int $parent ) #

Get the parent post, if the ID is valid.


Parameters

$parent

(int)(Required)Supplied ID.


Top ↑

Return

(WP_Post|WP_Error) 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_parent( $parent ) {
		$error = new WP_Error(
			'rest_post_invalid_parent',
			__( 'Invalid post parent ID.' ),
			array( 'status' => 404 )
		);
		if ( (int) $parent <= 0 ) {
			return $error;
		}

		$parent = get_post( (int) $parent );
		if ( empty( $parent ) || empty( $parent->ID ) || $this->parent_post_type !== $parent->post_type ) {
			return $error;
		}

		return $parent;
	}


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.