WP_REST_Global_Styles_Revisions_Controller::get_parent( int $parent_post_id ): WP_Post|WP_Error

Gets the parent post, if the ID is valid.


Description

Duplicate of WP_REST_Revisions_Controller::get_parent() .


Top ↑

Parameters

$parent_post_id 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-global-styles-revisions-controller.php. View all references

protected function get_parent( $parent_post_id ) {
	$error = new WP_Error(
		'rest_post_invalid_parent',
		__( 'Invalid post parent ID.' ),
		array( 'status' => 404 )
	);

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

	$parent_post = get_post( (int) $parent_post_id );

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

	return $parent_post;
}


Top ↑

Changelog

Changelog
Version Description
6.3.0 Introduced.

Top ↑

User Contributed Notes

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