Completed
Push — master ( 1070ce...7d21d0 )
by William
01:17
created
class-wp-bootstrap-navwalker.php 1 patch
Spacing   +117 added lines, -117 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
 	 */
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 		 * @since 4.2.0
39 39
 		 */
40 40
 		public function __construct() {
41
-			if ( ! has_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ) ) {
42
-				add_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) );
41
+			if ( ! has_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul'))) {
42
+				add_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul'));
43 43
 			}
44 44
 		}
45 45
 
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
 		 * @param int              $depth  Depth of menu item. Used for padding.
55 55
 		 * @param WP_Nav_Menu_Args $args   An object of wp_nav_menu() arguments.
56 56
 		 */
57
-		public function start_lvl( &$output, $depth = 0, $args = null ) {
58
-			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
57
+		public function start_lvl(&$output, $depth = 0, $args = null) {
58
+			if (isset($args->item_spacing) && 'discard' === $args->item_spacing) {
59 59
 				$t = '';
60 60
 				$n = '';
61 61
 			} else {
62 62
 				$t = "\t";
63 63
 				$n = "\n";
64 64
 			}
65
-			$indent = str_repeat( $t, $depth );
65
+			$indent = str_repeat($t, $depth);
66 66
 			// Default class to add to the file.
67
-			$classes = array( 'dropdown-menu' );
67
+			$classes = array('dropdown-menu');
68 68
 			/**
69 69
 			 * Filters the CSS class(es) applied to a menu list element.
70 70
 			 *
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 			 * @param stdClass $args    An object of `wp_nav_menu()` arguments.
75 75
 			 * @param int      $depth   Depth of menu item. Used for padding.
76 76
 			 */
77
-			$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
78
-			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
77
+			$class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth));
78
+			$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
79 79
 
80 80
 			/*
81 81
 			 * The `.dropdown-menu` container needs to have a labelledby
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 			 */
87 87
 			$labelledby = '';
88 88
 			// Find all links with an id in the output.
89
-			preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches );
89
+			preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches);
90 90
 			// With pointer at end of array check if we got an ID match.
91
-			if ( end( $matches[2] ) ) {
91
+			if (end($matches[2])) {
92 92
 				// Build a string to use as aria-labelledby.
93
-				$labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"';
93
+				$labelledby = 'aria-labelledby="' . esc_attr(end($matches[2])) . '"';
94 94
 			}
95 95
 			$output .= "{$n}{$indent}<ul$class_names $labelledby>{$n}";
96 96
 		}
@@ -109,30 +109,30 @@  discard block
 block discarded – undo
109 109
 		 * @param WP_Nav_Menu_Args $args   An object of wp_nav_menu() arguments.
110 110
 		 * @param int              $id     Current item ID.
111 111
 		 */
