Support » Fixing WordPress » walk_category_dropdown_tree error

  • It appears that the code for this function is missing some variables that need to be passed.

    The current function only receives 1 packed parameter labeled …%args and passes that parameter to walker but walker requires 2 parameters so an error is thrown that one was passed when two was expected. https://developer.wordpress.org/reference/classes/Walker/walk/

    From what I can tell, …$args is in place of the optional parameters and does not cover either of the required parameters. That said, I think it needs to be changed so line 1 of this function should be “function walk_category_dropdown_tree( $categories, $depth, …$args ) {” and line 11 should be “return $walker->walk( $categories, $depth, …$args );”

    I am also not all that sure why depth is required for walker considering it has a default set and can be retrieved by running the arguments passed through wp_parse_args. I am fairly new to WordPress development though so I may be missing something.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have a look at the PHP documentation here: https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list – the 1st argument of walk() is an array and that’s what is passed here.

    If you have a specific suggestion for improving the post, you could unload it to the WordPress Core Team here: https://core.trac.wordpress.org/newticket

    Thread Starter Ryan Kanawyer

    (@ryankanawyer)

    Hey threadi,

    I am actually used to asp.net development and it would appear that I had misunderstood how the ellipse works in PHP. I thought it only packed arrays (which I had assumed was some type of temporary compression to help with large arrays) and not that the passed variables are passed as an array of varying size.

    Still though, when I call walk_category_dropdown_tree I get an error that the wrong number of parameters are passed on line 1137 of category-template.php which is line 11 of this function. The fact that the walker class requires 2 parameters seems to be an issue here unless I am doing something wrong with my call. The following is a few lines from the plugin that I am working on. $defaults is an array of presets for the variables and $atts is variables that the end user sets.

    $parsed_args = wp_parse_args($atts, $defaults);
    $get_terms_args = $parsed_args;
    unset($get_terms_args[‘name’]);
    walk_category_dropdown_tree(get_terms($get_terms_args), $parsed_args[‘depth’], $parsed_args);

    If I update category-template.php with my suggested changes above, it works without any issues but of course updating a file in wp-includes is a bad idea as it will revert back when the site is upgraded.

    Thanks for the link for WordPress core tickets. I was not really sure where I should go with this so I just started in the forum and figured I would go for a bug ticket or something if others agreed it is an actual issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.