[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
Mon Mar 2 12:35:05 UTC 2026


#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:  has-patch needs-test-info has-unit-  |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by alexodiy):

 == Test Info & Reproduction Report

 === Steps to Reproduce

 1. Enable `WP_DEBUG` and `WP_DEBUG_DISPLAY` in `wp-config.php`.
 2. Have a post with at least one comment (default sample data works).
 3. Call `Walker_Comment` directly with empty `$args`:

 {{{#!php
 $comments = get_comments( array( 'number' => 1 ) );
 $walker   = new Walker_Comment();
 $output   = $walker->walk( $comments, -1, array() );
 }}}

 === Actual Results (PHP 8.1)

 {{{
 Warning: Undefined array key "format" in class-walker-comment.php on line
 196
 Warning: Undefined array key "style" in class-walker-comment.php on lines
 237, 300, 318, 392
 Warning: Undefined array key "avatar_size" in class-walker-comment.php on
 lines 323, 324
 Warning: Undefined array key "max_depth" in class-walker-comment.php on
 lines 371, 384
 }}}

 Methods `start_lvl`, `end_lvl`, `start_el`, `end_el`, `ping`, `comment`,
 `html5_comment` all access `$args` keys without `isset()`. The PHPDoc
 documents `$args` as optional with default `array()`, so this is a valid
 call.

 === Why a New Patch

 PR #4126 has been open since 2022 with no merge activity. It also has a
 few issues:

  * Mixes the actual fix with unrelated whitespace and indentation changes,
 making review harder.
  * Uses `array_merge()` for defaults instead of `wp_parse_args()`, which
 is the standard WordPress approach.
  * Does not include PHPUnit tests.

 I submitted a cleaner alternative: [https://github.com/WordPress
 /wordpress-develop/pull/11110 PR #11110]

 === What the Patch Does

  * Adds `wp_parse_args()` with sensible defaults at the top of each
 affected method: `start_lvl`, `end_lvl`, `start_el`, `end_el`, `ping`,
 `comment`, `html5_comment`.
  * Default values match `wp_list_comments()`: `style => 'ul'`,
 `avatar_size => 32`, `format => 'xhtml'`, `short_ping => false`,
 `max_depth => ''`.
  * No whitespace or indentation changes — only the fix itself.
  * Includes 5 PHPUnit tests covering all affected methods with empty args.

 All 9 warnings resolved after applying the patch.

 === Environment

  * WordPress: 7.0-beta2 (trunk)
  * PHP: 8.1.10
  * Server: Apache
  * OS: Windows 10
  * Theme: Twenty Twenty-Five

 cc @oglekler

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


More information about the wp-trac mailing list