112
-		public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
113
-			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
112
+		public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) {
113
+			if (isset($args->item_spacing) && 'discard' === $args->item_spacing) {
114 114
 				$t = '';
115 115
 				$n = '';
116 116
 			} else {
117 117
 				$t = "\t";
118 118
 				$n = "\n";
119 119
 			}
120
-			$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
120
+			$indent = ($depth) ? str_repeat($t, $depth) : '';
121 121
 
122
-			if ( false !== strpos( $args->items_wrap, 'itemscope' ) && false === $this->has_schema ) {
122
+			if (false !== strpos($args->items_wrap, 'itemscope') && false === $this->has_schema) {
123 123
 				$this->has_schema  = true;
124 124
 				$args->link_before = '<span itemprop="name">' . $args->link_before;
125 125
 				$args->link_after .= '</span>';
126 126
 			}
127 127
 
128
-			$classes = empty( $item->classes ) ? array() : (array) $item->classes;
128
+			$classes = empty($item->classes) ? array() : (array) $item->classes;
129 129
 
130 130
 			// Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined
131 131
 			// in that particular input box to come in as one big class string.
132
-			$split_on_spaces = function ( $class ) {
133
-				return preg_split( '/\s+/', $class );
132
+			$split_on_spaces = function($class) {
133
+				return preg_split('/\s+/', $class);
134 134
 			};
135
-			$classes         = $this->flatten( array_map( $split_on_spaces, $classes ) );
135
+			$classes         = $this->flatten(array_map($split_on_spaces, $classes));
136 136
 
137 137
 			/*
138 138
 			 * Initialize some holder variables to store specially handled item
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 			 * NOTE: linkmod and icon class arrays are passed by reference and
148 148
 			 * are maybe modified before being used later in this function.
149 149
 			 */
150
-			$classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth );
150
+			$classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth);
151 151
 
152 152
 			// Join any icon classes plucked from $classes into a string.
153
-			$icon_class_string = join( ' ', $icon_classes );
153
+			$icon_class_string = join(' ', $icon_classes);
154 154
 
155 155
 			/**
156 156
 			 * Filters the arguments for a single nav menu item.
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 			 *
164 164
 			 * @var WP_Nav_Menu_Args
165 165
 			 */
166
-			$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
166
+			$args = apply_filters('nav_menu_item_args', $args, $item, $depth);
167 167
 
168 168
 			// Add .dropdown or .active classes where they are needed.
169
-			if ( $this->has_children ) {
169
+			if ($this->has_children) {
170 170
 				$classes[] = 'dropdown';
171 171
 			}
172
-			if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
172
+			if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) {
173 173
 				$classes[] = 'active';
174 174
 			}
175 175
 
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 			$classes[] = 'nav-item';
179 179
 
180 180
 			// Allow filtering the classes.
181
-			$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
181
+			$classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth);
182 182
 
183 183
 			// Form a string of classes in format: class="class_names".
184
-			$class_names = join( ' ', $classes );
185
-			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
184
+			$class_names = join(' ', $classes);
185
+			$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
186 186
 
187 187
 			/**
188 188
 			 * Filters the ID applied to a menu item's list item element.
@@ -195,23 +195,23 @@  discard block
 block discarded – undo
195 195
 			 * @param WP_Nav_Menu_Args $args    An object of wp_nav_menu() arguments.
196 196
 			 * @param int              $depth   Depth of menu item. Used for padding.
197 197
 			 */
198
-			$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
199
-			$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
198
+			$id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
199
+			$id = $id ? ' id="' . esc_attr($id) . '"' : '';
200 200
 
201 201
 			$output .= $indent . '<li ' . $id . $class_names . '>';
202 202
 
203 203
 			// Initialize array for holding the $atts for the link item.
204 204
 			$atts           = array();
