[wp-trac] [WordPress Trac] #32991: wp_delete_post() does not return a WP_Post object

WordPress Trac noreply at wordpress.org
Tue Jul 14 16:32:01 UTC 2015

#32991: wp_delete_post() does not return a WP_Post object
 Reporter:  johnbillion                         |       Owner:
     Type:  defect (bug)                        |      Status:  new
 Priority:  normal                              |   Milestone:  Future
Component:  Posts, Post Types                   |  Release
 Severity:  normal                              |     Version:
 Keywords:  needs-docs needs-patch 2nd-opinion  |  Resolution:
                                                |     Focuses:
Changes (by DrewAPicture):

 * milestone:  Awaiting Review => Future Release


 Turns out that the return documentation is actually ''still'' incorrect
 because `wp_trash_post()` can return a `WP_Post` object. Should be
 `array|false|stdClass|WP_Post`, though once we get above about three or
 four types it makes a lot more sense to use something like a `mixed` type
 for readability (what it used to be prior to [29093]).

 That said, I definitely introduced the incorrect return documentation in
 [29093], not paying close enough attention that we were returning the row
 directly (looks like a `WP_Post` object, talks like a `WP_Post` object,
 but isn't one).

 Don't know that there's any other explanation than that maybe
 `wp_delete_post()` was introduced (sometime before [1353]) before
 `get_post()` [2478] and never got switched over from `wpdb->get_row()` to

 For that matter, looks like `wp_delete_attachment()` also returns the row
 instead of a `WP_Post` object though `wp_trash_post()` returns a `WP_Post`

 Seems like we might be safe in switching it now, especially since these
 two functions seem to be the exception. Also worth noting that
 `clean_post_cache()` takes the object through `get_post()`, so we might as
 well bring `wp_delete_post()` and `wp_delete_attachment()` into the fold.

Ticket URL: <https://core.trac.wordpress.org/ticket/32991#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list