Make WordPress Core

Opened 6 years ago

Last modified 2 years ago

#43695 new defect (bug)

$depth and $args are switched when using custom callback in wp_list_comments()

Reported by: vincurekf's profile vincurekf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.5
Component: Comments Keywords: has-patch
Focuses: docs, template Cc:


For the custom function I am using the [latest function from walker]( as a base.

When you use custom callback in comments.php template:

// comments.php
$args = [
    'type' => 'comment',
    'format' => 'html5',
    'style' => 'ol',
    'short_ping' => true,
// Use our custom callback if it's available
if( function_exists( 'custom_render_comment' ) ){
    $args['format'] = 'custom';
    $args['callback'] = 'custom_render_comment';
wp_list_comments( $args );

The arguments that get passed to custom_render_comment function are switched:

// custom_render_comment.php
function custom_render_comment( $comment, $depth, $args ) {
array(15) { ["walker"]=> NULL ["max_depth"]=> string(1) "5" ["style"]=> string(2) "ol" ["callback"]=> string(21) "faeiv2_render_comment" ["end-callback"]=> NULL ["type"]=> string(7) "comment" ["page"]=> int(0) ["per_page"]=> int(0) ["avatar_size"]=> int(32) ["reverse_top_level"]=> bool(false) ["reverse_children"]=> string(0) "" ["format"]=> string(6) "faeiv2" ["short_ping"]=> bool(true) ["echo"]=> bool(true) ["has_children"]=> bool(true) }

The result is this error:

Warning: array_merge(): Argument #1 is not an array in [...]/wp-content/themes/mytheme/inc/render-comment.php on line 56

I haven't found any mention of switching arguments in the WordPressCodex.

The fix is easy, just switch those variables, but I think it should be addressed somewhere in the documentation.

Attachments (1)

43695.patch (947 bytes) - added by hilayt24 3 years ago.
A note is added to the docs to notify the user about the issue.

Download all attachments as: .zip

Change History (4)

#1 @soulseekah
6 years ago

Welcome to Trac!

The fix is easy, just switch those variables

For back-compatibility reasons this would be a bad idea.

Docs? Probably a good idea.

Although lists an example (mytheme_comment).

Either way:

3 years ago

A note is added to the docs to notify the user about the issue.

#3 @hilayt24
2 years ago

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.