@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | |
20 | 20 | // Check if Class Exists. |
21 | -if ( class_exists( 'WP_Bootstrap_Navwalker' ) ) { |
|
21 | +if (class_exists('WP_Bootstrap_Navwalker')) { |
|
22 | 22 | return; |
23 | 23 | } |
24 | 24 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @since 4.2.0 |
49 | 49 | */ |
50 | 50 | public function __construct() { |
51 | - if ( ! has_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ) ) { |
|
52 | - add_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ); |
|
51 | + if ( ! has_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul'))) { |
|
52 | + add_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul')); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | * @param int $depth Depth of menu item. Used for padding. |
65 | 65 | * @param WP_Nav_Menu_Args $args An object of `wp_nav_menu()` arguments. |
66 | 66 | */ |
67 | - public function start_lvl( &$output, $depth = 0, $args = null ) { |
|
68 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
67 | + public function start_lvl(&$output, $depth = 0, $args = null) { |
|
68 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
69 | 69 | $t = ''; |
70 | 70 | $n = ''; |
71 | 71 | } else { |
72 | 72 | $t = "\t"; |
73 | 73 | $n = "\n"; |
74 | 74 | } |
75 | - $indent = str_repeat( $t, $depth ); |
|
75 | + $indent = str_repeat($t, $depth); |
|
76 | 76 | |
77 | 77 | // Default class to add to the start of the list (usually ul tag). |
78 | - $classes = array( 'dropdown-menu' ); |
|
78 | + $classes = array('dropdown-menu'); |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Filters the CSS class(es) applied to a menu list element. |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
87 | 87 | * @param int $depth Depth of menu item. Used for padding. |
88 | 88 | */ |
89 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
90 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
89 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
90 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
91 | 91 | |
92 | 92 | /* |
93 | 93 | * The `.dropdown-menu` container needs to have a labelledby |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | */ |
99 | 99 | $labelledby = ''; |
100 | 100 | // Find all links with an id in the output. |
101 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
101 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
102 | 102 | // With pointer at end of array check if we got an ID match. |
103 | - if ( end( $matches[2] ) ) { |
|
103 | + if (end($matches[2])) { |
|
104 | 104 | // Build a string to use as aria-labelledby. |
105 | - $labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"'; |
|
105 | + $labelledby = 'aria-labelledby="' . esc_attr(end($matches[2])) . '"'; |
|
106 | 106 | } |
107 | 107 | $output .= "{$n}{$indent}<ul$class_names $labelledby>{$n}"; |
108 | 108 | } |
@@ -121,33 +121,33 @@ discard block |
||
121 | 121 | * @param WP_Nav_Menu_Args $args An object of `wp_nav_menu()` arguments. |
122 | 122 | * @param int $id Current item ID. |
123 | 123 | */ |
124 | - public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { |
|
125 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
124 | + public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) { |
|
125 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
126 | 126 | $t = ''; |
127 | 127 | $n = ''; |
128 | 128 | } else { |
129 | 129 | $t = "\t"; |
130 | 130 | $n = "\n"; |
131 | 131 | } |
132 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
132 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
133 | 133 | |
134 | - if ( false !== strpos( $args->items_wrap, 'itemscope' ) && false === $this->has_schema ) { |
|
134 | + if (false !== strpos($args->items_wrap, 'itemscope') && false === $this->has_schema) { |
|
135 | 135 | $this->has_schema = true; |
136 | 136 | $args->link_before = '<span itemprop="name">' . $args->link_before; |
137 | 137 | $args->link_after .= '</span>'; |
138 | 138 | } |
139 | 139 | |
140 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
140 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
141 | 141 | |
142 | 142 | /* |
143 | 143 | * Updating the CSS classes of a menu item in the WordPress |
144 | 144 | * Customizer preview results in all classes defined in that |
145 | 145 | * particular input box to come in as one big class string. |
146 | 146 | */ |
147 | - $split_on_spaces = function ( $class ) { |
|
148 | - return preg_split( '/\s+/', $class ); |
|
147 | + $split_on_spaces = function($class) { |
|
148 | + return preg_split('/\s+/', $class); |
|
149 | 149 | }; |
150 | - $classes = $this->flatten( array_map( $split_on_spaces, $classes ) ); |
|
150 | + $classes = $this->flatten(array_map($split_on_spaces, $classes)); |
|
151 | 151 | |
152 | 152 | /* |
153 | 153 | * Initialize some holder variables to store specially handled item |
@@ -162,26 +162,26 @@ discard block |
||
162 | 162 | * NOTE: linkmod and icon class arrays are passed by reference and |
163 | 163 | * are maybe modified before being used later in this function. |
164 | 164 | */ |
165 | - $classes = $this->separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
165 | + $classes = $this->separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
166 | 166 | |
167 | 167 | // Join any icon classes plucked from $classes into a string. |
168 | - $icon_class_string = join( ' ', $icon_classes ); |
|
168 | + $icon_class_string = join(' ', $icon_classes); |
|
169 | 169 | |
170 | 170 | // Bootstrap version to create the markup for. |
171 | - $bs_version = $this->get_bs_version( $args ); |
|
171 | + $bs_version = $this->get_bs_version($args); |
|
172 | 172 | |
173 | 173 | // Whether the current item is a dropdown. |
174 | 174 | $is_dropdown = false; |
175 | - if ( $this->has_children && 1 !== $args->depth ) { |
|
175 | + if ($this->has_children && 1 !== $args->depth) { |
|
176 | 176 | $is_dropdown = true; |
177 | - if ( $depth >= $args->depth - 1 && 0 !== $args->depth ) { |
|
177 | + if ($depth >= $args->depth - 1 && 0 !== $args->depth) { |
|
178 | 178 | $is_dropdown = false; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Whether the current item is a dropdown item. |
183 | 183 | $is_dropdown_item = false; |
184 | - if ( ! ( $this->has_children && 0 === $depth ) && $depth > 0 ) { |
|
184 | + if ( ! ($this->has_children && 0 === $depth) && $depth > 0) { |
|
185 | 185 | $is_dropdown_item = true; |
186 | 186 | } |
187 | 187 | |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | * an active item. |
191 | 191 | */ |
192 | 192 | $is_active = false; |
193 | - if ( $item->current || $item->current_item_ancestor ) { |
|
194 | - if ( ! ( $item->current_item_ancestor && 1 === $args->depth ) ) { |
|
193 | + if ($item->current || $item->current_item_ancestor) { |
|
194 | + if ( ! ($item->current_item_ancestor && 1 === $args->depth)) { |
|
195 | 195 | $is_active = true; |
196 | 196 | } |
197 | 197 | } |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @var WP_Nav_Menu_Args |
209 | 209 | */ |
210 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
210 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
211 | 211 | |
212 | - if ( $is_dropdown ) { |
|
212 | + if ($is_dropdown) { |
|
213 | 213 | $classes[] = 'dropdown'; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $is_active && ! $is_dropdown_item && 5 !== $bs_version ) { |
|
216 | + if ($is_active && ! $is_dropdown_item && 5 !== $bs_version) { |
|
217 | 217 | // For dropdown items the .active class is set on the a tag. |
218 | 218 | $classes[] = 'active'; |
219 | 219 | } |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | $classes[] = 'nav-item'; |
224 | 224 | |
225 | 225 | // Allow filtering the classes. |
226 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
226 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
227 | 227 | |
228 | 228 | // Form a string of classes in format: class="class_names". |
229 | - $class_names = join( ' ', $classes ); |
|
230 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
229 | + $class_names = join(' ', $classes); |
|
230 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
231 | 231 | |
232 | 232 | /** |
233 | 233 | * Filters the ID applied to a menu item's list item element. |
@@ -240,44 +240,44 @@ discard block |
||
240 | 240 | * @param WP_Nav_Menu_Args $args An object of `wp_nav_menu()` arguments. |
241 | 241 | * @param int $depth Depth of menu item. Used for padding. |
242 | 242 | */ |
243 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
244 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
243 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
244 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
245 | 245 | |
246 | 246 | $output .= $indent . '<li ' . $id . $class_names . '>'; |
247 | 247 | |
248 | 248 | // Initialize array for holding the $atts for the link item. |
249 | 249 | $atts = array(); |
250 | - $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
|
251 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
252 | - if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
|
250 | + $atts['title'] = ! empty($item->attr_title) ? $item->attr_title : ''; |
|
251 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
252 | + if ('_blank' === $item->target && empty($item->xfn)) { |
|
253 | 253 | $atts['rel'] = 'noopener noreferrer'; |
254 | 254 | } else { |
255 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
255 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | // If the item has_children add atts to <a>. |
259 | - if ( $is_dropdown ) { |
|
259 | + if ($is_dropdown) { |
|
260 | 260 | $infix = ''; |
261 | - if ( 5 === $this->get_bs_version( $args ) ) { |
|
261 | + if (5 === $this->get_bs_version($args)) { |
|
262 | 262 | $infix = '-bs'; |
263 | 263 | } |
264 | 264 | |
265 | 265 | $atts['href'] = '#'; |
266 | - $atts[ "data$infix-toggle" ] = 'dropdown'; |
|
266 | + $atts["data$infix-toggle"] = 'dropdown'; |
|
267 | 267 | $atts['aria-expanded'] = 'false'; |
268 | 268 | $atts['class'] = 'dropdown-toggle nav-link'; |
269 | 269 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
270 | 270 | |
271 | - $atts['class'] .= ( $is_active && 5 === $bs_version ) ? ' active' : ''; |
|
271 | + $atts['class'] .= ($is_active && 5 === $bs_version) ? ' active' : ''; |
|
272 | 272 | } else { |
273 | - if ( true === $this->has_schema ) { |
|
273 | + if (true === $this->has_schema) { |
|
274 | 274 | $atts['itemprop'] = 'url'; |
275 | 275 | } |
276 | 276 | |
277 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
277 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
278 | 278 | |
279 | 279 | // For items in dropdowns use .dropdown-item instead of .nav-link. |
280 | - if ( $is_dropdown_item ) { |
|
280 | + if ($is_dropdown_item) { |
|
281 | 281 | $atts['class'] = 'dropdown-item'; |
282 | 282 | $atts['class'] .= $is_active ? ' active' : ''; |
283 | 283 | } else { |
@@ -288,33 +288,33 @@ discard block |
||
288 | 288 | $atts['aria-current'] = $item->current ? 'page' : ''; |
289 | 289 | |
290 | 290 | // Update atts of this item based on any custom linkmod classes. |
291 | - $atts = $this->update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
291 | + $atts = $this->update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
292 | 292 | |
293 | 293 | // Allow filtering of the $atts array before using it. |
294 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
294 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
295 | 295 | |
296 | 296 | // Build a string of html containing all the atts for the item. |
297 | 297 | $attributes = ''; |
298 | - foreach ( $atts as $attr => $value ) { |
|
299 | - if ( ! empty( $value ) ) { |
|
300 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
298 | + foreach ($atts as $attr => $value) { |
|
299 | + if ( ! empty($value)) { |
|
300 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
301 | 301 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Set a typeflag to easily test if this is a linkmod or not. |
306 | - $linkmod_type = $this->get_linkmod_type( $linkmod_classes ); |
|
306 | + $linkmod_type = $this->get_linkmod_type($linkmod_classes); |
|
307 | 307 | |
308 | 308 | // START appending the internal item contents to the output. |
309 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
309 | + $item_output = isset($args->before) ? $args->before : ''; |
|
310 | 310 | |
311 | 311 | /* |
312 | 312 | * This is the start of the internal nav item. Depending on what |
313 | 313 | * kind of linkmod we have we may need different wrapper elements. |
314 | 314 | */ |
315 | - if ( '' !== $linkmod_type ) { |
|
315 | + if ('' !== $linkmod_type) { |
|
316 | 316 | // Is linkmod, output the required element opener. |
317 | - $item_output .= $this->linkmod_element_open( $linkmod_type, $attributes ); |
|
317 | + $item_output .= $this->linkmod_element_open($linkmod_type, $attributes); |
|
318 | 318 | } else { |
319 | 319 | // With no link mod type set this must be a standard <a> tag. |
320 | 320 | $item_output .= '<a' . $attributes . '>'; |
@@ -326,13 +326,13 @@ discard block |
||
326 | 326 | * output inside of the item before the $title (the link text). |
327 | 327 | */ |
328 | 328 | $icon_html = ''; |
329 | - if ( ! empty( $icon_class_string ) ) { |
|
329 | + if ( ! empty($icon_class_string)) { |
|
330 | 330 | // Append an <i> with the icon classes to what is output before links. |
331 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
331 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** This filter is documented in wp-includes/post-template.php */ |
335 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
335 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
336 | 336 | |
337 | 337 | /** |
338 | 338 | * Filters a menu item's title. |
@@ -344,36 +344,36 @@ discard block |
||
344 | 344 | * @param WP_Nav_Menu_Args $args An object of `wp_nav_menu()` arguments. |
345 | 345 | * @param int $depth Depth of menu item. Used for padding. |
346 | 346 | */ |
347 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
347 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
348 | 348 | |
349 | 349 | // If the .sr-only class was set apply to the nav items text only. |
350 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
351 | - $title = $this->wrap_for_screen_reader( $title ); |
|
352 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
353 | - foreach ( $keys_to_unset as $k ) { |
|
354 | - unset( $linkmod_classes[ $k ] ); |
|
350 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
351 | + $title = $this->wrap_for_screen_reader($title); |
|
352 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
353 | + foreach ($keys_to_unset as $k) { |
|
354 | + unset($linkmod_classes[$k]); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
358 | 358 | // Put the item contents into $output. |
359 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
359 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
360 | 360 | |
361 | 361 | /* |
362 | 362 | * This is the end of the internal nav item. We need to close the |
363 | 363 | * correct element depending on the type of link or link mod. |
364 | 364 | */ |
365 | - if ( '' !== $linkmod_type ) { |
|
365 | + if ('' !== $linkmod_type) { |
|
366 | 366 | // Is linkmod, output the required closing element. |
367 | - $item_output .= $this->linkmod_element_close( $linkmod_type ); |
|
367 | + $item_output .= $this->linkmod_element_close($linkmod_type); |
|
368 | 368 | } else { |
369 | 369 | // With no link mod type set this must be a standard <a> tag. |
370 | 370 | $item_output .= '</a>'; |
371 | 371 | } |
372 | 372 | |
373 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
373 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
374 | 374 | |
375 | 375 | // END appending the internal item contents to the output. |
376 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
376 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * @param array $args Arguments passed from the `wp_nav_menu()` function. |
388 | 388 | * @return string|void String when echo is false. |
389 | 389 | */ |
390 | - public static function fallback( $args ) { |
|
391 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
390 | + public static function fallback($args) { |
|
391 | + if ( ! current_user_can('edit_theme_options')) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | |
398 | 398 | // Menu container opening tag. |
399 | 399 | $show_container = false; |
400 | - if ( $args['container'] ) { |
|
400 | + if ($args['container']) { |
|
401 | 401 | /** |
402 | 402 | * Filters the list of HTML tags that are valid for use as menu containers. |
403 | 403 | * |
@@ -406,29 +406,29 @@ discard block |
||
406 | 406 | * @param array $tags The acceptable HTML tags for use as menu containers. |
407 | 407 | * Default is array containing 'div' and 'nav'. |
408 | 408 | */ |
409 | - $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); |
|
410 | - if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) { |
|
409 | + $allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav')); |
|
410 | + if (is_string($args['container']) && in_array($args['container'], $allowed_tags, true)) { |
|
411 | 411 | $show_container = true; |
412 | - $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"'; |
|
413 | - $id = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : ''; |
|
412 | + $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr($args['container_class']) . '"' : ' class="menu-fallback-container"'; |
|
413 | + $id = $args['container_id'] ? ' id="' . esc_attr($args['container_id']) . '"' : ''; |
|
414 | 414 | $fallback_output .= '<' . $args['container'] . $id . $class . '>'; |
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | 418 | // The fallback menu. |
419 | - $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; |
|
420 | - $id = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : ''; |
|
419 | + $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr($args['menu_class']) . '"' : ' class="menu-fallback-menu"'; |
|
420 | + $id = $args['menu_id'] ? ' id="' . esc_attr($args['menu_id']) . '"' : ''; |
|
421 | 421 | $fallback_output .= '<ul' . $id . $class . '>'; |
422 | - $fallback_output .= '<li class="nav-item"><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" class="nav-link" title="' . esc_attr__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '">' . esc_html__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '</a></li>'; |
|
422 | + $fallback_output .= '<li class="nav-item"><a href="' . esc_url(admin_url('nav-menus.php')) . '" class="nav-link" title="' . esc_attr__('Add a menu', 'wp-bootstrap-navwalker') . '">' . esc_html__('Add a menu', 'wp-bootstrap-navwalker') . '</a></li>'; |
|
423 | 423 | $fallback_output .= '</ul>'; |
424 | 424 | |
425 | 425 | // Menu container closing tag. |
426 | - if ( $show_container ) { |
|
426 | + if ($show_container) { |
|
427 | 427 | $fallback_output .= '</' . $args['container'] . '>'; |
428 | 428 | } |
429 | 429 | |
430 | 430 | // If $args has 'echo' key and it's true echo, otherwise return. |
431 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
431 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
432 | 432 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
433 | 433 | echo $fallback_output; |
434 | 434 | } else { |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | * @param array $args The nav instance arguments. |
445 | 445 | * @return array $args The altered nav instance arguments. |
446 | 446 | */ |
447 | - public function add_schema_to_navbar_ul( $args ) { |
|
448 | - if ( isset( $args['items_wrap'] ) ) { |
|
447 | + public function add_schema_to_navbar_ul($args) { |
|
448 | + if (isset($args['items_wrap'])) { |
|
449 | 449 | $wrap = $args['items_wrap']; |
450 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
451 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); |
|
450 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
451 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | return $args; |
@@ -471,32 +471,32 @@ discard block |
||
471 | 471 | * @param integer $depth An integer holding current depth level. |
472 | 472 | * @return array $classes A maybe modified array of classnames. |
473 | 473 | */ |
474 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
474 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
475 | 475 | // Loop through $classes array to find linkmod or icon classes. |
476 | - foreach ( $classes as $key => $class ) { |
|
476 | + foreach ($classes as $key => $class) { |
|
477 | 477 | /* |
478 | 478 | * If any special classes are found, store the class in it's |
479 | 479 | * holder array and and unset the item from $classes. |
480 | 480 | */ |
481 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
481 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
482 | 482 | // Test for .disabled or .sr-only classes. |
483 | 483 | $linkmod_classes[] = $class; |
484 | - unset( $classes[ $key ] ); |
|
485 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
484 | + unset($classes[$key]); |
|
485 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
486 | 486 | /* |
487 | 487 | * Test for .dropdown-header or .dropdown-divider and a |
488 | 488 | * depth greater than 0 - IE inside a dropdown. |
489 | 489 | */ |
490 | 490 | $linkmod_classes[] = $class; |
491 | - unset( $classes[ $key ] ); |
|
492 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
491 | + unset($classes[$key]); |
|
492 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
493 | 493 | // Font Awesome. |
494 | 494 | $icon_classes[] = $class; |
495 | - unset( $classes[ $key ] ); |
|
496 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
495 | + unset($classes[$key]); |
|
496 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
497 | 497 | // Glyphicons. |
498 | 498 | $icon_classes[] = $class; |
499 | - unset( $classes[ $key ] ); |
|
499 | + unset($classes[$key]); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
@@ -512,19 +512,19 @@ discard block |
||
512 | 512 | * @param array $linkmod_classes Array of any link modifier classes. |
513 | 513 | * @return string Empty for default, a linkmod type string otherwise. |
514 | 514 | */ |
515 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
515 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
516 | 516 | $linkmod_type = ''; |
517 | 517 | // Loop through array of linkmod classes to handle their $atts. |
518 | - if ( ! empty( $linkmod_classes ) ) { |
|
519 | - foreach ( $linkmod_classes as $link_class ) { |
|
520 | - if ( ! empty( $link_class ) ) { |
|
518 | + if ( ! empty($linkmod_classes)) { |
|
519 | + foreach ($linkmod_classes as $link_class) { |
|
520 | + if ( ! empty($link_class)) { |
|
521 | 521 | |
522 | 522 | // Check for special class types and set a flag for them. |
523 | - if ( 'dropdown-header' === $link_class ) { |
|
523 | + if ('dropdown-header' === $link_class) { |
|
524 | 524 | $linkmod_type = 'dropdown-header'; |
525 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
525 | + } elseif ('dropdown-divider' === $link_class) { |
|
526 | 526 | $linkmod_type = 'dropdown-divider'; |
527 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
527 | + } elseif ('dropdown-item-text' === $link_class) { |
|
528 | 528 | $linkmod_type = 'dropdown-item-text'; |
529 | 529 | } |
530 | 530 | } |
@@ -542,26 +542,26 @@ discard block |
||
542 | 542 | * @param array $linkmod_classes An array of classes that modify link or nav item behaviors or displays. |
543 | 543 | * @return array Maybe updated array of attributes for item. |
544 | 544 | */ |
545 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
546 | - if ( ! empty( $linkmod_classes ) ) { |
|
547 | - foreach ( $linkmod_classes as $link_class ) { |
|
548 | - if ( ! empty( $link_class ) ) { |
|
545 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
546 | + if ( ! empty($linkmod_classes)) { |
|
547 | + foreach ($linkmod_classes as $link_class) { |
|
548 | + if ( ! empty($link_class)) { |
|
549 | 549 | /* |
550 | 550 | * Update $atts with a space and the extra classname |
551 | 551 | * so long as it's not a sr-only class. |
552 | 552 | */ |
553 | - if ( 'sr-only' !== $link_class ) { |
|
554 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
553 | + if ('sr-only' !== $link_class) { |
|
554 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
555 | 555 | } |
556 | 556 | // Check for special class types we need additional handling for. |
557 | - if ( 'disabled' === $link_class ) { |
|
557 | + if ('disabled' === $link_class) { |
|
558 | 558 | // Convert link to '#' and unset open targets. |
559 | 559 | $atts['href'] = '#'; |
560 | - unset( $atts['target'] ); |
|
561 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
560 | + unset($atts['target']); |
|
561 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
562 | 562 | // Store a type flag and unset href and target. |
563 | - unset( $atts['href'] ); |
|
564 | - unset( $atts['target'] ); |
|
563 | + unset($atts['href']); |
|
564 | + unset($atts['target']); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | } |
@@ -577,8 +577,8 @@ discard block |
||
577 | 577 | * @param string $text The string of text to be wrapped in a screen reader class. |
578 | 578 | * @return string The string wrapped in a span with the class. |
579 | 579 | */ |
580 | - private function wrap_for_screen_reader( $text = '' ) { |
|
581 | - if ( $text ) { |
|
580 | + private function wrap_for_screen_reader($text = '') { |
|
581 | + if ($text) { |
|
582 | 582 | $text = '<span class="sr-only">' . $text . '</span>'; |
583 | 583 | } |
584 | 584 | return $text; |
@@ -593,17 +593,17 @@ discard block |
||
593 | 593 | * @param string $attributes A string of attributes to add to the element. |
594 | 594 | * @return string A string with the opening tag for the element with attribibutes added. |
595 | 595 | */ |
596 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
596 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
597 | 597 | $output = ''; |
598 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
598 | + if ('dropdown-item-text' === $linkmod_type) { |
|
599 | 599 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
600 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
600 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
601 | 601 | /* |
602 | 602 | * For a header use a span with the .h6 class instead of a real |
603 | 603 | * header tag so that it doesn't confuse screen readers. |
604 | 604 | */ |
605 | 605 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
606 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
606 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
607 | 607 | // This is a divider. |
608 | 608 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
609 | 609 | } |
@@ -618,15 +618,15 @@ discard block |
||
618 | 618 | * @param string $linkmod_type A string containing a special linkmod type. |
619 | 619 | * @return string A string with the closing tag for this linkmod type. |
620 | 620 | */ |
621 | - private function linkmod_element_close( $linkmod_type ) { |
|
621 | + private function linkmod_element_close($linkmod_type) { |
|
622 | 622 | $output = ''; |
623 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
623 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
624 | 624 | /* |
625 | 625 | * For a header use a span with the .h6 class instead of a real |
626 | 626 | * header tag so that it doesn't confuse screen readers. |
627 | 627 | */ |
628 | 628 | $output .= '</span>'; |
629 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
629 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
630 | 630 | // This is a divider. |
631 | 631 | $output .= '</div>'; |
632 | 632 | } |
@@ -639,11 +639,11 @@ discard block |
||
639 | 639 | * @param array $array A multidimensional array. |
640 | 640 | * @return array A simple array. |
641 | 641 | */ |
642 | - public function flatten( $array ) { |
|
642 | + public function flatten($array) { |
|
643 | 643 | $result = array(); |
644 | - foreach ( $array as $element ) { |
|
645 | - if ( is_array( $element ) ) { |
|
646 | - array_push( $result, ...$this->flatten( $element ) ); |
|
644 | + foreach ($array as $element) { |
|
645 | + if (is_array($element)) { |
|
646 | + array_push($result, ...$this->flatten($element)); |
|
647 | 647 | } else { |
648 | 648 | $result[] = $element; |
649 | 649 | } |
@@ -657,8 +657,8 @@ discard block |
||
657 | 657 | * @param WP_Nav_Menu_Args $args An object of `wp_nav_menu()` arguments. |
658 | 658 | * @return int Major Bootstrap version |
659 | 659 | */ |
660 | - private function get_bs_version( $args ) { |
|
661 | - if ( property_exists( $args, 'bs_version' ) && 5 === (int) $args->bs_version ) { |
|
660 | + private function get_bs_version($args) { |
|
661 | + if (property_exists($args, 'bs_version') && 5 === (int) $args->bs_version) { |
|
662 | 662 | return (int) $args->bs_version; |
663 | 663 | } |
664 | 664 | return $this->bs_version; |