From 2c0c9d7673d5ce8c61ca495bdb3df05dec38e336 Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 8 Dec 2016 10:53:03 +0000 Subject: [PATCH 01/61] Added a '.nav-item' class to menu items for BS4 support --- wp_bootstrap_navwalker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wp_bootstrap_navwalker.php b/wp_bootstrap_navwalker.php index 8dabc00..ffc795a 100644 --- a/wp_bootstrap_navwalker.php +++ b/wp_bootstrap_navwalker.php @@ -59,7 +59,9 @@ 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; - + // BSv4 classname - as of v4-alpha-5 + $classes[] = 'nav-item'; + $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); if ( $args->has_children ) From d3fb24e3bee1621b1f4e52b5fc479f7e9a70f4fe Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 15 Jun 2017 13:56:47 +0100 Subject: [PATCH 02/61] Drop the link title attribute method for adding fa/glphicon icons and modifying link types (will move to a class attribute method of usage) --- wp-bootstrap-navwalker.php | 124 ++++++++++++++----------------------- 1 file changed, 45 insertions(+), 79 deletions(-) diff --git a/wp-bootstrap-navwalker.php b/wp-bootstrap-navwalker.php index 4bee7e1..9b6e5ec 100644 --- a/wp-bootstrap-navwalker.php +++ b/wp-bootstrap-navwalker.php @@ -62,89 +62,55 @@ public function start_lvl( &$output, $depth = 0, $args = array() ) { public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; - /** - * Dividers, Headers or Disabled - * ============================= - * Determine whether the item is a Divider, Header, Disabled or regular - * menu item. To prevent errors we use the strcasecmp() function to so a - * comparison that is not case sensitive. The strcasecmp() function returns - * a 0 if the strings are equal. - */ - if ( 0 === strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) { - $output .= $indent . '
  • '; - $atts = array(); + $value = ''; + $class_names = $value; + $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 ) ); + if ( $args->has_children ) { + $class_names .= ' dropdown'; + } + if ( in_array( 'current-menu-item', $classes, true ) ) { + $class_names .= ' active'; + } + $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; + $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args ); + $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; + $output .= $indent . '
  • '; + $atts = array(); - if ( empty( $item->attr_title ) ) { - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; - } else { - $atts['title'] = $item->attr_title; - } + if ( empty( $item->attr_title ) ) { + $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; + } else { + $atts['title'] = $item->attr_title; + } - $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 ) { - $atts['href'] = '#'; - $atts['data-toggle'] = 'dropdown'; - $atts['class'] = 'dropdown-toggle'; - $atts['aria-haspopup'] = 'true'; - } else { - $atts['href'] = ! empty( $item->url ) ? $item->url : ''; - } - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); - $attributes = ''; - foreach ( $atts as $attr => $value ) { - if ( ! empty( $value ) ) { - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); - $attributes .= ' ' . $attr . '="' . $value . '"'; - } + $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 ) { + $atts['href'] = '#'; + $atts['data-toggle'] = 'dropdown'; + $atts['class'] = 'dropdown-toggle'; + $atts['aria-haspopup'] = 'true'; + } else { + $atts['href'] = ! empty( $item->url ) ? $item->url : ''; + } + $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); + $attributes = ''; + foreach ( $atts as $attr => $value ) { + if ( ! empty( $value ) ) { + $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); + $attributes .= ' ' . $attr . '="' . $value . '"'; } - $item_output = $args->before; + } + $item_output = $args->before; + $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; + $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); - /* - * Glyphicons/Font-Awesome - * =========== - * Since the the menu item is NOT a Divider or Header we check the see - * if there is a value in the attr_title property. If the attr_title - * property is NOT null we apply it as the class name for the glyphicon. - */ - if ( ! empty( $item->attr_title ) ) { - $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' ); - if ( false !== $pos ) { - $item_output .= ' '; - } else { - $item_output .= ' '; - } - } 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; - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); - } // End if(). } /** From 9cfa5a4a4f72e82c1a87a5b9840e5cd7c88ace33 Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 15 Jun 2017 14:43:40 +0100 Subject: [PATCH 03/61] Update branch to match latest master and add in some BS4 specific classes. Also removed old title_attribute based divider/header/disabled/icon support. Will be replaced with a class based method of modifying the links for those. --- wp-bootstrap-navwalker.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wp-bootstrap-navwalker.php b/wp-bootstrap-navwalker.php index 9b6e5ec..aadb1f2 100644 --- a/wp-bootstrap-navwalker.php +++ b/wp-bootstrap-navwalker.php @@ -66,6 +66,8 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $class_names = $value; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; + // BSv4 classname - as of v4-alpha. + $classes[] = 'nav-item'; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); if ( $args->has_children ) { $class_names .= ' dropdown'; @@ -91,10 +93,12 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 if ( $args->has_children && 0 === $depth ) { $atts['href'] = '#'; $atts['data-toggle'] = 'dropdown'; - $atts['class'] = 'dropdown-toggle'; $atts['aria-haspopup'] = 'true'; + $atts['aria-expanded'] = 'false'; + $atts['class'] = 'dropdown-toggle nav-link'; } else { - $atts['href'] = ! empty( $item->url ) ? $item->url : ''; + $atts['href'] = ! empty( $item->url ) ? $item->url : ''; + $atts['class'] = 'nav-link'; } $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); $attributes = ''; From 6ea2a62ace90edb27d283a4ee4d7e5bdf62753bb Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 15 Jun 2017 14:46:25 +0100 Subject: [PATCH 04/61] prefix main filename with `class` --- wp-bootstrap-navwalker.php => class-wp-bootstrap-navwalker.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename wp-bootstrap-navwalker.php => class-wp-bootstrap-navwalker.php (100%) diff --git a/wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php similarity index 100% rename from wp-bootstrap-navwalker.php rename to class-wp-bootstrap-navwalker.php From 6c9907c1ef7c23a5235554726358b85d851f3c8e Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 15 Jun 2017 14:47:22 +0100 Subject: [PATCH 05/61] Version bumb --- class-wp-bootstrap-navwalker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index aadb1f2..59d8f38 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -10,8 +10,8 @@ * Plugin Name: WP Bootstrap Navwalker * 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 - * Version: 2.0.5 + * Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz + * Version: 3 * Author URI: https://github.com/wp-bootstrap * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker * GitHub Branch: master From 69b0b9aea4a41900a2c09478b90cfb34221997a2 Mon Sep 17 00:00:00 2001 From: William Patton Date: Thu, 15 Jun 2017 17:05:07 +0100 Subject: [PATCH 06/61] Exclude /tests/ directory from being checked by phpcs --- phpcs.ruleset.xml | 1 + phpcs.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/phpcs.ruleset.xml b/phpcs.ruleset.xml index 210c25a..c17aea0 100644 --- a/phpcs.ruleset.xml +++ b/phpcs.ruleset.xml @@ -7,4 +7,5 @@ */node_modules/* */vendor/* + */tests/* diff --git a/phpcs.xml b/phpcs.xml index 563f72e..49b7969 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -10,6 +10,7 @@ */tests/* */vendor/* + */tests/* - - + + Navbar 'primary', - 'theme_location' => 'primary', - 'depth' => 2, - 'container' => 'div', - 'container_class' => 'collapse navbar-collapse', - 'container_id' => 'bs-example-navbar-collapse-1', - 'menu_class' => 'nav navbar-nav', - 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new WP_Bootstrap_Navwalker()) - ); + wp_nav_menu( array( + 'theme_location' => 'primary', + 'depth' => 2, + 'container' => 'div', + 'container_class' => 'collapse navbar-collapse', + 'container_id' => 'bs-example-navbar-collapse-1', + 'menu_class' => 'nav navbar-nav', + 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', + 'walker' => new WP_Bootstrap_Navwalker()) + ); ?> @@ -101,23 +91,15 @@ To display the menu you must associate your menu with your theme location. You c ### Extras -This script included the ability to add Bootstrap dividers, dropdown headers, glyphicons and disables links to your menus through the WordPress menu UI. - -### Dividers - -Simply add a Link menu item with a **URL** of `#` and a **Link Text** or **Title Attribute** of `divider` (case-insensitive so ‘divider’ or ‘Divider’ will both work ) and the class will do the rest. - -### Glyphicons - -To add an Icon to your link simple place the Glyphicon class name in the links **Title Attribute** field and the class will do the rest. IE `glyphicon-bullhorn` +This script included the ability to use Bootstrap nav link mods in your menus through the WordPress menu UI. Currently only disabled links are supported. Additionally icon support is built-in for Glyphicons and font Awesome (note: you will need to include the icon stylesheets or assets separately) -### Dropdown Headers +#### Icons -Adding a dropdown header is very similar, add a new link with a **URL** of `#` and a **Title Attribute** of `dropdown-header` (it matches the Bootstrap CSS class so it's easy to remember). set the **Navigation Label** to your header text and the class will do the rest. +To add an Icon to your link simpley enter Glypicons or Font Awesome class names in the links **Classes** field in the Menu UI and the walker class will do the rest. IE `glyphicons glyphicons-bullhorn` or `fa fa-arrow-left`. -### Disabled Links +#### Disabled Links -To set a disabled link simply set the **Title Attribute** to `disabled` and the class will do the rest. +To set a disabled link simply add `disabled` to the **Classes** field in the Menu UI and the walker class will do the rest. Note: _In addition to adding the .disabled class this will change the link `href` to `#` as well so that it is not a followable link._ ### Changelog From b899688ca588b449beb739ed82a2687308b30cd1 Mon Sep 17 00:00:00 2001 From: William Patton Date: Fri, 16 Jun 2017 01:06:01 +0100 Subject: [PATCH 11/61] Fix menus with depth of 1 from having dropdown atts and caret. Closes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/pull/145 Credits: @chrisgeary92 --- class-wp-bootstrap-navwalker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 9f2090f..b4532ef 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -112,7 +112,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 ( $args->has_children && 0 === $depth && $args->depth > 1 ) { $atts['href'] = '#'; $atts['data-toggle'] = 'dropdown'; $atts['aria-haspopup'] = 'true'; @@ -154,7 +154,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $args->link_before = $args->link_before . ' '; } $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->has_children && 0 === $depth && $args->depth > 1 ) ? ' ' : ''; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); From f94fe339657f3dd3e70bbda2f4e6d999fe7931ea Mon Sep 17 00:00:00 2001 From: William Patton Date: Fri, 16 Jun 2017 01:14:04 +0100 Subject: [PATCH 12/61] Reasign filtered classes back to $classes array. Fixes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues/156 Closes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/pull/158 Credits: @lf-jeremy --- class-wp-bootstrap-navwalker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index b4532ef..6386be6 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -90,7 +90,9 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $classes[] = 'menu-item-' . $item->ID; // BSv4 classname - as of v4-alpha. $classes[] = 'nav-item'; - $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); + // reasign any filtered classes back to the $classes array. + $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ); + $class_names = join( ' ', $classes ); if ( $args->has_children ) { $class_names .= ' dropdown'; } From 174ad6120fb7235bf0c5365158f7c967aca09261 Mon Sep 17 00:00:00 2001 From: William Patton Date: Fri, 16 Jun 2017 01:50:32 +0100 Subject: [PATCH 13/61] Move to a local var for icon html instead of global $args->link_before. This prevents icons from cascading into future elements without the need to flush the icon from $args->link_before each time. --- class-wp-bootstrap-navwalker.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 6386be6..51a6537 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -150,12 +150,14 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } $item_output = $args->before; $item_output .= ''; - // if we have a string containing icon classes... + + // initiate empty icon var then if we have a string containing icon classes... + $icon_html = ''; if ( ! empty( $icon_class_string ) ) { // append an with the icon classes to what is output before links. - $args->link_before = $args->link_before . ' '; + $icon_html = ' '; } - $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; + $item_output .= $args->link_before . $icon_html . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; $item_output .= ( $args->has_children && 0 === $depth && $args->depth > 1 ) ? ' ' : ''; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); From 8e17a369678f13590f5ef7d8d24d71a433862501 Mon Sep 17 00:00:00 2001 From: William Patton Date: Fri, 16 Jun 2017 19:05:37 +0100 Subject: [PATCH 14/61] Version bump to 3.0.1, changelog updated --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64be195..781dde3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ #CHANGELOG +## [3.0.1] + +- Fix to correct output of dropdown atts and styles when depth passed to wp_nav_menu is <= 1 + - credit: @chrisgeary92 +- Move icon output to a local var instead of modifying and clearing a global object. +- Reassign filtered classes back to $classes array so that updated classes can be accessed later if needed. + - credit: @lf-jeremy + ## [3.0.0] - Update to work with Bootstrap v4. From c876bafb7348013a6720d9cdf950176c05c3723c Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 18 Jun 2017 19:18:58 +0100 Subject: [PATCH 15/61] Support `echo` arg in fallback function. props @toddlevy fixes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issue/249 closes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/pull/268 --- CHANGELOG.md | 5 +++++ class-wp-bootstrap-navwalker.php | 38 +++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 781dde3..4f5ef64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [3.0.1] +- Support `echo` arg in fallback menu. + - credit: @toddlevy + +## [3.0.1] + - Fix to correct output of dropdown atts and styles when depth passed to wp_nav_menu is <= 1 - credit: @chrisgeary92 - Move icon output to a local var instead of modifying and clearing a global object. diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 51a6537..1516b21 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-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 + * Version: 3.0. * Author URI: https://github.com/wp-bootstrap * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker * GitHub Branch: master @@ -215,26 +215,38 @@ public static function fallback( $args ) { $menu_class = $args['menu_class']; $menu_id = $args['menu_id']; + // initialize var to store fallback html. + $fallback_output = ''; + if ( $container ) { - echo '<' . esc_attr( $container ); + $fallback_output = '<' . esc_attr( $container ); if ( $container_id ) { - echo ' id="' . esc_attr( $container_id ) . '"'; + $fallback_output = ' id="' . esc_attr( $container_id ) . '"'; } if ( $container_class ) { - echo ' class="' . sanitize_html_class( $container_class ) . '"'; } - echo '>'; + $fallback_output = ' class="' . sanitize_html_class( $container_class ) . '"'; + } + $fallback_output = '>'; } - echo ''; - echo '
  • ' . esc_attr( 'Add a menu', '' ) . '
  • '; - echo ''; + $fallback_output = ' class="' . esc_attr( $menu_class ) . '"'; } + $fallback_output = '>'; + $fallback_output = '
  • ' . esc_attr( 'Add a menu', '' ) . '
  • '; + $fallback_output = ''; if ( $container ) { - echo ''; } - } + $fb_output = ''; + } + + // if $args has 'echo' key and it's true echo, otherwise return. + if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { + echo $fallback_output; // WPCS: XSS OK. + } else { + return $fallback_output; + } + } // End if(). } } } // End if(). From ff0e4190d0faeab280029b14ecf4dfcbe705e6bd Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 18 Jun 2017 19:19:42 +0100 Subject: [PATCH 16/61] Accessibile icons (aria-hidden="true", they are decorative). --- class-wp-bootstrap-navwalker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 1516b21..902cbe6 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -155,10 +155,10 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $icon_html = ''; if ( ! empty( $icon_class_string ) ) { // append an with the icon classes to what is output before links. - $icon_html = ' '; + $icon_html = ' '; } $item_output .= $args->link_before . $icon_html . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; - $item_output .= ( $args->has_children && 0 === $depth && $args->depth > 1 ) ? ' ' : ''; + $item_output .= ( $args->has_children && 0 === $depth && $args->depth > 1 ) ? ' ' : ''; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); From 5ea2df11f1071f1b6f7b5e9b0b01833d331ef2f4 Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 18 Jun 2017 19:48:18 +0100 Subject: [PATCH 17/61] Add `.active` to parent when a child is current page. props @zyberspace Closes: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/pull/101 --- CHANGELOG.md | 2 ++ class-wp-bootstrap-navwalker.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f5ef64..cf1d476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Support `echo` arg in fallback menu. - credit: @toddlevy +- Add `.active` to parent when a child is current page. + - credit: @zyberspace ## [3.0.1] diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 902cbe6..9431271 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -96,7 +96,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 if ( $args->has_children ) { $class_names .= ' dropdown'; } - if ( in_array( 'current-menu-item', $classes, true ) ) { + if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { $class_names .= ' active'; } $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; From f4d3829196375f13cc69ccc6907f13ab9696f588 Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 18 Jun 2017 19:57:35 +0100 Subject: [PATCH 18/61] Version bump 3.0.2 --- CHANGELOG.md | 2 +- class-wp-bootstrap-navwalker.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1d476..764c6e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ #CHANGELOG -## [3.0.1] +## [3.0.2] - Support `echo` arg in fallback menu. - credit: @toddlevy diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 9431271..9ce1cf5 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-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. + * Version: 3.0.2 * Author URI: https://github.com/wp-bootstrap * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker * GitHub Branch: master From e485e94c77b98c2cadfdfba5d70642791f6691e2 Mon Sep 17 00:00:00 2001 From: William Patton Date: Sun, 18 Jun 2017 20:29:05 +0100 Subject: [PATCH 19/61] Remove `` from after parent dropdown items. No longer needed, applied via css with :pseudo classes --- CHANGELOG.md | 1 + class-wp-bootstrap-navwalker.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 764c6e3..ac8cc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [3.0.2] +- Remove `` after parent dropdown items - Support `echo` arg in fallback menu. - credit: @toddlevy - Add `.active` to parent when a child is current page. diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 9ce1cf5..23359e0 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -158,7 +158,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $icon_html = ' '; } $item_output .= $args->link_before . $icon_html . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; - $item_output .= ( $args->has_children && 0 === $depth && $args->depth > 1 ) ? ' ' : ''; + $item_output .= ''; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); From 3034f6a1a7a0387074019a88307caca9effb0589 Mon Sep 17 00:00:00 2001 From: William Patton Date: Wed, 16 Aug 2017 10:00:04 +0100 Subject: [PATCH 20/61] fix typo in fallback --- class-wp-bootstrap-navwalker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 23359e0..1c44baf 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -237,7 +237,7 @@ public static function fallback( $args ) { $fallback_output = '
  • ' . esc_attr( 'Add a menu', '' ) . '
  • '; $fallback_output = ''; if ( $container ) { - $fb_output = ''; + $fallback_output = ''; } // if $args has 'echo' key and it's true echo, otherwise return. From fff383dd6cb50f8f0f18822ac30e591a89ab275d Mon Sep 17 00:00:00 2001 From: William Patton Date: Wed, 16 Aug 2017 13:02:56 +0100 Subject: [PATCH 21/61] Accessibility: Add an id to dropdown parent for labeling --- class-wp-bootstrap-navwalker.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 1c44baf..d1cfa66 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -42,7 +42,14 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { */ public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat( "\t", $depth ); - $output .= "\n$indent