From ab716b270ce20afeb47c8c7fa44f7cae6cd9ffe6 Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 16:59:54 +0100 Subject: [PATCH 01/63] schema markup addition --- class-wp-bootstrap-navwalker.php | 49 +++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index cd598e1..5eb3509 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -28,6 +28,25 @@ */ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { + /** + * Whether the items_wrap contains schema microdata or not. + * + * @since 4.2.0 + * @var type bool + */ + private $has_schema = false; + + /** + * Ensure the items_wrap argument contains microdata. + * + * @since 4.2.0 + */ + public function __construct() { + if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { + add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); + } + } + /** * Starts the list before the elements are added. * @@ -103,6 +122,12 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; + if ( strpos( $args->items_wrap, 'itemscope' ) !== false && $this->has_schema === false ) { + $this->has_schema = true; + $args->link_before = '' . $args->link_before; + $args->link_after .= ''; + } + $classes = empty( $item->classes ) ? array() : (array) $item->classes; // Initialize some holder variables to store specially handled item @@ -165,7 +190,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; - $output .= $indent . '
  • '; + $output .= $indent . '
  • '; // initialize array for holding the $atts for the link item. $atts = array(); @@ -189,6 +214,10 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $atts['class'] = 'dropdown-toggle nav-link'; $atts['id'] = 'menu-item-dropdown-' . $item->ID; } else { + if ( $this->has_schema === true ) { + $atts['itemprop'] = 'url'; + } + $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; // Items in dropdowns use .dropdown-item instead of .nav-link. if ( $depth > 0 ) { @@ -200,6 +229,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 // update atts of this item based on any custom linkmod classes. $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); + // Allow filtering of the $atts array before using it. $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); @@ -378,6 +408,23 @@ public static function fallback( $args ) { } } + /** + * Filter to ensure the items_Wrap argument contains microdata. + * + * @since 4.2.0 + * + * @param array $args The nav instance arguments. + * @return array $args The altered nav instance arguments. + */ + public function add_schema_to_navbar_ul( $args ) { + $wrap = $args['items_wrap']; + if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { + $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap ); + } + + return $args; + } + /** * Find any custom linkmod or icon classes and store in their holder * arrays then remove them from the main classes array. From 096c5a2982fe67ab56bcb843ac2c31237d46a7cf Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 17:17:04 +0100 Subject: [PATCH 02/63] Manual phpcs edits Via the travis output --- class-wp-bootstrap-navwalker.php | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 5eb3509..91c1c5d 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -28,24 +28,24 @@ */ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { - /** - * Whether the items_wrap contains schema microdata or not. - * - * @since 4.2.0 - * @var type bool - */ - private $has_schema = false; - - /** - * Ensure the items_wrap argument contains microdata. - * - * @since 4.2.0 - */ - public function __construct() { - if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { - add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); - } - } + /** + * Whether the items_wrap contains schema microdata or not. + * + * @since 4.2.0 + * @var type bool + */ + private $has_schema = false; + + /** + * Ensure the items_wrap argument contains microdata. + * + * @since 4.2.0 + */ + public function __construct() { + if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { + add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); + } + } /** * Starts the list before the elements are added. @@ -122,11 +122,11 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; - if ( strpos( $args->items_wrap, 'itemscope' ) !== false && $this->has_schema === false ) { - $this->has_schema = true; - $args->link_before = '' . $args->link_before; - $args->link_after .= ''; - } + if ( false !== strpos( $args->items_wrap, 'itemscope' ) && false === $this->has_schema ) { + $this->has_schema = true; + $args->link_before = '' . $args->link_before; + $args->link_after .= ''; + } $classes = empty( $item->classes ) ? array() : (array) $item->classes; @@ -215,8 +215,8 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $atts['id'] = 'menu-item-dropdown-' . $item->ID; } else { if ( $this->has_schema === true ) { - $atts['itemprop'] = 'url'; - } + $atts['itemprop'] = 'url'; + } $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; // Items in dropdowns use .dropdown-item instead of .nav-link. @@ -409,21 +409,21 @@ public static function fallback( $args ) { } /** - * Filter to ensure the items_Wrap argument contains microdata. - * - * @since 4.2.0 - * - * @param array $args The nav instance arguments. - * @return array $args The altered nav instance arguments. - */ - public function add_schema_to_navbar_ul( $args ) { - $wrap = $args['items_wrap']; - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap ); - } - - return $args; - } + * Filter to ensure the items_Wrap argument contains microdata. + * + * @since 4.2.0 + * + * @param array $args The nav instance arguments. + * @return array $args The altered nav instance arguments. + */ + public function add_schema_to_navbar_ul( $args ) { + $wrap = $args['items_wrap']; + if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { + $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"'."$0", $wrap ); + } + + return $args; + } /** * Find any custom linkmod or icon classes and store in their holder From 1411f096389353fd4de005a967bf46ac317453be Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 17:45:36 +0100 Subject: [PATCH 03/63] Additional standards fixes --- 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 91c1c5d..b2f1191 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -43,7 +43,7 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { */ public function __construct() { if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { - add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); + add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); } } @@ -419,7 +419,7 @@ public static function fallback( $args ) { public function add_schema_to_navbar_ul( $args ) { $wrap = $args['items_wrap']; if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"'."$0", $wrap ); + $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); } return $args; From e4954caafc38c1d2d69c47871d62a7c4f6bfee46 Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 17:49:39 +0100 Subject: [PATCH 04/63] Added yoda condition As per PHPCS recommendations --- 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 b2f1191..7c43761 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -32,7 +32,7 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { * Whether the items_wrap contains schema microdata or not. * * @since 4.2.0 - * @var type bool + * @var type boolean */ private $has_schema = false; @@ -214,7 +214,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $atts['class'] = 'dropdown-toggle nav-link'; $atts['id'] = 'menu-item-dropdown-' . $item->ID; } else { - if ( $this->has_schema === true ) { + if ( true === $this->has_schema ) { $atts['itemprop'] = 'url'; } From ef38f311a6e3c53c5ce83f28febf279afb5736b1 Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 17:55:36 +0100 Subject: [PATCH 05/63] Remove phpdoc rogue 'type' --- 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 7c43761..33bc0de 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -32,7 +32,7 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { * Whether the items_wrap contains schema microdata or not. * * @since 4.2.0 - * @var type boolean + * @var boolean */ private $has_schema = false; From d2ea1e3af2cbbc73213e70753fca858e3e71ba38 Mon Sep 17 00:00:00 2001 From: jake whiteley Date: Sun, 3 Jun 2018 18:03:29 +0100 Subject: [PATCH 06/63] Remove short array syntax To support PHP 5.3 --- 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 33bc0de..e8f5fe3 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -42,8 +42,8 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { * @since 4.2.0 */ public function __construct() { - if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { - add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); + if ( ! has_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ) ) { + add_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ); } } From c3b0cdd75010bd1a773c8b32f1dee531952bdc26 Mon Sep 17 00:00:00 2001 From: zethodderskov Date: Fri, 24 Aug 2018 15:41:40 +0200 Subject: [PATCH 07/63] Add require to function (improved installation) --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be9e978..812a21a 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,13 @@ Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-c Open your WordPress themes **functions.php** file - `/wp-content/your-theme/functions.php` - and add the following code: ```php -// Register Custom Navigation Walker -require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; +/** + * Register Custom Navigation Walker + */ +function register_navwalker(){ + require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; +} +add_action( 'after_setup_theme', 'register_navwalker' ); ``` If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem. From 493668dadee01d907636e66d9dce9e4c5029390c Mon Sep 17 00:00:00 2001 From: Luciano van der Veekens Date: Sat, 26 Jan 2019 18:18:33 +0100 Subject: [PATCH 08/63] Fix bug in the WordPress Customizer preview related to the CSS classes of a menu item --- class-wp-bootstrap-navwalker.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 2ea36d7..3d90dfe 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -105,6 +105,13 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $classes = empty( $item->classes ) ? array() : (array) $item->classes; + // Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined + // in that particular input box to come in as one big class string. + $split_on_spaces = function ( $class ) { + return preg_split( '/\s+/', $class ); + }; + $classes = flatten( array_map( $split_on_spaces, $classes ) ); + // Initialize some holder variables to store specially handled item // wrappers and icons. $linkmod_classes = array(); @@ -552,4 +559,23 @@ private function linkmod_element_close( $linkmod_type ) { return $output; } } + + /** + * Flattens a multidimensional array to a simple array. + * + * @param array $array a multidimensional array. + * + * @return array a simple array + */ + function flatten( $array ) { + $result = array(); + foreach ( $array as $element ) { + if ( is_array( $element ) ) { + array_push( $result, ...flatten( $element ) ); + } else { + $result[] = $element; + } + } + return $result; + } } From f9d3130b8a008e627fa8301da9bbfd3f8cae84fe Mon Sep 17 00:00:00 2001 From: Marcio Zebedeu Date: Mon, 25 Mar 2019 21:37:35 +0100 Subject: [PATCH 09/63] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be9e978..9e0dad4 100644 --- a/README.md +++ b/README.md @@ -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' => new WP_Bootstrap_Navwalker(), ) ); } add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' ); From 15b726570f99d5deb684a8af8ef85f69095c97b7 Mon Sep 17 00:00:00 2001 From: BraydenGray416 <48417845+BraydenGray416@users.noreply.github.com> Date: Wed, 23 Oct 2019 10:56:18 +1300 Subject: [PATCH 10/63] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2633c9c..7224b6f 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ Here is a list of the most notable changes: ## Installation -Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content/your-theme/` +Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-content/themes/your-theme/` -Open your WordPress themes **functions.php** file - `/wp-content/your-theme/functions.php` - and add the following code: +Open your WordPress themes **functions.php** file - `/wp-content/themes/your-theme/functions.php` - and add the following code: ```php /** From 6e65b9797c6f5a90d6fe1d2980ece995b710942e Mon Sep 17 00:00:00 2001 From: BraydenGray416 <48417845+BraydenGray416@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:24:49 +1300 Subject: [PATCH 11/63] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2633c9c..ba93255 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Review options in the Bootstrap docs for more information on [nav classes](https To display the menu you must associate your menu with your theme location. You can do this by selecting your theme location in the *Theme Locations* list while editing a menu in the WordPress menu manager. -### Making this Walker the Default Walker for Nav Manus +### Making this Walker the Default Walker for Nav Menus There has been some interest in making this walker the default walker for all menus. That could result in some unexpected situations but it can be achieved by adding this function to your functions.php file. From 15661323db81b713391f9f9d1ea6301136ca0469 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 8 Nov 2019 19:24:12 +0100 Subject: [PATCH 12/63] Add rel="noopener noreferrer" to target="_blank" Added to class Walker_Nav_Menu in WP 5.2 --- class-wp-bootstrap-navwalker.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 94adf76..ccd6471 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -177,7 +177,11 @@ 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 ( '_blank' === $item->target && empty( $item->xfn ) ) { + $atts['rel'] = 'noopener noreferrer'; + } else { + $atts['rel'] = $item->xfn; + } // If item has_children add atts to . if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { $atts['href'] = '#'; From d755253326ea3280d9394489d565948e894e1ad5 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Sat, 9 Nov 2019 12:46:44 +0100 Subject: [PATCH 13/63] Remove esc_html() from $item->title Removes esc_html() from $item->title since the use of HTML in the title is allowed. --- 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 94adf76..2c5570b 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -245,7 +245,7 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 } /** This filter is documented in wp-includes/post-template.php */ - $title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID ); + $title = apply_filters( 'the_title', $item->title, $item->ID ); /** * Filters a menu item's title. From fbe7a35bb32a484e398eff7d3f7db50f99720158 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Sat, 9 Nov 2019 19:01:18 +0100 Subject: [PATCH 14/63] Rewrite fallback() * Adds filter hook for allowed container HTML tags * Adds CSS classes menu-fallback-container and menu-fallback-menu to target the fallback container and menu styling * Fixes a typo in the function description --- class-wp-bootstrap-navwalker.php | 55 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 94adf76..67df043 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -326,10 +326,10 @@ public function display_element( $element, &$children_elements, $max_depth, $dep /** * Menu Fallback - * ============= + * * If this function is assigned to the wp_nav_menu's fallback_cb variable * and a menu has not been assigned to the theme location in the WordPress - * menu manager the function with display nothing to a non-logged in user, + * menu manager the function will display nothing to a non-logged in user, * and will add a link to the WordPress menu manager if logged in as an admin. * * @param array $args passed from the wp_nav_menu function. @@ -337,36 +337,39 @@ public function display_element( $element, &$children_elements, $max_depth, $dep public static function fallback( $args ) { if ( current_user_can( 'edit_theme_options' ) ) { - /* Get Arguments. */ - $container = $args['container']; - $container_id = $args['container_id']; - $container_class = $args['container_class']; - $menu_class = $args['menu_class']; - $menu_id = $args['menu_id']; - - // initialize var to store fallback html. + // Initialize var to store fallback html. $fallback_output = ''; - if ( $container ) { - $fallback_output .= '<' . esc_attr( $container ); - if ( $container_id ) { - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; - } - if ( $container_class ) { - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; + // Menu container opening tag. + $show_container = false; + if ( $args['container'] ) { + /** + * Filters the list of HTML tags that are valid for use as menu containers. + * + * @since WP 3.0.0 + * + * @param array $tags The acceptable HTML tags for use as menu containers. + * Default is array containing 'div' and 'nav'. + */ + $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); + if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) { + $show_container = true; + $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; + $id = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : ''; + $fallback_output .= '<' . $args['container'] . $id . $class . '>'; } - $fallback_output .= '>'; } - $fallback_output .= ''; $fallback_output .= '
  • '; $fallback_output .= ''; - if ( $container ) { - $fallback_output .= ''; + + // Menu container closing tag. + if ( $show_container ) { + $fallback_output .= ''; } // if $args has 'echo' key and it's true echo, otherwise return. From 932fa35142fc1b13ba84d17101cbc43b712cdba2 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Sat, 9 Nov 2019 19:33:07 +0100 Subject: [PATCH 15/63] Add @return tag --- class-wp-bootstrap-navwalker.php | 1 + 1 file changed, 1 insertion(+) diff --git a/class-wp-bootstrap-navwalker.php b/class-wp-bootstrap-navwalker.php index 67df043..be5f437 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -333,6 +333,7 @@ public function display_element( $element, &$children_elements, $max_depth, $dep * and will add a link to the WordPress menu manager if logged in as an admin. * * @param array $args passed from the wp_nav_menu function. + * @return string|void String when echo is false. */ public static function fallback( $args ) { if ( current_user_can( 'edit_theme_options' ) ) { From 6a3d6def10e6f336c742769ba1f32e46989d76a5 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Sun, 10 Nov 2019 02:26:28 +0100 Subject: [PATCH 16/63] Fix container class --- 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 be5f437..315a9ad 100644 --- a/class-wp-bootstrap-navwalker.php +++ b/class-wp-bootstrap-navwalker.php @@ -355,14 +355,14 @@ public static function fallback( $args ) { $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) { $show_container = true; - $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; + $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"'; $id = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : ''; $fallback_output .= '<' . $args['container'] . $id . $class . '>'; } } // The fallback menu. - $class = $args['menu_class'] ? ' class="' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; + $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; $id = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : ''; $fallback_output .= ''; $fallback_output .= ''; From 5c6823c4f4033ad54abf1b5616624cbed23a8db8 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Sun, 10 Nov 2019 02:39:30 +0100 Subject: [PATCH 17/63] Update fallback output test for logged-in users Include the new CSS class `menu-fallback-container` in the fallback output test for logged-in users. --- tests/test-navwalker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-navwalker.php b/tests/test-navwalker.php index 0e96488..1981f18 100644 --- a/tests/test-navwalker.php +++ b/tests/test-navwalker.php @@ -220,7 +220,7 @@ public function test_fallback_function_output_loggedin() { // rudimentary content test - confirm it opens a div with 2 expected // values and ends by closing a div. - $match = ( preg_match( '/^(
    )(.*?)(<\/div>)$/', $fallback_output_echo ) ) ? true : false; + $match = ( preg_match( '/^(