@@ -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::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
113 | + $classes = self::separate_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,9 +172,9 @@ 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'; |
@@ -183,32 +183,32 @@ discard block |
||
183 | 183 | |
184 | 184 | |
185 | 185 | // update atts of this item based on any custom linkmod classes. |
186 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
186 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
187 | 187 | // Allow filtering of the $atts array before using it. |
188 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
188 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
189 | 189 | // Build a string of html containing all the atts for the item. |
190 | 190 | $attributes = ''; |
191 | - foreach ( $atts as $attr => $value ) { |
|
192 | - if ( ! empty( $value ) ) { |
|
193 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
191 | + foreach ($atts as $attr => $value) { |
|
192 | + if ( ! empty($value)) { |
|
193 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
194 | 194 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
195 | 195 | } |
196 | 196 | } |
197 | 197 | /** |
198 | 198 | * Set a typeflag to easily test if this is a linkmod or not. |
199 | 199 | */ |
200 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
200 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
201 | 201 | /** |
202 | 202 | * START appending the internal item contents to the output. |
203 | 203 | */ |
204 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
204 | + $item_output = isset($args->before) ? $args->before : ''; |
|
205 | 205 | /** |
206 | 206 | * This is the start of the internal nav item. Depending on what |
207 | 207 | * kind of linkmod we have we may need different wrapper elements. |
208 | 208 | */ |
209 | - if ( '' !== $linkmod_type ) { |
|
209 | + if ('' !== $linkmod_type) { |
|
210 | 210 | // is linkmod, output the required element opener. |
211 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
211 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
212 | 212 | } else { |
213 | 213 | // With no link mod type set this must be a standard <a> tag. |
214 | 214 | $item_output .= '<a' . $attributes . '>'; |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | * output inside of the item before the $title (the link text). |
220 | 220 | */ |
221 | 221 | $icon_html = ''; |
222 | - if ( ! empty( $icon_class_string ) ) { |
|
222 | + if ( ! empty($icon_class_string)) { |
|
223 | 223 | // append an <i> with the icon classes to what is output before links. |
224 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
224 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
225 | 225 | } |
226 | 226 | /** This filter is documented in wp-includes/post-template.php */ |
227 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
227 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
228 | 228 | /** |
229 | 229 | * Filters a menu item's title. |
230 | 230 | * |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | * @param stdClass $args An object of wp_nav_menu() arguments. |
236 | 236 | * @param int $depth Depth of menu item. Used for padding. |
237 | 237 | */ |
238 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
238 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
239 | 239 | /** |
240 | 240 | * If the .sr-only class was set apply to the nav items text only. |
241 | 241 | */ |
242 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
243 | - $title = self::wrap_for_screen_reader( $title ); |
|
244 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
|
245 | - foreach ( $keys_to_unset as $k ) { |
|
246 | - unset( $linkmod_classes[ $k ] ); |
|
242 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
243 | + $title = self::wrap_for_screen_reader($title); |
|
244 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only'); |
|
245 | + foreach ($keys_to_unset as $k) { |
|
246 | + unset($linkmod_classes[$k]); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | /** add description item */ |
250 | - if (!empty($item->description)){ |
|
250 | + if ( ! empty($item->description)) { |
|
251 | 251 | $object = $item->object; |
252 | 252 | $type = $item->type; |
253 | 253 | $title = $item->title; |
@@ -255,28 +255,28 @@ discard block |
||
255 | 255 | $permalink = $item->url; |
256 | 256 | |
257 | 257 | |
258 | - if( $description != '' && $depth == 0 ) { |
|
258 | + if ($description != '' && $depth == 0) { |
|
259 | 259 | $output .= '<small class="nav-description">' . $description . '</small>'; |
260 | 260 | } |
261 | 261 | } |
262 | 262 | // Put the item contents into $output. |
263 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
263 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
264 | 264 | /** |
265 | 265 | * This is the end of the internal nav item. We need to close the |
266 | 266 | * correct element depending on the type of link or link mod. |
267 | 267 | */ |
268 | - if ( '' !== $linkmod_type ) { |
|
268 | + if ('' !== $linkmod_type) { |
|
269 | 269 | // is linkmod, output the required element opener. |
270 | - $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
|
270 | + $item_output .= self::linkmod_element_close($linkmod_type, $attributes); |
|
271 | 271 | } else { |
272 | 272 | // With no link mod type set this must be a standard <a> tag. |
273 | 273 | $item_output .= '</a>'; |
274 | 274 | } |
275 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
275 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
276 | 276 | /** |
277 | 277 | * END appending the internal item contents to the output. |
278 | 278 | */ |
279 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
279 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | * @param array $args An array of arguments. |
301 | 301 | * @param string $output Used to append additional content (passed by reference). |
302 | 302 | */ |
303 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
304 | - if ( ! $element ) { |
|
303 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
304 | + if ( ! $element) { |
|
305 | 305 | return; } |
306 | 306 | $id_field = $this->db_fields['id']; |
307 | 307 | // Display this element. |
308 | - if ( is_object( $args[0] ) ) { |
|
309 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
310 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
308 | + if (is_object($args[0])) { |
|
309 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
310 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
311 | 311 | } |
312 | 312 | /** |
313 | 313 | * Menu Fallback |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @param array $args passed from the wp_nav_menu function. |
321 | 321 | */ |
322 | - public static function fallback( $args ) { |
|
323 | - if ( current_user_can( 'edit_theme_options' ) ) { |
|
322 | + public static function fallback($args) { |
|
323 | + if (current_user_can('edit_theme_options')) { |
|
324 | 324 | /* Get Arguments. */ |
325 | 325 | $container = $args['container']; |
326 | 326 | $container_id = $args['container_id']; |
@@ -329,29 +329,29 @@ discard block |
||
329 | 329 | $menu_id = $args['menu_id']; |
330 | 330 | // initialize var to store fallback html. |
331 | 331 | $fallback_output = ''; |
332 | - if ( $container ) { |
|
333 | - $fallback_output .= '<' . esc_attr( $container ); |
|
334 | - if ( $container_id ) { |
|
335 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
332 | + if ($container) { |
|
333 | + $fallback_output .= '<' . esc_attr($container); |
|
334 | + if ($container_id) { |
|
335 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
336 | 336 | } |
337 | - if ( $container_class ) { |
|
338 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
337 | + if ($container_class) { |
|
338 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
339 | 339 | } |
340 | 340 | $fallback_output .= '>'; |
341 | 341 | } |
342 | 342 | $fallback_output .= '<ul'; |
343 | - if ( $menu_id ) { |
|
344 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
345 | - if ( $menu_class ) { |
|
346 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
343 | + if ($menu_id) { |
|
344 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
345 | + if ($menu_class) { |
|
346 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
347 | 347 | $fallback_output .= '>'; |
348 | - $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>'; |
|
348 | + $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>'; |
|
349 | 349 | $fallback_output .= '</ul>'; |
350 | - if ( $container ) { |
|
351 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
350 | + if ($container) { |
|
351 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
352 | 352 | } |
353 | 353 | // if $args has 'echo' key and it's true echo, otherwise return. |
354 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
354 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
355 | 355 | echo $fallback_output; // WPCS: XSS OK. |
356 | 356 | } else { |
357 | 357 | return $fallback_output; |
@@ -376,28 +376,28 @@ discard block |
||
376 | 376 | * |
377 | 377 | * @return array $classes a maybe modified array of classnames. |
378 | 378 | */ |
379 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
379 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
380 | 380 | // Loop through $classes array to find linkmod or icon classes. |
381 | - foreach ( $classes as $key => $class ) { |
|
381 | + foreach ($classes as $key => $class) { |
|
382 | 382 | // If any special classes are found, store the class in it's |
383 | 383 | // holder array and and unset the item from $classes. |
384 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
384 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
385 | 385 | // Test for .disabled or .sr-only classes. |
386 | 386 | $linkmod_classes[] = $class; |
387 | - unset( $classes[ $key ] ); |
|
388 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
387 | + unset($classes[$key]); |
|
388 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
389 | 389 | // Test for .dropdown-header or .dropdown-divider and a |
390 | 390 | // depth greater than 0 - IE inside a dropdown. |
391 | 391 | $linkmod_classes[] = $class; |
392 | - unset( $classes[ $key ] ); |
|
393 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
392 | + unset($classes[$key]); |
|
393 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
394 | 394 | // Font Awesome. |
395 | 395 | $icon_classes[] = $class; |
396 | - unset( $classes[ $key ] ); |
|
397 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
396 | + unset($classes[$key]); |
|
397 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
398 | 398 | // Glyphicons. |
399 | 399 | $icon_classes[] = $class; |
400 | - unset( $classes[ $key ] ); |
|
400 | + unset($classes[$key]); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | return $classes; |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | * |
413 | 413 | * @return string empty for default, a linkmod type string otherwise. |
414 | 414 | */ |
415 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
415 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
416 | 416 | $linkmod_type = ''; |
417 | 417 | // Loop through array of linkmod classes to handle their $atts. |
418 | - if ( ! empty( $linkmod_classes ) ) { |
|
419 | - foreach ( $linkmod_classes as $link_class ) { |
|
420 | - if ( ! empty( $link_class ) ) { |
|
418 | + if ( ! empty($linkmod_classes)) { |
|
419 | + foreach ($linkmod_classes as $link_class) { |
|
420 | + if ( ! empty($link_class)) { |
|
421 | 421 | // check for special class types and set a flag for them. |
422 | - if ( 'dropdown-header' === $link_class ) { |
|
422 | + if ('dropdown-header' === $link_class) { |
|
423 | 423 | $linkmod_type = 'dropdown-header'; |
424 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
424 | + } elseif ('dropdown-divider' === $link_class) { |
|
425 | 425 | $linkmod_type = 'dropdown-divider'; |
426 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
426 | + } elseif ('dropdown-item-text' === $link_class) { |
|
427 | 427 | $linkmod_type = 'dropdown-item-text'; |
428 | 428 | } |
429 | 429 | } |
@@ -441,24 +441,24 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return array maybe updated array of attributes for item. |
443 | 443 | */ |
444 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
445 | - if ( ! empty( $linkmod_classes ) ) { |
|
446 | - foreach ( $linkmod_classes as $link_class ) { |
|
447 | - if ( ! empty( $link_class ) ) { |
|
444 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
445 | + if ( ! empty($linkmod_classes)) { |
|
446 | + foreach ($linkmod_classes as $link_class) { |
|
447 | + if ( ! empty($link_class)) { |
|
448 | 448 | // update $atts with a space and the extra classname... |
449 | 449 | // so long as it's not a sr-only class. |
450 | - if ( 'sr-only' !== $link_class ) { |
|
451 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
450 | + if ('sr-only' !== $link_class) { |
|
451 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
452 | 452 | } |
453 | 453 | // check for special class types we need additional handling for. |
454 | - if ( 'disabled' === $link_class ) { |
|
454 | + if ('disabled' === $link_class) { |
|
455 | 455 | // Convert link to '#' and unset open targets. |
456 | 456 | $atts['href'] = '#'; |
457 | - unset( $atts['target'] ); |
|
458 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
457 | + unset($atts['target']); |
|
458 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
459 | 459 | // Store a type flag and unset href and target. |
460 | - unset( $atts['href'] ); |
|
461 | - unset( $atts['target'] ); |
|
460 | + unset($atts['href']); |
|
461 | + unset($atts['target']); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | * @param string $text the string of text to be wrapped in a screen reader class. |
474 | 474 | * @return string the string wrapped in a span with the class. |
475 | 475 | */ |
476 | - private function wrap_for_screen_reader( $text = '' ) { |
|
477 | - if ( $text ) { |
|
476 | + private function wrap_for_screen_reader($text = '') { |
|
477 | + if ($text) { |
|
478 | 478 | $text = '<span class="sr-only">' . $text . '</span>'; |
479 | 479 | } |
480 | 480 | return $text; |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | * |
490 | 490 | * @return string a string with the openign tag for the element with attribibutes added. |
491 | 491 | */ |
492 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
492 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
493 | 493 | $output = ''; |
494 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
494 | + if ('dropdown-item-text' === $linkmod_type) { |
|
495 | 495 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
496 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
496 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
497 | 497 | // For a header use a span with the .h6 class instead of a real |
498 | 498 | // header tag so that it doesn't confuse screen readers. |
499 | 499 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
500 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
500 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
501 | 501 | // this is a divider. |
502 | 502 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
503 | 503 | } |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @return string a string with the closing tag for this linkmod type. |
514 | 514 | */ |
515 | - private function linkmod_element_close( $linkmod_type ) { |
|
515 | + private function linkmod_element_close($linkmod_type) { |
|
516 | 516 | $output = ''; |
517 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
517 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
518 | 518 | // For a header use a span with the .h6 class instead of a real |
519 | 519 | // header tag so that it doesn't confuse screen readers. |
520 | 520 | $output .= '</span>'; |
521 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
521 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
522 | 522 | // this is a divider. |
523 | 523 | $output .= '</div>'; |
524 | 524 | } |