Completed
Pull Request — master (#447)
by
unknown
01:10
created

class-wp-bootstrap-navwalker.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * WP Bootstrap Navwalker.
4
 *
5
 * @package WP-Bootstrap-Navwalker
6
 *
7
 * @wordpress-plugin
8
 * Plugin Name: WP Bootstrap Navwalker
9
 * Plugin URI:  https://github.com/wp-bootstrap/wp-bootstrap-navwalker
10
 * Description: A custom WordPress nav walker class to implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.
11
 * Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz
12
 * Version: 4.3.0
13
 * Author URI: https://github.com/wp-bootstrap
14
 * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker
15
 * GitHub Branch: master
16
 * License: GPL-3.0+
17
 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
18
 */
19
20
/* Check if Class Exists. */
21
if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) {
22
	/**
23
	 * WP_Bootstrap_Navwalker class.
24
	 *
25
	 * @extends Walker_Nav_Menu
26
	 */
27
	class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {
28
29
		/**
30
		 * Starts the list before the elements are added.
31
		 *
32
		 * @since WP 3.0.0
33
		 *
34
		 * @see Walker_Nav_Menu::start_lvl()
35
		 *
36
		 * @param string   $output Used to append additional content (passed by reference).
37
		 * @param int      $depth  Depth of menu item. Used for padding.
38
		 * @param stdClass $args   An object of wp_nav_menu() arguments.
39
		 */
40
		public function start_lvl( &$output, $depth = 0, $args = array() ) {
41 View Code Duplication
			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
				$t = '';
43
				$n = '';
44
			} else {
45
				$t = "\t";
46
				$n = "\n";
47
			}
48
			$indent = str_repeat( $t, $depth );
49
			// Default class to add to the file.
50
			$classes = array( 'dropdown-menu' );
51
			/**
52
			 * Filters the CSS class(es) applied to a menu list element.
53
			 *
54
			 * @since WP 4.8.0
55
			 *
56
			 * @param array    $classes The CSS classes that are applied to the menu `<ul>` element.
57
			 * @param stdClass $args    An object of `wp_nav_menu()` arguments.
58
			 * @param int      $depth   Depth of menu item. Used for padding.
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 ) . '"' : '';
62
			/**
63
			 * The `.dropdown-menu` container needs to have a labelledby
64
			 * attribute which points to it's trigger link.
65
			 *
66
			 * Form a string for the labelledby attribute from the the latest
67
			 * link with an id that was added to the $output.
68
			 */
69
			$labelledby = '';
70
			// find all links with an id in the output.
71
			preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches );
72
			// with pointer at end of array check if we got an ID match.
73
			if ( end( $matches[2] ) ) {
74
				// build a string to use as aria-labelledby.
75
				$labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"';
76
			}
77
			$output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}";
78
		}
79
80
		/**
81
		 * Starts the element output.
82
		 *
83
		 * @since WP 3.0.0
84
		 * @since WP 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
85
		 *
86
		 * @see Walker_Nav_Menu::start_el()
87
		 *
88
		 * @param string   $output Used to append additional content (passed by reference).
89
		 * @param WP_Post  $item   Menu item data object.
90
		 * @param int      $depth  Depth of menu item. Used for padding.
91
		 * @param stdClass $args   An object of wp_nav_menu() arguments.
92
		 * @param int      $id     Current item ID.
93
		 */
94
		public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
95 View Code Duplication
			if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
				$t = '';
97
				$n = '';
0 ignored issues
show
$n is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
98
			} else {
99
				$t = "\t";
100
				$n = "\n";
0 ignored issues
show
$n is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
101
			}
102
			$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
103
104
			$classes = empty( $item->classes ) ? array() : (array) $item->classes;
105
106
			// Initialize some holder variables to store specially handled item
107
			// wrappers and icons.
108
			$linkmod_classes = array();
109
			$icon_classes    = array();
110
111
			/**
112
			 * Get an updated $classes array without linkmod or icon classes.
113
			 *
114
			 * NOTE: linkmod and icon class arrays are passed by reference and
115
			 * are maybe modified before being used later in this function.
116
			 */
