Make WordPress Core

Opened 4 years ago

Last modified 2 months ago

#55309 new enhancement

Incorrect post comment count after deleting comment with replies

Reported by: jwz's profile jwz Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Comments Keywords:
Focuses: Cc:

Description

If you move a comment to the trash, and that comment has sub-comments, none of those comments are visible (which is desired) but post->comment_count is reduced by 1 rather than by the total number of comments that have now been hidden.

For example: post has 1 comment with 3 replies. Comment count is 4. Delete the first comment. Now no comments are visible but comment count is 3.

The first comment has comment_approved set to 'trash' but the other 3 comments are still '1'. Perhaps the right fix is that when trashing a comment, all of its sub-comments are also trashed explicitly rather than implicitly.

Change History (6)

#1 @davidbaumwald
4 years ago

  • Keywords dev-feedback added

@jwz I'm going to tag this for dev-feedback to see if a conversation can be sparked to determine _if_ this should be done. I agree, it seems reasonable since those comments are no longer visible.

In the interim, you could always filter the number of comments for each post when the count is updated by using the pre_wp_update_comment_count_now hook and checking the parent comment of each child comment's status.

#2 @callumbw95
7 months ago

Hi @jwz,
I agree with @davidbaumwald here and believe there should be more conversation around this. I have also included a test report below to hopefully help increase the visibility of this ticket:

Bug Report

Description

Deleting the parent comment still counts the child comments for a post on the post comment count.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.4.7
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.4.7)
  • Browser: Chrome 137.0.0.0
  • OS: macOS
  • Theme: Twenty Seventeen 3.9
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Steps to Reproduce

  1. Add a comment to a post. (comment count: 1)
  2. Add a reply to the comment. (comment count: 2)
  3. Delete the top level comment. (comment count: 1)

Expected Results

  1. No comments are displayed on the front end.
  2. The comment count for the post is equal to the displayed comments on the post, in this case 0.

Actual Results

  1. No comments are displayed on the front end.
  2. The comment count displays active comments on the post, in this scenario 1, however should this be counting child comments to comments that have been deleted?

Additional Notes

  • Whilst from a technical perspective it makes sense to count all comments that are linked to the post, should we counting child comments that are under a deleted comment?
  • Technically what is happening now is "correct", but isn't the clearest as it is somewhat ambiguous, and could cause some confusion when comments don't show on a post.

#3 @SirLouen
7 months ago

  • Keywords 2nd-opinion added; dev-feedback removed
  • Type changed from defect (bug) to enhancement

Personally, I think that we should take the same approach as very well established places like Reddit:

In the case of parent deletion, a placeholder comment should appear with the text "Deleted" or "Deleted Comment" and the rest of the child non-deleted posts should appear afterwards.

No need to modify the post count, nor trash the child comments.

#4 @desrosj
3 months ago

  • Keywords 2nd-opinion removed

I found this while working on the new Notes feature for WordPress 6.9, which under the hood is using the default comment object with a new note comment type. I discovered a bug where nested comments were not also being trashed when the parent note was.

I did a bit of research that I think may be helpful for this ticket, so sharing it here as well.

I think that there are reasonable arguments for both sides of the argument: child comments to continue showing vs. they are hidden (current behavior).

I took a few minutes and looked into how this is handled and I found conflicting experiences in the wild with very large social networks.

One instance is Reddit.

  • User deletes their account, the comment remains and their user shows as deleted.
  • User deletes the comment itself, then both user and comment text show as deleted.
  • If a user is blocked by the comment author, the comment and author are shown as deleted.

In all scenarios, every nested comments remains.

On the other hand, deleting a comment on Facebook that has replies or nested comments deletes all of the child comments.

The current behavior in Core is somewhere in between. Child comments are not deleted, but they are no longer shown on the front end. This is the same regardless of whether the top level comment is trashed or marked as spam.

For Notes, I have recommended that we follow the Google Docs model of trashing all replies for the given Note at the same time. But coming back to default comments, There are several tickets that need to be taken into account as this is in some ways a foundational problem. This is not an all-encompassing list, but it shows that there are inconsistencies in how WordPress handles deleting parent comments, counting comments who's parents have been trashed/deleted/marked as spam, re-nesting child comments, etc. #63931, #53674, #54234, #63931.

#5 @SirLouen
3 months ago

  • Version 5.9.1 deleted

Related #63931

Note: See TracTickets for help on using tickets.