#35068 closed defect (bug) (fixed)
Comments not showing up when there are unapproved messages
Reported by: | arash_hemmat | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.4.1 | Priority: | normal |
Severity: | critical | Version: | 4.4 |
Component: | Comments | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Hi,
The problem occurs when there are some unapproved messages for a post.
If (sum of the root comments for a post (approved and unapproved) divided by the number of root comments in page) is more than the shown pagination number on the page, the comments have_comments() function returns false.
In my situation, the number of comments per page is set to 20, showing last page by default, displaying newest comments.
For example my post had 33 approved comments and 8 unapproved comments. The problem occurred when the eighth unapproved comment was added, the problem was resolved when all the eight were approved or one of them was deleted (sum of the comments would be 40 again)
Attachments (1)
Change History (15)
#2
@
9 years ago
- Keywords needs-patch removed
- Milestone changed from Awaiting Review to 4.4.1
- Severity changed from normal to critical
#4
@
9 years ago
- Keywords has-patch needs-testing added
35068.diff should make the problem fairly clear, but just to spell it out a bit more: The improved paginated-comment queries in 4.4 work by only querying for the specific comments that the current comment-page needs, rather than *all* of the post's comments. See #8071. We do this by passing 'number' and 'offset' params to WP_Comment_Query
in comments_template()
.
Generally, the calculation of 'number' and 'offset' is pretty simple, given that we usually have comments_per_page
and cpage
. But the case where 'default_comments_page=newest' and where we're looking at the post permalink (no cpage) is a special one: we need to show the last page of comments, but the only way to know the proper offset for the "last" comments is to have a count of all comments on the post. The problem in 4.4 is that the total-top-level-comments-for-the-post query does not account for 'comment_approved'. https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes/comment-template.php?marks=1316-1323#L1300
Could I get a second (and third and fourth) set of eyes on the patch and tests? Sorry for the ugliness of the tests, btw - blame comments_template()
, not me :-D
#5
@
9 years ago
@boonebgorges: 35068.diff looks pretty straightforward and the tests pass. Did you mean to leave the var_dump()
in the tests?
#6
@
9 years ago
@DrewAPicture Thanks for looking. No I didn't mean to leave var_dump()
there - it didn't show up when testing because it's inside of an output buffer, so good catch.
Note to self that this problem was sorta independently found here https://wordpress.org/support/topic/wp-44-update-comments-with-last-page-displayed-by-default-are-not-showing
#7
follow-up:
↓ 8
@
9 years ago
I haven't tested, but I just wanted to check - will this include unapproved comments by the current user?
#8
in reply to:
↑ 7
@
9 years ago
Replying to pento:
I haven't tested, but I just wanted to check - will this include unapproved comments by the current user?
Yes: unapproved comments by the current user are (and always have been) counted when calculating pagination; with 35068.diff, they will also be counted when calculating the max-number-of-pages.
#9
@
9 years ago
- Owner set to boonebgorges
- Status changed from new to assigned
One additional thing, looks like you left @group bbg
on one of the tests. Otherwise, this looks good to me.
assigning to @boonebgorges as comment query master.
#10
@
9 years ago
assigning to @boonebgorges as comment query master.
A title I wish I'd never taken on. Thanks for the review.
Thanks very much for the report.
I've confirmed the problem. The offset calculation in the new
comments_template()
does not properly account for approval status. I've got a fix coming up.