#34073 closed defect (bug) (fixed)
Comment walker calls get_comment_link with invalid arguments
Reported by: | peterwilsoncc | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Comments | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
The comment walker calls get_comment_link such the the returned link is always includes the first page of comment pagination links, ie comment-page-1
(literally one, not any positive integer).
The pagination portion of the $args passed by the walker always sets the page to 1.
array(15) { // snip ["page"]=> int(1) ["per_page"]=> string(1) "5" // snip }
Attachments (2)
Change History (17)
#2
follow-up:
↓ 3
@
9 years ago
- Keywords reporter-feedback added
- Milestone changed from Awaiting Review to 4.4
See #8071. The way it used to work is that comments_template()
would fetch *all* comments, and Walker_Comment
would handle pagination. [34561] changed this behavior so that only the proper comments are fetched in the initial query. Then, to fool Walker_Comment
into displaying all and only the comments we pass to it, we pass 'page=1'.
It appears that the problem with get_comment_link()
occurs only when a theme doesn't provide a comment-formatting 'callback' param, or when the callback explicitly passes $args
to get_comment_link()
. (I guess I'd been testing with default themes - like twentytwelve - that get_comment_link()
without any parameters.) Can you share your setup when testing? What theme are you using?
I'll need to do some more analysis, but it may be that in order to fix this, get_comment_link()
will need to ignore some of the $args
passed to it in at least some cases. Grumble grumble grumble.
#3
in reply to:
↑ 2
@
9 years ago
- Keywords reporter-feedback removed
Replying to boonebgorges:
It appears that the problem with
get_comment_link()
occurs only when a theme doesn't provide a comment-formatting 'callback' param, or when the callback explicitly passes$args
toget_comment_link()
. (I guess I'd been testing with default themes - like twentytwelve - thatget_comment_link()
without any parameters.) Can you share your setup when testing? What theme are you using?
Of course:
- trunk install using twenty fifteen
- five comments per page
- occurred in both first- and last page first modes
- test post had twelve comments
twenty fifteen displays comments with:
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 56,
) );
#5
@
9 years ago
- Keywords has-patch needs-testing added
34073.diff is a pass at fixing this ticket as well as #34068. (They're slightly different, but the same technique has to be used in both places.)
The trick in the case of wp_list_comments()
was (a) to detect that we were inside of a comments_template()
loop (something we already know because of the $wp_query->max_num_comment_pages
check), and if so, (b) pass the new cpage
parameter down through the stack, all the way to get_comment_link()
. When get_comment_link()
sees cpage
, it trusts it - it doesn't do any calculation at all.
As for get_comment_link()
when called outside the context of a comment loop (the problem in #34068), the logic is much the same - calculate total pages, and then remove the 'cpage' query arg when looking at the newest/oldest page, depending on your settings - but it had to go into the calculation logic of the function itself. This meant reorganizing the function quite a bit, mainly for readability, but also to break apart some hairy if/else chains.
My eyes are nearly bleeding from writing tests and doing manual tests of the approach in the patch. I feel pretty confident about it, but a second (and third, and fourth) opinion would be swell.
This ticket was mentioned in Slack in #core by boone. View the logs.
9 years ago
#7
@
9 years ago
Testing with the same set up as earlier:
- Twenty fifteen
- post with twelve comments
- five comments per page
- comment widget displays latest five comments
Last page of comments first:
- oldest three comment widget links are incorrect
- links within comment walker are correct
- page portion not shown for comments on default page
First page of comments first works as expected in both comment walker and widget.
There is a spread sheet.
Edit: fixed references to comment walker (initially wrote loop)
#8
follow-up:
↓ 10
@
9 years ago
Thanks, peterwilsoncc!
page portion not shown for comments on default page
This was originally a design decision, but ViperBond007 pointed out on #8071 that having the 'cpage'/comment-page-x
var here is important to ensure that comment pagination links are permanent when new comments are added.
oldest three comment widget links are incorrect
Can you clarify this? Does this mean that two of the widget links are working? Where do the incorrect links go? Where *should* they go? Are your comments threaded? This may be an unrelated (and existing) bug, perhaps #13939.
#10
in reply to:
↑ 8
@
9 years ago
Replying to boonebgorges:
oldest three comment widget links are incorrect
Can you clarify this? Does this mean that two of the widget links are working? Where do the incorrect links go? Where *should* they go? Are your comments threaded? This may be an unrelated (and existing) bug, perhaps #13939.
That's correct, in last page first:
- two newest comment links worked (comments 11 & 12) linked to page 0
- following three links (comments 8 - 10) linked to page 2 but displayed on page 0
Based on the discussion in #29462 and ViperBond007's comments, it looks like comment pagination in last page first has regressed but I think you mentioned in Slack you were looking into that.
Discovered this checking out #34068. Could be a dupe but my reading is the earlier ticket is about the comment pagination portion of comment links always been present.