Completed
Pull Request — master (#468)
by
unknown
01:18
created
class-wp-bootstrap-navwalker.php 1 patch
Spacing   +111 added lines, -111 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
 	 *
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
 		 * @param int      $depth  Depth of menu item. Used for padding.
38 38
 		 * @param stdClass $args   An object of wp_nav_menu() arguments.
39 39
 		 */
40
-		public function start_lvl( &$output, $depth = 0, $args = array() ) {
41
-			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
40
+		public function start_lvl(&$output, $depth = 0, $args = array()) {
41
+			if (isset($args->item_spacing) && 'discard' === $args->item_spacing) {
42 42
 				$t = '';
43 43
 				$n = '';
44 44
 			} else {
45 45
 				$t = "\t";
46 46
 				$n = "\n";
47 47
 			}
48
-			$indent = str_repeat( $t, $depth );
48
+			$indent = str_repeat($t, $depth);
49 49
 			// Default class to add to the file.
50
-			$classes = array( 'dropdown-menu' );
50
+			$classes = array('dropdown-menu');
51 51
 			/**
52 52
 			 * Filters the CSS class(es) applied to a menu list element.
53 53
 			 *
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 			 * @param stdClass $args    An object of `wp_nav_menu()` arguments.
58 58
 			 * @param int      $depth   Depth of menu item. Used for padding.
59 59
 			 */
60
-			$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
61
-			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
60
+			$class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth));
61
+			$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
62 62
 
63 63
 			/*
64 64
 			 * The `.dropdown-menu` container needs to have a labelledby
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
 			 */
70 70
 			$labelledby = '';
71 71
 			// Find all links with an id in the output.
72
-			preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches );
72
+			preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches);
73 73
 			// With pointer at end of array check if we got an ID match.
74
-			if ( end( $matches[2] ) ) {
74
+			if (end($matches[2])) {
75 75
 				// Build a string to use as aria-labelledby.
76
-				$labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"';
76
+				$labelledby = 'aria-labelledby="' . esc_attr(end($matches[2])) . '"';
77 77
 			}
78 78
 			$output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}";
79 79
 		}
@@ -92,17 +92,17 @@  discard block
 block discarded – undo
92 92
 		 * @param stdClass $args   An object of wp_nav_menu() arguments.
93 93
 		 * @param int      $id     Current item ID.
94 94
 		 */
95
-		public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
96
-			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
95
+		public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
96
+			if (isset($args->item_spacing) && 'discard' === $args->item_spacing) {
97 97
 				$t = '';
98 98
 				$n = '';
99 99
 			} else {
100 100
 				$t = "\t";
101 101
 				$n = "\n";
102 102
 			}
103
-			$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
103
+			$indent = ($depth) ? str_repeat($t, $depth) : '';
104 104
 
105
-			$classes = empty( $item->classes ) ? array() : (array) $item->classes;
105
+			$classes = empty($item->classes) ? array() : (array) $item->classes;
106 106
 
107 107
 			/*
108 108
 			 * Initialize some holder variables to store specially handled item
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 			 * NOTE: linkmod and icon class arrays are passed by reference and
118 118
 			 * are maybe modified before being used later in this function.
119 119
 			 */
120
-			$classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth );
120
+			$classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth);
121 121
 
122 122
 			// Join any icon classes plucked from $classes into a string.
123
-			$icon_class_string = join( ' ', $icon_classes );
123
+			$icon_class_string = join(' ', $icon_classes);
124 124
 
125 125
 			/**
126 126
 			 * Filters the arguments for a single nav menu item.
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
 			 * @param WP_Post  $item  Menu item data object.
132 132
 			 * @param int      $depth Depth of menu item. Used for padding.
133 133
 			 */
134
-			$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
134
+			$args = apply_filters('nav_menu_item_args', $args, $item, $depth);
135 135
 
136 136
 			// Add .dropdown or .active classes where they are needed.
137
-			if ( isset( $args->has_children ) && $args->has_children ) {
137
+			if (isset($args->has_children) && $args->has_children) {
138 138
 				$classes[] = 'dropdown';
139 139
 			}
140
-			if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
140
+			if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) {
141 141
 				$classes[] = 'active';
142 142
 			}
143 143
 
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			$classes[] = 'nav-item';
147 147
 
148 148
 			// Allow filtering the classes.
149
-			$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
149
+			$classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth);
150 150
 
151 151
 			// Form a string of classes in format: class="class_names".
