Completed
Pull Request — master (#446)
by
unknown
01:48
created
class-wp-bootstrap-navwalker.php 1 patch
Spacing   +110 added lines, -110 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 role=\"menu\">{$n}";
96 96
 		}
@@ -109,23 +109,23 @@  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
 			/*
131 131
 			 * Initialize some holder variables to store specially handled item
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 			 * NOTE: linkmod and icon class arrays are passed by reference and
141 141
 			 * are maybe modified before being used later in this function.
142 142
 			 */
143
-			$classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth );
143
+			$classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth);
144 144
 
145 145
 			// Join any icon classes plucked from $classes into a string.
146
-			$icon_class_string = join( ' ', $icon_classes );
146
+			$icon_class_string = join(' ', $icon_classes);
147 147
 
148 148
 			/**
149 149
 			 * Filters the arguments for a single nav menu item.
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
 			 *
157 157
 			 * @var WP_Nav_Menu_Args
158 158
 			 */
159
-			$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
159
+			$args = apply_filters('nav_menu_item_args', $args, $item, $depth);
160 160
 
161 161
 			// Add .dropdown or .active classes where they are needed.
162
-			if ( $this->has_children ) {
162
+			if ($this->has_children) {
163 163
 				$classes[] = 'dropdown';
164 164
 			}
165
-			if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
165
+			if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) {
166 166
 				$classes[] = 'active';
167 167
 			}
168 168
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 			$classes[] = 'nav-item';
172 172
 
173 173
 			// Allow filtering the classes.
174
-			$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
174
+			$classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth);
175 175
 
176 176
 			// Form a string of classes in format: class="class_names".
177
-			$class_names = join( ' ', $classes );
178
-			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
177
+			$class_names = join(' ', $classes);
178
+			$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
179 179
 
180 180
 			/**
181 181
 			 * Filters the ID applied to a menu item's list item element.
@@ -188,26 +188,26 @@  discard block
 block discarded – undo
188 188
 			 * @param WP_Nav_Menu_Args $args    An object of wp_nav_menu() arguments.
189 189
 			 * @param int              $depth   Depth of menu item. Used for padding.
190 190
 			 */
191
-			$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
192
-			$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
191
+			$id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
192
+			$id = $id ? ' id="' . esc_attr($id) . '"' : '';
193 193
 
194 194
 			$output .= $indent . '<li ' . $id . $class_names . '>';
195 195
 
196 196
 			// Initialize array for holding the $atts for the link item.
197 197
 			$atts = array();
198 198
 
199
-			$atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
199
+			$atts['title']  = ! empty($item->attr_title) ? $item->attr_title : '';
200 200
 
201
-			$atts['target'] = ! empty( $item->target ) ? $item->target : '';
201
+			$atts['target'] = ! empty($item->target) ? $item->target : '';
202 202
 
