WP_REST_Revisions_Controller::get_parent() protected WP 4.7.2
Get the parent post, if the ID is valid.
{} It's a method of the class: WP_REST_Revisions_Controller{}
No Hooks.
Return
WP_Post/WP_Error. Post object if ID is valid, WP_Error otherwise.
Usage
// protected - for code of main (parent) or child class $result = $this->get_parent( $parent );
- $parent(int) (required)
- Supplied ID.
Changelog
Since 4.7.2 | Introduced. |
Code of WP_REST_Revisions_Controller::get_parent() WP REST Revisions Controller::get parent WP 5.6
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;
}