Brandon Powell
Brandon Powell

Reputation: 105

Wordpress Issue with Walker Class

What does an Illegal offset type in isset or empty, I have never ran into this error message before? Could you explain this message to me, please?

Have also place code that learning how to do in here the reviews

  <?php
  if (has_nav_menu('primary_navigation')) :
    wp_nav_menu( array(
      'theme_location' => 'primary_navigation',
      'menu_class' => 'menu',
      'menu_class' => 'mobile-menu',
      'walker' => new  Walker_Nav_Primary (),
      )
    );
  endif;
  ?>

class Walker_Nav_Primary extends Walker {
  function start_lvl( &$output, $depth = 0, $args = array() ) { //ul
    $indent = str_repeat("\t",$depth);
    $submenu = ($depth > 0) ? ' sub-menu' : '';
    $output .= "\n$indent<ul class=\"fallback$submenu depth_$depth\">\n";
  }
Warning: Illegal offset type in isset or empty in /Users/brandonpowell/sites/valet/wordpress-development/web/wp/wp-includes/class-wp-walker.php on line 140

Upvotes: 2

Views: 2021

Answers (2)

Kuzgun
Kuzgun

Reputation: 4737

You are extending Walker class. Therefore you have to define db_fields in your class, it is mandatory. You wouldn't need it if you have extended Walker_Nav_Menu class. Example:

class Walker_Nav_Primary extends Walker {

// Tell Walker where to inherit it's parent and id values
    var $db_fields = array(
        'parent' => 'menu_item_parent', 
        'id'     => 'db_id' 
    );

  function start_lvl( &$output, $depth = 0, $args = array() ) { //ul
    $indent = str_repeat("\t",$depth);
    $submenu = ($depth > 0) ? ' sub-menu' : '';
    $output .= "\n$indent<ul class=\"fallback$submenu depth_$depth\">\n";
  }

Upvotes: 0

vard
vard

Reputation: 4156

This error happen when you use Walker instead of Walker_Nav_Menu in extends. You should use this instead:

class Walker_Nav_Primary extends Walker_Nav_Menu {

Walker_Nav_Menu heritate itself of Walker class, and provide the proper properties / methods for your own walker class.

Upvotes: 6

Related Questions