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