From fa39e92ffee61b3b82c831b2b97f5aeff65a7787 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 09:14:02 -0400 Subject: [PATCH 01/11] Update composer.json --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index ede2ee2..de5817a 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,10 @@ "post-update-cmd": [ "wp-enforcer" ] + }, + "autoload": { + "files": [ + "class-wp-bootstrap-navwalker.php" + ] } } From 610bbd2ec6ffaade2ea96951e2deadd99921867b Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 09:15:30 -0400 Subject: [PATCH 02/11] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index de5817a..d1b23f1 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "wp-bootstrap/wp-bootstrap-navwalker", + "name": "mwdelaney/wp-bootstrap-navwalker", "description": "A custom WordPress nav walker class to fully implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.", "type": "library", "license": "GPL-3.0+", @@ -13,8 +13,8 @@ } ], "support": { - "issues": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues/", - "source": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/" + "issues": "https://github.com/mwdelaney/wp-bootstrap-navwalker/issues/", + "source": "https://github.com/mwdelaney/wp-bootstrap-navwalker/" }, "require": { "composer/installers": "~1.0" From 866cc2f752ef67db083b17eb217a5be29e57ad8b Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 09:48:06 -0400 Subject: [PATCH 03/11] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index be9e978..8e6e5a5 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ wp_nav_menu( array( 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'navbar-nav mr-auto', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new WP_Bootstrap_Navwalker(), + 'walker' => new \WP_Bootstrap_Navwalker(), ) ); ``` @@ -97,7 +97,7 @@ Typically the menu is wrapped with additional markup, here is an example of a ` 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'nav navbar-nav', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new WP_Bootstrap_Navwalker(), + 'walker' => new \WP_Bootstrap_Navwalker(), ) ); ?> @@ -120,7 +120,7 @@ There has been some interest in making this walker the default walker for all me ```php function prefix_modify_nav_menu_args( $args ) { return array_merge( $args, array( - 'walker' => WP_Bootstrap_Navwalker(), + 'walker' => \WP_Bootstrap_Navwalker(), ) ); } add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' ); From 79b6ad8a558b6c3eac0e0912a8b24882574ce583 Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Tue, 31 Jul 2018 14:06:47 -0400 Subject: [PATCH 04/11] PSR2 standards, class autoloading --- class-wp-bootstrap-navwalker.php | 1094 +++++++++++++++--------------- composer.json | 77 ++- 2 files changed, 602 insertions(+), 569 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index cd598e1..7d9b193 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -1,4 +1,7 @@ item_spacing ) && 'discard' === $args->item_spacing ) { - $t = ''; - $n = ''; - } else { - $t = "\t"; - $n = "\n"; - } - $indent = str_repeat( $t, $depth ); - // Default class to add to the file. - $classes = array( 'dropdown-menu' ); - /** - * Filters the CSS class(es) applied to a menu list element. - * - * @since WP 4.8.0 - * - * @param array $classes The CSS classes that are applied to the menu `'; - if ( $container ) { - $fallback_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; - } - } - } - - /** - * Find any custom linkmod or icon classes and store in their holder - * arrays then remove them from the main classes array. - * - * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only - * Supported iconsets: Font Awesome 4/5, Glypicons - * - * NOTE: This accepts the linkmod and icon arrays by reference. - * - * @since 4.0.0 - * - * @param array $classes an array of classes currently assigned to the item. - * @param array $linkmod_classes an array to hold linkmod classes. - * @param array $icon_classes an array to hold icon classes. - * @param integer $depth an integer holding current depth level. - * - * @return array $classes a maybe modified array of classnames. - */ - private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { - // Loop through $classes array to find linkmod or icon classes. - foreach ( $classes as $key => $class ) { - // If any special classes are found, store the class in it's - // holder array and and unset the item from $classes. - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { - // Test for .disabled or .sr-only classes. - $linkmod_classes[] = $class; - unset( $classes[ $key ] ); - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { - // Test for .dropdown-header or .dropdown-divider and a - // depth greater than 0 - IE inside a dropdown. - $linkmod_classes[] = $class; - unset( $classes[ $key ] ); - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { - // Font Awesome. - $icon_classes[] = $class; - unset( $classes[ $key ] ); - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { - // Glyphicons. - $icon_classes[] = $class; - unset( $classes[ $key ] ); - } - } - - return $classes; - } - - /** - * Return a string containing a linkmod type and update $atts array - * accordingly depending on the decided. - * - * @since 4.0.0 - * - * @param array $linkmod_classes array of any link modifier classes. - * - * @return string empty for default, a linkmod type string otherwise. - */ - private function get_linkmod_type( $linkmod_classes = array() ) { - $linkmod_type = ''; - // Loop through array of linkmod classes to handle their $atts. - if ( ! empty( $linkmod_classes ) ) { - foreach ( $linkmod_classes as $link_class ) { - if ( ! empty( $link_class ) ) { - - // check for special class types and set a flag for them. - if ( 'dropdown-header' === $link_class ) { - $linkmod_type = 'dropdown-header'; - } elseif ( 'dropdown-divider' === $link_class ) { - $linkmod_type = 'dropdown-divider'; - } elseif ( 'dropdown-item-text' === $link_class ) { - $linkmod_type = 'dropdown-item-text'; - } - } - } - } - return $linkmod_type; - } - - /** - * Update the attributes of a nav item depending on the limkmod classes. - * - * @since 4.0.0 - * - * @param array $atts array of atts for the current link in nav item. - * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. - * - * @return array maybe updated array of attributes for item. - */ - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { - if ( ! empty( $linkmod_classes ) ) { - foreach ( $linkmod_classes as $link_class ) { - if ( ! empty( $link_class ) ) { - // update $atts with a space and the extra classname... - // so long as it's not a sr-only class. - if ( 'sr-only' !== $link_class ) { - $atts['class'] .= ' ' . esc_attr( $link_class ); - } - // check for special class types we need additional handling for. - if ( 'disabled' === $link_class ) { - // Convert link to '#' and unset open targets. - $atts['href'] = '#'; - unset( $atts['target'] ); - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { - // Store a type flag and unset href and target. - unset( $atts['href'] ); - unset( $atts['target'] ); - } - } - } - } - return $atts; - } - - /** - * Wraps the passed text in a screen reader only class. - * - * @since 4.0.0 - * - * @param string $text the string of text to be wrapped in a screen reader class. - * @return string the string wrapped in a span with the class. - */ - private function wrap_for_screen_reader( $text = '' ) { - if ( $text ) { - $text = '' . $text . ''; - } - return $text; - } - - /** - * Returns the correct opening element and attributes for a linkmod. - * - * @since 4.0.0 - * - * @param string $linkmod_type a sting containing a linkmod type flag. - * @param string $attributes a string of attributes to add to the element. - * - * @return string a string with the openign tag for the element with attribibutes added. - */ - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { - $output = ''; - if ( 'dropdown-item-text' === $linkmod_type ) { - $output .= ''; - } elseif ( 'dropdown-header' === $linkmod_type ) { - // For a header use a span with the .h6 class instead of a real - // header tag so that it doesn't confuse screen readers. - $output .= ''; - } elseif ( 'dropdown-divider' === $linkmod_type ) { - // this is a divider. - $output .= ''; - } - return $output; - } - } +if (class_exists('Walker_Nav_Menu')) { + if (! class_exists('WP_Bootstrap_Navwalker')) { + /** + * WP_Bootstrap_Navwalker class. + * + * @extends Walker_Nav_Menu + */ + class WP_Bootstrap_Navwalker extends Walker_Nav_Menu + { + + + /** + * Starts the list before the elements are added. + * + * @since WP 3.0.0 + * + * @see Walker_Nav_Menu::start_lvl() + * + * @param string $output Used to append additional content (passed by reference). + * @param int $depth Depth of menu item. Used for padding. + * @param stdClass $args An object of wp_nav_menu() arguments. + */ + public function start_lvl(&$output, $depth = 0, $args = array()) + { + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { + $t = ''; + $n = ''; + } else { + $t = "\t"; + $n = "\n"; + } + $indent = str_repeat($t, $depth); + // Default class to add to the file. + $classes = array( 'dropdown-menu' ); + /** + * Filters the CSS class(es) applied to a menu list element. + * + * @since WP 4.8.0 + * + * @param array $classes The CSS classes that are applied to the menu `'; + if ($container) { + $fallback_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; + } + } + } + + + /** + * Find any custom linkmod or icon classes and store in their holder + * arrays then remove them from the main classes array. + * + * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only + * Supported iconsets: Font Awesome 4/5, Glypicons + * + * NOTE: This accepts the linkmod and icon arrays by reference. + * + * @since 4.0.0 + * + * @param array $classes an array of classes currently assigned to the item. + * @param array $linkmod_classes an array to hold linkmod classes. + * @param array $icon_classes an array to hold icon classes. + * @param integer $depth an integer holding current depth level. + * + * @return array $classes a maybe modified array of classnames. + */ + private function seporate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) + { + // Loop through $classes array to find linkmod or icon classes. + foreach ($classes as $key => $class) { + // If any special classes are found, store the class in it's + // holder array and and unset the item from $classes. + if (preg_match('/^disabled|^sr-only/i', $class)) { + // Test for .disabled or .sr-only classes. + $linkmod_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { + // Test for .dropdown-header or .dropdown-divider and a + // depth greater than 0 - IE inside a dropdown. + $linkmod_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { + // Font Awesome. + $icon_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { + // Glyphicons. + $icon_classes[] = $class; + unset($classes[ $key ]); + } + } + + return $classes; + } + + + /** + * Return a string containing a linkmod type and update $atts array + * accordingly depending on the decided. + * + * @since 4.0.0 + * + * @param array $linkmod_classes array of any link modifier classes. + * + * @return string empty for default, a linkmod type string otherwise. + */ + private function get_linkmod_type($linkmod_classes = array()) + { + $linkmod_type = ''; + // Loop through array of linkmod classes to handle their $atts. + if (! empty($linkmod_classes)) { + foreach ($linkmod_classes as $link_class) { + if (! empty($link_class)) { + + // check for special class types and set a flag for them. + if ('dropdown-header' === $link_class) { + $linkmod_type = 'dropdown-header'; + } elseif ('dropdown-divider' === $link_class) { + $linkmod_type = 'dropdown-divider'; + } elseif ('dropdown-item-text' === $link_class) { + $linkmod_type = 'dropdown-item-text'; + } + } + } + } + return $linkmod_type; + } + + + /** + * Update the attributes of a nav item depending on the limkmod classes. + * + * @since 4.0.0 + * + * @param array $atts array of atts for the current link in nav item. + * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. + * + * @return array maybe updated array of attributes for item. + */ + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) + { + if (! empty($linkmod_classes)) { + foreach ($linkmod_classes as $link_class) { + if (! empty($link_class)) { + // update $atts with a space and the extra classname... + // so long as it's not a sr-only class. + if ('sr-only' !== $link_class) { + $atts['class'] .= ' ' . esc_attr($link_class); + } + // check for special class types we need additional handling for. + if ('disabled' === $link_class) { + // Convert link to '#' and unset open targets. + $atts['href'] = '#'; + unset($atts['target']); + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { + // Store a type flag and unset href and target. + unset($atts['href']); + unset($atts['target']); + } + } + } + } + return $atts; + } + + + /** + * Wraps the passed text in a screen reader only class. + * + * @since 4.0.0 + * + * @param string $text the string of text to be wrapped in a screen reader class. + * @return string the string wrapped in a span with the class. + */ + private function wrap_for_screen_reader($text = '') + { + if ($text) { + $text = '' . $text . ''; + } + return $text; + } + + + /** + * Returns the correct opening element and attributes for a linkmod. + * + * @since 4.0.0 + * + * @param string $linkmod_type a sting containing a linkmod type flag. + * @param string $attributes a string of attributes to add to the element. + * + * @return string a string with the openign tag for the element with attribibutes added. + */ + private function linkmod_element_open($linkmod_type, $attributes = '') + { + $output = ''; + if ('dropdown-item-text' === $linkmod_type) { + $output .= ''; + } elseif ('dropdown-header' === $linkmod_type) { + // For a header use a span with the .h6 class instead of a real + // header tag so that it doesn't confuse screen readers. + $output .= ''; + } elseif ('dropdown-divider' === $linkmod_type) { + // this is a divider. + $output .= ''; + } + return $output; + } + } + } } diff --git a/composer.json b/composer.json index d1b23f1..0def86f 100644 --- a/composer.json +++ b/composer.json @@ -1,41 +1,44 @@ { - "name": "mwdelaney/wp-bootstrap-navwalker", - "description": "A custom WordPress nav walker class to fully implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.", - "type": "library", - "license": "GPL-3.0+", - "authors": [ - { - "name": "Brandon Hubbard" - }, - { - "name": "William Patton", - "email": "will@pattonwebz.com" - } - ], - "support": { - "issues": "https://github.com/mwdelaney/wp-bootstrap-navwalker/issues/", - "source": "https://github.com/mwdelaney/wp-bootstrap-navwalker/" - }, - "require": { - "composer/installers": "~1.0" - }, - "require-dev": { - "stevegrunwell/wp-enforcer": "^0.5.0" - }, - "archive": { - "exclude": ["/.*", "/composer.lock"] + "name": "mwdelaney/wp-bootstrap-navwalker", + "description": "A custom WordPress nav walker class to fully implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.", + "type": "library", + "license": "GPL-3.0+", + "authors": [ + { + "name": "Brandon Hubbard" }, - "scripts": { - "post-install-cmd": [ - "wp-enforcer" - ], - "post-update-cmd": [ - "wp-enforcer" - ] - }, - "autoload": { - "files": [ - "class-wp-bootstrap-navwalker.php" - ] + { + "name": "William Patton", + "email": "will@pattonwebz.com" + } + ], + "support": { + "issues": "https://github.com/mwdelaney/wp-bootstrap-navwalker/issues/", + "source": "https://github.com/mwdelaney/wp-bootstrap-navwalker/" + }, + "require": { + "composer/installers": "~1.0" + }, + "require-dev": { + "stevegrunwell/wp-enforcer": "^0.5.0" + }, + "archive": { + "exclude": [ + "/.*", + "/composer.lock" + ] + }, + "scripts": { + "post-install-cmd": [ + "wp-enforcer" + ], + "post-update-cmd": [ + "wp-enforcer" + ] + }, + "autoload": { + "psr-4": { + "WPBOOTSTRAP\\WPBootstrapNavwalker\\": "app/" } + } } From 1ec28dbaf64eb756200ae0df44d7acf86e8a5875 Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Tue, 31 Jul 2018 14:14:34 -0400 Subject: [PATCH 05/11] Move class to /app --- .../class-wp-bootstrap-navwalker.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename class-wp-bootstrap-navwalker.php => app/class-wp-bootstrap-navwalker.php (100%) diff --git a/class-wp-bootstrap-navwalker.php b/app/class-wp-bootstrap-navwalker.php similarity index 100% rename from class-wp-bootstrap-navwalker.php rename to app/class-wp-bootstrap-navwalker.php From df15dc99599608e1f4b076e456c1258bbcbe97ec Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Tue, 31 Jul 2018 14:54:11 -0400 Subject: [PATCH 06/11] Move navwalker class to /app --- ...navwalker.php => WPBootstrapNavwalker.php} | 11 ++----- composer.json | 2 +- composer.lock | 32 ++++++++++--------- 3 files changed, 21 insertions(+), 24 deletions(-) rename app/{class-wp-bootstrap-navwalker.php => WPBootstrapNavwalker.php} (99%) diff --git a/app/class-wp-bootstrap-navwalker.php b/app/WPBootstrapNavwalker.php similarity index 99% rename from app/class-wp-bootstrap-navwalker.php rename to app/WPBootstrapNavwalker.php index 7d9b193..7c28f01 100644 --- a/app/class-wp-bootstrap-navwalker.php +++ b/app/WPBootstrapNavwalker.php @@ -1,11 +1,11 @@ =5.3", "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" }, + "require-dev": { + "phpcompatibility/php-compatibility": "*" + }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -259,7 +261,7 @@ "standards", "wordpress" ], - "time": "2018-02-16 01:57:48" + "time": "2018-07-25T18:10:35+00:00" } ], "aliases": [], From 556d744aee5eb40e0cae10271a0621eb471a0447 Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Tue, 31 Jul 2018 14:59:19 -0400 Subject: [PATCH 07/11] Spacing --- app/WPBootstrapNavwalker.php | 1032 +++++++++++++++++----------------- 1 file changed, 516 insertions(+), 516 deletions(-) diff --git a/app/WPBootstrapNavwalker.php b/app/WPBootstrapNavwalker.php index 7c28f01..259adb4 100644 --- a/app/WPBootstrapNavwalker.php +++ b/app/WPBootstrapNavwalker.php @@ -22,559 +22,559 @@ * License URI: http://www.gnu.org/licenses/gpl-3.0.txt */ - /** - * WP_Bootstrap_Navwalker class. - * - * @extends Walker_Nav_Menu - */ - class WPBootstrapNavwalker extends \Walker_Nav_Menu - { +/** + * WP_Bootstrap_Navwalker class. + * + * @extends Walker_Nav_Menu + */ +class WPBootstrapNavwalker extends \Walker_Nav_Menu +{ +/** + * Starts the list before the elements are added. + * + * @since WP 3.0.0 + * + * @see Walker_Nav_Menu::start_lvl() + * + * @param string $output Used to append additional content (passed by reference). + * @param int $depth Depth of menu item. Used for padding. + * @param stdClass $args An object of wp_nav_menu() arguments. + */ + public function start_lvl(&$output, $depth = 0, $args = array()) + { + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { + $t = ''; + $n = ''; + } else { + $t = "\t"; + $n = "\n"; + } + $indent = str_repeat($t, $depth); + // Default class to add to the file. + $classes = array( 'dropdown-menu' ); /** - * Starts the list before the elements are added. + * Filters the CSS class(es) applied to a menu list element. * - * @since WP 3.0.0 + * @since WP 4.8.0 * - * @see Walker_Nav_Menu::start_lvl() + * @param array $classes The CSS classes that are applied to the menu `'; + if ($container) { + $fallback_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; + } + } + } + + + /** + * Find any custom linkmod or icon classes and store in their holder + * arrays then remove them from the main classes array. + * + * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only + * Supported iconsets: Font Awesome 4/5, Glypicons + * + * NOTE: This accepts the linkmod and icon arrays by reference. + * + * @since 4.0.0 + * + * @param array $classes an array of classes currently assigned to the item. + * @param array $linkmod_classes an array to hold linkmod classes. + * @param array $icon_classes an array to hold icon classes. + * @param integer $depth an integer holding current depth level. + * + * @return array $classes a maybe modified array of classnames. + */ + private function seporate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) + { + // Loop through $classes array to find linkmod or icon classes. + foreach ($classes as $key => $class) { + // If any special classes are found, store the class in it's + // holder array and and unset the item from $classes. + if (preg_match('/^disabled|^sr-only/i', $class)) { + // Test for .disabled or .sr-only classes. + $linkmod_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { + // Test for .dropdown-header or .dropdown-divider and a + // depth greater than 0 - IE inside a dropdown. + $linkmod_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { + // Font Awesome. + $icon_classes[] = $class; + unset($classes[ $key ]); + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { + // Glyphicons. + $icon_classes[] = $class; + unset($classes[ $key ]); + } + } - /** - * Returns the correct opening element and attributes for a linkmod. - * - * @since 4.0.0 - * - * @param string $linkmod_type a sting containing a linkmod type flag. - * @param string $attributes a string of attributes to add to the element. - * - * @return string a string with the openign tag for the element with attribibutes added. - */ - private function linkmod_element_open($linkmod_type, $attributes = '') - { - $output = ''; - if ('dropdown-item-text' === $linkmod_type) { - $output .= ''; - } elseif ('dropdown-header' === $linkmod_type) { - // For a header use a span with the .h6 class instead of a real - // header tag so that it doesn't confuse screen readers. - $output .= ''; - } elseif ('dropdown-divider' === $linkmod_type) { - // this is a divider. - $output .= ''; + } + return $linkmod_type; + } + + + /** + * Update the attributes of a nav item depending on the limkmod classes. + * + * @since 4.0.0 + * + * @param array $atts array of atts for the current link in nav item. + * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays. + * + * @return array maybe updated array of attributes for item. + */ + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) + { + if (! empty($linkmod_classes)) { + foreach ($linkmod_classes as $link_class) { + if (! empty($link_class)) { + // update $atts with a space and the extra classname... + // so long as it's not a sr-only class. + if ('sr-only' !== $link_class) { + $atts['class'] .= ' ' . esc_attr($link_class); + } + // check for special class types we need additional handling for. + if ('disabled' === $link_class) { + // Convert link to '#' and unset open targets. + $atts['href'] = '#'; + unset($atts['target']); + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { + // Store a type flag and unset href and target. + unset($atts['href']); + unset($atts['target']); + } } - return $output; } } + return $atts; + } + + + /** + * Wraps the passed text in a screen reader only class. + * + * @since 4.0.0 + * + * @param string $text the string of text to be wrapped in a screen reader class. + * @return string the string wrapped in a span with the class. + */ + private function wrap_for_screen_reader($text = '') + { + if ($text) { + $text = '' . $text . ''; + } + return $text; + } + + + /** + * Returns the correct opening element and attributes for a linkmod. + * + * @since 4.0.0 + * + * @param string $linkmod_type a sting containing a linkmod type flag. + * @param string $attributes a string of attributes to add to the element. + * + * @return string a string with the openign tag for the element with attribibutes added. + */ + private function linkmod_element_open($linkmod_type, $attributes = '') + { + $output = ''; + if ('dropdown-item-text' === $linkmod_type) { + $output .= ''; + } elseif ('dropdown-header' === $linkmod_type) { + // For a header use a span with the .h6 class instead of a real + // header tag so that it doesn't confuse screen readers. + $output .= ''; + } elseif ('dropdown-divider' === $linkmod_type) { + // this is a divider. + $output .= ''; + } + return $output; + } +} From cdcabd128f177f5c32c15e6e4111d551eb9e1fcf Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 15:09:04 -0400 Subject: [PATCH 08/11] Update and rename WPBootstrapNavwalker.php to WP_Bootstrap_Navwalker.php --- app/{WPBootstrapNavwalker.php => WP_Bootstrap_Navwalker.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/{WPBootstrapNavwalker.php => WP_Bootstrap_Navwalker.php} (99%) diff --git a/app/WPBootstrapNavwalker.php b/app/WP_Bootstrap_Navwalker.php similarity index 99% rename from app/WPBootstrapNavwalker.php rename to app/WP_Bootstrap_Navwalker.php index 259adb4..6db24a4 100644 --- a/app/WPBootstrapNavwalker.php +++ b/app/WP_Bootstrap_Navwalker.php @@ -27,7 +27,7 @@ * * @extends Walker_Nav_Menu */ -class WPBootstrapNavwalker extends \Walker_Nav_Menu +class WP_Bootstrap_Navwalker extends \Walker_Nav_Menu { From 5ba4d2bd9b12a127f4e0a4d975d8f677a93ebaf0 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 15:09:30 -0400 Subject: [PATCH 09/11] Update WP_Bootstrap_Navwalker.php --- app/WP_Bootstrap_Navwalker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/WP_Bootstrap_Navwalker.php b/app/WP_Bootstrap_Navwalker.php index 6db24a4..2e93f19 100644 --- a/app/WP_Bootstrap_Navwalker.php +++ b/app/WP_Bootstrap_Navwalker.php @@ -5,7 +5,7 @@ /** * WP Bootstrap Navwalker * - * @package WP-Bootstrap-Navwaoh exlker + * @package WP-Bootstrap-Navwalker */ /* From 5b769195dc5af7ec82686f961c207d1ca1622776 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 15:17:25 -0400 Subject: [PATCH 10/11] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e6e5a5..0c10f9e 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ wp_nav_menu( array( 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'navbar-nav mr-auto', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new \WP_Bootstrap_Navwalker(), + 'walker' => new \WP_Bootstrap\WP_Bootstrap_Navwalker(), ) ); ``` @@ -97,7 +97,7 @@ Typically the menu is wrapped with additional markup, here is an example of a ` 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'nav navbar-nav', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', - 'walker' => new \WP_Bootstrap_Navwalker(), + 'walker' => new \WP_Bootstrap\WP_Bootstrap_Navwalker(), ) ); ?> @@ -120,7 +120,7 @@ There has been some interest in making this walker the default walker for all me ```php function prefix_modify_nav_menu_args( $args ) { return array_merge( $args, array( - 'walker' => \WP_Bootstrap_Navwalker(), + 'walker' => \WP_Bootstrap\WP_Bootstrap_Navwalker(), ) ); } add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' ); From 2260b3adb96932ef4e496edd8d7da73a726a228a Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Tue, 31 Jul 2018 15:20:05 -0400 Subject: [PATCH 11/11] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index aca33e2..3006bb6 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "mwdelaney/wp-bootstrap-navwalker", + "name": "wp-bootstrap/wp-bootstrap-navwalker", "description": "A custom WordPress nav walker class to fully implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.", "type": "library", "license": "GPL-3.0+", @@ -13,8 +13,8 @@ } ], "support": { - "issues": "https://github.com/mwdelaney/wp-bootstrap-navwalker/issues/", - "source": "https://github.com/mwdelaney/wp-bootstrap-navwalker/" + "issues": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues/", + "source": "https://github.com/wp-bootstrap/wp-bootstrap-navwalker/" }, "require": { "composer/installers": "~1.0"