diff --git a/CHANGELOG.md b/CHANGELOG.md index c0489ed..dec649c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ #CHANGELOG +## [3.1.0] + +- Backport 2 improvements from v4.x branch: + - Prevent error `trying to get property of non-object` when no menu is set to a location using the walker. + - Add `$depth` as 4th parameter passed to `nav_menu_link_attributes`. + ## [3.0.3] - Revert composer autoload changes. diff --git a/wp-bootstrap-navwalker.php b/wp-bootstrap-navwalker.php index 78c18cf..cdb8a4a 100644 --- a/wp-bootstrap-navwalker.php +++ b/wp-bootstrap-navwalker.php @@ -11,7 +11,7 @@ * Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker * Description: A custom WordPress nav walker class to implement the Bootstrap 3 navigation style in a custom theme using the WordPress built in menu manager. * Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz - * Version: 3.0.3 + * Version: 3.1.0 * Author URI: https://github.com/wp-bootstrap * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker * GitHub Branch: master @@ -84,7 +84,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); - if ( $args->has_children ) { + if ( isset( $args->has_children ) && $args->has_children ) { $class_names .= ' dropdown'; } if ( in_array( 'current-menu-item', $classes, true ) ) { @@ -105,7 +105,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $atts['target'] = ! empty( $item->target ) ? $item->target : ''; $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; // If item has_children add atts to a. - if ( $args->has_children && 0 === $depth ) { + if ( isset( $args->has_children ) && $args->has_children && 0 === $depth ) { $atts['href'] = '#'; $atts['data-toggle'] = 'dropdown'; $atts['class'] = 'dropdown-toggle'; @@ -113,7 +113,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } else { $atts['href'] = ! empty( $item->url ) ? $item->url : ''; } - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); + $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); $icon_attributes = ''; $attributes = ''; foreach ( $atts as $attr => $value ) { @@ -127,7 +127,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } } } - $item_output = $args->before; + $item_output = isset( $args->before ) ? $args->before : ''; /* * Glyphicons/Font-Awesome @@ -146,9 +146,11 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } else { $item_output .= ''; } - $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; - $item_output .= ( $args->has_children && 0 === $depth ) ? ' ' : ''; - $item_output .= $args->after; + $item_output .= isset( $args->link_before ) ? $args->link_before : '' + $item_output .= apply_filters( 'the_title', $item->title, $item->ID ); + $item_output .= isset( $args->link_after ) ? $args->link_after: ''; + $item_output .= ( isset( $args->has_children ) && $args->has_children && 0 === $depth ) ? ' ' : ''; + $item_output .= isset( $args->after ) ? $args->after : ''; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } // End if(). }