203
-			if ( '_blank' === $item->target && empty( $item->xfn ) ) {
203
+			if ('_blank' === $item->target && empty($item->xfn)) {
204 204
 				$atts['rel'] = 'noopener noreferrer';
205 205
 			} else {
206
-				$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
206
+				$atts['rel'] = ! empty($item->xfn) ? $item->xfn : '';
207 207
 			}
208 208
 
209 209
 			// If the item has_children add atts to <a>.
210
-			if ( $args->has_children && 0 === $depth && $args->depth > 1 ) {
210
+			if ($args->has_children && 0 === $depth && $args->depth > 1) {
211 211
 				$atts['href']          = '#';
212 212
 				$atts['data-toggle']   = 'dropdown';
213 213
 				$atts['aria-haspopup'] = 'true';
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 				$atts['class']         = 'dropdown-toggle nav-link';
216 216
 				$atts['id']            = 'menu-item-dropdown-' . $item->ID;
217 217
 			} else {
218
-				if ( true === $this->has_schema ) {
218
+				if (true === $this->has_schema) {
219 219
 					$atts['itemprop'] = 'url';
220 220
 				}
221 221
 
222
-				$atts['href'] = ! empty( $item->url ) ? $item->url : '#';
222
+				$atts['href'] = ! empty($item->url) ? $item->url : '#';
223 223
 				// For items in dropdowns use .dropdown-item instead of .nav-link.
224
-				if ( $depth > 0 ) {
224
+				if ($depth > 0) {
225 225
 					$atts['class'] = 'dropdown-item';
226 226
 				} else {
227 227
 					$atts['class'] = 'nav-link';
@@ -231,33 +231,33 @@  discard block
 block discarded – undo
231 231
 			$atts['aria-current'] = $item->current ? 'page' : '';
232 232
 
233 233
 			// Update atts of this item based on any custom linkmod classes.
234
-			$atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes );
234
+			$atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes);
235 235
 
236 236
 			// Allow filtering of the $atts array before using it.
237
-			$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
237
+			$atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
238 238
 
239 239
 			// Build a string of html containing all the atts for the item.
240 240
 			$attributes = '';
241
-			foreach ( $atts as $attr => $value ) {
242
-				if ( ! empty( $value ) ) {
243
-					$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
241
+			foreach ($atts as $attr => $value) {
242
+				if ( ! empty($value)) {
243
+					$value       = ('href' === $attr) ? esc_url($value) : esc_attr($value);
244 244
 					$attributes .= ' ' . $attr . '="' . $value . '"';
245 245
 				}
246 246
 			}
247 247
 
248 248
 			// Set a typeflag to easily test if this is a linkmod or not.
249
-			$linkmod_type = self::get_linkmod_type( $linkmod_classes );
249
+			$linkmod_type = self::get_linkmod_type($linkmod_classes);
250 250
 
251 251
 			// START appending the internal item contents to the output.
252
-			$item_output = isset( $args->before ) ? $args->before : '';
252
+			$item_output = isset($args->before) ? $args->before : '';
253 253
 
254 254
 			/*
255 255
 			 * This is the start of the internal nav item. Depending on what
256 256
 			 * kind of linkmod we have we may need different wrapper elements.
257 257
 			 */
258
-			if ( '' !== $linkmod_type ) {
258
+			if ('' !== $linkmod_type) {
259 259
 				// Is linkmod, output the required element opener.
260
-				$item_output .= self::linkmod_element_open( $linkmod_type, $attributes );
260
+				$item_output .= self::linkmod_element_open($linkmod_type, $attributes);
261 261
 			} else {
262 262
 				// With no link mod type set this must be a standard <a> tag.
263 263
 				$item_output .= '<a' . $attributes . '>';
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
 			 * output inside of the item before the $title (the link text).
270 270
 			 */
271 271
 			$icon_html = '';
272
-			if ( ! empty( $icon_class_string ) ) {
272
+			if ( ! empty($icon_class_string)) {
273 273
 				// Append an <i> with the icon classes to what is output before links.
274
-				$icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> ';
274
+				$icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> ';
275 275
 			}
276 276
 
277 277
 			/** This filter is documented in wp-includes/post-template.php */
278
-			$title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID );
278
+			$title = apply_filters('the_title', esc_html($item->title), $item->ID);
279 279
 
280 280
 			/**
281 281
 			 * Filters a menu item's title.
@@ -287,36 +287,36 @@  discard block
 block discarded – undo
287 287
 			 * @param WP_Nav_Menu_Args $args  An object of wp_nav_menu() arguments.
288 288
 			 * @param int              $depth Depth of menu item. Used for padding.
289 289
 			 */
290
-			$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
290
+			$title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth);
291 291
 
292 292
 			// If the .sr-only class was set apply to the nav items text only.
293
-			if ( in_array( 'sr-only', $linkmod_classes, true ) ) {
294
-				$title         = self::wrap_for_screen_reader( $title );
295
-				$keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true );
296
-				foreach ( $keys_to_unset as $k ) {
297
-					unset( $linkmod_classes[ $k ] );
293
+			if (in_array('sr-only', $linkmod_classes, true)) {
294
+				$title         = self::wrap_for_screen_reader($title);
295
+				$keys_to_unset = array_keys($linkmod_classes, 'sr-only', true);
296
+				foreach ($keys_to_unset as $k) {
297
+					unset($linkmod_classes[$k]);
298 298
 				}
299 299
 			}
300 300
 
301 301
 			// Put the item contents into $output.
302
-			$item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : '';
302
+			$item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : '';
303 303
 
304 304
 			/*
305 305
 			 * This is the end of the internal nav item. We need to close the
306 306
 			 * correct element depending on the type of link or link mod.
307 307
 			 */
308
-			if ( '' !== $linkmod_type ) {
308
+			if ('' !== $linkmod_type) {
309 309
 				// Is linkmod, output the required closing element.
310
-				$item_output .= self::linkmod_element_close( $linkmod_type );
310
+				$item_output .= self::linkmod_element_close($linkmod_type);
311 311
 			} else {
312 312
 				// With no link mod type set this must be a standard <a> tag.
313 313
 				$item_output .= '</a>';
314 314
 			}
315 315
 
316
-			$item_output .= isset( $args->after ) ? $args->after : '';
316
+			$item_output .= isset($args->after) ? $args->after : '';
317 317
 
318 318
 			// END appending the internal item contents to the output.
319
-			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
319
+			$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
320 320
 		}
321 321
 
322 322
 		/**
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
 		 * @param array $args passed from the wp_nav_menu function.
331 331
 		 * @return string|void String when echo is false.
332 332
 		 */
333
-		public static function fallback( $args ) {
334
-			if ( ! current_user_can( 'edit_theme_options' ) ) {
333
+		public static function fallback($args) {
334
+			if ( ! current_user_can('edit_theme_options')) {
335 335
 				return;
336 336
 			}
337 337
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 
341 341
 			// Menu container opening tag.
342 342
 			$show_container = false;
343
-			if ( $args['container'] ) {
343
+			if ($args['container']) {
344 344
 				/**
345 345
 				 * Filters the list of HTML tags that are valid for use as menu containers.
346 346
 				 *
@@ -349,29 +349,29 @@  discard block
 block discarded – undo
349 349
 				 * @param array $tags The acceptable HTML tags for use as menu containers.
350 350
 				 *                    Default is array containing 'div' and 'nav'.
351 351
 				 */
352
-				$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
353
-				if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) {
352
+				$allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav'));
353
+				if (is_string($args['container']) && in_array($args['container'], $allowed_tags, true)) {
354 354
 					$show_container   = true;
355
-					$class            = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"';
356
-					$id               = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : '';
355
+					$class            = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr($args['container_class']) . '"' : ' class="menu-fallback-container"';
356
+					$id               = $args['container_id'] ? ' id="' . esc_attr($args['container_id']) . '"' : '';
357 357
 					$fallback_output .= '<' . $args['container'] . $id . $class . '>';
358 358
 				}
359 359
 			}
360 360
 
361 361
 			// The fallback menu.
362
-			$class            = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"';
363
-			$id               = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : '';
362
+			$class            = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr($args['menu_class']) . '"' : ' class="menu-fallback-menu"';
363
+			$id               = $args['menu_id'] ? ' id="' . esc_attr($args['menu_id']) . '"' : '';
364 364
 			$fallback_output .= '<ul' . $id . $class . '>';
365
-			$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>';
365
+			$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>';
366 366
 			$fallback_output .= '</ul>';
367 367
 
368 368
 			// Menu container closing tag.
369
-			if ( $show_container ) {
369
+			if ($show_container) {
370 370
 				$fallback_output .= '</' . $args['container'] . '>';
371 371
 			}
372 372
 
373 373
 			// if $args has 'echo' key and it's true echo, otherwise return.
374
-			if ( array_key_exists( 'echo', $args ) && $args['echo'] ) {
374
+			if (array_key_exists('echo', $args) && $args['echo']) {
375 375
 				echo $fallback_output; // WPCS: XSS OK.
376 376
 			} else {
377 377
 				return $fallback_output;
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 		 * @param  array $args The nav instance arguments.
387 387
 		 * @return array $args The altered nav instance arguments.
388 388
 		 */
389
-		public function add_schema_to_navbar_ul( $args ) {
389
+		public function add_schema_to_navbar_ul($args) {
390 390
 			$wrap = $args['items_wrap'];
391
-			if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) {
392
-				$args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap );
391
+			if (strpos($wrap, 'SiteNavigationElement') === false) {
392
+				$args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap);
393 393
 			}
394 394
 
395 395
 			return $args;
@@ -413,32 +413,32 @@  discard block
 block discarded – undo
413 413
 		 *
414 414
 		 * @return array  $classes         a maybe modified array of classnames.
415 415
 		 */
416
-		private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) {
416
+		private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) {
417 417
 			// Loop through $classes array to find linkmod or icon classes.
418
-			foreach ( $classes as $key => $class ) {
418
+			foreach ($classes as $key => $class) {
419 419
 				/*
420 420
 				 * If any special classes are found, store the class in it's
421 421
 				 * holder array and and unset the item from $classes.
422 422
 				 */
423
-				if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
423
+				if (preg_match('/^disabled|^sr-only/i', $class)) {
424 424
 					// Test for .disabled or .sr-only classes.
425 425
 					$linkmod_classes[] = $class;
426
-					unset( $classes[ $key ] );
427
-				} elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) {
426
+					unset($classes[$key]);
427
+				} elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) {
428 428
 					/*
429 429
 					 * Test for .dropdown-header or .dropdown-divider and a
430 430
 					 * depth greater than 0 - IE inside a dropdown.
431 431
 					 */
432 432
 					$linkmod_classes[] = $class;
433
-					unset( $classes[ $key ] );
434
-				} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
433
+					unset($classes[$key]);
434
+				} elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) {
435 435
 					// Font Awesome.
436 436
 					$icon_classes[] = $class;
437
-					unset( $classes[ $key ] );
438
-				} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
437
+					unset($classes[$key]);
438
+				} elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) {
439 439
 					// Glyphicons.
440 440
 					$icon_classes[] = $class;
441
-					unset( $classes[ $key ] );
441
+					unset($classes[$key]);
442 442
 				}
443 443
 			}
444 444
 
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
 		 *
456 456
 		 * @return string                empty for default, a linkmod type string otherwise.
457 457
 		 */
458
-		private function get_linkmod_type( $linkmod_classes = array() ) {
458
+		private function get_linkmod_type($linkmod_classes = array()) {
459 459
 			$linkmod_type = '';
460 460
 			// Loop through array of linkmod classes to handle their $atts.
461
-			if ( ! empty( $linkmod_classes ) ) {
462
-				foreach ( $linkmod_classes as $link_class ) {
463
-					if ( ! empty( $link_class ) ) {
461
+			if ( ! empty($linkmod_classes)) {
462
+				foreach ($linkmod_classes as $link_class) {
463
+					if ( ! empty($link_class)) {
464 464
 
465 465
 						// Check for special class types and set a flag for them.
466
-						if ( 'dropdown-header' === $link_class ) {
466
+						if ('dropdown-header' === $link_class) {
467 467
 							$linkmod_type = 'dropdown-header';
468
-						} elseif ( 'dropdown-divider' === $link_class ) {
468
+						} elseif ('dropdown-divider' === $link_class) {
469 469
 							$linkmod_type = 'dropdown-divider';
470
-						} elseif ( 'dropdown-item-text' === $link_class ) {
470
+						} elseif ('dropdown-item-text' === $link_class) {
471 471
 							$linkmod_type = 'dropdown-item-text';
472 472
 						}
473 473
 					}
@@ -486,26 +486,26 @@  discard block
 block discarded – undo
486 486
 		 *
487 487
 		 * @return array                 maybe updated array of attributes for item.
488 488
 		 */
489
-		private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) {
490
-			if ( ! empty( $linkmod_classes ) ) {
491
-				foreach ( $linkmod_classes as $link_class ) {
492
-					if ( ! empty( $link_class ) ) {
489
+		private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) {
490
+			if ( ! empty($linkmod_classes)) {
491
+				foreach ($linkmod_classes as $link_class) {
492
+					if ( ! empty($link_class)) {
493 493
 						/*
494 494
 						 * Update $atts with a space and the extra classname
495 495
 						 * so long as it's not a sr-only class.
496 496
 						 */
497
-						if ( 'sr-only' !== $link_class ) {
498
-							$atts['class'] .= ' ' . esc_attr( $link_class );
497
+						if ('sr-only' !== $link_class) {
498
+							$atts['class'] .= ' ' . esc_attr($link_class);
499 499
 						}
500 500
 						// Check for special class types we need additional handling for.
501
-						if ( 'disabled' === $link_class ) {
501
+						if ('disabled' === $link_class) {
502 502
 							// Convert link to '#' and unset open targets.
503 503
 							$atts['href'] = '#';
504
-							unset( $atts['target'] );
505
-						} elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) {
504
+							unset($atts['target']);
505
+						} elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) {
506 506
 							// Store a type flag and unset href and target.
507
-							unset( $atts['href'] );
508
-							unset( $atts['target'] );
507
+							unset($atts['href']);
508
+							unset($atts['target']);
509 509
 						}
510 510
 					}
511 511
 				}
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 		 * @param string $text the string of text to be wrapped in a screen reader class.
522 522
 		 * @return string      the string wrapped in a span with the class.
523 523
 		 */
524
-		private function wrap_for_screen_reader( $text = '' ) {
525
-			if ( $text ) {
524
+		private function wrap_for_screen_reader($text = '') {
525
+			if ($text) {
526 526
 				$text = '<span class="sr-only">' . $text . '</span>';
527 527
 			}
528 528
 			return $text;
@@ -538,17 +538,17 @@  discard block
 block discarded – undo
538 538
 		 *
539 539
 		 * @return string              a string with the openign tag for the element with attribibutes added.
540 540
 		 */
541
-		private function linkmod_element_open( $linkmod_type, $attributes = '' ) {
541
+		private function linkmod_element_open($linkmod_type, $attributes = '') {
542 542
 			$output = '';
543
-			if ( 'dropdown-item-text' === $linkmod_type ) {
543
+			if ('dropdown-item-text' === $linkmod_type) {
544 544
 				$output .= '<span class="dropdown-item-text"' . $attributes . '>';
545
-			} elseif ( 'dropdown-header' === $linkmod_type ) {
545
+			} elseif ('dropdown-header' === $linkmod_type) {
546 546
 				/*
547 547
 				 * For a header use a span with the .h6 class instead of a real
548 548
 				 * header tag so that it doesn't confuse screen readers.
549 549
 				 */
550 550
 				$output .= '<span class="dropdown-header h6"' . $attributes . '>';
551
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
551
+			} elseif ('dropdown-divider' === $linkmod_type) {
552 552
 				// This is a divider.
553 553
 				$output .= '<div class="dropdown-divider"' . $attributes . '>';
554 554
 			}
@@ -564,15 +564,15 @@  discard block
 block discarded – undo
564 564
 		 *
565 565
 		 * @return string              a string with the closing tag for this linkmod type.
566 566
 		 */
567
-		private function linkmod_element_close( $linkmod_type ) {
567
+		private function linkmod_element_close($linkmod_type) {
568 568
 			$output = '';
569
-			if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) {
569
+			if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) {
570 570
 				/*
571 571
 				 * For a header use a span with the .h6 class instead of a real
572 572
 				 * header tag so that it doesn't confuse screen readers.
573 573
 				 */
574 574
 				$output .= '</span>';
575
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
575
+			} elseif ('dropdown-divider' === $linkmod_type) {
576 576
 				// This is a divider.
577 577
 				$output .= '</div>';
578 578
 			}
Please login to merge, or discard this patch.