152
-			$class_names = join( ' ', $classes );
153
-			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
152
+			$class_names = join(' ', $classes);
153
+			$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
154 154
 
155 155
 			/**
156 156
 			 * Filters the ID applied to a menu item's list item element.
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
 			 * @param stdClass $args    An object of wp_nav_menu() arguments.
164 164
 			 * @param int      $depth   Depth of menu item. Used for padding.
165 165
 			 */
166
-			$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
167
-			$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
166
+			$id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
167
+			$id = $id ? ' id="' . esc_attr($id) . '"' : '';
168 168
 
169 169
 			$output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>';
170 170
 
171 171
 			// Initialize array for holding the $atts for the link item.
172 172
 			$atts = array();
173 173
 
174
-			$atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
174
+			$atts['title']  = ! empty($item->attr_title) ? $item->attr_title : '';
175 175
 
176
-			$atts['target'] = ! empty( $item->target ) ? $item->target : '';
177
-			$atts['rel']    = ! empty( $item->xfn ) ? $item->xfn : '';
176
+			$atts['target'] = ! empty($item->target) ? $item->target : '';
177
+			$atts['rel']    = ! empty($item->xfn) ? $item->xfn : '';
178 178
 			// If the item has children, add atts to the <a>.
179
-			if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) {
179
+			if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) {
180 180
 				$atts['href']          = '#';
181 181
 				$atts['data-toggle']   = 'dropdown';
182 182
 				$atts['aria-haspopup'] = 'true';
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
 				$atts['class']         = 'dropdown-toggle nav-link';
185 185
 				$atts['id']            = 'menu-item-dropdown-' . $item->ID;
186 186
 			} else {
187
-				$atts['href'] = ! empty( $item->url ) ? $item->url : '#';
187
+				$atts['href'] = ! empty($item->url) ? $item->url : '#';
188 188
 				// For items in dropdowns use .dropdown-item instead of .nav-link.
189
-				if ( $depth > 0 ) {
189
+				if ($depth > 0) {
190 190
 					$atts['class'] = 'dropdown-item';
191 191
 				} else {
192 192
 					$atts['class'] = 'nav-link';
@@ -196,32 +196,32 @@  discard block
 block discarded – undo
196 196
 			$atts['aria-current'] = $item->current ? 'page' : '';
197 197
 
198 198
 			// Update atts of this item based on any custom linkmod classes.
199
-			$atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes );
199
+			$atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes);
200 200
 			// Allow filtering of the $atts array before using it.
201
-			$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
201
+			$atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
202 202
 
203 203
 			// Build a string of html containing all the atts for the item.
204 204
 			$attributes = '';
205
-			foreach ( $atts as $attr => $value ) {
206
-				if ( ! empty( $value ) ) {
207
-					$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
205
+			foreach ($atts as $attr => $value) {
206
+				if ( ! empty($value)) {
207
+					$value       = ('href' === $attr) ? esc_url($value) : esc_attr($value);
208 208
 					$attributes .= ' ' . $attr . '="' . $value . '"';
209 209
 				}
210 210
 			}
211 211
 
212 212
 			// Set a typeflag to easily test if this is a linkmod or not.
213
-			$linkmod_type = self::get_linkmod_type( $linkmod_classes );
213
+			$linkmod_type = self::get_linkmod_type($linkmod_classes);
214 214
 
215 215
 			// START appending the internal item contents to the output.
216
-			$item_output = isset( $args->before ) ? $args->before : '';
216
+			$item_output = isset($args->before) ? $args->before : '';
217 217
 
218 218
 			/*
219 219
 			 * This is the start of the internal nav item. Depending on what
220 220
 			 * kind of linkmod we have we may need different wrapper elements.
221 221
 			 */
222
-			if ( '' !== $linkmod_type ) {
222
+			if ('' !== $linkmod_type) {
223 223
 				// Is linkmod, output the required element opener.
224
-				$item_output .= self::linkmod_element_open( $linkmod_type, $attributes );
224
+				$item_output .= self::linkmod_element_open($linkmod_type, $attributes);
225 225
 			} else {
226 226
 				// With no link mod type set this must be a standard <a> tag.
227 227
 				$item_output .= '<a' . $attributes . '>';
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 			 * output inside of the item before the $title (the link text).
234 234
 			 */
235 235
 			$icon_html = '';
236
-			if ( ! empty( $icon_class_string ) ) {
236
+			if ( ! empty($icon_class_string)) {
237 237
 				// Append an <i> with the icon classes to what is output before links.
238
-				$icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> ';
238
+				$icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> ';
239 239
 			}
240 240
 
241 241
 			/** This filter is documented in wp-includes/post-template.php */
242
-			$title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID );
242
+			$title = apply_filters('the_title', esc_html($item->title), $item->ID);
243 243
 
244 244
 			/**
245 245
 			 * Filters a menu item's title.
@@ -251,36 +251,36 @@  discard block
 block discarded – undo
251 251
 			 * @param stdClass $args  An object of wp_nav_menu() arguments.
252 252
 			 * @param int      $depth Depth of menu item. Used for padding.
253 253
 			 */
254
-			$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
254
+			$title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth);
255 255
 
256 256
 			// If the .sr-only class was set apply to the nav items text only.
257
-			if ( in_array( 'sr-only', $linkmod_classes, true ) ) {
258
-				$title         = self::wrap_for_screen_reader( $title );
259
-				$keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true );
260
-				foreach ( $keys_to_unset as $k ) {
261
-					unset( $linkmod_classes[ $k ] );
257
+			if (in_array('sr-only', $linkmod_classes, true)) {
258
+				$title         = self::wrap_for_screen_reader($title);
259
+				$keys_to_unset = array_keys($linkmod_classes, 'sr-only', true);
260
+				foreach ($keys_to_unset as $k) {
261
+					unset($linkmod_classes[$k]);
262 262
 				}
263 263
 			}
264 264
 
265 265
 			// Put the item contents into $output.
266
-			$item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : '';
266
+			$item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : '';
267 267
 
268 268
 			/*
269 269
 			 * This is the end of the internal nav item. We need to close the
270 270
 			 * correct element depending on the type of link or link mod.
271 271
 			 */
272
-			if ( '' !== $linkmod_type ) {
272
+			if ('' !== $linkmod_type) {
273 273
 				// Is linkmod, output the required closing element.
274
-				$item_output .= self::linkmod_element_close( $linkmod_type );
274
+				$item_output .= self::linkmod_element_close($linkmod_type);
275 275
 			} else {
276 276
 				// With no link mod type set this must be a standard <a> tag.
277 277
 				$item_output .= '</a>';
278 278
 			}
279 279
 
280
-			$item_output .= isset( $args->after ) ? $args->after : '';
280
+			$item_output .= isset($args->after) ? $args->after : '';
281 281
 
282 282
 			// END appending the internal item contents to the output.
283
-			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
283
+			$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
284 284
 
285 285
 		}
286 286
 
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 		 * @param array  $args              An array of arguments.
306 306
 		 * @param string $output            Used to append additional content (passed by reference).
307 307
 		 */
308
-		public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
309
-			if ( ! $element ) {
308
+		public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {
309
+			if ( ! $element) {
310 310
 				return; }
311 311
 			$id_field = $this->db_fields['id'];
312 312
 			// Display this element.
313
-			if ( is_object( $args[0] ) ) {
314
-				$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); }
315
-			parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
313
+			if (is_object($args[0])) {
314
+				$args[0]->has_children = ! empty($children_elements[$element->$id_field]); }
315
+			parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
316 316
 		}
317 317
 
318 318
 		/**
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		 *
326 326
 		 * @param array $args passed from the wp_nav_menu function.
327 327
 		 */
328
-		public static function fallback( $args ) {
329
-			if ( current_user_can( 'edit_theme_options' ) ) {
328
+		public static function fallback($args) {
329
+			if (current_user_can('edit_theme_options')) {
330 330
 
331 331
 				// Get Arguments.
332 332
 				$container       = $args['container'];
@@ -338,30 +338,30 @@  discard block
 block discarded – undo
338 338
 				// Initialize var to store fallback html.
339 339
 				$fallback_output = '';
340 340
 
341
-				if ( $container ) {
342
-					$fallback_output .= '<' . esc_attr( $container );
343
-					if ( $container_id ) {
344
-						$fallback_output .= ' id="' . esc_attr( $container_id ) . '"';
341
+				if ($container) {
342
+					$fallback_output .= '<' . esc_attr($container);
343
+					if ($container_id) {
344
+						$fallback_output .= ' id="' . esc_attr($container_id) . '"';
345 345
 					}
346
-					if ( $container_class ) {
347
-						$fallback_output .= ' class="' . esc_attr( $container_class ) . '"';
346
+					if ($container_class) {
347
+						$fallback_output .= ' class="' . esc_attr($container_class) . '"';
348 348
 					}
349 349
 					$fallback_output .= '>';
350 350
 				}
351 351
 				$fallback_output .= '<ul';
352
-				if ( $menu_id ) {
353
-					$fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; }
354
-				if ( $menu_class ) {
355
-					$fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; }
352
+				if ($menu_id) {
353
+					$fallback_output .= ' id="' . esc_attr($menu_id) . '"'; }
354
+				if ($menu_class) {
355
+					$fallback_output .= ' class="' . esc_attr($menu_class) . '"'; }
356 356
 				$fallback_output .= '>';
357
-				$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>';
357
+				$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>';
358 358
 				$fallback_output .= '</ul>';
359
-				if ( $container ) {
360
-					$fallback_output .= '</' . esc_attr( $container ) . '>';
359
+				if ($container) {
360
+					$fallback_output .= '</' . esc_attr($container) . '>';
361 361
 				}
362 362
 
363 363
 				// If $args has 'echo' key and it's true echo, otherwise return.
364
-				if ( array_key_exists( 'echo', $args ) && $args['echo'] ) {
364
+				if (array_key_exists('echo', $args) && $args['echo']) {
365 365
 					echo $fallback_output; // WPCS: XSS OK.
366 366
 				} else {
367 367
 					return $fallback_output;
@@ -387,32 +387,32 @@  discard block
 block discarded – undo
387 387
 		 *
388 388
 		 * @return array  $classes         a maybe modified array of classnames.
389 389
 		 */
390
-		private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) {
390
+		private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) {
391 391
 			// Loop through $classes array to find linkmod or icon classes.
392
-			foreach ( $classes as $key => $class ) {
392
+			foreach ($classes as $key => $class) {
393 393
 				/*
394 394
 				 * If any special classes are found, store the class in it's
395 395
 				 * holder array and and unset the item from $classes.
396 396
 				 */
397
-				if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
397
+				if (preg_match('/^disabled|^sr-only/i', $class)) {
398 398
 					// Test for .disabled or .sr-only classes.
399 399
 					$linkmod_classes[] = $class;
400
-					unset( $classes[ $key ] );
401
-				} elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) {
400
+					unset($classes[$key]);
401
+				} elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) {
402 402
 					/*
403 403
 					 * Test for .dropdown-header or .dropdown-divider and a
404 404
 					 * depth greater than 0 - IE inside a dropdown.
405 405
 					 */
406 406
 					$linkmod_classes[] = $class;
407
-					unset( $classes[ $key ] );
408
-				} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
407
+					unset($classes[$key]);
408
+				} elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) {
409 409
 					// Font Awesome.
410 410
 					$icon_classes[] = $class;
411
-					unset( $classes[ $key ] );
412
-				} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
411
+					unset($classes[$key]);
412
+				} elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) {
413 413
 					// Glyphicons.
414 414
 					$icon_classes[] = $class;
415
-					unset( $classes[ $key ] );
415
+					unset($classes[$key]);
416 416
 				}
417 417
 			}
418 418
 
@@ -429,19 +429,19 @@  discard block
 block discarded – undo
429 429
 		 *
430 430
 		 * @return string                empty for default, a linkmod type string otherwise.
431 431
 		 */
432
-		private function get_linkmod_type( $linkmod_classes = array() ) {
432
+		private function get_linkmod_type($linkmod_classes = array()) {
433 433
 			$linkmod_type = '';
434 434
 			// Loop through array of linkmod classes to handle their $atts.
435
-			if ( ! empty( $linkmod_classes ) ) {
436
-				foreach ( $linkmod_classes as $link_class ) {
437
-					if ( ! empty( $link_class ) ) {
435
+			if ( ! empty($linkmod_classes)) {
436
+				foreach ($linkmod_classes as $link_class) {
437
+					if ( ! empty($link_class)) {
438 438
 
439 439
 						// Check for special class types and set a flag for them.
440
-						if ( 'dropdown-header' === $link_class ) {
440
+						if ('dropdown-header' === $link_class) {
441 441
 							$linkmod_type = 'dropdown-header';
442
-						} elseif ( 'dropdown-divider' === $link_class ) {
442
+						} elseif ('dropdown-divider' === $link_class) {
443 443
 							$linkmod_type = 'dropdown-divider';
444
-						} elseif ( 'dropdown-item-text' === $link_class ) {
444
+						} elseif ('dropdown-item-text' === $link_class) {
445 445
 							$linkmod_type = 'dropdown-item-text';
446 446
 						}
447 447
 					}
@@ -460,26 +460,26 @@  discard block
 block discarded – undo
460 460
 		 *
461 461
 		 * @return array                 maybe updated array of attributes for item.
462 462
 		 */
463
-		private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) {
464
-			if ( ! empty( $linkmod_classes ) ) {
465
-				foreach ( $linkmod_classes as $link_class ) {
466
-					if ( ! empty( $link_class ) ) {
463
+		private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) {
464
+			if ( ! empty($linkmod_classes)) {
465
+				foreach ($linkmod_classes as $link_class) {
466
+					if ( ! empty($link_class)) {
467 467
 						/*
468 468
 						 * Update $atts with a space and the extra classname
469 469
 						 * so long as it's not a sr-only class.
470 470
 						 */
471
-						if ( 'sr-only' !== $link_class ) {
472
-							$atts['class'] .= ' ' . esc_attr( $link_class );
471
+						if ('sr-only' !== $link_class) {
472
+							$atts['class'] .= ' ' . esc_attr($link_class);
473 473
 						}
474 474
 						// Check for special class types we need additional handling for.
475
-						if ( 'disabled' === $link_class ) {
475
+						if ('disabled' === $link_class) {
476 476
 							// Convert link to '#' and unset open targets.
477 477
 							$atts['href'] = '#';
478
-							unset( $atts['target'] );
479
-						} elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) {
478
+							unset($atts['target']);
479
+						} elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) {
480 480
 							// Store a type flag and unset href and target.
481
-							unset( $atts['href'] );
482
-							unset( $atts['target'] );
481
+							unset($atts['href']);
482
+							unset($atts['target']);
483 483
 						}
484 484
 					}
485 485
 				}
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 		 * @param string $text the string of text to be wrapped in a screen reader class.
496 496
 		 * @return string      the string wrapped in a span with the class.
497 497
 		 */
498
-		private function wrap_for_screen_reader( $text = '' ) {
499
-			if ( $text ) {
498
+		private function wrap_for_screen_reader($text = '') {
499
+			if ($text) {
500 500
 				$text = '<span class="sr-only">' . $text . '</span>';
501 501
 			}
502 502
 			return $text;
@@ -512,17 +512,17 @@  discard block
 block discarded – undo
512 512
 		 *
513 513
 		 * @return string              a string with the openign tag for the element with attribibutes added.
514 514
 		 */
515
-		private function linkmod_element_open( $linkmod_type, $attributes = '' ) {
515
+		private function linkmod_element_open($linkmod_type, $attributes = '') {
516 516
 			$output = '';
517
-			if ( 'dropdown-item-text' === $linkmod_type ) {
517
+			if ('dropdown-item-text' === $linkmod_type) {
518 518
 				$output .= '<span class="dropdown-item-text"' . $attributes . '>';
519
-			} elseif ( 'dropdown-header' === $linkmod_type ) {
519
+			} elseif ('dropdown-header' === $linkmod_type) {
520 520
 				/*
521 521
 				 * For a header use a span with the .h6 class instead of a real
522 522
 				 * header tag so that it doesn't confuse screen readers.
523 523
 				 */
524 524
 				$output .= '<span class="dropdown-header h6"' . $attributes . '>';
525
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
525
+			} elseif ('dropdown-divider' === $linkmod_type) {
526 526
 				// This is a divider.
527 527
 				$output .= '<div class="dropdown-divider"' . $attributes . '>';
528 528
 			}
@@ -538,15 +538,15 @@  discard block
 block discarded – undo
538 538
 		 *
539 539
 		 * @return string              a string with the closing tag for this linkmod type.
540 540
 		 */
541
-		private function linkmod_element_close( $linkmod_type ) {
541
+		private function linkmod_element_close($linkmod_type) {
542 542
 			$output = '';
543
-			if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) {
543
+			if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) {
544 544
 				/*
545 545
 				 * For a header use a span with the .h6 class instead of a real
546 546
 				 * header tag so that it doesn't confuse screen readers.
547 547
 				 */
548 548
 				$output .= '</span>';
549
-			} elseif ( 'dropdown-divider' === $linkmod_type ) {
549
+			} elseif ('dropdown-divider' === $linkmod_type) {
550 550
 				// This is a divider.
551 551
 				$output .= '</div>';
552 552
 			}
Please login to merge, or discard this patch.