205
-			$atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
206
-			$atts['target'] = ! empty( $item->target ) ? $item->target : '';
207
-			if ( '_blank' === $item->target && empty( $item->xfn ) ) {
205
+			$atts['title']  = ! empty($item->attr_title) ? $item->attr_title : '';
206
+			$atts['target'] = ! empty($item->target) ? $item->target : '';
207
+			if ('_blank' === $item->target && empty($item->xfn)) {
208 208
 				$atts['rel'] = 'noopener noreferrer';
209 209
 			} else {
210
-				$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
210
+				$atts['rel'] = ! empty($item->xfn) ? $item->xfn : '';
211 211
 			}
212 212
 
213 213
 			// If the item has_children add atts to <a>.
214
-			if ( $this->has_children && 0 === $depth ) {
214
+			if ($this->has_children && 0 === $depth) {
215 215
 				$atts['href']          = '#';
216 216
 				$atts['data-toggle']   = 'dropdown';
217 217
 				$atts['aria-haspopup'] = 'true';
@@ -219,13 +219,13 @@  discard block
 block discarded – undo
219 219
 				$atts['class']         = 'dropdown-toggle nav-link';
220 220
 				$atts['id']            = 'menu-item-dropdown-' . $item->ID;
221 221
 			} else {
222
-				if ( true === $this->has_schema ) {
222
+				if (true === $this->has_schema) {
223 223
 					$atts['itemprop'] = 'url';
224 224
 				}
225 225
 
226
-				$atts['href'] = ! empty( $item->url ) ? $item->url : '#';
226
+				$atts['href'] = ! empty($item->url) ? $item->url : '#';
227 227
 				// For items in dropdowns use .dropdown-item instead of .nav-link.
228
-				if ( $depth > 0 ) {
228
+				if ($depth > 0) {
229 229
 					$atts['class'] = 'dropdown-item';
230 230
 				} else {
231 231
 					$atts['class'] = 'nav-link';
@@ -235,33 +235,33 @@  discard block
 block discarded – undo
235 235
 			$atts['aria-current'] = $item->current ? 'page' : '';
236 236
 
237 237
 			// Update atts of this item based on any custom linkmod classes.
238
-			$atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes );
238
+			$atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes);
239 239
 
240 240
 			// Allow filtering of the $atts array before using it.
241
-			$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
241
+			$atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
242 242
 
243 243
 			// Build a string of html containing all the atts for the item.
244 244
 			$attributes = '';
245
-			foreach ( $atts as $attr => $value ) {
246
-				if ( ! empty( $value ) ) {
247
-					$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
245
+			foreach ($atts as $attr => $value) {
246
+				if ( ! empty($value)) {
247
+					$value       = ('href' === $attr) ? esc_url($value) : esc_attr($value);
248 248
 					$attributes .= ' ' . $attr . '="' . $value . '"';
249 249
 				}
250 250
 			}
251 251
 
252 252
 			// Set a typeflag to easily test if this is a linkmod or not.
253
-			$linkmod_type = self::get_linkmod_type( $linkmod_classes );
253
+			$linkmod_type = self::get_linkmod_type($linkmod_classes);
254 254
 
255 255
 			// START appending the internal item contents to the output.
256
-			$item_output = isset( $args->before ) ? $args->before : '';
256
+			$item_output = isset($args->before) ? $args->before : '';
257 257
 
258 258
 			/*
259 259
 			 * This is the start of the internal nav item. Depending on what
260 260
 			 * kind of linkmod we have we may need different wrapper elements.
261 261
 			 */
262
-			if ( '' !== $linkmod_type ) {
262
+			if ('' !== $linkmod_type) {
263 263
 				// Is linkmod, output the required element opener.
264
-				$item_output .= self::linkmod_element_open( $linkmod_type, $attributes );
264
+				$item_output .= self::linkmod_element_open($linkmod_type, $attributes);
265 265
 			} else {
266 266
 				// With no link mod type set this must be a standard <a> tag.
267 267
 				$item_output .= '<a' . $attributes . '>';
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
 			 * output inside of the item before the $title (the link text).
274 274
 			 */
275 275
 			$icon_html = '';
276
-			if ( ! empty( $icon_class_string ) ) {
276
+			if ( ! empty($icon_class_string)) {
277 277
 				// Append an <i> with the icon classes to what is output before links.
278
-				$icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> ';
278
+				$icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> ';
279 279
 			}
280 280
 
281 281
 			/** This filter is documented in wp-includes/post-template.php */
282
-			$title = apply_filters( 'the_title', $item->title, $item->ID );
282
+			$title = apply_filters('the_title', $item->title, $item->ID);
283 283
 
284 284
 			/**
285 285
 			 * Filters a menu item's title.
@@ -291,36 +291,36 @@  discard block
 block discarded – undo
291 291
 			 * @param WP_Nav_Menu_Args $args  An object of wp_nav_menu() arguments.
292 292
 			 * @param int              $depth Depth of menu item. Used for padding.
293 293
 			 */
294
-			$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
294
+			$title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth);
295 295
 
296 296
 			// If the .sr-only class was set apply to the nav items text only.
297
-			if ( in_array( 'sr-only', $linkmod_classes, true ) ) {
298
-				$title         = self::wrap_for_screen_reader( $title );
299
-				$keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true );
300
-				foreach ( $keys_to_unset as $k ) {
301
-					unset( $linkmod_classes[ $k ] );
297
+			if (in_array('sr-only', $linkmod_classes, true)) {
298
+				$title         = self::wrap_for_screen_reader($title);
299
+				$keys_to_unset = array_keys($linkmod_classes, 'sr-only', true);
300
+				foreach ($keys_to_unset as $k) {
301
+					unset($linkmod_classes[$k]);
302 302
 				}
303 303
 			}
304 304
 
305 305
 			// Put the item contents into $output.
306
-			$item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : '';
306
+			$item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : '';
307 307
 
308 308
 			/*
309 309
 			 * This is the end of the internal nav item. We need to close the
310 310
 			 * correct element depending on the type of link or link mod.
311 311
 			 */
312
-			if ( '' !== $linkmod_type ) {
312
+			if ('' !== $linkmod_type) {
313 313
 				// Is linkmod, output the required closing element.
314
-				$item_output .= self::linkmod_element_close( $linkmod_type );
314
+				$item_output .= self::linkmod_element_close($linkmod_type);
315 315
 			} else {
316 316
 				// With no link mod type set this must be a standard <a> tag.
317 317
 				$item_output .= '</a>';
318 318
 			}
319 319
 
320
-			$item_output .= isset( $args->after ) ? $args->after : '';
320
+			$item_output .= isset($args->after) ? $args->after : '';
321 321
 
322 322
 			// END appending the internal item contents to the output.
323
-			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
323
+			$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
324 324
 		}
325 325
 
326 326
 		/**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 		 * @param array $args passed from the wp_nav_menu function.
335 335
 		 * @return string|void String when echo is false.
336 336
 		 */
337
-		public static function fallback( $args ) {
338
-			if ( ! current_user_can( 'edit_theme_options' ) ) {
337
+		public static function fallback($args) {
338
+			if ( ! current_user_can('edit_theme_options')) {
339 339
 				return;
340 340
 			}
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
 			// Menu container opening tag.
346 346
 			$show_container = false;
347
-			if ( $args['container'] ) {
347
+			if ($args['container']) {
348 348
 				/**
349 349
 				 * Filters the list of HTML tags that are valid for use as menu containers.
350 350
 				 *
@@ -353,29 +353,29 @@  discard block
 block discarded – undo
353 353
 				 * @param array $tags The acceptable HTML tags for use as menu containers.
354 354
 				 *                    Default is array containing 'div' and 'nav'.
355 355
 				 */
356
-				$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
357
-				if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) {
356
+				$allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav'));
357
+				if (is_string($args['container']) && in_array($args['container'], $allowed_tags, true)) {
358 358
 					$show_container   = true;
359
-					$class            = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"';
360
-					$id               = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : '';
359
+					$class            = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr($args['container_class']) . '"' : ' class="menu-fallback-container"';
360
+					$id               = $args['container_id'] ? ' id="' . esc_attr($args['container_id']) . '"' : '';
361 361
 					$fallback_output .= '<' . $args['container'] . $id . $class . '>';
362 362
 				}
363 363
 			}
364 364
 
365 365
 			// The fallback menu.
366
-			$class            = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"';
367
-			$id               = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : '';
366
+			$class            = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr($args['menu_class']) . '"' : ' class="menu-fallback-menu"';
367
+			$id               = $args['menu_id'] ? ' id="' . esc_attr($args['menu_id']) . '"' : '';
368 368
 			$fallback_output .= '<ul' . $id . $class . '>';
369
-			$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>';
369
+			$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>';
370 370
 			$fallback_output .= '</ul>';
371 371
 
372 372
 			// Menu container closing tag.
373
-			if ( $show_container ) {
373
+			if ($show_container) {
374 374
 				$fallback_output .= '</' . $args['container'] . '>';
375 375
 			}
376 376
 
377 377
 			// if $args has 'echo' key and it's true echo, otherwise return.
378
-			if ( array_key_exists( 'echo', $args ) && $args['echo'] ) {
378
+			if (array_key_exists('echo', $args) && $args['echo']) {
379 379
 				echo $fallback_output; // WPCS: XSS OK.
380 380
 			} else {
381 381
 				return $fallback_output;
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 		 * @param  array $args The nav instance arguments.
391 391
 		 * @return array $args The altered nav instance arguments.
392 392
 		 */
393
-		public function add_schema_to_navbar_ul( $args ) {
393
+		public function add_schema_to_navbar_ul($args) {
394 394
 			$wrap = $args['items_wrap'];
395
-			if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) {
396
-				$args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap );
395
+			if (strpos($wrap, 'SiteNavigationElement') === false) {
396
+				$args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap);
397 397
 			}
398 398
 
399 399
 			return $args;
@@ -417,32 +417,32 @@  discard block
 block discarded – undo
417 417
 		 *
418 418
 		 * @return array  $classes         a maybe modified array of classnames.
419 419
 		 */
420
-		private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) {
420
+		private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) {
421 421
 			// Loop through $classes array to find linkmod or icon classes.
422
-			foreach ( $classes as $key => $class ) {
422
+			foreach ($classes as $key => $class) {
423 423
 				/*
424 424
 				 * If any special classes are found, store the class in it's
425 425
 				 * holder array and and unset the item from $classes.
426 426
 				 */
427
-				if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
427
+				if (preg_match('/^disabled|^sr-only/i', $class)) {
428 428
 					// Test for .disabled or .sr-only classes.
429 429
 					$linkmod_classes[] = $class;
430
-					unset( $classes[ $key ] );
431
-				} elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) {
430
+					unset($classes[$key]);
431
+				} elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) {
432 432
 					/*
433 433
 					 * Test for .dropdown-header or .dropdown-divider and a
434 434
 					 * depth greater than 0 - IE inside a dropdown.
435 435
 					 */
436 436
 					$linkmod_classes[] = $class;
437
-					unset( $classes[ $key ] );
438
-				} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
437
+					unset($classes[$key]);
438
+				} elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) {
439 439
 					// Font Awesome.
440 440
 					$icon_classes[] = $class;
441
-					unset( $classes[ $key ] );
442
-				} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
441
+					unset($classes[$key]);
442
+				} elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) {
443 443
 					// Glyphicons.
444 444
 					$icon_classes[] = $class;
445
-					unset( $classes[ $key ] );
445
+					unset($classes[$key]);
446 446
 				}
447 447
 			}
448 448
 
@@ -459,19 +459,19 @@  discard block
 block discarded – undo
459 459
 		 *
460 460
 		 * @return string                empty for default, a linkmod type string otherwise.
461 461
 		 */
462
-		private function get_linkmod_type( $linkmod_classes = array() ) {
462
+		private function get_linkmod_type($linkmod_classes = array()) {
463 463
 			$linkmod_type = '';
464 464
 			// Loop through array of linkmod classes to handle their $atts.
465
-			if ( ! empty( $linkmod_classes ) ) {
466
-				foreach ( $linkmod_classes as $link_class ) {
467
-					if ( ! empty( $link_class ) ) {
465
+			if ( ! empty($linkmod_classes)) {
466
+				foreach ($linkmod_classes as $link_class) {
467
+					if ( ! empty($link_class)) {
468 468
 
469 469
 						// Check for special class types and set a flag for them.
470
-						if ( 'dropdown-header' === $link_class ) {
470
+						if ('dropdown-header' === $link_class) {
471 471
 							$linkmod_type = 'dropdown-header';
472
-						} elseif ( 'dropdown-divider' === $link_class ) {
472
+						} elseif ('dropdown-divider' === $link_class) {
473 473
 							$linkmod_type = 'dropdown-divider';
474
-						} elseif ( 'dropdown-item-text' === $link_class ) {
474
+						} elseif ('dropdown-item-text' === $link_class) {
475 475
 							$linkmod_type = 'dropdown-item-text';
476 476
 						}
477 477
 					}
@@ -490,26 +490,26 @@  discard block
 block discarded – undo
490 490
 		 *
491 491
 		 * @return array                 maybe updated array of attributes for item.
492 492
 		 */
493
-		private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) {
494
-			if ( ! empty( $linkmod_classes ) ) {
495
-				foreach ( $linkmod_classes as $link_class ) {
496
-					if ( ! empty( $link_class ) ) {
493
+		private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) {
494
+			if ( ! empty($linkmod_classes)) {
495
+				foreach ($linkmod_classes as $link_class) {
496
+					if ( ! empty($link_class)) {
497 497
 						/*
498 498
 						 * Update $atts with a space and the extra classname
499 499
 						 * so long as it's not a sr-only class.
500 500
 						 */
501
-						if ( 'sr-only' !== $link_class ) {
502
-							$atts['class'] .= ' ' . esc_attr( $link_class );
501
+						if ('sr-only' !== $link_class) {
502
+							$atts['class'] .= ' ' . esc_attr($link_class);
503 503
 						}
504 504
 						// Check for special class types we need additional handling for.
505
-						if ( 'disabled' === $link_class ) {
505
+						if ('disabled' === $link_class) {
506 506
 							// Convert link to '#' and unset open targets.
507 507
 							$atts['href'] = '#';
508
-							unset( $atts['target'] );
509
-						} elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) {
508
+							unset($atts['target']);
509
+						} elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) {
510 510
 							// Store a type flag and unset href and target.
511
-							unset( $atts['href'] );
512
-							unset( $atts['target'] );
511
+							unset($atts['href']);
512
+							unset($atts['target']);
513 513
 						}
514 514
 					}
515 515
 				}
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 		 * @param string $text the string of text to be wrapped in a screen reader class.
526 526
 		 * @return string      the string wrapped in a span with the class.
527 527
 		 */
528
-		private function wrap_for_screen_reader( $text = '' ) {
529
-			if ( $text ) {
528
+		private function wrap_for_screen_reader($text = '') {
529
+			if ($text) {
530 530
 				$text = '<span class="sr-only">' . $text . '</span>';
531 531
 			}
532 532
 			return $text;
@@ -542,17 +542,17 @@  discard block
 block discarded – undo
542 542
 		 *
543 543
 		 * @return string              a string with the openign tag for the element with attribibutes added.
544 544
 		 */
545
-		private function linkmod_element_open( $linkmod_type, $attributes = '' ) {
545
+		private function linkmod_element_open($linkmod_type, $attributes = '') {
546 546
 			$output = '';
547
-			if ( 'dropdown-item-text' === $linkmod_type ) {
547
+			if ('dropdown-item-text' === $linkmod_type) {
548 548
 				$output .= '<span class="dropdown-item-text"' . $attributes . '>';
549
-			} elseif ( 'dropdown-header' === $linkmod_type ) {
549
+			} elseif ('dropdown-header' === $linkmod_type) {
550 550
 				/*
551 551
 				 * For a header use a span with the .h6 class instead of a real
552 552
 				 * header tag so that it doesn't confuse screen readers.
553 553
 				 */
554 554
 				$output .= '<span class="dropdown-header h6"' . $attributes . '>';
555
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
555
+			} elseif ('dropdown-divider' === $linkmod_type) {
556 556
 				// This is a divider.
557 557
 				$output .= '<div class="dropdown-divider"' . $attributes . '>';
558 558
 			}
@@ -568,15 +568,15 @@  discard block
 block discarded – undo
568 568
 		 *
569 569
 		 * @return string              a string with the closing tag for this linkmod type.
570 570
 		 */
571
-		private function linkmod_element_close( $linkmod_type ) {
571
+		private function linkmod_element_close($linkmod_type) {
572 572
 			$output = '';
573
-			if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) {
573
+			if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) {
574 574
 				/*
575 575
 				 * For a header use a span with the .h6 class instead of a real
576 576
 				 * header tag so that it doesn't confuse screen readers.
577 577
 				 */
578 578
 				$output .= '</span>';
579
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
579
+			} elseif ('dropdown-divider' === $linkmod_type) {
580 580
 				// This is a divider.
581 581
 				$output .= '</div>';
582 582
 			}
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
 		 *
591 591
 		 * @return array a simple array
592 592
 		 */
593
-		public function flatten( $array ) {
593
+		public function flatten($array) {
594 594
 			$result = array();
595
-			foreach ( $array as $element ) {
596
-				if ( is_array( $element ) ) {
597
-					array_push( $result, ...$this->flatten( $element ) );
595
+			foreach ($array as $element) {
596
+				if (is_array($element)) {
597
+					array_push($result, ...$this->flatten($element));
598 598
 				} else {
599 599
 					$result[] = $element;
600 600
 				}
Please login to merge, or discard this patch.