Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#11073 closed defect (bug) (fixed)

Comment Status for Posts in the Trash

Reported by: mtdewvirus Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.9
Component: Comments Keywords: comments, trash, dev-reviewed
Focuses: Cc:


When sending a post to the trash, the status of the comments associated with the post do not get changed. The comments still get counted for the totals displayed in the Right Now module on the Dashboard. The comments are also counted and used for the paging links on the Edit Comments screen, so you end up with empty pages.

When a post is permanently deleted from the trash, the comments do not get deleted. The comments are still counted as explained above.

Tested with r12139

Attachments (5)

11073.diff (3.9 KB) - added by ryan 6 years ago.
11073.2.diff (4.3 KB) - added by ryan 6 years ago.
11073.3.diff (4.3 KB) - added by ryan 6 years ago.
11073.4.diff (4.4 KB) - added by ryan 6 years ago.
11073.5.diff (4.9 KB) - added by ryan 6 years ago.

Download all attachments as: .zip

Change History (17)

#1 @ryan
6 years ago

The right now counts being off are due to [12116]. The query that gets the counts right is very slow. This might also be affecting the paging.

#2 @ryan
6 years ago

(In [12141]) Fix comment and postmeta delete queries when deleting a post. see #11073

6 years ago

#3 @ryan
6 years ago

Patch introduce wp_trash_post_comments() and wp_untrash_post_comments(). Comments for trashed posts have their status (comment_approved) set to post-trashed. Changing the status allows us to avoid slow joins with the posts table while keeping correct comment counts. A status of "post-trashed" is used instead of "trash" so that comments belonging to a trashed post don't show up in the comment trash. They cannot be restored if their post is trashed so showing them is confusing. The queries in edit-comments.php still use the join on the posts table. I left it there for the moment so that comments whose post was trashed prior to this patch don't show up.

Status for each comment is preserved in an array in postmeta. Status is restored when the post is untrashed. If a comment was in the trash before the post was trashed, it will remain in the trash with its previous state still stored in commentmeta.

#4 @ryan
6 years ago

Using wp_set_comment_status() causes new comment notifications to be sent. It's also slow. I think I'll do some raw updates, maybe do one update per status type in the statuses array.

6 years ago

6 years ago

#5 @ryan
6 years ago

Use direct UPDATEs instead of API to change comment status. Much faster and avoids the state transitions that cause email notifications to be sent.

#6 @westi
6 years ago

11073.3.diff comments:

  • _wp_trash_meta_comment_status should be _wp_trash_meta_comments_status as it is for more than one comment.
  • Code has a race condition between collecting the comments to be post_trashed and the post_trashing - any comments which arrive between that period will have there status lost which could be an issue on high volume sites - they would lost on restore as we treat the post_meta as gold

6 years ago

#7 @ryan
6 years ago

New patch addressing westi's comments.

#8 @ryan
6 years ago

wp-comments-post.php needs to check for trash status on the post.

6 years ago

#9 @ryan
6 years ago

Patch adds check for trash status to wp-comments-post.php to narrow race condition window.

#10 @westi
6 years ago

  • Keywords dev-reviewed added


#12 @ryan
6 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.