117
			$classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth );
118
119
			// Join any icon classes plucked from $classes into a string.
120
			$icon_class_string = join( ' ', $icon_classes );
121
122
			/**
123
			 * Filters the arguments for a single nav menu item.
124
			 *
125
			 *  WP 4.4.0
126
			 *
127
			 * @param stdClass $args  An object of wp_nav_menu() arguments.
128
			 * @param WP_Post  $item  Menu item data object.
129
			 * @param int      $depth Depth of menu item. Used for padding.
130
			 */
131
			$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
132
133
			// Add .dropdown or .active classes where they are needed.
134
			if ( isset( $args->has_children ) && $args->has_children ) {
135
				$classes[] = 'dropdown';
136
			}
137
			if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
138
				$classes[] = 'active';
139
			}
140
141
			// Add some additional default classes to the item.
142
			$classes[] = 'menu-item-' . $item->ID;
143
			$classes[] = 'nav-item';
144
145
			// Allow filtering the classes.
146
			$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
147
148
			// Form a string of classes in format: class="class_names".
149
			$class_names = join( ' ', $classes );
150
			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
151
152
			/**
153
			 * Filters the ID applied to a menu item's list item element.
154
			 *
155
			 * @since WP 3.0.1
156
			 * @since WP 4.1.0 The `$depth` parameter was added.
157
			 *
158
			 * @param string   $menu_id The ID that is applied to the menu item's `<li>` element.
159
			 * @param WP_Post  $item    The current menu item.
160
			 * @param stdClass $args    An object of wp_nav_menu() arguments.
161
			 * @param int      $depth   Depth of menu item. Used for padding.
162
			 */
163
			$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
164
			$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
165
166
			$output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>';
167
168
			// initialize array for holding the $atts for the link item.
169
			$atts = array();
170
171
			// Set title from item to the $atts array - if title is empty then
172
			// default to item title.
173
			if ( empty( $item->attr_title ) ) {
174
				$atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : '';
175
			} else {
176
				$atts['title'] = $item->attr_title;
177
			}
178
179
			$atts['target'] = ! empty( $item->target ) ? $item->target : '';
180
			$atts['rel']    = ! empty( $item->xfn ) ? $item->xfn : '';
181
			// If item has_children add atts to <a>.
182
			if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) {
183
				$atts['href']          = '#';
184
				$atts['data-toggle']   = 'dropdown';
185
				$atts['aria-haspopup'] = 'true';
186
				$atts['aria-expanded'] = 'false';
187
				$atts['class']         = 'dropdown-toggle nav-link';
188
				$atts['id']            = 'menu-item-dropdown-' . $item->ID;
189
			} else {
190
				$atts['href'] = ! empty( $item->url ) ? $item->url : '#';
191
				$atts['itemprop'] = 'url';
192
				// Items in dropdowns use .dropdown-item instead of .nav-link.
193
				if ( $depth > 0 ) {
194
					$atts['class'] = 'dropdown-item';
195
				} else {
196
					$atts['class'] = 'nav-link';
197
				}
198
			}
199
200
			$atts['aria-current'] = $item->current ? 'page' : '';
201
202
			// update atts of this item based on any custom linkmod classes.
203
			$atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes );
204
			// Allow filtering of the $atts array before using it.
205
			$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
206
207
			// Build a string of html containing all the atts for the item.
208
			$attributes = '';
209
			foreach ( $atts as $attr => $value ) {
210
				if ( ! empty( $value ) ) {
211
					$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
212
					$attributes .= ' ' . $attr . '="' . $value . '"';
213
				}
214
			}
215
216
			/**
217
			 * Set a typeflag to easily test if this is a linkmod or not.
218
			 */
219
			$linkmod_type = self::get_linkmod_type( $linkmod_classes );
220
221
			/**
222
			 * START appending the internal item contents to the output.
223
			 */
224
			$item_output = isset( $args->before ) ? $args->before : '';
225
			/**
226
			 * This is the start of the internal nav item. Depending on what
227
			 * kind of linkmod we have we may need different wrapper elements.
228
			 */
