Opened 2 years ago
Closed 20 months ago
#57023 closed defect (bug) (fixed)
_update_posts_count_on_delete() is still called incorrectly
Reported by: | SergeyBiryukov | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Posts, Post Types | Keywords: | has-patch |
Focuses: | multisite | Cc: |
Description
Some history of the affected code:
- [28835] introduced
_update_posts_count_on_delete()
hooked todelete_post
. - [52207] moved the call to
after_delete_post
, which runs after the post is actually deleted from the database.
The issue is that _update_posts_count_on_delete()
checks the status of the post being deleted, and then only calls update_posts_count()
if the deleted post was previously published, as the query would be unnecessary otherwise. Since the post is no longer available, the function bails early and update_posts_count()
is never called:
- In [28835], the post count could be off by one because the function was called too early.
- In [52207], the function is called in the right place, but the post status check no longer works.
Why didn't the associated unit test catch this? Because it calls wp_delete_post()
without the $force_delete
argument, so the post is actually trashed, not deleted, and the after_delete_post
action never runs.
Coincidentally, the assertion still works because of _update_posts_count_on_transition_post_status()
, which runs on transition_post_status
as the post is trashed. That means the test passes, but it does not test both callbacks as it's supposed to, only one of them.
Since after_delete_post
receives the post object as the second argument, the solution would be to use that object for the status check, instead of trying to retrieve the post by an ID that no longer exists.
Attachments (2)
Change History (10)
#3
@
2 years ago
- Keywords has-patch added
57023.diff fixes the issue and corrects the test so that it actually fails before the fix and passes after.
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
20 months ago
#6
@
20 months ago
This ticket was discussed during the recent bug scrub. It looks like it's unlikely that work will be done on this during the 6.2 cycle.
@SergeyBiryukov Is this still possible to land in 6.2, or should it be moved to Future Release
for now?
In 54760: