@@ -19,8 +19,8 @@ class wp_bootstrap_navwalker extends Walker_Nav_Menu {
19
19
* @param string $output Passed by reference. Used to append additional content.
20
20
* @param int $depth Depth of page. Used for padding.
21
21
*/
22
- function start_lvl ( &$ output , $ depth = 0 , $ args = array () ) {
23
- $ indent = str_repeat ("\t" , $ depth );
22
+ public function start_lvl ( &$ output , $ depth = 0 , $ args = array () ) {
23
+ $ indent = str_repeat ( "\t" , $ depth );
24
24
$ output .= "\n$ indent<ul role= \"menu \" class= \" dropdown-menu \"> \n" ;
25
25
}
26
26
@@ -34,8 +34,7 @@ function start_lvl( &$output, $depth = 0, $args = array() ) {
34
34
* @param int $current_page Menu item ID.
35
35
* @param object $args
36
36
*/
37
-
38
- function start_el ( &$ output , $ item , $ depth = 0 , $ args = array (), $ id = 0 ) {
37
+ public function start_el ( &$ output , $ item , $ depth = 0 , $ args = array (), $ id = 0 ) {
39
38
$ indent = ( $ depth ) ? str_repeat ( "\t" , $ depth ) : '' ;
40
39
41
40
/**
@@ -46,13 +45,13 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
46
45
* comparison that is not case sensitive. The strcasecmp() function returns
47
46
* a 0 if the strings are equal.
48
47
*/
49
- if (strcasecmp ($ item ->attr_title , 'divider ' ) == 0 && $ depth === 1 ) {
48
+ if ( strcasecmp ( $ item ->attr_title , 'divider ' ) == 0 && $ depth === 1 ) {
50
49
$ output .= $ indent . '<li role="presentation" class="divider"> ' ;
51
- } else if (strcasecmp ($ item ->title , 'divider ' ) == 0 && $ depth === 1 ) {
50
+ } else if ( strcasecmp ( $ item ->title , 'divider ' ) == 0 && $ depth === 1 ) {
52
51
$ output .= $ indent . '<li role="presentation" class="divider"> ' ;
53
- } else if (strcasecmp ($ item ->attr_title , 'dropdown-header ' ) == 0 && $ depth === 1 ) {
52
+ } else if ( strcasecmp ( $ item ->attr_title , 'dropdown-header ' ) == 0 && $ depth === 1 ) {
54
53
$ output .= $ indent . '<li role="presentation" class="dropdown-header"> ' . esc_attr ( $ item ->title );
55
- } else if (strcasecmp ($ item ->attr_title , 'disabled ' ) == 0 ) {
54
+ } else if ( strcasecmp ($ item ->attr_title , 'disabled ' ) == 0 ) {
56
55
$ output .= $ indent . '<li role="presentation" class="disabled"><a href="#"> ' . esc_attr ( $ item ->title ) . '</a> ' ;
57
56
} else {
58
57
@@ -62,9 +61,12 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
62
61
$ classes [] = 'menu-item- ' . $ item ->ID ;
63
62
64
63
$ class_names = join ( ' ' , apply_filters ( 'nav_menu_css_class ' , array_filter ( $ classes ), $ item , $ args ) );
65
-
66
- if ($ args ->has_children ) { $ class_names .= ' dropdown ' ; }
67
- if (in_array ('current-menu-item ' , $ classes )) { $ class_names .= ' active ' ; }
64
+
65
+ if ( $ args ->has_children )
66
+ $ class_names .= ' dropdown ' ;
67
+
68
+ if ( in_array ( 'current-menu-item ' , $ classes ) )
69
+ $ class_names .= ' active ' ;
68
70
69
71
$ class_names = $ class_names ? ' class=" ' . esc_attr ( $ class_names ) . '" ' : '' ;
70
72
@@ -74,12 +76,12 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
74
76
$ output .= $ indent . '<li ' . $ id . $ value . $ class_names .'> ' ;
75
77
76
78
$ atts = array ();
77
- $ atts ['title ' ] = ! empty ( $ item ->title ) ? $ item ->title : '' ;
78
- $ atts ['target ' ] = ! empty ( $ item ->target ) ? $ item ->target : '' ;
79
- $ atts ['rel ' ] = ! empty ( $ item ->xfn ) ? $ item ->xfn : '' ;
79
+ $ atts ['title ' ] = ! empty ( $ item ->title ) ? $ item ->title : '' ;
80
+ $ atts ['target ' ] = ! empty ( $ item ->target ) ? $ item ->target : '' ;
81
+ $ atts ['rel ' ] = ! empty ( $ item ->xfn ) ? $ item ->xfn : '' ;
80
82
81
- //If item has_children add atts to a
82
- if ( $ args ->has_children && $ depth === 0 ) {
83
+ // If item has_children add atts to a.
84
+ if ( $ args ->has_children && $ depth === 0 ) {
83
85
$ atts ['href ' ] = '# ' ;
84
86
$ atts ['data-toggle ' ] = 'dropdown ' ;
85
87
$ atts ['class ' ] = 'dropdown-toggle ' ;
@@ -106,15 +108,13 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
106
108
* if there is a value in the attr_title property. If the attr_title
107
109
* property is NOT null we apply it as the class name for the glyphicon.
108
110
*/
109
-
110
- if (! empty ( $ item ->attr_title )){
111
+ if ( ! empty ( $ item ->attr_title ) )
111
112
$ item_output .= '<a ' . $ attributes .'><span class="glyphicon ' . esc_attr ( $ item ->attr_title ) . '"></span> ' ;
112
- } else {
113
+ else
113
114
$ item_output .= '<a ' . $ attributes .'> ' ;
114
- }
115
-
115
+
116
116
$ item_output .= $ args ->link_before . apply_filters ( 'the_title ' , $ item ->title , $ item ->ID ) . $ args ->link_after ;
117
- $ item_output .= ($ args ->has_children && $ depth === 0 ) ? ' <span class="caret"></span></a> ' : '</a> ' ;
117
+ $ item_output .= ( $ args ->has_children && 0 === $ depth ) ? ' <span class="caret"></span></a> ' : '</a> ' ;
118
118
$ item_output .= $ args ->after ;
119
119
120
120
$ output .= apply_filters ( 'walker_nav_menu_start_el ' , $ item_output , $ item , $ depth , $ args );
@@ -126,7 +126,7 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
126
126
*
127
127
* Display one element if the element doesn't have any children otherwise,
128
128
* display the element and its children. Will only traverse up to the max
129
- * depth and no ignore elements under that depth.
129
+ * depth and no ignore elements under that depth.
130
130
*
131
131
* This method shouldn't be called directly, use the walk() method instead.
132
132
*
@@ -141,20 +141,17 @@ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
141
141
* @param string $output Passed by reference. Used to append additional content.
142
142
* @return null Null on failure with no changes to parameters.
143
143
*/
144
-
145
- function display_element ( $ element , &$ children_elements , $ max_depth , $ depth , $ args , &$ output ) {
146
- if ( !$ element ) {
144
+ public function display_element ( $ element , &$ children_elements , $ max_depth , $ depth , $ args , &$ output ) {
145
+ if ( ! $ element )
147
146
return ;
148
- }
149
147
150
148
$ id_field = $ this ->db_fields ['id ' ];
151
149
152
- //display this element
153
- if ( is_object ( $ args [0 ] ) ) {
154
- $ args [0 ]->has_children = ! empty ( $ children_elements [$ element ->$ id_field ] );
155
- }
150
+ // Display this element.
151
+ if ( is_object ( $ args [0 ] ) )
152
+ $ args [0 ]->has_children = ! empty ( $ children_elements [ $ element ->$ id_field ] );
156
153
157
- parent ::display_element ($ element , $ children_elements , $ max_depth , $ depth , $ args , $ output );
154
+ parent ::display_element ( $ element , $ children_elements , $ max_depth , $ depth , $ args , $ output );
158
155
}
159
156
160
157
/**
@@ -165,11 +162,10 @@ function display_element( $element, &$children_elements, $max_depth, $depth, $ar
165
162
* menu manager the function with display nothing to a non-logged in user,
166
163
* and will add a link to the WordPress menu manager if logged in as an admin.
167
164
*
168
- * @param array $args passed from the wp_nav_menu function
165
+ * @param array $args passed from the wp_nav_menu function.
169
166
*
170
167
*/
171
-
172
- function fallback ( $ args ) {
168
+ public static function fallback ( $ args ) {
173
169
if ( current_user_can ( 'manage_options ' ) ) {
174
170
175
171
extract ( $ args );
@@ -179,38 +175,31 @@ function fallback( $args ) {
179
175
if ( $ container ) {
180
176
$ fb_output = '< ' . $ container ;
181
177
182
- if ( $ container_id ) {
178
+ if ( $ container_id )
183
179
$ fb_output .= ' id=" ' . $ container_id . '" ' ;
184
- }
185
180
186
- if ( $ container_class ) {
181
+ if ( $ container_class )
187
182
$ fb_output .= ' class=" ' . $ container_class . '" ' ;
188
- }
189
183
190
184
$ fb_output .= '> ' ;
191
185
}
192
-
186
+
193
187
$ fb_output .= '<ul ' ;
194
188
195
- if ( $ menu_id ) {
189
+ if ( $ menu_id )
196
190
$ fb_output .= ' id=" ' . $ menu_id . '" ' ;
197
- }
198
191
199
- if ( $ menu_class ) {
192
+ if ( $ menu_class )
200
193
$ fb_output .= ' class=" ' . $ menu_class . '" ' ;
201
- }
202
194
203
195
$ fb_output .= '> ' ;
204
196
$ fb_output .= '<li><a href=" ' . admin_url ( 'nav-menus.php ' ) . '">Add a menu</a></li> ' ;
205
197
$ fb_output .= '</ul> ' ;
206
198
207
- if ( $ container ) {
199
+ if ( $ container )
208
200
$ fb_output .= '</ ' . $ container . '> ' ;
209
- }
210
201
211
202
echo $ fb_output ;
212
203
}
213
204
}
214
205
}
215
-
216
- ?>
0 commit comments