229
			if ( '' !== $linkmod_type ) {
230
				// is linkmod, output the required element opener.
231
				$item_output .= self::linkmod_element_open( $linkmod_type, $attributes );
232
			} else {
233
				// With no link mod type set this must be a standard <a> tag.
234
				$item_output .= '<a' . $attributes . '>';
235
			}
236
237
			/**
238
			 * Initiate empty icon var, then if we have a string containing any
239
			 * icon classes form the icon markup with an <i> element. This is
240
			 * output inside of the item before the $title (the link text).
241
			 */
242
			$icon_html = '';
243
			if ( ! empty( $icon_class_string ) ) {
244
				// append an <i> with the icon classes to what is output before links.
245
				$icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> ';
246
			}
247
248
			/** This filter is documented in wp-includes/post-template.php */
249
			$title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID );
250
251
			/**
252
			 * Filters a menu item's title.
253
			 *
254
			 * @since WP 4.4.0
255
			 *
256
			 * @param string   $title The menu item's title.
257
			 * @param WP_Post  $item  The current menu item.
258
			 * @param stdClass $args  An object of wp_nav_menu() arguments.
259
			 * @param int      $depth Depth of menu item. Used for padding.
260
			 */
261
			$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
262
263
			/**
264
			 * If the .sr-only class was set apply to the nav items text only.
265
			 */
266
			if ( in_array( 'sr-only', $linkmod_classes, true ) ) {
267
				$title         = self::wrap_for_screen_reader( $title );
268
				$keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true );
269
				foreach ( $keys_to_unset as $k ) {
270
					unset( $linkmod_classes[ $k ] );
271
				}
272
			}
273
274
			// Put the item contents into $output.
275
			$item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : '';
276
			/**
277
			 * This is the end of the internal nav item. We need to close the
278
			 * correct element depending on the type of link or link mod.
279
			 */
280
			if ( '' !== $linkmod_type ) {
281
				// is linkmod, output the required closing element.
282
				$item_output .= self::linkmod_element_close( $linkmod_type );
283
			} else {
284
				// With no link mod type set this must be a standard <a> tag.
285
				$item_output .= '</a>';
286
			}
287
288
			$item_output .= isset( $args->after ) ? $args->after : '';
289
290
			/**
291
			 * END appending the internal item contents to the output.
292
			 */
293
			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
294
295
		}
296
297
		/**
298
		 * Traverse elements to create list from elements.
299
		 *
300
		 * Display one element if the element doesn't have any children otherwise,
301
		 * display the element and its children. Will only traverse up to the max
302
		 * depth and no ignore elements under that depth. It is possible to set the
303
		 * max depth to include all depths, see walk() method.
304
		 *
305
		 * This method should not be called directly, use the walk() method instead.
306
		 *
307
		 * @since WP 2.5.0
308
		 *
309
		 * @see Walker::start_lvl()
310
		 *
311
		 * @param object $element           Data object.
312
		 * @param array  $children_elements List of elements to continue traversing (passed by reference).
313
		 * @param int    $max_depth         Max depth to traverse.
314
		 * @param int    $depth             Depth of current element.
315
		 * @param array  $args              An array of arguments.
316
		 * @param string $output            Used to append additional content (passed by reference).
317
		 */
318
		public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
319
			if ( ! $element ) {
320
				return; }
321
			$id_field = $this->db_fields['id'];
322
			// Display this element.
323
			if ( is_object( $args[0] ) ) {
324
				$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); }
325
			parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
326
		}
327
328
		/**
329
		 * Menu Fallback
330
		 * =============
331
		 * If this function is assigned to the wp_nav_menu's fallback_cb variable
332
		 * and a menu has not been assigned to the theme location in the WordPress
333
		 * menu manager the function with display nothing to a non-logged in user,
334
		 * and will add a link to the WordPress menu manager if logged in as an admin.
335
		 *
336
		 * @param array $args passed from the wp_nav_menu function.
337
		 */
