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