33/**
44 * Class Name: wp_bootstrap_navwalker
55 * GitHub URI: https://github.com/twittem/wp-bootstrap-navwalker
6- * Description: A custom WordPress nav walker class to implement the Twitter Bootstrap 2.3.2 navigation style in a custom theme using the WordPress built in menu manager.
7- * Version: 2.0.3
6+ * 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.
7+ * Version: 2.0.4
88 * Author: Edward McIntyre - @twittem
99 * License: GPL-2.0+
1010 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
1111 */
1212
1313class wp_bootstrap_navwalker extends Walker_Nav_Menu {
14-
14+
1515 /**
1616 * @see Walker::start_lvl()
1717 * @since 3.0.0
@@ -40,11 +40,7 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
4040
4141 /**
4242 * Dividers, Headers or Disabled
43- <<<<<<< HEAD
44- * =============================
45- =======
4643 * =============================
47- >>>>>>> Added a fallback function when no menu assigned
4844 * Determine whether the item is a Divider, Header, Disabled or regular
4945 * menu item. To prevent errors we use the strcasecmp() function to so a
5046 * comparison that is not case sensitive. The strcasecmp() function returns
@@ -147,19 +143,19 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
147143 */
148144
149145 function display_element ( $ element , &$ children_elements , $ max_depth , $ depth , $ args , &$ output ) {
150- if ( !$ element ) {
151- return ;
152- }
146+ if ( !$ element ) {
147+ return ;
148+ }
153149
154- $ id_field = $ this ->db_fields ['id ' ];
150+ $ id_field = $ this ->db_fields ['id ' ];
155151
156- //display this element
157- if ( is_object ( $ args [0 ] ) ) {
158- $ args [0 ]->has_children = ! empty ( $ children_elements [$ element ->$ id_field ] );
159- }
152+ //display this element
153+ if ( is_object ( $ args [0 ] ) ) {
154+ $ args [0 ]->has_children = ! empty ( $ children_elements [$ element ->$ id_field ] );
155+ }
160156
161- parent ::display_element ($ element , $ children_elements , $ max_depth , $ depth , $ args , $ output );
162- }
157+ parent ::display_element ($ element , $ children_elements , $ max_depth , $ depth , $ args , $ output );
158+ }
163159
164160 /**
165161 * Menu Fallback
@@ -168,13 +164,50 @@ function display_element( $element, &$children_elements, $max_depth, $depth, $ar
168164 * and a manu has not been assigned to the theme location in the WordPress
169165 * menu manager the function with display nothing to a non-logged in user,
170166 * and will add a link to the WordPress menu manager if logged in as an admin.
167+ *
168+ * @param array $args passed from the wp_nav_menu function
169+ *
171170 */
172171
173- function fallback () {
174- if ( current_user_can ( 'manage_options ' ) ) {
175- echo '<li><a href=" ' . admin_url ( 'nav-menus.php ' ) . '">Add a menu</a></li> ' ;
172+ function fallback ( $ args ) {
173+ if ( current_user_can ( 'manage_options ' ) ) {
174+ $ fb_output = null ;
175+
176+ if ( $ container ) {
177+ $ fb_output = '< ' . $ container ;
178+
179+ if ( $ container_id ) {
180+ $ fb_output .= ' id=" ' . $ container_id . '" ' ;
181+ }
182+
183+ if ( $ container_class ) {
184+ $ fb_output .= ' class=" ' . $ container_class . '" ' ;
185+ }
186+
187+ $ fb_output .= '> ' ;
188+ }
189+
190+ $ fb_output .= '<ul ' ;
191+
192+ if ( $ menu_id ) {
193+ $ fb_output .= ' id=" ' . $ menu_id . '" ' ;
194+ }
195+
196+ if ( $ menu_class ) {
197+ $ fb_output .= ' class=" ' . $ menu_class . '" ' ;
198+ }
199+
200+ $ fb_output .= '> ' ;
201+ $ fb_output .= '<li><a href=" ' . admin_url ( 'nav-menus.php ' ) . '">Add a menu</a></li> ' ;
202+ $ fb_output .= '</ul> ' ;
203+
204+ if ( $ container ) {
205+ $ fb_output .= '</ ' . $ container . '> ' ;
206+ }
207+
208+ echo $ fb_output ;
176209 }
177210 }
178211}
179212
180- ?>
213+ ?>
0 commit comments