Skip to content

Commit

Permalink
Now that WordPress#5655 has landed, use inherited methods for getting…
Browse files Browse the repository at this point in the history
… individual items.
  • Loading branch information
ramonjd committed May 18, 2024
1 parent a7d3e4b commit fd33d14
Showing 1 changed file with 0 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,56 +246,6 @@ public function get_items( $request ) {
return $response;
}

/**
* Retrieves one global styles revision from the collection.
*
* @since 6.5.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$parent = $this->get_parent( $request['parent'] );
if ( is_wp_error( $parent ) ) {
return $parent;
}

$revision = $this->get_revision( $request['id'] );
if ( is_wp_error( $revision ) ) {
return $revision;
}

$response = $this->prepare_item_for_response( $revision, $request );
return rest_ensure_response( $response );
}

/**
* Gets the global styles revision, if the ID is valid.
*
* @since 6.5.0
*
* @param int $id Supplied ID.
* @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise.
*/
protected function get_revision( $id ) {
$error = new WP_Error(
'rest_post_invalid_id',
__( 'Invalid global styles 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;
}

/**
* Prepares the revision for the REST response.
*
Expand Down

0 comments on commit fd33d14

Please sign in to comment.