@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * License URI: http://www.gnu.org/licenses/gpl-3.0.txt |
20 | 20 | */ |
21 | 21 | /* Check if Class Exists. */ |
22 | -if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) { |
|
22 | +if ( ! class_exists('WP_Bootstrap_Navwalker')) { |
|
23 | 23 | /** |
24 | 24 | * WP_Bootstrap_Navwalker class. |
25 | 25 | * |
@@ -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 | * The `.dropdown-menu` container needs to have a labelledby |
64 | 64 | * attribute which points to it's trigger link. |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | */ |
69 | 69 | $labelledby = ''; |
70 | 70 | // find all links with an id in the output. |
71 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
71 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
72 | 72 | // with pointer at end of array check if we got an ID match. |
73 | - if ( end( $matches[2] ) ) { |
|
73 | + if (end($matches[2])) { |
|
74 | 74 | // build a string to use as aria-labelledby. |
75 | - $labelledby = 'aria-labelledby="' . end( $matches[2] ) . '"'; |
|
75 | + $labelledby = 'aria-labelledby="' . end($matches[2]) . '"'; |
|
76 | 76 | } |
77 | 77 | $output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}"; |
78 | 78 | } |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | * @param stdClass $args An object of wp_nav_menu() arguments. |
91 | 91 | * @param int $id Current item ID. |
92 | 92 | */ |
93 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
94 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
93 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
94 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
95 | 95 | $t = ''; |
96 | 96 | $n = ''; |
97 | 97 | } else { |
98 | 98 | $t = "\t"; |
99 | 99 | $n = "\n"; |
100 | 100 | } |
101 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
102 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
101 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
102 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
103 | 103 | // Initialize some holder variables to store specially handled item |
104 | 104 | // wrappers and icons. |
105 | 105 | $linkmod_classes = array(); |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * NOTE: linkmod and icon class arrays are passed by reference and |
111 | 111 | * are maybe modified before being used later in this function. |
112 | 112 | */ |
113 | - $classes = self::seporate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
113 | + $classes = self::seporate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
114 | 114 | // Join any icon classes plucked from $classes into a string. |
115 | - $icon_class_string = join( ' ', $icon_classes ); |
|
115 | + $icon_class_string = join(' ', $icon_classes); |
|
116 | 116 | /** |
117 | 117 | * Filters the arguments for a single nav menu item. |
118 | 118 | * |
@@ -122,22 +122,22 @@ discard block |
||
122 | 122 | * @param WP_Post $item Menu item data object. |
123 | 123 | * @param int $depth Depth of menu item. Used for padding. |
124 | 124 | */ |
125 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
125 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
126 | 126 | // Add .dropdown or .active classes where they are needed. |
127 | - if ( isset($args->has_children) && $args->has_children ) { |
|
127 | + if (isset($args->has_children) && $args->has_children) { |
|
128 | 128 | $classes[] = 'dropdown'; |
129 | 129 | } |
130 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
130 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
131 | 131 | $classes[] = 'active'; |
132 | 132 | } |
133 | 133 | // Add some additional default classes to the item. |
134 | 134 | $classes[] = 'menu-item-' . $item->ID; |
135 | 135 | $classes[] = 'nav-item'; |
136 | 136 | // Allow filtering the classes. |
137 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
137 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
138 | 138 | // Form a string of classes in format: class="class_names". |
139 | - $class_names = join( ' ', $classes ); |
|
140 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
139 | + $class_names = join(' ', $classes); |
|
140 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
141 | 141 | /** |
142 | 142 | * Filters the ID applied to a menu item's list item element. |
143 | 143 | * |
@@ -149,22 +149,22 @@ discard block |
||
149 | 149 | * @param stdClass $args An object of wp_nav_menu() arguments. |
150 | 150 | * @param int $depth Depth of menu item. Used for padding. |
151 | 151 | */ |
152 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
153 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
152 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
153 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
154 | 154 | $output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $class_names . '>'; |
155 | 155 | // initialize array for holding the $atts for the link item. |
156 | 156 | $atts = array(); |
157 | 157 | // Set title from item to the $atts array - if title is empty then |
158 | 158 | // default to item title. |
159 | - if ( empty( $item->attr_title ) ) { |
|
160 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
159 | + if (empty($item->attr_title)) { |
|
160 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
161 | 161 | } else { |
162 | 162 | $atts['title'] = $item->attr_title; |
163 | 163 | } |
164 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
165 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
164 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
165 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
166 | 166 | // If item has_children add atts to <a>. |
167 | - if ( isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
167 | + if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) { |
|
168 | 168 | $atts['href'] = '#'; |
169 | 169 | $atts['data-toggle'] = 'dropdown'; |
170 | 170 | $atts['aria-haspopup'] = 'true'; |
@@ -172,30 +172,30 @@ discard block |
||
172 | 172 | $atts['class'] = 'dropdown-toggle nav-link'; |
173 | 173 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
174 | 174 | } else { |
175 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
175 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
176 | 176 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
177 | - if ( $depth > 0 ) { |
|
177 | + if ($depth > 0) { |
|
178 | 178 | $atts['class'] = 'dropdown-item'; |
179 | 179 | } else { |
180 | 180 | $atts['class'] = 'nav-link'; |
181 | 181 | } |
182 | 182 | } |
183 | 183 | // update atts of this item based on any custom linkmod classes. |
184 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
184 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
185 | 185 | // Allow filtering of the $atts array before using it. |
186 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
|
186 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args); |
|
187 | 187 | // Build a string of html containing all the atts for the item. |
188 | 188 | $attributes = ''; |
189 | - foreach ( $atts as $attr => $value ) { |
|
190 | - if ( ! empty( $value ) ) { |
|
191 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
189 | + foreach ($atts as $attr => $value) { |
|
190 | + if ( ! empty($value)) { |
|
191 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
192 | 192 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | /** |
196 | 196 | * Set a typeflag to easily test if this is a linkmod or not. |
197 | 197 | */ |
198 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
198 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
199 | 199 | /** |
200 | 200 | * START appending the internal item contents to the output. |
201 | 201 | */ |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * This is the start of the internal nav item. Depending on what |
205 | 205 | * kind of linkmod we have we may need different wrapper elements. |
206 | 206 | */ |
207 | - if ( '' !== $linkmod_type ) { |
|
207 | + if ('' !== $linkmod_type) { |
|
208 | 208 | // is linkmod, output the required element opener. |
209 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
209 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
210 | 210 | } else { |
211 | 211 | // With no link mod type set this must be a standard <a> tag. |
212 | 212 | $item_output .= '<a' . $attributes . '>'; |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * output inside of the item before the $title (the link text). |
218 | 218 | */ |
219 | 219 | $icon_html = ''; |
220 | - if ( ! empty( $icon_class_string ) ) { |
|
220 | + if ( ! empty($icon_class_string)) { |
|
221 | 221 | // append an <i> with the icon classes to what is output before links. |
222 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
222 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
223 | 223 | } |
224 | 224 | /** This filter is documented in wp-includes/post-template.php */ |
225 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
225 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
226 | 226 | /** |
227 | 227 | * Filters a menu item's title. |
228 | 228 | * |
@@ -233,15 +233,15 @@ discard block |
||
233 | 233 | * @param stdClass $args An object of wp_nav_menu() arguments. |
234 | 234 | * @param int $depth Depth of menu item. Used for padding. |
235 | 235 | */ |
236 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
236 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
237 | 237 | /** |
238 | 238 | * If the .sr-only class was set apply to the nav items text only. |
239 | 239 | */ |
240 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
241 | - $title = self::wrap_for_screen_reader( $title ); |
|
242 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
|
243 | - foreach ( $keys_to_unset as $k ) { |
|
244 | - unset( $linkmod_classes[ $k ] ); |
|
240 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
241 | + $title = self::wrap_for_screen_reader($title); |
|
242 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only'); |
|
243 | + foreach ($keys_to_unset as $k) { |
|
244 | + unset($linkmod_classes[$k]); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | // Put the item contents into $output. |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | * This is the end of the internal nav item. We need to close the |
251 | 251 | * correct element depending on the type of link or link mod. |
252 | 252 | */ |
253 | - if ( '' !== $linkmod_type ) { |
|
253 | + if ('' !== $linkmod_type) { |
|
254 | 254 | // is linkmod, output the required element opener. |
255 | - $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
|
255 | + $item_output .= self::linkmod_element_close($linkmod_type, $attributes); |
|
256 | 256 | } else { |
257 | 257 | // With no link mod type set this must be a standard <a> tag. |
258 | 258 | $item_output .= '</a>'; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | /** |
262 | 262 | * END appending the internal item contents to the output. |
263 | 263 | */ |
264 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
264 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
265 | 265 | } |
266 | 266 | /** |
267 | 267 | * Traverse elements to create list from elements. |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | * @param array $args An array of arguments. |
285 | 285 | * @param string $output Used to append additional content (passed by reference). |
286 | 286 | */ |
287 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
288 | - if ( ! $element ) { |
|
287 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
288 | + if ( ! $element) { |
|
289 | 289 | return; } |
290 | 290 | $id_field = $this->db_fields['id']; |
291 | 291 | // Display this element. |
292 | - if ( is_object( $args[0] ) ) { |
|
293 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
294 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
292 | + if (is_object($args[0])) { |
|
293 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
294 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
295 | 295 | } |
296 | 296 | /** |
297 | 297 | * Menu Fallback |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param array $args passed from the wp_nav_menu function. |
305 | 305 | */ |
306 | - public static function fallback( $args ) { |
|
307 | - if ( current_user_can( 'edit_theme_options' ) ) { |
|
306 | + public static function fallback($args) { |
|
307 | + if (current_user_can('edit_theme_options')) { |
|
308 | 308 | /* Get Arguments. */ |
309 | 309 | $container = $args['container']; |
310 | 310 | $container_id = $args['container_id']; |
@@ -313,29 +313,29 @@ discard block |
||
313 | 313 | $menu_id = $args['menu_id']; |
314 | 314 | // initialize var to store fallback html. |
315 | 315 | $fallback_output = ''; |
316 | - if ( $container ) { |
|
317 | - $fallback_output .= '<' . esc_attr( $container ); |
|
318 | - if ( $container_id ) { |
|
319 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
316 | + if ($container) { |
|
317 | + $fallback_output .= '<' . esc_attr($container); |
|
318 | + if ($container_id) { |
|
319 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
320 | 320 | } |
321 | - if ( $container_class ) { |
|
322 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
321 | + if ($container_class) { |
|
322 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
323 | 323 | } |
324 | 324 | $fallback_output .= '>'; |
325 | 325 | } |
326 | 326 | $fallback_output .= '<ul'; |
327 | - if ( $menu_id ) { |
|
328 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
329 | - if ( $menu_class ) { |
|
330 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
327 | + if ($menu_id) { |
|
328 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
329 | + if ($menu_class) { |
|
330 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
331 | 331 | $fallback_output .= '>'; |
332 | - $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>'; |
|
332 | + $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>'; |
|
333 | 333 | $fallback_output .= '</ul>'; |
334 | - if ( $container ) { |
|
335 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
334 | + if ($container) { |
|
335 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
336 | 336 | } |
337 | 337 | // if $args has 'echo' key and it's true echo, otherwise return. |
338 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
338 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
339 | 339 | echo $fallback_output; // WPCS: XSS OK. |
340 | 340 | } else { |
341 | 341 | return $fallback_output; |
@@ -360,28 +360,28 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @return array $classes a maybe modified array of classnames. |
362 | 362 | */ |
363 | - private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
363 | + private function seporate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
364 | 364 | // Loop through $classes array to find linkmod or icon classes. |
365 | - foreach ( $classes as $key => $class ) { |
|
365 | + foreach ($classes as $key => $class) { |
|
366 | 366 | // If any special classes are found, store the class in it's |
367 | 367 | // holder array and and unset the item from $classes. |
368 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
368 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
369 | 369 | // Test for .disabled or .sr-only classes. |
370 | 370 | $linkmod_classes[] = $class; |
371 | - unset( $classes[ $key ] ); |
|
372 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider/i', $class ) && $depth > 0 ) { |
|
371 | + unset($classes[$key]); |
|
372 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider/i', $class) && $depth > 0) { |
|
373 | 373 | // Test for .dropdown-header or .dropdown-divider and a |
374 | 374 | // depth greater than 0 - IE inside a dropdown. |
375 | 375 | $linkmod_classes[] = $class; |
376 | - unset( $classes[ $key ] ); |
|
377 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
376 | + unset($classes[$key]); |
|
377 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
378 | 378 | // Font Awesome. |
379 | 379 | $icon_classes[] = $class; |
380 | - unset( $classes[ $key ] ); |
|
381 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
380 | + unset($classes[$key]); |
|
381 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
382 | 382 | // Glyphicons. |
383 | 383 | $icon_classes[] = $class; |
384 | - unset( $classes[ $key ] ); |
|
384 | + unset($classes[$key]); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | return $classes; |
@@ -396,16 +396,16 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @return string empty for default, a linkmod type string otherwise. |
398 | 398 | */ |
399 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
399 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
400 | 400 | $linkmod_type = ''; |
401 | 401 | // Loop through array of linkmod classes to handle their $atts. |
402 | - if ( ! empty( $linkmod_classes ) ) { |
|
403 | - foreach ( $linkmod_classes as $link_class ) { |
|
404 | - if ( ! empty( $link_class ) ) { |
|
402 | + if ( ! empty($linkmod_classes)) { |
|
403 | + foreach ($linkmod_classes as $link_class) { |
|
404 | + if ( ! empty($link_class)) { |
|
405 | 405 | // check for special class types and set a flag for them. |
406 | - if ( 'dropdown-header' === $link_class ) { |
|
406 | + if ('dropdown-header' === $link_class) { |
|
407 | 407 | $linkmod_type = 'dropdown-header'; |
408 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
408 | + } elseif ('dropdown-divider' === $link_class) { |
|
409 | 409 | $linkmod_type = 'dropdown-divider'; |
410 | 410 | } |
411 | 411 | } |
@@ -423,24 +423,24 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @return array maybe updated array of attributes for item. |
425 | 425 | */ |
426 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
427 | - if ( ! empty( $linkmod_classes ) ) { |
|
428 | - foreach ( $linkmod_classes as $link_class ) { |
|
429 | - if ( ! empty( $link_class ) ) { |
|
426 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
427 | + if ( ! empty($linkmod_classes)) { |
|
428 | + foreach ($linkmod_classes as $link_class) { |
|
429 | + if ( ! empty($link_class)) { |
|
430 | 430 | // update $atts with a space and the extra classname... |
431 | 431 | // so long as it's not a sr-only class. |
432 | - if ( 'sr-only' !== $link_class ) { |
|
433 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
432 | + if ('sr-only' !== $link_class) { |
|
433 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
434 | 434 | } |
435 | 435 | // check for special class types we need additional handling for. |
436 | - if ( 'disabled' === $link_class ) { |
|
436 | + if ('disabled' === $link_class) { |
|
437 | 437 | // Convert link to '#' and unset open targets. |
438 | 438 | $atts['href'] = '#'; |
439 | - unset( $atts['target'] ); |
|
440 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class ) { |
|
439 | + unset($atts['target']); |
|
440 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class) { |
|
441 | 441 | // Store a type flag and unset href and target. |
442 | - unset( $atts['href'] ); |
|
443 | - unset( $atts['target'] ); |
|
442 | + unset($atts['href']); |
|
443 | + unset($atts['target']); |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | } |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | * @param string $text the string of text to be wrapped in a screen reader class. |
456 | 456 | * @return string the string wrapped in a span with the class. |
457 | 457 | */ |
458 | - private function wrap_for_screen_reader( $text = '' ) { |
|
459 | - if ( $text ) { |
|
458 | + private function wrap_for_screen_reader($text = '') { |
|
459 | + if ($text) { |
|
460 | 460 | $text = '<span class="sr-only">' . $text . '</span>'; |
461 | 461 | } |
462 | 462 | return $text; |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | * |
472 | 472 | * @return string a string with the openign tag for the element with attribibutes added. |
473 | 473 | */ |
474 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
474 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
475 | 475 | $output = ''; |
476 | - if ( 'dropdown-header' === $linkmod_type ) { |
|
476 | + if ('dropdown-header' === $linkmod_type) { |
|
477 | 477 | // For a header use a span with the .h6 class instead of a real |
478 | 478 | // header tag so that it doesn't confuse screen readers. |
479 | 479 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
480 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
480 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
481 | 481 | // this is a divider. |
482 | 482 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
483 | 483 | } |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | * |
493 | 493 | * @return string a string with the closing tag for this linkmod type. |
494 | 494 | */ |
495 | - private function linkmod_element_close( $linkmod_type ) { |
|
495 | + private function linkmod_element_close($linkmod_type) { |
|
496 | 496 | $output = ''; |
497 | - if ( 'dropdown-header' === $linkmod_type ) { |
|
497 | + if ('dropdown-header' === $linkmod_type) { |
|
498 | 498 | // For a header use a span with the .h6 class instead of a real |
499 | 499 | // header tag so that it doesn't confuse screen readers. |
500 | 500 | $output .= '</span>'; |
501 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
501 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
502 | 502 | // this is a divider. |
503 | 503 | $output .= '</div>'; |
504 | 504 | } |