338
		public static function fallback( $args ) {
339
			if ( current_user_can( 'edit_theme_options' ) ) {
340
341
				/* Get Arguments. */
342
				$container       = $args['container'];
343
				$container_id    = $args['container_id'];
344
				$container_class = $args['container_class'];
345
				$menu_class      = $args['menu_class'];
346
				$menu_id         = $args['menu_id'];
347
348
				// initialize var to store fallback html.
349
				$fallback_output = '';
350
351
				if ( $container ) {
352
					$fallback_output .= '<' . esc_attr( $container );
353
					if ( $container_id ) {
354
						$fallback_output .= ' id="' . esc_attr( $container_id ) . '"';
355
					}
356
					if ( $container_class ) {
357
						$fallback_output .= ' class="' . esc_attr( $container_class ) . '"';
358
					}
359
					$fallback_output .= '>';
360
				}
361
				$fallback_output .= '<ul';
362
				if ( $menu_id ) {
363
					$fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; }
364
				if ( $menu_class ) {
365
					$fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; }
366
				$fallback_output .= '>';
367
				$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>';
368
				$fallback_output .= '</ul>';
369
				if ( $container ) {
370
					$fallback_output .= '</' . esc_attr( $container ) . '>';
371
				}
372
373
				// if $args has 'echo' key and it's true echo, otherwise return.
374
				if ( array_key_exists( 'echo', $args ) && $args['echo'] ) {
375
					echo $fallback_output; // WPCS: XSS OK.
376
				} else {
377
					return $fallback_output;
378
				}
379
			}
380
		}
381
382
		/**
383
		 * Find any custom linkmod or icon classes and store in their holder
384
		 * arrays then remove them from the main classes array.
385
		 *
386
		 * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only
387
		 * Supported iconsets: Font Awesome 4/5, Glypicons
388
		 *
389
		 * NOTE: This accepts the linkmod and icon arrays by reference.
390
		 *
391
		 * @since 4.0.0
392
		 *
393
		 * @param array   $classes         an array of classes currently assigned to the item.
394
		 * @param array   $linkmod_classes an array to hold linkmod classes.
395
		 * @param array   $icon_classes    an array to hold icon classes.
396
		 * @param integer $depth           an integer holding current depth level.
397
		 *
398
		 * @return array  $classes         a maybe modified array of classnames.
399
		 */
400
		private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) {
401
			// Loop through $classes array to find linkmod or icon classes.
402
			foreach ( $classes as $key => $class ) {
403
				// If any special classes are found, store the class in it's
404
				// holder array and and unset the item from $classes.
405
				if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
406
					// Test for .disabled or .sr-only classes.
407
					$linkmod_classes[] = $class;
408
					unset( $classes[ $key ] );
409
				} elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) {
410
					// Test for .dropdown-header or .dropdown-divider and a
411
					// depth greater than 0 - IE inside a dropdown.
412
					$linkmod_classes[] = $class;
413
					unset( $classes[ $key ] );
414
				} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
415
					// Font Awesome.
416
					$icon_classes[] = $class;
417
					unset( $classes[ $key ] );
418
				} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
419
					// Glyphicons.
420
					$icon_classes[] = $class;
421
					unset( $classes[ $key ] );
422
				}
423
			}
424
425
			return $classes;
426
		}
427
428
		/**
429
		 * Return a string containing a linkmod type and update $atts array
430
		 * accordingly depending on the decided.
431
		 *
432
		 * @since 4.0.0
433
		 *
434
		 * @param array $linkmod_classes array of any link modifier classes.
435
		 *
436
		 * @return string                empty for default, a linkmod type string otherwise.
437
		 */
438
		private function get_linkmod_type( $linkmod_classes = array() ) {
439
			$linkmod_type = '';
440
			// Loop through array of linkmod classes to handle their $atts.
441
			if ( ! empty( $linkmod_classes ) ) {
442
				foreach ( $linkmod_classes as $link_class ) {
443
					if ( ! empty( $link_class ) ) {
444
445
						// check for special class types and set a flag for them.
446
						if ( 'dropdown-header' === $link_class ) {
447
							$linkmod_type = 'dropdown-header';
448
						} elseif ( 'dropdown-divider' === $link_class ) {
449
							$linkmod_type = 'dropdown-divider';
450
						} elseif ( 'dropdown-item-text' === $link_class ) {
451
							$linkmod_type = 'dropdown-item-text';
452
						}
453
					}
454
				}
455
			}
456
			return $linkmod_type;
457
		}
