[wp-trac] [WordPress Trac] #43695: $depth and $args are switched when using custom callback in wp_list_comments()

WordPress Trac noreply at wordpress.org
Thu Apr 5 05:55:33 UTC 2018


#43695: $depth and $args are switched when using custom callback in
wp_list_comments()
----------------------------+-----------------------------
 Reporter:  vincurekf       |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Comments        |    Version:  4.9.5
 Severity:  normal          |   Keywords:
  Focuses:  docs, template  |
----------------------------+-----------------------------
 For the custom function I am using the [latest function from
 walker](https://github.com/WordPress/WordPress/blob/master/wp-includes
 /class-walker-comment.php#L343) as a base.

 When you use custom callback in comments.php template:
 {{{#!php
 <?php
 // 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:
 {{{#!php
 <?php
 // custom_render_comment.php
 function custom_render_comment( $comment, $depth, $args ) {
 /*
 var_dump($depth):
 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) }
 }
 var_dump($args):
 int(1)
 */
 }
 }}}

 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43695>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list