[wp-trac] [WordPress Trac] #56539: Check if index in $args isset / ! empty before using it in Walker_Comment methods or create default $args in case if it is empty

WordPress Trac noreply at wordpress.org
Fri Sep 9 18:34:34 UTC 2022


#56539: Check if index in $args isset / ! empty before using it in Walker_Comment
methods or create default $args in case if it is empty
--------------------------+------------------------------
 Reporter:  oglekler      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Comments      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------------------
Changes (by SergeyBiryukov):

 * keywords:   => needs-patch


Old description:

> Taking into account the comments in #53449, I suggest local fix for the
> comments walker (wp-includes/class-walker-comment.php).
>
> Class Walker_Comment uses some $args indexes without checking if they
> exist. And in my case, they don't exist, $args are empty array and I am
> getting notices. I will consider adding $args into the call, but they are
> commented as optional and don't suppose to be used in such way.
>
> Examples:
>
> public function start_el uses:
>
> {{{
> $args['short_ping']
> $args['format']
> }}}
>
> And
> {{{
> $args['style']
> }}}
>  is used without checking that it exists in several methods - end_el,
> end_lvl, ping, comment, html5_comment, start_lvl.

New description:

 Taking into account the comments in #53449, I suggest local fix for the
 comments walker (wp-includes/class-walker-comment.php).

 Class Walker_Comment uses some $args indexes without checking if they
 exist. And in my case, they don't exist, $args are empty array and I am
 getting notices. I will consider adding $args into the call, but they are
 commented as optional and don't suppose to be used in such way.

 Examples:

 public function start_el uses:

 {{{
 $args['short_ping']
 $args['format']
 }}}

 And
 {{{
 $args['style']
 }}}
 is used without checking that it exists in several methods - end_el,
 end_lvl, ping, comment, html5_comment, start_lvl.

--

Comment:

 Hi there, thanks for the ticket!

 It looks like the `Walker_Comment` class assumes that all the default
 arguments of [https://core.trac.wordpress.org/browser/tags/6.0.2/src/wp-
 includes/comment-template.php#L2071 wp_list_comments()] would always be
 available, which may not necessarily be a correct assumption, so checking
 if they exist seems like a good idea.

 To help move the ticket forward, could you share the steps to reproduce
 the issue on a clean install?

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


More information about the wp-trac mailing list