Opened 9 years ago
Closed 9 years ago
#42296 closed defect (bug) (invalid)
REST API: logical error while checking for already deleted post
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.7.2 |
| Component: | REST API | Keywords: | |
| Focuses: | rest-api | Cc: |
Description
In the delete_item() method of the REST API posts controller, there's a piece of code that checks whether the post to be deleted has already been deleted before:
<?php if ( 'trash' === $post->post_status ) { return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) ); }
The problem with this code is that the post was fetched with the get_post() method that was introduced with Changeset 39954. That method already returns a rest_post_invalid_id if the post_type does not match the one that was used for constructing the controller. So the condition that is being checked for can never be true. It seems this was an unintentional breaking change in v4.7.2.
I can see two valid options for making this work correctly (and return the correct error type):
- Avoid the use of the
get_post()method indelete_item(), and fetch the post directly. This makes it possible to keep posts of typetrashas valid results still.
- Change the
get_post()method to also let posts of typetrashthrough. This might mean that some of the controller method might need additional filtering.
Change History (2)
Note: See
TracTickets for help on using
tickets.
@schlessera I might be missing something here, but the post_type doesn't change when a post is trashed, so why would
this->get_post()ever returnrest_post_invalid_id? It sounds as if you are getting post type and status crossed over?