458
459
		/**
460
		 * Update the attributes of a nav item depending on the limkmod classes.
461
		 *
462
		 * @since 4.0.0
463
		 *
464
		 * @param array $atts            array of atts for the current link in nav item.
465
		 * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays.
466
		 *
467
		 * @return array                 maybe updated array of attributes for item.
468
		 */
469
		private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) {
470
			if ( ! empty( $linkmod_classes ) ) {
471
				foreach ( $linkmod_classes as $link_class ) {
472
					if ( ! empty( $link_class ) ) {
473
						// update $atts with a space and the extra classname...
474
						// so long as it's not a sr-only class.
475
						if ( 'sr-only' !== $link_class ) {
476
							$atts['class'] .= ' ' . esc_attr( $link_class );
477
						}
478
						// check for special class types we need additional handling for.
479
						if ( 'disabled' === $link_class ) {
480
							// Convert link to '#' and unset open targets.
481
							$atts['href'] = '#';
482
							unset( $atts['target'] );
483
						} elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) {
484
							// Store a type flag and unset href and target.
485
							unset( $atts['href'] );
486
							unset( $atts['target'] );
487
						}
488
					}
489
				}
490
			}
491
			return $atts;
492
		}
493
494
		/**
495
		 * Wraps the passed text in a screen reader only class.
496
		 *
497
		 * @since 4.0.0
498
		 *
499
		 * @param string $text the string of text to be wrapped in a screen reader class.
500
		 * @return string      the string wrapped in a span with the class.
501
		 */
502
		private function wrap_for_screen_reader( $text = '' ) {
503
			if ( $text ) {
504
				$text = '<span class="sr-only">' . $text . '</span>';
505
			}
506
			return $text;
507
		}
508
509
		/**
510
		 * Returns the correct opening element and attributes for a linkmod.
511
		 *
512
		 * @since 4.0.0
513
		 *
514
		 * @param string $linkmod_type a sting containing a linkmod type flag.
515
		 * @param string $attributes   a string of attributes to add to the element.
516
		 *
517
		 * @return string              a string with the openign tag for the element with attribibutes added.
518
		 */
519
		private function linkmod_element_open( $linkmod_type, $attributes = '' ) {
520
			$output = '';
521
			if ( 'dropdown-item-text' === $linkmod_type ) {
522
				$output .= '<span class="dropdown-item-text"' . $attributes . '>';
523
			} elseif ( 'dropdown-header' === $linkmod_type ) {
524
				// For a header use a span with the .h6 class instead of a real
525
				// header tag so that it doesn't confuse screen readers.
526
				$output .= '<span class="dropdown-header h6"' . $attributes . '>';
527
			} elseif ( 'dropdown-divider' === $linkmod_type ) {
528
				// this is a divider.
529
				$output .= '<div class="dropdown-divider"' . $attributes . '>';
530
			}
531
			return $output;
532
		}
533
534
		/**
535
		 * Return the correct closing tag for the linkmod element.
536
		 *
537
		 * @since 4.0.0
538
		 *
539
		 * @param string $linkmod_type a string containing a special linkmod type.
540
		 *
541
		 * @return string              a string with the closing tag for this linkmod type.
542
		 */
543
		private function linkmod_element_close( $linkmod_type ) {
544
			$output = '';
545
			if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) {
546
				// For a header use a span with the .h6 class instead of a real
547
				// header tag so that it doesn't confuse screen readers.
548
				$output .= '</span>';
549
			} elseif ( 'dropdown-divider' === $linkmod_type ) {
550
				// this is a divider.
551
				$output .= '</div>';
552
			}
553
			return $output;
554
		}
555
	}
556
}
557