@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | |
22 | 22 | /* Check if Class Exists. */ |
23 | -if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) { |
|
23 | +if ( ! class_exists('WP_Bootstrap_Navwalker')) { |
|
24 | 24 | /** |
25 | 25 | * WP_Bootstrap_Navwalker class. |
26 | 26 | * |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | * @param int $depth Depth of menu item. Used for padding. |
40 | 40 | * @param stdClass $args An object of wp_nav_menu() arguments. |
41 | 41 | */ |
42 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
43 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
42 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
43 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
44 | 44 | $t = ''; |
45 | 45 | $n = ''; |
46 | 46 | } else { |
47 | 47 | $t = "\t"; |
48 | 48 | $n = "\n"; |
49 | 49 | } |
50 | - $indent = str_repeat( $t, $depth ); |
|
50 | + $indent = str_repeat($t, $depth); |
|
51 | 51 | // Default class to add to the file. |
52 | - $classes = array( 'dropdown-menu' ); |
|
52 | + $classes = array('dropdown-menu'); |
|
53 | 53 | /** |
54 | 54 | * Filters the CSS class(es) applied to a menu list element. |
55 | 55 | * |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
60 | 60 | * @param int $depth Depth of menu item. Used for padding. |
61 | 61 | */ |
62 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
63 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
62 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
63 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
64 | 64 | /** |
65 | 65 | * The `.dropdown-menu` container needs to have a labelledby |
66 | 66 | * attribute which points to it's trigger link. |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | */ |
71 | 71 | $labelledby = ''; |
72 | 72 | // find all links with an id in the output. |
73 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
73 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
74 | 74 | // with pointer at end of array check if we got an ID match. |
75 | - if ( end( $matches[2] ) ) { |
|
75 | + if (end($matches[2])) { |
|
76 | 76 | // build a string to use as aria-labelledby. |
77 | - $labelledby = 'aria-labelledby="' . end( $matches[2] ) . '"'; |
|
77 | + $labelledby = 'aria-labelledby="' . end($matches[2]) . '"'; |
|
78 | 78 | } |
79 | 79 | $output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}"; |
80 | 80 | } |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | * @param stdClass $args An object of wp_nav_menu() arguments. |
94 | 94 | * @param int $id Current item ID. |
95 | 95 | */ |
96 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
97 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
96 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
97 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
98 | 98 | $t = ''; |
99 | 99 | $n = ''; |
100 | 100 | } else { |
101 | 101 | $t = "\t"; |
102 | 102 | $n = "\n"; |
103 | 103 | } |
104 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
104 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
105 | 105 | |
106 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
106 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
107 | 107 | |
108 | 108 | // Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined |
109 | 109 | // in that particular input box to come in as one big class string. |
110 | - $split_on_spaces = function ( $class ) { |
|
111 | - return preg_split( '/\s+/', $class ); |
|
110 | + $split_on_spaces = function($class) { |
|
111 | + return preg_split('/\s+/', $class); |
|
112 | 112 | }; |
113 | - $classes = flatten( array_map( $split_on_spaces, $classes ) ); |
|
113 | + $classes = flatten(array_map($split_on_spaces, $classes)); |
|
114 | 114 | |
115 | 115 | // Initialize some holder variables to store specially handled item |
116 | 116 | // wrappers and icons. |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | * NOTE: linkmod and icon class arrays are passed by reference and |
124 | 124 | * are maybe modified before being used later in this function. |
125 | 125 | */ |
126 | - $classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
126 | + $classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
127 | 127 | |
128 | 128 | // Join any icon classes plucked from $classes into a string. |
129 | - $icon_class_string = join( ' ', $icon_classes ); |
|
129 | + $icon_class_string = join(' ', $icon_classes); |
|
130 | 130 | |
131 | 131 | /** |
132 | 132 | * Filters the arguments for a single nav menu item. |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | * @param WP_Post $item Menu item data object. |
138 | 138 | * @param int $depth Depth of menu item. Used for padding. |
139 | 139 | */ |
140 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
140 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
141 | 141 | |
142 | 142 | // Add .dropdown or .active classes where they are needed. |
143 | - if ( isset( $args->has_children ) && $args->has_children ) { |
|
143 | + if (isset($args->has_children) && $args->has_children) { |
|
144 | 144 | $classes[] = 'dropdown'; |
145 | 145 | } |
146 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
146 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
147 | 147 | $classes[] = 'active'; |
148 | 148 | } |
149 | 149 | |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | $classes[] = 'nav-item'; |
153 | 153 | |
154 | 154 | // Allow filtering the classes. |
155 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
155 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
156 | 156 | |
157 | 157 | // Form a string of classes in format: class="class_names". |
158 | - $class_names = join( ' ', $classes ); |
|
159 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
158 | + $class_names = join(' ', $classes); |
|
159 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Filters the ID applied to a menu item's list item element. |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @param stdClass $args An object of wp_nav_menu() arguments. |
170 | 170 | * @param int $depth Depth of menu item. Used for padding. |
171 | 171 | */ |
172 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
173 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
172 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
173 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
174 | 174 | |
175 | 175 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>'; |
176 | 176 | |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | |
180 | 180 | // Set title from item to the $atts array - if title is empty then |
181 | 181 | // default to item title. |
182 | - if ( empty( $item->attr_title ) ) { |
|
183 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
182 | + if (empty($item->attr_title)) { |
|
183 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
184 | 184 | } else { |
185 | 185 | $atts['title'] = $item->attr_title; |
186 | 186 | } |
187 | 187 | |
188 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
189 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
188 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
189 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
190 | 190 | // If item has_children add atts to <a>. |
191 | - if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
191 | + if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) { |
|
192 | 192 | $atts['href'] = '#'; |
193 | 193 | $atts['data-toggle'] = 'dropdown'; |
194 | 194 | $atts['aria-haspopup'] = 'true'; |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | $atts['class'] = 'dropdown-toggle nav-link'; |
197 | 197 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
198 | 198 | } else { |
199 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
199 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
200 | 200 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
201 | - if ( $depth > 0 ) { |
|
201 | + if ($depth > 0) { |
|
202 | 202 | $atts['class'] = 'dropdown-item'; |
203 | 203 | } else { |
204 | 204 | $atts['class'] = 'nav-link'; |
@@ -206,15 +206,15 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | // update atts of this item based on any custom linkmod classes. |
209 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
209 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
210 | 210 | // Allow filtering of the $atts array before using it. |
211 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
211 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
212 | 212 | |
213 | 213 | // Build a string of html containing all the atts for the item. |
214 | 214 | $attributes = ''; |
215 | - foreach ( $atts as $attr => $value ) { |
|
216 | - if ( ! empty( $value ) ) { |
|
217 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
215 | + foreach ($atts as $attr => $value) { |
|
216 | + if ( ! empty($value)) { |
|
217 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
218 | 218 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
219 | 219 | } |
220 | 220 | } |
@@ -222,19 +222,19 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * Set a typeflag to easily test if this is a linkmod or not. |
224 | 224 | */ |
225 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
225 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
226 | 226 | |
227 | 227 | /** |
228 | 228 | * START appending the internal item contents to the output. |
229 | 229 | */ |
230 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
230 | + $item_output = isset($args->before) ? $args->before : ''; |
|
231 | 231 | /** |
232 | 232 | * This is the start of the internal nav item. Depending on what |
233 | 233 | * kind of linkmod we have we may need different wrapper elements. |
234 | 234 | */ |
235 | - if ( '' !== $linkmod_type ) { |
|
235 | + if ('' !== $linkmod_type) { |
|
236 | 236 | // is linkmod, output the required element opener. |
237 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
237 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
238 | 238 | } else { |
239 | 239 | // With no link mod type set this must be a standard <a> tag. |
240 | 240 | $item_output .= '<a' . $attributes . '>'; |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | * output inside of the item before the $title (the link text). |
247 | 247 | */ |
248 | 248 | $icon_html = ''; |
249 | - if ( ! empty( $icon_class_string ) ) { |
|
249 | + if ( ! empty($icon_class_string)) { |
|
250 | 250 | // append an <i> with the icon classes to what is output before links. |
251 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
251 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** This filter is documented in wp-includes/post-template.php */ |
255 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
255 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
256 | 256 | |
257 | 257 | /** |
258 | 258 | * Filters a menu item's title. |
@@ -264,39 +264,39 @@ discard block |
||
264 | 264 | * @param stdClass $args An object of wp_nav_menu() arguments. |
265 | 265 | * @param int $depth Depth of menu item. Used for padding. |
266 | 266 | */ |
267 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
267 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * If the .sr-only class was set apply to the nav items text only. |
271 | 271 | */ |
272 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
273 | - $title = self::wrap_for_screen_reader( $title ); |
|
274 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
|
275 | - foreach ( $keys_to_unset as $k ) { |
|
276 | - unset( $linkmod_classes[ $k ] ); |
|
272 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
273 | + $title = self::wrap_for_screen_reader($title); |
|
274 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only'); |
|
275 | + foreach ($keys_to_unset as $k) { |
|
276 | + unset($linkmod_classes[$k]); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | 280 | // Put the item contents into $output. |
281 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
281 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
282 | 282 | /** |
283 | 283 | * This is the end of the internal nav item. We need to close the |
284 | 284 | * correct element depending on the type of link or link mod. |
285 | 285 | */ |
286 | - if ( '' !== $linkmod_type ) { |
|
286 | + if ('' !== $linkmod_type) { |
|
287 | 287 | // is linkmod, output the required element opener. |
288 | - $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
|
288 | + $item_output .= self::linkmod_element_close($linkmod_type, $attributes); |
|
289 | 289 | } else { |
290 | 290 | // With no link mod type set this must be a standard <a> tag. |
291 | 291 | $item_output .= '</a>'; |
292 | 292 | } |
293 | 293 | |
294 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
294 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * END appending the internal item contents to the output. |
298 | 298 | */ |
299 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
299 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
300 | 300 | |
301 | 301 | } |
302 | 302 | |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | * @param array $args An array of arguments. |
322 | 322 | * @param string $output Used to append additional content (passed by reference). |
323 | 323 | */ |
324 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
325 | - if ( ! $element ) { |
|
324 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
325 | + if ( ! $element) { |
|
326 | 326 | return; } |
327 | 327 | $id_field = $this->db_fields['id']; |
328 | 328 | // Display this element. |
329 | - if ( is_object( $args[0] ) ) { |
|
330 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
331 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
329 | + if (is_object($args[0])) { |
|
330 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
331 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * |
342 | 342 | * @param array $args passed from the wp_nav_menu function. |
343 | 343 | */ |
344 | - public static function fallback( $args ) { |
|
345 | - if ( current_user_can( 'edit_theme_options' ) ) { |
|
344 | + public static function fallback($args) { |
|
345 | + if (current_user_can('edit_theme_options')) { |
|
346 | 346 | |
347 | 347 | /* Get Arguments. */ |
348 | 348 | $container = $args['container']; |
@@ -354,30 +354,30 @@ discard block |
||
354 | 354 | // initialize var to store fallback html. |
355 | 355 | $fallback_output = ''; |
356 | 356 | |
357 | - if ( $container ) { |
|
358 | - $fallback_output .= '<' . esc_attr( $container ); |
|
359 | - if ( $container_id ) { |
|
360 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
357 | + if ($container) { |
|
358 | + $fallback_output .= '<' . esc_attr($container); |
|
359 | + if ($container_id) { |
|
360 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
361 | 361 | } |
362 | - if ( $container_class ) { |
|
363 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
362 | + if ($container_class) { |
|
363 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
364 | 364 | } |
365 | 365 | $fallback_output .= '>'; |
366 | 366 | } |
367 | 367 | $fallback_output .= '<ul'; |
368 | - if ( $menu_id ) { |
|
369 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
370 | - if ( $menu_class ) { |
|
371 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
368 | + if ($menu_id) { |
|
369 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
370 | + if ($menu_class) { |
|
371 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
372 | 372 | $fallback_output .= '>'; |
373 | - $fallback_output .= '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="' . esc_attr__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '">' . esc_html__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '</a></li>'; |
|
373 | + $fallback_output .= '<li><a href="' . esc_url(admin_url('nav-menus.php')) . '" title="' . esc_attr__('Add a menu', 'wp-bootstrap-navwalker') . '">' . esc_html__('Add a menu', 'wp-bootstrap-navwalker') . '</a></li>'; |
|
374 | 374 | $fallback_output .= '</ul>'; |
375 | - if ( $container ) { |
|
376 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
375 | + if ($container) { |
|
376 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | // if $args has 'echo' key and it's true echo, otherwise return. |
380 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
380 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
381 | 381 | echo $fallback_output; // WPCS: XSS OK. |
382 | 382 | } else { |
383 | 383 | return $fallback_output; |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @return array $classes a maybe modified array of classnames. |
405 | 405 | */ |
406 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
406 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
407 | 407 | // Loop through $classes array to find linkmod or icon classes. |
408 | - foreach ( $classes as $key => $class ) { |
|
408 | + foreach ($classes as $key => $class) { |
|
409 | 409 | // If any special classes are found, store the class in it's |
410 | 410 | // holder array and and unset the item from $classes. |
411 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
411 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
412 | 412 | // Test for .disabled or .sr-only classes. |
413 | 413 | $linkmod_classes[] = $class; |
414 | - unset( $classes[ $key ] ); |
|
415 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
414 | + unset($classes[$key]); |
|
415 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
416 | 416 | // Test for .dropdown-header or .dropdown-divider and a |
417 | 417 | // depth greater than 0 - IE inside a dropdown. |
418 | 418 | $linkmod_classes[] = $class; |
419 | - unset( $classes[ $key ] ); |
|
420 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
419 | + unset($classes[$key]); |
|
420 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
421 | 421 | // Font Awesome. |
422 | 422 | $icon_classes[] = $class; |
423 | - unset( $classes[ $key ] ); |
|
424 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
423 | + unset($classes[$key]); |
|
424 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
425 | 425 | // Glyphicons. |
426 | 426 | $icon_classes[] = $class; |
427 | - unset( $classes[ $key ] ); |
|
427 | + unset($classes[$key]); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
@@ -441,19 +441,19 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return string empty for default, a linkmod type string otherwise. |
443 | 443 | */ |
444 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
444 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
445 | 445 | $linkmod_type = ''; |
446 | 446 | // Loop through array of linkmod classes to handle their $atts. |
447 | - if ( ! empty( $linkmod_classes ) ) { |
|
448 | - foreach ( $linkmod_classes as $link_class ) { |
|
449 | - if ( ! empty( $link_class ) ) { |
|
447 | + if ( ! empty($linkmod_classes)) { |
|
448 | + foreach ($linkmod_classes as $link_class) { |
|
449 | + if ( ! empty($link_class)) { |
|
450 | 450 | |
451 | 451 | // check for special class types and set a flag for them. |
452 | - if ( 'dropdown-header' === $link_class ) { |
|
452 | + if ('dropdown-header' === $link_class) { |
|
453 | 453 | $linkmod_type = 'dropdown-header'; |
454 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
454 | + } elseif ('dropdown-divider' === $link_class) { |
|
455 | 455 | $linkmod_type = 'dropdown-divider'; |
456 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
456 | + } elseif ('dropdown-item-text' === $link_class) { |
|
457 | 457 | $linkmod_type = 'dropdown-item-text'; |
458 | 458 | } |
459 | 459 | } |
@@ -472,24 +472,24 @@ discard block |
||
472 | 472 | * |
473 | 473 | * @return array maybe updated array of attributes for item. |
474 | 474 | */ |
475 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
476 | - if ( ! empty( $linkmod_classes ) ) { |
|
477 | - foreach ( $linkmod_classes as $link_class ) { |
|
478 | - if ( ! empty( $link_class ) ) { |
|
475 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
476 | + if ( ! empty($linkmod_classes)) { |
|
477 | + foreach ($linkmod_classes as $link_class) { |
|
478 | + if ( ! empty($link_class)) { |
|
479 | 479 | // update $atts with a space and the extra classname... |
480 | 480 | // so long as it's not a sr-only class. |
481 | - if ( 'sr-only' !== $link_class ) { |
|
482 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
481 | + if ('sr-only' !== $link_class) { |
|
482 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
483 | 483 | } |
484 | 484 | // check for special class types we need additional handling for. |
485 | - if ( 'disabled' === $link_class ) { |
|
485 | + if ('disabled' === $link_class) { |
|
486 | 486 | // Convert link to '#' and unset open targets. |
487 | 487 | $atts['href'] = '#'; |
488 | - unset( $atts['target'] ); |
|
489 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
488 | + unset($atts['target']); |
|
489 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
490 | 490 | // Store a type flag and unset href and target. |
491 | - unset( $atts['href'] ); |
|
492 | - unset( $atts['target'] ); |
|
491 | + unset($atts['href']); |
|
492 | + unset($atts['target']); |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | } |
@@ -505,8 +505,8 @@ discard block |
||
505 | 505 | * @param string $text the string of text to be wrapped in a screen reader class. |
506 | 506 | * @return string the string wrapped in a span with the class. |
507 | 507 | */ |
508 | - private function wrap_for_screen_reader( $text = '' ) { |
|
509 | - if ( $text ) { |
|
508 | + private function wrap_for_screen_reader($text = '') { |
|
509 | + if ($text) { |
|
510 | 510 | $text = '<span class="sr-only">' . $text . '</span>'; |
511 | 511 | } |
512 | 512 | return $text; |
@@ -522,15 +522,15 @@ discard block |
||
522 | 522 | * |
523 | 523 | * @return string a string with the openign tag for the element with attribibutes added. |
524 | 524 | */ |
525 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
525 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
526 | 526 | $output = ''; |
527 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
527 | + if ('dropdown-item-text' === $linkmod_type) { |
|
528 | 528 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
529 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
529 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
530 | 530 | // For a header use a span with the .h6 class instead of a real |
531 | 531 | // header tag so that it doesn't confuse screen readers. |
532 | 532 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
533 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
533 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
534 | 534 | // this is a divider. |
535 | 535 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
536 | 536 | } |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @return string a string with the closing tag for this linkmod type. |
548 | 548 | */ |
549 | - private function linkmod_element_close( $linkmod_type ) { |
|
549 | + private function linkmod_element_close($linkmod_type) { |
|
550 | 550 | $output = ''; |
551 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
551 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
552 | 552 | // For a header use a span with the .h6 class instead of a real |
553 | 553 | // header tag so that it doesn't confuse screen readers. |
554 | 554 | $output .= '</span>'; |
555 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
555 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
556 | 556 | // this is a divider. |
557 | 557 | $output .= '</div>'; |
558 | 558 | } |
@@ -567,11 +567,11 @@ discard block |
||
567 | 567 | * |
568 | 568 | * @return array a simple array |
569 | 569 | */ |
570 | - function flatten( $array ) { |
|
570 | + function flatten($array) { |
|
571 | 571 | $result = array(); |
572 | - foreach ( $array as $element ) { |
|
573 | - if ( is_array( $element ) ) { |
|
574 | - array_push( $result, ...flatten( $element ) ); |
|
572 | + foreach ($array as $element) { |
|
573 | + if (is_array($element)) { |
|
574 | + array_push($result, ...flatten($element)); |
|
575 | 575 | } else { |
576 | 576 | $result[] = $element; |
577 | 577 | } |