Opened 9 years ago
Last modified 6 months ago
#36409 assigned defect (bug)
Comments number is wrong
Reported by: | sidati | Owned by: | pbearne |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch has-unit-tests |
Focuses: | template, performance | Cc: |
Description
Hi,
the comment number return the number of approved comments, this means all approved comments even those are replies to unapproved comments, for example if a user post comment and people replied to it, then the admin decide to hide this parent comment by disapproving it, the comment number will decrease only by one and keeping counting the hidden replies
So there are two option to fix that :
- Hold/Disapprove all children when disapproving the parent.
- Recalculate the comment number and excluding comments has an unapproved parent.
Regards,
Sidati
Attachments (3)
Change History (17)
#4
@
9 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
Hi @sidati - Thanks for the patch. I agree that this is unexpected and incorrect behavior.
Your basic idea for fixing it seems right to me. A couple comments on the patch:
- Could you generate it from the root of your WP installation? It makes it a bit easier to apply and test.
- Your
$depth
logic reads backward to me. I mean, I can see that the patch works, but I would've counted the depth up instead of down. Maybe our minds work differently ;) Anyway, I wonder if the algorithm would be more transparent (and less subject to bugs related to 'thread_comment_depth' if it looked something like this (pseudocode):
$bad_parents = $wpdb->get_col( "SELECT comment_ID from $wpdb->comments WHERE comment_approved != 1" ); $_bad_parents = array(); do { $_bad_parents = $wpdb->get_col( "SELECT comment_ID from $wpdb->comments WHERE comment_parent IN (" . implode( ',', array_map( 'intval', $bad_parents ) ) . ")"; $bad_parents += $_bad_parents; } while ( $_bad_parents );
This separates the initial comment_approved
query for clarity, and it ensures that we keep walking down the tree as long as bad comments are found.
We will also need unit tests to cover the problem.
#5
@
9 years ago
@boonebgorges;
I like your approach but if you realize the loop is infinite :), so i add a third variable to hold only the found children IDs to be used in the next loop.
You can test it now : 36409-3.patch
#6
in reply to:
↑ description
@
9 years ago
For what it's worth, this looks very similar to #18603. I sort of hope it fixes that one as well. :)
Art
This ticket was mentioned in Slack in #core-comments by sidati. View the logs.
8 years ago
#9
@
8 years ago
I'll create a plugin on github to solve this issue and post it here with unit-tests
This ticket was mentioned in PR #6431 on WordPress/wordpress-develop by @pbearne.
6 months ago
#11
- Keywords has-unit-tests added; needs-unit-tests removed
This update revises the logic used in the wp_update_comment_count_now function. The change ensures that unapproved comments and their children are not included when calculating the comment count for a post. This method involves creating a list of 'bad parents', which represents comments that are not approved, and their associated child comments.
Sorry wrong patch