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

WP_Bootstrap_Navwalker::fallback()   B

Complexity

Conditions 10
Paths 81

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 7.6666
c 0
b 0
f 0
cc 10
nc 81
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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