[wp-trac] [WordPress Trac] #35624: Use of get_comment() function shows Notice

WordPress Trac noreply at wordpress.org
Fri Feb 5 14:14:58 UTC 2016


#35624: Use of get_comment() function shows Notice
--------------------------+------------------------------
 Reporter:  WisdmLabs     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Comments      |     Version:  4.4.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by d4z_c0nf):

 Hello guys,
 I was about to open a new ticket for the same issue. As @boonebgorges says
 {{{get_comment()}}} and similar are intended to be used inside the
 "comment loop", so that's not the problem.
 For my understanding the problem is here:
 https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes
 /comment-template.php#L1859

 Called by:
 https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes
 /comment-template.php#L2219

 When does this happen?
 When you reply to a comment but you haven't ran (or you're outside te
 'comment loop') the comment query ( global {{{$comment}}} is not set =>
 {{{get_comment_ID()}}} breaks).
 For example when you show(call) the comment form before the list of
 comments ({{{wp_list_comments()}}}) and you reply to a comment without
 using js.
 I mean, that's when you get the notice, but overall this line:
 {{{
 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() .
 '">' . get_comment_author( $comment ) . '</a>' : get_comment_author(
 $comment );
 }}}


 is wrong even if you call the comment form after the list of comments
 (always without using js), 'cause in that case global {{{comment}} is set,
 but points to the latest comment, not to the one you're replying to.

 The fix is simple. In the line above replace {{{get_comment_ID()}}} with
 the already known {{{$replytoid}}}.

 I'm also not sure about this:
 https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes
 /comment-template.php#L1848

 as that variable is not used in that function if not in the "reply" block,
 where it's retrieved again but passing the id of the comment to reply to
 (.. but maybe I'm missing something).

 Here's a simple way to reproduce the issue with a standard theme (I know
 .. I'm lazy :D):
 - use Twentysixteen theme
 - in its comments template (comments.php) move the comment comment form
 call ({{{comment_form(...)}}}) from the current position to before
 {{{wp_list_comments(...)}}} call
 - go in a page/post with comments
 - be sure you're not using the comment-reply.js (e.g disabling js with
 google-chrome inspect element *)
 - click on a reply button

 p.s.
 will attach a patch agains the latest trunk

 *
 another way to reproduce this without disabling js or dequeuing the
 comment-reply.js is accessing the page/post with comments + clicking on a
 reply button from the Customizer, it will reload the preview due to a bug
 (I think) of the preview js dealing with links to anchors .. but this is
 another story :)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35624#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list