Make WordPress Core

Opened 3 years ago

Last modified 22 months ago

#56539 new defect (bug)

Check if index in $args isset / ! empty before using it in Walker_Comment methods or create default $args in case if it is empty

Reported by: oglekler's profile oglekler Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch needs-testing
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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.

Change History (3)

#1 @SergeyBiryukov
3 years ago

  • Description modified (diff)
  • Keywords needs-patch added

Hi there, thanks for the ticket!

It looks like the Walker_Comment class assumes that all the default arguments of 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?

This ticket was mentioned in PR #4126 on WordPress/wordpress-develop by CrochetFeve0251.


2 years ago
#2

  • Keywords has-patch added; needs-patch removed

I added default values to each methods from Walker_Comment using $args to prevent using values without being sure they were initialized.

Trac ticket: https://core.trac.wordpress.org/ticket/56539

#3 @oglekler
22 months ago

  • Keywords needs-testing added
Note: See TracTickets for help on using tickets.