@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | |
22 | 22 | /* Check if Class Exists. */ |
23 | -if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) { |
|
23 | +if ( ! class_exists('WP_Bootstrap_Navwalker')) { |
|
24 | 24 | /** |
25 | 25 | * WP_Bootstrap_Navwalker class. |
26 | 26 | * |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | * @param int $depth Depth of menu item. Used for padding. |
40 | 40 | * @param stdClass $args An object of wp_nav_menu() arguments. |
41 | 41 | */ |
42 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
43 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
42 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
43 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
44 | 44 | $t = ''; |
45 | 45 | $n = ''; |
46 | 46 | } else { |
47 | 47 | $t = "\t"; |
48 | 48 | $n = "\n"; |
49 | 49 | } |
50 | - $indent = str_repeat( $t, $depth ); |
|
50 | + $indent = str_repeat($t, $depth); |
|
51 | 51 | // Default class to add to the file. |
52 | - $classes = array( 'dropdown-menu' ); |
|
52 | + $classes = array('dropdown-menu'); |
|
53 | 53 | /** |
54 | 54 | * Filters the CSS class(es) applied to a menu list element. |
55 | 55 | * |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
60 | 60 | * @param int $depth Depth of menu item. Used for padding. |
61 | 61 | */ |
62 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
63 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
62 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
63 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
64 | 64 | /** |
65 | 65 | * The `.dropdown-menu` container needs to have a labelledby |
66 | 66 | * attribute which points to it's trigger link. |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | * link with an id that was added to the $output. |
70 | 70 | */ |
71 | 71 | // find all links with an id in the output. |
72 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
72 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
73 | 73 | // with pointer at end of array check if we got an ID match. |
74 | - if ( end( $matches[2] ) ) { |
|
74 | + if (end($matches[2])) { |
|
75 | 75 | // build a string to use as aria-labelledby. |
76 | - $lablledby = 'aria-labelledby="' . end( $matches[2] ) . '"'; |
|
76 | + $lablledby = 'aria-labelledby="' . end($matches[2]) . '"'; |
|
77 | 77 | } |
78 | 78 | $output .= "{$n}{$indent}<ul$class_names $lablledby role=\"menu\">{$n}"; |
79 | 79 | } |
@@ -92,19 +92,19 @@ discard block |
||
92 | 92 | * @param stdClass $args An object of wp_nav_menu() arguments. |
93 | 93 | * @param int $id Current item ID. |
94 | 94 | */ |
95 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
96 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
95 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
96 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
97 | 97 | $t = ''; |
98 | 98 | $n = ''; |
99 | 99 | } else { |
100 | 100 | $t = "\t"; |
101 | 101 | $n = "\n"; |
102 | 102 | } |
103 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
103 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
104 | 104 | |
105 | 105 | $value = ''; |
106 | 106 | $class_names = $value; |
107 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
107 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
108 | 108 | |
109 | 109 | // Initialize some holder variables to store specially handled item |
110 | 110 | // wrappers and icons. |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $icon_class_string = ''; |
114 | 114 | |
115 | 115 | // Loop and begin handling any special linkmod or icon classes. |
116 | - foreach ( $classes as $key => $class ) { |
|
116 | + foreach ($classes as $key => $class) { |
|
117 | 117 | /** |
118 | 118 | * Find any custom link mods or icons, store in their holder |
119 | 119 | * arrays and remove them from the classes array. |
@@ -121,28 +121,28 @@ discard block |
||
121 | 121 | * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider |
122 | 122 | * Supported iconsets: Font Awesome 4/5, Glypicons |
123 | 123 | */ |
124 | - if ( preg_match( '/disabled/', $class ) ) { |
|
124 | + if (preg_match('/disabled/', $class)) { |
|
125 | 125 | // Test for .disabled. |
126 | 126 | $extra_link_classes[] = $class; |
127 | - unset( $classes[ $key ] ); |
|
128 | - } elseif ( preg_match( '/dropdown-header|dropdown-divider/', $class ) && $depth > 0 ) { |
|
127 | + unset($classes[$key]); |
|
128 | + } elseif (preg_match('/dropdown-header|dropdown-divider/', $class) && $depth > 0) { |
|
129 | 129 | // Test for .dropdown-header or .dropdown-divider and a |
130 | 130 | // depth greater than 0 - IE inside a dropdown. |
131 | 131 | $extra_link_classes[] = $class; |
132 | - unset( $classes[ $key ] ); |
|
133 | - } elseif ( preg_match( '/fa-(\S*)?|fas(\s?)|fa(\s?)/', $class ) ) { |
|
132 | + unset($classes[$key]); |
|
133 | + } elseif (preg_match('/fa-(\S*)?|fas(\s?)|fa(\s?)/', $class)) { |
|
134 | 134 | // Font Awesome. |
135 | 135 | $icon_classes[] = $class; |
136 | - unset( $classes[ $key ] ); |
|
137 | - } elseif ( preg_match( '/glyphicons-(\S*)?|glyphicons(\s?)/', $class ) ) { |
|
136 | + unset($classes[$key]); |
|
137 | + } elseif (preg_match('/glyphicons-(\S*)?|glyphicons(\s?)/', $class)) { |
|
138 | 138 | // Glyphicons. |
139 | 139 | $icon_classes[] = $class; |
140 | - unset( $classes[ $key ] ); |
|
140 | + unset($classes[$key]); |
|
141 | 141 | } |
142 | 142 | } // End foreach(). |
143 | 143 | |
144 | 144 | // Join any icon classes plucked from $classes into a string. |
145 | - $icon_class_string = join( ' ', $icon_classes ); |
|
145 | + $icon_class_string = join(' ', $icon_classes); |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Filters the arguments for a single nav menu item. |
@@ -153,25 +153,25 @@ discard block |
||
153 | 153 | * @param WP_Post $item Menu item data object. |
154 | 154 | * @param int $depth Depth of menu item. Used for padding. |
155 | 155 | */ |
156 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
156 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
157 | 157 | |
158 | 158 | $classes[] = 'menu-item-' . $item->ID; |
159 | 159 | $classes[] = 'nav-item'; |
160 | 160 | |
161 | 161 | // Add .dropdown or .active classes where they are needed. |
162 | - if ( $args->has_children ) { |
|
162 | + if ($args->has_children) { |
|
163 | 163 | $classes[] = 'dropdown'; |
164 | 164 | } |
165 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
165 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
166 | 166 | $classes[] = 'active'; |
167 | 167 | } |
168 | 168 | |
169 | 169 | // Allow filtering the classes. |
170 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
170 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
171 | 171 | |
172 | 172 | // Form a string of classes in format: class="class_names". |
173 | - $class_names = join( ' ', $classes ); |
|
174 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
173 | + $class_names = join(' ', $classes); |
|
174 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * Filters the ID applied to a menu item's list item element. |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param stdClass $args An object of wp_nav_menu() arguments. |
185 | 185 | * @param int $depth Depth of menu item. Used for padding. |
186 | 186 | */ |
187 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
188 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
187 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
188 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
189 | 189 | |
190 | 190 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $value . $class_names . '>'; |
191 | 191 | |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | |
195 | 195 | // Set title from item to the $atts array - if title is empty then |
196 | 196 | // default to item title. |
197 | - if ( empty( $item->attr_title ) ) { |
|
198 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
197 | + if (empty($item->attr_title)) { |
|
198 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
199 | 199 | } else { |
200 | 200 | $atts['title'] = $item->attr_title; |
201 | 201 | } |
202 | 202 | |
203 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
204 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
203 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
204 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
205 | 205 | // If item has_children add atts to <a>. |
206 | - if ( $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
206 | + if ($args->has_children && 0 === $depth && $args->depth > 1) { |
|
207 | 207 | $atts['href'] = '#'; |
208 | 208 | $atts['data-toggle'] = 'dropdown'; |
209 | 209 | $atts['aria-haspopup'] = 'true'; |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | $atts['class'] = 'dropdown-toggle nav-link'; |
212 | 212 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
213 | 213 | } else { |
214 | - $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
|
214 | + $atts['href'] = ! empty($item->url) ? $item->url : ''; |
|
215 | 215 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
216 | - if ( $depth > 0 ) { |
|
216 | + if ($depth > 0) { |
|
217 | 217 | $atts['class'] = 'dropdown-item'; |
218 | 218 | } else { |
219 | 219 | $atts['class'] = 'nav-link'; |
@@ -225,40 +225,40 @@ discard block |
||
225 | 225 | $type_flag = ''; |
226 | 226 | // Loop through the array of extra link classes plucked from the |
227 | 227 | // parent <li>s classes array. |
228 | - if ( ! empty( $extra_link_classes ) ) { |
|
229 | - foreach ( $extra_link_classes as $link_class ) { |
|
230 | - if ( ! empty( $link_class ) ) { |
|
228 | + if ( ! empty($extra_link_classes)) { |
|
229 | + foreach ($extra_link_classes as $link_class) { |
|
230 | + if ( ! empty($link_class)) { |
|
231 | 231 | // update $atts with the extra classname. |
232 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
232 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
233 | 233 | |
234 | 234 | // check for special class types we need additional handling for. |
235 | - if ( 'disabled' === $link_class ) { |
|
235 | + if ('disabled' === $link_class) { |
|
236 | 236 | // Convert link to '#' and unset open targets. |
237 | 237 | $atts['href'] = '#'; |
238 | - unset( $atts['target'] ); |
|
239 | - } elseif ( 'dropdown-header' === $link_class ) { |
|
238 | + unset($atts['target']); |
|
239 | + } elseif ('dropdown-header' === $link_class) { |
|
240 | 240 | // Store a type flag and unset href and target. |
241 | 241 | $type_flag = 'dropdown-header'; |
242 | - unset( $atts['href'] ); |
|
243 | - unset( $atts['target'] ); |
|
244 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
242 | + unset($atts['href']); |
|
243 | + unset($atts['target']); |
|
244 | + } elseif ('dropdown-divider' === $link_class) { |
|
245 | 245 | // Store a type flag and unset href and target. |
246 | 246 | $type_flag = 'dropdown-divider'; |
247 | - unset( $atts['href'] ); |
|
248 | - unset( $atts['target'] ); |
|
247 | + unset($atts['href']); |
|
248 | + unset($atts['target']); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | 254 | // Allow filtering of the $atts array before using it. |
255 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
|
255 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args); |
|
256 | 256 | |
257 | 257 | // Build a string of html containing all the atts for the item. |
258 | 258 | $attributes = ''; |
259 | - foreach ( $atts as $attr => $value ) { |
|
260 | - if ( ! empty( $value ) ) { |
|
261 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
259 | + foreach ($atts as $attr => $value) { |
|
260 | + if ( ! empty($value)) { |
|
261 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
262 | 262 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
263 | 263 | } |
264 | 264 | } |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | * This is the start of the internal nav item. Depending on what |
273 | 273 | * kind of link mod we have we need different wrapper elements. |
274 | 274 | */ |
275 | - if ( 'dropdown-header' === $type_flag ) { |
|
275 | + if ('dropdown-header' === $type_flag) { |
|
276 | 276 | // For a header use a span with the .h6 class instead of a real |
277 | 277 | // header tag so that it doesn't confuse screen readers. |
278 | 278 | $item_output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
279 | - } elseif ( 'dropdown-divider' === $type_flag ) { |
|
279 | + } elseif ('dropdown-divider' === $type_flag) { |
|
280 | 280 | // this is a divider. |
281 | 281 | $item_output .= '<div class="dropdown-divider"' . $attributes . '>'; |
282 | 282 | } else { |
@@ -290,13 +290,13 @@ discard block |
||
290 | 290 | * output inside of the item before the $title (the link text). |
291 | 291 | */ |
292 | 292 | $icon_html = ''; |
293 | - if ( ! empty( $icon_class_string ) ) { |
|
293 | + if ( ! empty($icon_class_string)) { |
|
294 | 294 | // append an <i> with the icon classes to what is output before links. |
295 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
295 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** This filter is documented in wp-includes/post-template.php */ |
299 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
299 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
300 | 300 | /** |
301 | 301 | * Filters a menu item's title. |
302 | 302 | * |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * @param stdClass $args An object of wp_nav_menu() arguments. |
308 | 308 | * @param int $depth Depth of menu item. Used for padding. |
309 | 309 | */ |
310 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
310 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
311 | 311 | |
312 | 312 | // Put the item contents into $output. |
313 | 313 | $item_output .= $args->link_before . $icon_html . $title . $args->link_after; |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | * This is the end of the internal nav item. We need to close the |
317 | 317 | * correct element depending on the type of link or link mod. |
318 | 318 | */ |
319 | - if ( 'dropdown-header' === $type_flag ) { |
|
319 | + if ('dropdown-header' === $type_flag) { |
|
320 | 320 | // this is a header. |
321 | 321 | $item_output .= '</span>'; |
322 | - } elseif ( 'dropdown-divider' === $type_flag ) { |
|
322 | + } elseif ('dropdown-divider' === $type_flag) { |
|
323 | 323 | // this is a divider. |
324 | 324 | $item_output .= '</div>'; |
325 | 325 | } else { |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * END appending the internal item contents to the output. |
333 | 333 | */ |
334 | 334 | |
335 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
335 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | |
@@ -357,14 +357,14 @@ discard block |
||
357 | 357 | * @param array $args An array of arguments. |
358 | 358 | * @param string $output Used to append additional content (passed by reference). |
359 | 359 | */ |
360 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
361 | - if ( ! $element ) { |
|
360 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
361 | + if ( ! $element) { |
|
362 | 362 | return; } |
363 | 363 | $id_field = $this->db_fields['id']; |
364 | 364 | // Display this element. |
365 | - if ( is_object( $args[0] ) ) { |
|
366 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
367 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
365 | + if (is_object($args[0])) { |
|
366 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
367 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @param array $args passed from the wp_nav_menu function. |
379 | 379 | */ |
380 | - public static function fallback( $args ) { |
|
381 | - if ( current_user_can( 'edit_theme_options' ) ) { |
|
380 | + public static function fallback($args) { |
|
381 | + if (current_user_can('edit_theme_options')) { |
|
382 | 382 | |
383 | 383 | /* Get Arguments. */ |
384 | 384 | $container = $args['container']; |
@@ -390,30 +390,30 @@ discard block |
||
390 | 390 | // initialize var to store fallback html. |
391 | 391 | $fallback_output = ''; |
392 | 392 | |
393 | - if ( $container ) { |
|
394 | - $fallback_output .= '<' . esc_attr( $container ); |
|
395 | - if ( $container_id ) { |
|
396 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
393 | + if ($container) { |
|
394 | + $fallback_output .= '<' . esc_attr($container); |
|
395 | + if ($container_id) { |
|
396 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
397 | 397 | } |
398 | - if ( $container_class ) { |
|
399 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
398 | + if ($container_class) { |
|
399 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
400 | 400 | } |
401 | 401 | $fallback_output .= '>'; |
402 | 402 | } |
403 | 403 | $fallback_output .= '<ul'; |
404 | - if ( $menu_id ) { |
|
405 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
406 | - if ( $menu_class ) { |
|
407 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
404 | + if ($menu_id) { |
|
405 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
406 | + if ($menu_class) { |
|
407 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
408 | 408 | $fallback_output .= '>'; |
409 | - $fallback_output .= '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="">' . esc_attr( 'Add a menu', '' ) . '</a></li>'; |
|
409 | + $fallback_output .= '<li><a href="' . esc_url(admin_url('nav-menus.php')) . '" title="">' . esc_attr('Add a menu', '') . '</a></li>'; |
|
410 | 410 | $fallback_output .= '</ul>'; |
411 | - if ( $container ) { |
|
412 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
411 | + if ($container) { |
|
412 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // if $args has 'echo' key and it's true echo, otherwise return. |
416 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
416 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
417 | 417 | echo $fallback_output; // WPCS: XSS OK. |
418 | 418 | } else { |
419 | 419 | return $fallback_output; |