Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#27007 closed defect (bug) (fixed)

problem using wp_list_comments with 'per_page' without calling comments_template

Reported by: monotom's profile monotom Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch commit
Focuses: Cc:

Description (last modified by SergeyBiryukov)

if you want to use wp_list_comments like this

  wp_list_comments(
    ['style'       => 'div',
    'reply_text'  => 'kommentieren',
    'avatar_size' => 73,
    'per_page'    => 10000000 //or 0 or something
    ])
  )

without using the comments_template method, there will be corrupted comment metadata links like this

.../comment-page-#comment-15922

...in my opinion( and this core hack fixed it temporarily) it has to do with the methods Walker_Comment::comment and Walker_Comment::html5_comment which doesnt pass the $args to the get_comment_link method.

So i think they should pass the args or if there are good reasons for this behavior the documentation have to be changed(http://codex.wordpress.org/Function_Reference/wp_list_comments).

Attachments (1)

27007.patch (1.2 KB) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (8)

#1 follow-up: @bcworkz
12 years ago

The original arguments are not available to pass to get_comment_link().

It appears nearly all the methods involved prior to that call are capable of passing the arguments through. wp_list_comments() actually tries to pass the arguments as $r in the call to $walker->paged_walk(). The paged_walk() method is not overridden, so the call goes to Walker::paged_walk() which only accepts 4 parameters, $r was the 5th!

This of course does not alone solve the corrupted link issue, but by ensuring the arguments can actually get passed through the walker object as was apparently intended would at least make it possible.

#2 @SergeyBiryukov
12 years ago

  • Description modified (diff)

#3 in reply to: ↑ 1 @SergeyBiryukov
12 years ago

Replying to bcworkz:

The paged_walk() method is not overridden, so the call goes to Walker::paged_walk() which only accepts 4 parameters, $r was the 5th!

That's not actually an issue, additional arguments are retrieved using func_get_args():
tags/3.8.1/src/wp-includes/class-wp-walker.php#L276

#4 @SergeyBiryukov
12 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.9

per_page is actually not required, I was able to reproduce the issue with this example:

wp_list_comments( array(), get_comments() );

Looks like get_comment_link() can only generate an invalid link if $in_comment_loop is true and cpage query var is empty: tags/3.8.1/src/wp-includes/comment-template.php#L586.

$in_comment_loop is set by wp_list_comments(), and cpage is normally set by comments_template(): tags/3.8.1/src/wp-includes/comment-template.php#L1078.

So, if wp_list_comments() is called outside of comments.php template, invalid links are generated. Passing $args to get_comment_link() in Walker_Comment::html5_comment() and Walker_Comment::comment() does indeed fix the issue.

#5 @samuelsidler
12 years ago

  • Keywords commit added

#6 @nacin
12 years ago

This is really weird. get_comment_link() takes extra arguments but they've never been used in core. See #8287 for history.

#7 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27799:

Pass walker arguments to get_comment_link() so pagination works when wp_list_comments() is used outside the comment template.

props SergeyBiryukov.
fixes #27007.

Note: See TracTickets for help on using tickets.