@@ -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 | * |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * @param int $depth Depth of menu item. Used for padding. |
38 | 38 | * @param stdClass $args An object of wp_nav_menu() arguments. |
39 | 39 | */ |
40 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
41 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
40 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
41 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
42 | 42 | $t = ''; |
43 | 43 | $n = ''; |
44 | 44 | } else { |
45 | 45 | $t = "\t"; |
46 | 46 | $n = "\n"; |
47 | 47 | } |
48 | - $indent = str_repeat( $t, $depth ); |
|
48 | + $indent = str_repeat($t, $depth); |
|
49 | 49 | // Default class to add to the file. |
50 | - $classes = array( 'dropdown-menu' ); |
|
50 | + $classes = array('dropdown-menu'); |
|
51 | 51 | /** |
52 | 52 | * Filters the CSS class(es) applied to a menu list element. |
53 | 53 | * |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
58 | 58 | * @param int $depth Depth of menu item. Used for padding. |
59 | 59 | */ |
60 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
61 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
60 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
61 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
62 | 62 | |
63 | 63 | /* |
64 | 64 | * The `.dropdown-menu` container needs to have a labelledby |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | */ |
70 | 70 | $labelledby = ''; |
71 | 71 | // Find all links with an id in the output. |
72 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
72 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
73 | 73 | // With pointer at end of array check if we got an ID match. |
74 | - if ( end( $matches[2] ) ) { |
|
74 | + if (end($matches[2])) { |
|
75 | 75 | // Build a string to use as aria-labelledby. |
76 | - $labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"'; |
|
76 | + $labelledby = 'aria-labelledby="' . esc_attr(end($matches[2])) . '"'; |
|
77 | 77 | } |
78 | 78 | $output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}"; |
79 | 79 | } |
@@ -92,17 +92,17 @@ discard block |
||
92 | 92 | * @param stdClass $args An object of wp_nav_menu() arguments. |
93 | 93 | * @param int $id Current item ID. |
94 | 94 | */ |
95 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
96 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
95 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
96 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
97 | 97 | $t = ''; |
98 | 98 | $n = ''; |
99 | 99 | } else { |
100 | 100 | $t = "\t"; |
101 | 101 | $n = "\n"; |
102 | 102 | } |
103 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
103 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
104 | 104 | |
105 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
105 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
106 | 106 | |
107 | 107 | /* |
108 | 108 | * Initialize some holder variables to store specially handled item |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | * NOTE: linkmod and icon class arrays are passed by reference and |
118 | 118 | * are maybe modified before being used later in this function. |
119 | 119 | */ |
120 | - $classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
120 | + $classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
121 | 121 | |
122 | 122 | // Join any icon classes plucked from $classes into a string. |
123 | - $icon_class_string = join( ' ', $icon_classes ); |
|
123 | + $icon_class_string = join(' ', $icon_classes); |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Filters the arguments for a single nav menu item. |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param WP_Post $item Menu item data object. |
132 | 132 | * @param int $depth Depth of menu item. Used for padding. |
133 | 133 | */ |
134 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
134 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
135 | 135 | |
136 | 136 | // Add .dropdown or .active classes where they are needed. |
137 | - if ( isset( $args->has_children ) && $args->has_children ) { |
|
137 | + if (isset($args->has_children) && $args->has_children) { |
|
138 | 138 | $classes[] = 'dropdown'; |
139 | 139 | } |
140 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
140 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
141 | 141 | $classes[] = 'active'; |
142 | 142 | } |
143 | 143 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | $classes[] = 'nav-item'; |
147 | 147 | |
148 | 148 | // Allow filtering the classes. |
149 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
149 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
150 | 150 | |
151 | 151 | // Form a string of classes in format: class="class_names". |
152 | - $class_names = join( ' ', $classes ); |
|
153 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
152 | + $class_names = join(' ', $classes); |
|
153 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
154 | 154 | |
155 | 155 | /** |
156 | 156 | * Filters the ID applied to a menu item's list item element. |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @param stdClass $args An object of wp_nav_menu() arguments. |
164 | 164 | * @param int $depth Depth of menu item. Used for padding. |
165 | 165 | */ |
166 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
167 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
166 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
167 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
168 | 168 | |
169 | 169 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>'; |
170 | 170 | |
@@ -175,16 +175,16 @@ discard block |
||
175 | 175 | * Set title from item to the $atts array - if title is empty then |
176 | 176 | * default to item title. |
177 | 177 | */ |
178 | - if ( empty( $item->attr_title ) ) { |
|
179 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
178 | + if (empty($item->attr_title)) { |
|
179 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
180 | 180 | } else { |
181 | 181 | $atts['title'] = $item->attr_title; |
182 | 182 | } |
183 | 183 | |
184 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
185 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
184 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
185 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
186 | 186 | // If the item has children, add atts to the <a>. |
187 | - if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
187 | + if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) { |
|
188 | 188 | $atts['href'] = '#'; |
189 | 189 | $atts['data-toggle'] = 'dropdown'; |
190 | 190 | $atts['aria-haspopup'] = 'true'; |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | $atts['class'] = 'dropdown-toggle nav-link'; |
193 | 193 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
194 | 194 | } else { |
195 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
195 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
196 | 196 | // For items in dropdowns use .dropdown-item instead of .nav-link. |
197 | - if ( $depth > 0 ) { |
|
197 | + if ($depth > 0) { |
|
198 | 198 | $atts['class'] = 'dropdown-item'; |
199 | 199 | } else { |
200 | 200 | $atts['class'] = 'nav-link'; |
@@ -204,32 +204,32 @@ discard block |
||
204 | 204 | $atts['aria-current'] = $item->current ? 'page' : ''; |
205 | 205 | |
206 | 206 | // Update atts of this item based on any custom linkmod classes. |
207 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
207 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
208 | 208 | // Allow filtering of the $atts array before using it. |
209 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
209 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
210 | 210 | |
211 | 211 | // Build a string of html containing all the atts for the item. |
212 | 212 | $attributes = ''; |
213 | - foreach ( $atts as $attr => $value ) { |
|
214 | - if ( ! empty( $value ) ) { |
|
215 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
213 | + foreach ($atts as $attr => $value) { |
|
214 | + if ( ! empty($value)) { |
|
215 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
216 | 216 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Set a typeflag to easily test if this is a linkmod or not. |
221 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
221 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
222 | 222 | |
223 | 223 | // START appending the internal item contents to the output. |
224 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
224 | + $item_output = isset($args->before) ? $args->before : ''; |
|
225 | 225 | |
226 | 226 | /* |
227 | 227 | * This is the start of the internal nav item. Depending on what |
228 | 228 | * kind of linkmod we have we may need different wrapper elements. |
229 | 229 | */ |
230 | - if ( '' !== $linkmod_type ) { |
|
230 | + if ('' !== $linkmod_type) { |
|
231 | 231 | // Is linkmod, output the required element opener. |
232 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
232 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
233 | 233 | } else { |
234 | 234 | // With no link mod type set this must be a standard <a> tag. |
235 | 235 | $item_output .= '<a' . $attributes . '>'; |
@@ -241,22 +241,22 @@ discard block |
||
241 | 241 | * output inside of the item before the $title (the link text). |
242 | 242 | */ |
243 | 243 | $icon_html = ''; |
244 | - if ( ! empty( $icon_class_string ) ) { |
|
244 | + if ( ! empty($icon_class_string)) { |
|
245 | 245 | // Append an <i> with the icon classes to what is output before links. |
246 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
246 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** This filter is documented in wp-includes/post-template.php */ |
250 | - if ( $item -> type == "wpml_ls_menu_item" ) { |
|
251 | - if ( strpos( $item -> title, 'wpml-ls-flag' ) > 0 ) { |
|
250 | + if ($item -> type == "wpml_ls_menu_item") { |
|
251 | + if (strpos($item -> title, 'wpml-ls-flag') > 0) { |
|
252 | 252 | $title = $item -> title; |
253 | 253 | } else { |
254 | - $title = strip_tags( $item -> title ); |
|
254 | + $title = strip_tags($item -> title); |
|
255 | 255 | } |
256 | 256 | } else { |
257 | - $title = esc_html( $item -> title ); |
|
257 | + $title = esc_html($item -> title); |
|
258 | 258 | } |
259 | - $title = apply_filters( 'the_title', $title, $item -> ID ); |
|
259 | + $title = apply_filters('the_title', $title, $item -> ID); |
|
260 | 260 | |
261 | 261 | /** |
262 | 262 | * Filters a menu item's title. |
@@ -268,36 +268,36 @@ discard block |
||
268 | 268 | * @param stdClass $args An object of wp_nav_menu() arguments. |
269 | 269 | * @param int $depth Depth of menu item. Used for padding. |
270 | 270 | */ |
271 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
271 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
272 | 272 | |
273 | 273 | // If the .sr-only class was set apply to the nav items text only. |
274 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
275 | - $title = self::wrap_for_screen_reader( $title ); |
|
276 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
277 | - foreach ( $keys_to_unset as $k ) { |
|
278 | - unset( $linkmod_classes[ $k ] ); |
|
274 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
275 | + $title = self::wrap_for_screen_reader($title); |
|
276 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
277 | + foreach ($keys_to_unset as $k) { |
|
278 | + unset($linkmod_classes[$k]); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Put the item contents into $output. |
283 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
283 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
284 | 284 | |
285 | 285 | /* |
286 | 286 | * This is the end of the internal nav item. We need to close the |
287 | 287 | * correct element depending on the type of link or link mod. |
288 | 288 | */ |
289 | - if ( '' !== $linkmod_type ) { |
|
289 | + if ('' !== $linkmod_type) { |
|
290 | 290 | // Is linkmod, output the required closing element. |
291 | - $item_output .= self::linkmod_element_close( $linkmod_type ); |
|
291 | + $item_output .= self::linkmod_element_close($linkmod_type); |
|
292 | 292 | } else { |
293 | 293 | // With no link mod type set this must be a standard <a> tag. |
294 | 294 | $item_output .= '</a>'; |
295 | 295 | } |
296 | 296 | |
297 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
297 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
298 | 298 | |
299 | 299 | // END appending the internal item contents to the output. |
300 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
300 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
301 | 301 | |
302 | 302 | } |
303 | 303 | |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | * @param array $args An array of arguments. |
323 | 323 | * @param string $output Used to append additional content (passed by reference). |
324 | 324 | */ |
325 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
326 | - if ( ! $element ) { |
|
325 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
326 | + if ( ! $element) { |
|
327 | 327 | return; } |
328 | 328 | $id_field = $this->db_fields['id']; |
329 | 329 | // Display this element. |
330 | - if ( is_object( $args[0] ) ) { |
|
331 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
332 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
330 | + if (is_object($args[0])) { |
|
331 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
332 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @param array $args passed from the wp_nav_menu function. |
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 | |
348 | 348 | // Get Arguments. |
349 | 349 | $container = $args['container']; |
@@ -355,30 +355,30 @@ discard block |
||
355 | 355 | // Initialize var to store fallback html. |
356 | 356 | $fallback_output = ''; |
357 | 357 | |
358 | - if ( $container ) { |
|
359 | - $fallback_output .= '<' . esc_attr( $container ); |
|
360 | - if ( $container_id ) { |
|
361 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
358 | + if ($container) { |
|
359 | + $fallback_output .= '<' . esc_attr($container); |
|
360 | + if ($container_id) { |
|
361 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
362 | 362 | } |
363 | - if ( $container_class ) { |
|
364 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
363 | + if ($container_class) { |
|
364 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
365 | 365 | } |
366 | 366 | $fallback_output .= '>'; |
367 | 367 | } |
368 | 368 | $fallback_output .= '<ul'; |
369 | - if ( $menu_id ) { |
|
370 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
371 | - if ( $menu_class ) { |
|
372 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
369 | + if ($menu_id) { |
|
370 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
371 | + if ($menu_class) { |
|
372 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
373 | 373 | $fallback_output .= '>'; |
374 | - $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>'; |
|
374 | + $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>'; |
|
375 | 375 | $fallback_output .= '</ul>'; |
376 | - if ( $container ) { |
|
377 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
376 | + if ($container) { |
|
377 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | // If $args has 'echo' key and it's true echo, otherwise return. |
381 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
381 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
382 | 382 | echo $fallback_output; // WPCS: XSS OK. |
383 | 383 | } else { |
384 | 384 | return $fallback_output; |
@@ -404,32 +404,32 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @return array $classes a maybe modified array of classnames. |
406 | 406 | */ |
407 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
407 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
408 | 408 | // Loop through $classes array to find linkmod or icon classes. |
409 | - foreach ( $classes as $key => $class ) { |
|
409 | + foreach ($classes as $key => $class) { |
|
410 | 410 | /* |
411 | 411 | * If any special classes are found, store the class in it's |
412 | 412 | * holder array and and unset the item from $classes. |
413 | 413 | */ |
414 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
414 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
415 | 415 | // Test for .disabled or .sr-only classes. |
416 | 416 | $linkmod_classes[] = $class; |
417 | - unset( $classes[ $key ] ); |
|
418 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
417 | + unset($classes[$key]); |
|
418 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
419 | 419 | /* |
420 | 420 | * Test for .dropdown-header or .dropdown-divider and a |
421 | 421 | * depth greater than 0 - IE inside a dropdown. |
422 | 422 | */ |
423 | 423 | $linkmod_classes[] = $class; |
424 | - unset( $classes[ $key ] ); |
|
425 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
424 | + unset($classes[$key]); |
|
425 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
426 | 426 | // Font Awesome. |
427 | 427 | $icon_classes[] = $class; |
428 | - unset( $classes[ $key ] ); |
|
429 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
428 | + unset($classes[$key]); |
|
429 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
430 | 430 | // Glyphicons. |
431 | 431 | $icon_classes[] = $class; |
432 | - unset( $classes[ $key ] ); |
|
432 | + unset($classes[$key]); |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | |
@@ -446,19 +446,19 @@ discard block |
||
446 | 446 | * |
447 | 447 | * @return string empty for default, a linkmod type string otherwise. |
448 | 448 | */ |
449 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
449 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
450 | 450 | $linkmod_type = ''; |
451 | 451 | // Loop through array of linkmod classes to handle their $atts. |
452 | - if ( ! empty( $linkmod_classes ) ) { |
|
453 | - foreach ( $linkmod_classes as $link_class ) { |
|
454 | - if ( ! empty( $link_class ) ) { |
|
452 | + if ( ! empty($linkmod_classes)) { |
|
453 | + foreach ($linkmod_classes as $link_class) { |
|
454 | + if ( ! empty($link_class)) { |
|
455 | 455 | |
456 | 456 | // Check for special class types and set a flag for them. |
457 | - if ( 'dropdown-header' === $link_class ) { |
|
457 | + if ('dropdown-header' === $link_class) { |
|
458 | 458 | $linkmod_type = 'dropdown-header'; |
459 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
459 | + } elseif ('dropdown-divider' === $link_class) { |
|
460 | 460 | $linkmod_type = 'dropdown-divider'; |
461 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
461 | + } elseif ('dropdown-item-text' === $link_class) { |
|
462 | 462 | $linkmod_type = 'dropdown-item-text'; |
463 | 463 | } |
464 | 464 | } |
@@ -477,26 +477,26 @@ discard block |
||
477 | 477 | * |
478 | 478 | * @return array maybe updated array of attributes for item. |
479 | 479 | */ |
480 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
481 | - if ( ! empty( $linkmod_classes ) ) { |
|
482 | - foreach ( $linkmod_classes as $link_class ) { |
|
483 | - if ( ! empty( $link_class ) ) { |
|
480 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
481 | + if ( ! empty($linkmod_classes)) { |
|
482 | + foreach ($linkmod_classes as $link_class) { |
|
483 | + if ( ! empty($link_class)) { |
|
484 | 484 | /* |
485 | 485 | * Update $atts with a space and the extra classname |
486 | 486 | * so long as it's not a sr-only class. |
487 | 487 | */ |
488 | - if ( 'sr-only' !== $link_class ) { |
|
489 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
488 | + if ('sr-only' !== $link_class) { |
|
489 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
490 | 490 | } |
491 | 491 | // Check for special class types we need additional handling for. |
492 | - if ( 'disabled' === $link_class ) { |
|
492 | + if ('disabled' === $link_class) { |
|
493 | 493 | // Convert link to '#' and unset open targets. |
494 | 494 | $atts['href'] = '#'; |
495 | - unset( $atts['target'] ); |
|
496 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
495 | + unset($atts['target']); |
|
496 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
497 | 497 | // Store a type flag and unset href and target. |
498 | - unset( $atts['href'] ); |
|
499 | - unset( $atts['target'] ); |
|
498 | + unset($atts['href']); |
|
499 | + unset($atts['target']); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | * @param string $text the string of text to be wrapped in a screen reader class. |
513 | 513 | * @return string the string wrapped in a span with the class. |
514 | 514 | */ |
515 | - private function wrap_for_screen_reader( $text = '' ) { |
|
516 | - if ( $text ) { |
|
515 | + private function wrap_for_screen_reader($text = '') { |
|
516 | + if ($text) { |
|
517 | 517 | $text = '<span class="sr-only">' . $text . '</span>'; |
518 | 518 | } |
519 | 519 | return $text; |
@@ -529,17 +529,17 @@ discard block |
||
529 | 529 | * |
530 | 530 | * @return string a string with the openign tag for the element with attribibutes added. |
531 | 531 | */ |
532 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
532 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
533 | 533 | $output = ''; |
534 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
534 | + if ('dropdown-item-text' === $linkmod_type) { |
|
535 | 535 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
536 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
536 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
537 | 537 | /* |
538 | 538 | * For a header use a span with the .h6 class instead of a real |
539 | 539 | * header tag so that it doesn't confuse screen readers. |
540 | 540 | */ |
541 | 541 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
542 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
542 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
543 | 543 | // This is a divider. |
544 | 544 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
545 | 545 | } |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | * |
556 | 556 | * @return string a string with the closing tag for this linkmod type. |
557 | 557 | */ |
558 | - private function linkmod_element_close( $linkmod_type ) { |
|
558 | + private function linkmod_element_close($linkmod_type) { |
|
559 | 559 | $output = ''; |
560 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
560 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
561 | 561 | /* |
562 | 562 | * For a header use a span with the .h6 class instead of a real |
563 | 563 | * header tag so that it doesn't confuse screen readers. |
564 | 564 | */ |
565 | 565 | $output .= '</span>'; |
566 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
566 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
567 | 567 | // This is a divider. |
568 | 568 | $output .= '</div>'; |
569 | 569 | } |