@@ -18,7 +18,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,15 +188,15 @@ discard block |
||
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 | /** |
195 | 195 | * Filters whether to output schema markup. |
196 | 196 | * |
197 | 197 | * @param bool $show Whether to output the schmema markup. |
198 | 198 | */ |
199 | - $show_schema = apply_filters( 'wp_bootstrap_navwalker_show_schema', $show = true ); |
|
199 | + $show_schema = apply_filters('wp_bootstrap_navwalker_show_schema', $show = true); |
|
200 | 200 | $schema = $show_schema ? ' itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' : ''; |
201 | 201 | |
202 | 202 | $output .= $indent . '<li' . $schema . $id . $class_names . '>'; |
@@ -204,18 +204,18 @@ discard block |
||
204 | 204 | // Initialize array for holding the $atts for the link item. |
205 | 205 | $atts = array(); |
206 | 206 | |
207 | - $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
|
207 | + $atts['title'] = ! empty($item->attr_title) ? $item->attr_title : ''; |
|
208 | 208 | |
209 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
209 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
210 | 210 | |
211 | - if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
|
211 | + if ('_blank' === $item->target && empty($item->xfn)) { |
|
212 | 212 | $atts['rel'] = 'noopener noreferrer'; |
213 | 213 | } else { |
214 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
214 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | // If the item has_children add atts to <a>. |
218 | - if ( $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
218 | + if ($args->has_children && 0 === $depth && $args->depth > 1) { |
|
219 | 219 | $atts['href'] = '#'; |
220 | 220 | $atts['data-toggle'] = 'dropdown'; |
221 | 221 | $atts['aria-haspopup'] = 'true'; |
@@ -223,17 +223,17 @@ discard block |
||
223 | 223 | $atts['class'] = 'dropdown-toggle nav-link'; |
224 | 224 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
225 | 225 | } else { |
226 | - if ( true === $this->has_schema ) { |
|
226 | + if (true === $this->has_schema) { |
|
227 | 227 | $atts['itemprop'] = 'url'; |
228 | 228 | } |
229 | 229 | |
230 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
230 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
231 | 231 | |
232 | - if ( $show_schema ) { |
|
232 | + if ($show_schema) { |
|
233 | 233 | $atts['itemprop'] = 'url'; |
234 | 234 | } |
235 | 235 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
236 | - if ( $depth > 0 ) { |
|
236 | + if ($depth > 0) { |
|
237 | 237 | $atts['class'] = 'dropdown-item'; |
238 | 238 | } else { |
239 | 239 | $atts['class'] = 'nav-link'; |
@@ -243,33 +243,33 @@ discard block |
||
243 | 243 | $atts['aria-current'] = $item->current ? 'page' : ''; |
244 | 244 | |
245 | 245 | // Update atts of this item based on any custom linkmod classes. |
246 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
246 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
247 | 247 | |
248 | 248 | // Allow filtering of the $atts array before using it. |
249 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
249 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
250 | 250 | |
251 | 251 | // Build a string of html containing all the atts for the item. |
252 | 252 | $attributes = ''; |
253 | - foreach ( $atts as $attr => $value ) { |
|
254 | - if ( ! empty( $value ) ) { |
|
255 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
253 | + foreach ($atts as $attr => $value) { |
|
254 | + if ( ! empty($value)) { |
|
255 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
256 | 256 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Set a typeflag to easily test if this is a linkmod or not. |
261 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
261 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
262 | 262 | |
263 | 263 | // START appending the internal item contents to the output. |
264 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
264 | + $item_output = isset($args->before) ? $args->before : ''; |
|
265 | 265 | |
266 | 266 | /* |
267 | 267 | * This is the start of the internal nav item. Depending on what |
268 | 268 | * kind of linkmod we have we may need different wrapper elements. |
269 | 269 | */ |
270 | - if ( '' !== $linkmod_type ) { |
|
270 | + if ('' !== $linkmod_type) { |
|
271 | 271 | // Is linkmod, output the required element opener. |
272 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
272 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
273 | 273 | } else { |
274 | 274 | // With no link mod type set this must be a standard <a> tag. |
275 | 275 | $item_output .= '<a' . $attributes . '>'; |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | * output inside of the item before the $title (the link text). |
282 | 282 | */ |
283 | 283 | $icon_html = ''; |
284 | - if ( ! empty( $icon_class_string ) ) { |
|
284 | + if ( ! empty($icon_class_string)) { |
|
285 | 285 | // Append an <i> with the icon classes to what is output before links. |
286 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
286 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** This filter is documented in wp-includes/post-template.php */ |
290 | - $title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID ); |
|
290 | + $title = apply_filters('the_title', esc_html($item->title), $item->ID); |
|
291 | 291 | |
292 | 292 | /** |
293 | 293 | * Filters a menu item's title. |
@@ -299,36 +299,36 @@ discard block |
||
299 | 299 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
300 | 300 | * @param int $depth Depth of menu item. Used for padding. |
301 | 301 | */ |
302 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
302 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
303 | 303 | |
304 | 304 | // If the .sr-only class was set apply to the nav items text only. |
305 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
306 | - $title = self::wrap_for_screen_reader( $title ); |
|
307 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
308 | - foreach ( $keys_to_unset as $k ) { |
|
309 | - unset( $linkmod_classes[ $k ] ); |
|
305 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
306 | + $title = self::wrap_for_screen_reader($title); |
|
307 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
308 | + foreach ($keys_to_unset as $k) { |
|
309 | + unset($linkmod_classes[$k]); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Put the item contents into $output. |
314 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
314 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
315 | 315 | |
316 | 316 | /* |
317 | 317 | * This is the end of the internal nav item. We need to close the |
318 | 318 | * correct element depending on the type of link or link mod. |
319 | 319 | */ |
320 | - if ( '' !== $linkmod_type ) { |
|
320 | + if ('' !== $linkmod_type) { |
|
321 | 321 | // Is linkmod, output the required closing element. |
322 | - $item_output .= self::linkmod_element_close( $linkmod_type ); |
|
322 | + $item_output .= self::linkmod_element_close($linkmod_type); |
|
323 | 323 | } else { |
324 | 324 | // With no link mod type set this must be a standard <a> tag. |
325 | 325 | $item_output .= '</a>'; |
326 | 326 | } |
327 | 327 | |
328 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
328 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
329 | 329 | |
330 | 330 | // END appending the internal item contents to the output. |
331 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
331 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | * @param array $args passed from the wp_nav_menu function. |
343 | 343 | * @return string|void |
344 | 344 | */ |
345 | - public static function fallback( $args ) { |
|
346 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
345 | + public static function fallback($args) { |
|
346 | + if ( ! current_user_can('edit_theme_options')) { |
|
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
@@ -357,30 +357,30 @@ discard block |
||
357 | 357 | // Initialize var to store fallback html. |
358 | 358 | $fallback_output = ''; |
359 | 359 | |
360 | - if ( $container ) { |
|
361 | - $fallback_output .= '<' . esc_attr( $container ); |
|
362 | - if ( $container_id ) { |
|
363 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
360 | + if ($container) { |
|
361 | + $fallback_output .= '<' . esc_attr($container); |
|
362 | + if ($container_id) { |
|
363 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
364 | 364 | } |
365 | - if ( $container_class ) { |
|
366 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
365 | + if ($container_class) { |
|
366 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
367 | 367 | } |
368 | 368 | $fallback_output .= '>'; |
369 | 369 | } |
370 | 370 | $fallback_output .= '<ul'; |
371 | - if ( $menu_id ) { |
|
372 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
373 | - if ( $menu_class ) { |
|
374 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
371 | + if ($menu_id) { |
|
372 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
373 | + if ($menu_class) { |
|
374 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
375 | 375 | $fallback_output .= '>'; |
376 | - $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>'; |
|
376 | + $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>'; |
|
377 | 377 | $fallback_output .= '</ul>'; |
378 | - if ( $container ) { |
|
379 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
378 | + if ($container) { |
|
379 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | // If $args has 'echo' key and it's true echo, otherwise return. |
383 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
383 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
384 | 384 | echo $fallback_output; // WPCS: XSS OK. |
385 | 385 | return; |
386 | 386 | } |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | * @param array $args The nav instance arguments. |
397 | 397 | * @return array $args The altered nav instance arguments. |
398 | 398 | */ |
399 | - public function add_schema_to_navbar_ul( $args ) { |
|
399 | + public function add_schema_to_navbar_ul($args) { |
|
400 | 400 | $wrap = $args['items_wrap']; |
401 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
402 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); |
|
401 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
402 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | return $args; |
@@ -423,32 +423,32 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @return array $classes a maybe modified array of classnames. |
425 | 425 | */ |
426 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
426 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
427 | 427 | // Loop through $classes array to find linkmod or icon classes. |
428 | - foreach ( $classes as $key => $class ) { |
|
428 | + foreach ($classes as $key => $class) { |
|
429 | 429 | /* |
430 | 430 | * If any special classes are found, store the class in it's |
431 | 431 | * holder array and and unset the item from $classes. |
432 | 432 | */ |
433 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
433 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
434 | 434 | // Test for .disabled or .sr-only classes. |
435 | 435 | $linkmod_classes[] = $class; |
436 | - unset( $classes[ $key ] ); |
|
437 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
436 | + unset($classes[$key]); |
|
437 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
438 | 438 | /* |
439 | 439 | * Test for .dropdown-header or .dropdown-divider and a |
440 | 440 | * depth greater than 0 - IE inside a dropdown. |
441 | 441 | */ |
442 | 442 | $linkmod_classes[] = $class; |
443 | - unset( $classes[ $key ] ); |
|
444 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
443 | + unset($classes[$key]); |
|
444 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
445 | 445 | // Font Awesome. |
446 | 446 | $icon_classes[] = $class; |
447 | - unset( $classes[ $key ] ); |
|
448 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
447 | + unset($classes[$key]); |
|
448 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
449 | 449 | // Glyphicons. |
450 | 450 | $icon_classes[] = $class; |
451 | - unset( $classes[ $key ] ); |
|
451 | + unset($classes[$key]); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -465,19 +465,19 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @return string empty for default, a linkmod type string otherwise. |
467 | 467 | */ |
468 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
468 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
469 | 469 | $linkmod_type = ''; |
470 | 470 | // Loop through array of linkmod classes to handle their $atts. |
471 | - if ( ! empty( $linkmod_classes ) ) { |
|
472 | - foreach ( $linkmod_classes as $link_class ) { |
|
473 | - if ( ! empty( $link_class ) ) { |
|
471 | + if ( ! empty($linkmod_classes)) { |
|
472 | + foreach ($linkmod_classes as $link_class) { |
|
473 | + if ( ! empty($link_class)) { |
|
474 | 474 | |
475 | 475 | // Check for special class types and set a flag for them. |
476 | - if ( 'dropdown-header' === $link_class ) { |
|
476 | + if ('dropdown-header' === $link_class) { |
|
477 | 477 | $linkmod_type = 'dropdown-header'; |
478 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
478 | + } elseif ('dropdown-divider' === $link_class) { |
|
479 | 479 | $linkmod_type = 'dropdown-divider'; |
480 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
480 | + } elseif ('dropdown-item-text' === $link_class) { |
|
481 | 481 | $linkmod_type = 'dropdown-item-text'; |
482 | 482 | } |
483 | 483 | } |
@@ -496,26 +496,26 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @return array maybe updated array of attributes for item. |
498 | 498 | */ |
499 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
500 | - if ( ! empty( $linkmod_classes ) ) { |
|
501 | - foreach ( $linkmod_classes as $link_class ) { |
|
502 | - if ( ! empty( $link_class ) ) { |
|
499 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
500 | + if ( ! empty($linkmod_classes)) { |
|
501 | + foreach ($linkmod_classes as $link_class) { |
|
502 | + if ( ! empty($link_class)) { |
|
503 | 503 | /* |
504 | 504 | * Update $atts with a space and the extra classname |
505 | 505 | * so long as it's not a sr-only class. |
506 | 506 | */ |
507 | - if ( 'sr-only' !== $link_class ) { |
|
508 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
507 | + if ('sr-only' !== $link_class) { |
|
508 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
509 | 509 | } |
510 | 510 | // Check for special class types we need additional handling for. |
511 | - if ( 'disabled' === $link_class ) { |
|
511 | + if ('disabled' === $link_class) { |
|
512 | 512 | // Convert link to '#' and unset open targets. |
513 | 513 | $atts['href'] = '#'; |
514 | - unset( $atts['target'] ); |
|
515 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
514 | + unset($atts['target']); |
|
515 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
516 | 516 | // Store a type flag and unset href and target. |
517 | - unset( $atts['href'] ); |
|
518 | - unset( $atts['target'] ); |
|
517 | + unset($atts['href']); |
|
518 | + unset($atts['target']); |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | } |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @param string $text the string of text to be wrapped in a screen reader class. |
532 | 532 | * @return string the string wrapped in a span with the class. |
533 | 533 | */ |
534 | - private function wrap_for_screen_reader( $text = '' ) { |
|
535 | - if ( $text ) { |
|
534 | + private function wrap_for_screen_reader($text = '') { |
|
535 | + if ($text) { |
|
536 | 536 | $text = '<span class="sr-only">' . $text . '</span>'; |
537 | 537 | } |
538 | 538 | return $text; |
@@ -548,17 +548,17 @@ discard block |
||
548 | 548 | * |
549 | 549 | * @return string a string with the openign tag for the element with attribibutes added. |
550 | 550 | */ |
551 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
551 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
552 | 552 | $output = ''; |
553 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
553 | + if ('dropdown-item-text' === $linkmod_type) { |
|
554 | 554 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
555 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
555 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
556 | 556 | /* |
557 | 557 | * For a header use a span with the .h6 class instead of a real |
558 | 558 | * header tag so that it doesn't confuse screen readers. |
559 | 559 | */ |
560 | 560 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
561 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
561 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
562 | 562 | // This is a divider. |
563 | 563 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
564 | 564 | } |
@@ -574,15 +574,15 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @return string a string with the closing tag for this linkmod type. |
576 | 576 | */ |
577 | - private function linkmod_element_close( $linkmod_type ) { |
|
577 | + private function linkmod_element_close($linkmod_type) { |
|
578 | 578 | $output = ''; |
579 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
579 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
580 | 580 | /* |
581 | 581 | * For a header use a span with the .h6 class instead of a real |
582 | 582 | * header tag so that it doesn't confuse screen readers. |
583 | 583 | */ |
584 | 584 | $output .= '</span>'; |
585 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
585 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
586 | 586 | // This is a divider. |
587 | 587 | $output .= '</div>'; |
588 | 588 | } |