Walker changed in PLL 1.5.1? Custom nav broken
-
Hello Frédéric,
Congratulations on the success of your plugin, I am very pleased to see how it has developed. I was using it as early as ~0.7 ??
I built a site last year which was not touched until recently. Luckily there were not too many issues upgrading everything to the current versions, however I have a problem with Polylang.
With WP 4.0, site works on PLL 1.5. Doesn’t work on anything from 1.5.1 – 1.6b3.
It breaks the custom nav walker I created for the site. I have to admit I have not written any PHP for 18 months so I’ve actually forgotten how it works, but basically it outputs 3 unusual HTML menus specifically for this case.
I have 3 classes which extend Walker_Nav_Menu:
1-Main menu
2-Mobile menu
3-Secondary menuThese are the errors I receive:
Notice:
Trying to get property of non-object in functions.php on lines [XX in menus 1&2]PHP Warning:
array_intersect(): Argument #2 is not an array in functions.php on line [YY in menu 3]Some relevant snippets:
function start_el( &$output, $item, $depth=0, $args=array(), $id = 0 ) { // Don't print the 3rd-level elements or Home menu item if ( $depth == 2 || $item->menu_order == 1 ) return; // Now to override original WP Walker $classes = empty( $item->classes ) ? array() : (array) $item->classes; // Turn array into string and filter out thanks to horizonp_menu_classes() $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); // Booking element is a span if ( $item->menu_order == 2 ) { $li_output = '<span'; $class_names = $class_names ? $class_names . ' nav-menu' : $class_names . 'nav-menu'; } // More Info element is a div elseif ( $item->menu_order == 3 ) { $li_output = '<div'; $class_names = $class_names ? $class_names . ' nav-menu' : $class_names . 'nav-menu'; } // All other elements are li else { $li_output = '<li'; } $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; $output .= $li_output . $class_names .'>'; if ( $item->menu_order != 3) { $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; $prepend = ''; // optional $append = ''; // might use later XX $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; XX $item_output .= $args->link_before . $prepend . apply_filters( 'the_title', $item->title, $item->ID ) . $append; XX $item_output .= $args->link_after; $item_output .= '</a>'; XX $item_output .= $args->after; } else { // Print more info drop-down without href $item_output = '<a>' . apply_filters( 'the_title', $item->title, $item->ID ) . '</a>'; } $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); if ( $item->menu_order == 2 ) $output .= '</span>'; if ( $item->menu_order == 3 ) $output .= '</div>'; }
And
// Only follow down the current branch - this is the special salsa for sub_nav_walker function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { // Check if element has a 'current' class (from DB, I filter them to 'active' later) $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); YY $current_class = array_intersect( $current_element_markers, $element->classes ); // If element has a 'current' class, it is an ancestor of the current element $ancestor_of_current = ! empty( $current_class ); // If this is a 1st or 2nd-level link and not the current, or ancestor of the current menu item - stop here. if ( $depth <= 1 && !$ancestor_of_current ) return; parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); }
Sorry for such a long post but I didn’t know what to omit. I’m not really a programmer!
Thanks in advance for your help.
Cheers,
LloydP.S. I’m happy to provide the full source, it’s just really long. I can give you access to the site as well if you need it.
- The topic ‘Walker changed in PLL 1.5.1? Custom nav broken’ is closed to new replies.