@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // Check if Class Exists. |
| 21 | -if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) : |
|
| 21 | +if ( ! class_exists('WP_Bootstrap_Navwalker')) : |
|
| 22 | 22 | /** |
| 23 | 23 | * WP_Bootstrap_Navwalker class. |
| 24 | 24 | */ |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * @since 4.2.0 |
| 39 | 39 | */ |
| 40 | 40 | public function __construct() { |
| 41 | - if ( ! has_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ) ) { |
|
| 42 | - add_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ); |
|
| 41 | + if ( ! has_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul'))) { |
|
| 42 | + add_filter('wp_nav_menu_args', array($this, 'add_schema_to_navbar_ul')); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @param int $depth Depth of menu item. Used for padding. |
| 55 | 55 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 56 | 56 | */ |
| 57 | - public function start_lvl( &$output, $depth = 0, $args = null ) { |
|
| 58 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 57 | + public function start_lvl(&$output, $depth = 0, $args = null) { |
|
| 58 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
| 59 | 59 | $t = ''; |
| 60 | 60 | $n = ''; |
| 61 | 61 | } else { |
| 62 | 62 | $t = "\t"; |
| 63 | 63 | $n = "\n"; |
| 64 | 64 | } |
| 65 | - $indent = str_repeat( $t, $depth ); |
|
| 65 | + $indent = str_repeat($t, $depth); |
|
| 66 | 66 | // Default class to add to the file. |
| 67 | - $classes = array( 'dropdown-menu' ); |
|
| 67 | + $classes = array('dropdown-menu'); |
|
| 68 | 68 | /** |
| 69 | 69 | * Filters the CSS class(es) applied to a menu list element. |
| 70 | 70 | * |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
| 75 | 75 | * @param int $depth Depth of menu item. Used for padding. |
| 76 | 76 | */ |
| 77 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
| 78 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 77 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
| 78 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 79 | 79 | |
| 80 | 80 | /* |
| 81 | 81 | * The `.dropdown-menu` container needs to have a labelledby |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | $labelledby = ''; |
| 88 | 88 | // Find all links with an id in the output. |
| 89 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
| 89 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
| 90 | 90 | // With pointer at end of array check if we got an ID match. |
| 91 | - if ( end( $matches[2] ) ) { |
|
| 91 | + if (end($matches[2])) { |
|
| 92 | 92 | // Build a string to use as aria-labelledby. |
| 93 | - $labelledby = 'aria-labelledby="' . esc_attr( end( $matches[2] ) ) . '"'; |
|
| 93 | + $labelledby = 'aria-labelledby="' . esc_attr(end($matches[2])) . '"'; |
|
| 94 | 94 | } |
| 95 | 95 | $output .= "{$n}{$indent}<ul$class_names $labelledby>{$n}"; |
| 96 | 96 | } |
@@ -109,30 +109,30 @@ discard block |
||
| 109 | 109 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 110 | 110 | * @param int $id Current item ID. |
| 111 | 111 | */ |
| 112 | - public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { |
|
| 113 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 112 | + public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) { |
|
| 113 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
| 114 | 114 | $t = ''; |
| 115 | 115 | $n = ''; |
| 116 | 116 | } else { |
| 117 | 117 | $t = "\t"; |
| 118 | 118 | $n = "\n"; |
| 119 | 119 | } |
| 120 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
| 120 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
| 121 | 121 | |
| 122 | - if ( false !== strpos( $args->items_wrap, 'itemscope' ) && false === $this->has_schema ) { |
|
| 122 | + if (false !== strpos($args->items_wrap, 'itemscope') && false === $this->has_schema) { |
|
| 123 | 123 | $this->has_schema = true; |
| 124 | 124 | $args->link_before = '<span itemprop="name">' . $args->link_before; |
| 125 | 125 | $args->link_after .= '</span>'; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
| 128 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
| 129 | 129 | |
| 130 | 130 | // Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined |
| 131 | 131 | // in that particular input box to come in as one big class string. |
| 132 | - $split_on_spaces = function ( $class ) { |
|
| 133 | - return preg_split( '/\s+/', $class ); |
|
| 132 | + $split_on_spaces = function($class) { |
|
| 133 | + return preg_split('/\s+/', $class); |
|
| 134 | 134 | }; |
| 135 | - $classes = $this->flatten( array_map( $split_on_spaces, $classes ) ); |
|
| 135 | + $classes = $this->flatten(array_map($split_on_spaces, $classes)); |
|
| 136 | 136 | |
| 137 | 137 | /* |
| 138 | 138 | * Initialize some holder variables to store specially handled item |
@@ -147,31 +147,31 @@ discard block |
||
| 147 | 147 | * NOTE: linkmod and icon class arrays are passed by reference and |
| 148 | 148 | * are maybe modified before being used later in this function. |
| 149 | 149 | */ |
| 150 | - $classes = $this->separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
| 150 | + $classes = $this->separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
| 151 | 151 | |
| 152 | 152 | // Join any icon classes plucked from $classes into a string. |
| 153 | - $icon_class_string = join( ' ', $icon_classes ); |
|
| 153 | + $icon_class_string = join(' ', $icon_classes); |
|
| 154 | 154 | |
| 155 | 155 | // Whether the current item is a dropdown. |
| 156 | 156 | $is_dropdown = false; |
| 157 | - if ( $this->has_children && 1 !== $args->depth ) { |
|
| 157 | + if ($this->has_children && 1 !== $args->depth) { |
|
| 158 | 158 | $is_dropdown = true; |
| 159 | - if ( $depth >= $args->depth - 1 && 0 !== $args->depth ) { |
|
| 159 | + if ($depth >= $args->depth - 1 && 0 !== $args->depth) { |
|
| 160 | 160 | $is_dropdown = false; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Whether the current item is a dropdown item. |
| 165 | 165 | $is_dropdown_item = false; |
| 166 | - if ( ! ( $this->has_children && 0 === $depth ) && $depth > 0 ) { |
|
| 166 | + if ( ! ($this->has_children && 0 === $depth) && $depth > 0) { |
|
| 167 | 167 | $is_dropdown_item = true; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Whether the current item is active or the item is an ancestor of |
| 171 | 171 | // an active item. |
| 172 | 172 | $is_active = false; |
| 173 | - if ( $item->current || $item->current_item_ancestor ) { |
|
| 174 | - if ( ! ( $item->current_item_ancestor && 1 === $args->depth ) ) { |
|
| 173 | + if ($item->current || $item->current_item_ancestor) { |
|
| 174 | + if ( ! ($item->current_item_ancestor && 1 === $args->depth)) { |
|
| 175 | 175 | $is_active = true; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @var WP_Nav_Menu_Args |
| 189 | 189 | */ |
| 190 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
| 190 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
| 191 | 191 | |
| 192 | - if ( $is_dropdown ) { |
|
| 192 | + if ($is_dropdown) { |
|
| 193 | 193 | $classes[] = 'dropdown'; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ( $is_active && ! $is_dropdown_item ) { |
|
| 196 | + if ($is_active && ! $is_dropdown_item) { |
|
| 197 | 197 | // For dropdown items the .active class is set on the a tag. |
| 198 | 198 | $classes[] = 'active'; |
| 199 | 199 | } |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | $classes[] = 'nav-item'; |
| 204 | 204 | |
| 205 | 205 | // Allow filtering the classes. |
| 206 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
| 206 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
| 207 | 207 | |
| 208 | 208 | // Form a string of classes in format: class="class_names". |
| 209 | - $class_names = join( ' ', $classes ); |
|
| 210 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 209 | + $class_names = join(' ', $classes); |
|
| 210 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | 213 | * Filters the ID applied to a menu item's list item element. |
@@ -220,37 +220,37 @@ discard block |
||
| 220 | 220 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 221 | 221 | * @param int $depth Depth of menu item. Used for padding. |
| 222 | 222 | */ |
| 223 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
| 224 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
| 223 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
| 224 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
| 225 | 225 | |
| 226 | 226 | $output .= $indent . '<li ' . $id . $class_names . '>'; |
| 227 | 227 | |
| 228 | 228 | // Initialize array for holding the $atts for the link item. |
| 229 | 229 | $atts = array(); |
| 230 | - $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
|
| 231 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
| 232 | - if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
|
| 230 | + $atts['title'] = ! empty($item->attr_title) ? $item->attr_title : ''; |
|
| 231 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
| 232 | + if ('_blank' === $item->target && empty($item->xfn)) { |
|
| 233 | 233 | $atts['rel'] = 'noopener noreferrer'; |
| 234 | 234 | } else { |
| 235 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
| 235 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // If the item has_children add atts to <a>. |
| 239 | - if ( $is_dropdown ) { |
|
| 239 | + if ($is_dropdown) { |
|
| 240 | 240 | $atts['href'] = '#'; |
| 241 | 241 | $atts['data-toggle'] = 'dropdown'; |
| 242 | 242 | $atts['aria-expanded'] = 'false'; |
| 243 | 243 | $atts['class'] = 'dropdown-toggle nav-link'; |
| 244 | 244 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
| 245 | 245 | } else { |
| 246 | - if ( true === $this->has_schema ) { |
|
| 246 | + if (true === $this->has_schema) { |
|
| 247 | 247 | $atts['itemprop'] = 'url'; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
| 250 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
| 251 | 251 | |
| 252 | 252 | // For items in dropdowns use .dropdown-item instead of .nav-link. |
| 253 | - if ( $is_dropdown_item ) { |
|
| 253 | + if ($is_dropdown_item) { |
|
| 254 | 254 | $atts['class'] = 'dropdown-item'; |
| 255 | 255 | $atts['class'] .= $is_active ? ' active' : ''; |
| 256 | 256 | } else { |
@@ -261,33 +261,33 @@ discard block |
||
| 261 | 261 | $atts['aria-current'] = $item->current ? 'page' : ''; |
| 262 | 262 | |
| 263 | 263 | // Update atts of this item based on any custom linkmod classes. |
| 264 | - $atts = $this->update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
| 264 | + $atts = $this->update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
| 265 | 265 | |
| 266 | 266 | // Allow filtering of the $atts array before using it. |
| 267 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
| 267 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
| 268 | 268 | |
| 269 | 269 | // Build a string of html containing all the atts for the item. |
| 270 | 270 | $attributes = ''; |
| 271 | - foreach ( $atts as $attr => $value ) { |
|
| 272 | - if ( ! empty( $value ) ) { |
|
| 273 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
| 271 | + foreach ($atts as $attr => $value) { |
|
| 272 | + if ( ! empty($value)) { |
|
| 273 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
| 274 | 274 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Set a typeflag to easily test if this is a linkmod or not. |
| 279 | - $linkmod_type = $this->get_linkmod_type( $linkmod_classes ); |
|
| 279 | + $linkmod_type = $this->get_linkmod_type($linkmod_classes); |
|
| 280 | 280 | |
| 281 | 281 | // START appending the internal item contents to the output. |
| 282 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
| 282 | + $item_output = isset($args->before) ? $args->before : ''; |
|
| 283 | 283 | |
| 284 | 284 | /* |
| 285 | 285 | * This is the start of the internal nav item. Depending on what |
| 286 | 286 | * kind of linkmod we have we may need different wrapper elements. |
| 287 | 287 | */ |
| 288 | - if ( '' !== $linkmod_type ) { |
|
| 288 | + if ('' !== $linkmod_type) { |
|
| 289 | 289 | // Is linkmod, output the required element opener. |
| 290 | - $item_output .= $this->linkmod_element_open( $linkmod_type, $attributes ); |
|
| 290 | + $item_output .= $this->linkmod_element_open($linkmod_type, $attributes); |
|
| 291 | 291 | } else { |
| 292 | 292 | // With no link mod type set this must be a standard <a> tag. |
| 293 | 293 | $item_output .= '<a' . $attributes . '>'; |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | * output inside of the item before the $title (the link text). |
| 300 | 300 | */ |
| 301 | 301 | $icon_html = ''; |
| 302 | - if ( ! empty( $icon_class_string ) ) { |
|
| 302 | + if ( ! empty($icon_class_string)) { |
|
| 303 | 303 | // Append an <i> with the icon classes to what is output before links. |
| 304 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
| 304 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** This filter is documented in wp-includes/post-template.php */ |
| 308 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
| 308 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | 311 | * Filters a menu item's title. |
@@ -317,36 +317,36 @@ discard block |
||
| 317 | 317 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 318 | 318 | * @param int $depth Depth of menu item. Used for padding. |
| 319 | 319 | */ |
| 320 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
| 320 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
| 321 | 321 | |
| 322 | 322 | // If the .sr-only class was set apply to the nav items text only. |
| 323 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
| 324 | - $title = $this->wrap_for_screen_reader( $title ); |
|
| 325 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
| 326 | - foreach ( $keys_to_unset as $k ) { |
|
| 327 | - unset( $linkmod_classes[ $k ] ); |
|
| 323 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
| 324 | + $title = $this->wrap_for_screen_reader($title); |
|
| 325 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
| 326 | + foreach ($keys_to_unset as $k) { |
|
| 327 | + unset($linkmod_classes[$k]); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Put the item contents into $output. |
| 332 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 332 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 333 | 333 | |
| 334 | 334 | /* |
| 335 | 335 | * This is the end of the internal nav item. We need to close the |
| 336 | 336 | * correct element depending on the type of link or link mod. |
| 337 | 337 | */ |
| 338 | - if ( '' !== $linkmod_type ) { |
|
| 338 | + if ('' !== $linkmod_type) { |
|
| 339 | 339 | // Is linkmod, output the required closing element. |
| 340 | - $item_output .= $this->linkmod_element_close( $linkmod_type ); |
|
| 340 | + $item_output .= $this->linkmod_element_close($linkmod_type); |
|
| 341 | 341 | } else { |
| 342 | 342 | // With no link mod type set this must be a standard <a> tag. |
| 343 | 343 | $item_output .= '</a>'; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
| 346 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
| 347 | 347 | |
| 348 | 348 | // END appending the internal item contents to the output. |
| 349 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
| 349 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -360,8 +360,8 @@ discard block |
||
| 360 | 360 | * @param array $args passed from the wp_nav_menu function. |
| 361 | 361 | * @return string|void String when echo is false. |
| 362 | 362 | */ |
| 363 | - public static function fallback( $args ) { |
|
| 364 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
| 363 | + public static function fallback($args) { |
|
| 364 | + if ( ! current_user_can('edit_theme_options')) { |
|
| 365 | 365 | return; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | // Menu container opening tag. |
| 372 | 372 | $show_container = false; |
| 373 | - if ( $args['container'] ) { |
|
| 373 | + if ($args['container']) { |
|
| 374 | 374 | /** |
| 375 | 375 | * Filters the list of HTML tags that are valid for use as menu containers. |
| 376 | 376 | * |
@@ -379,29 +379,29 @@ discard block |
||
| 379 | 379 | * @param array $tags The acceptable HTML tags for use as menu containers. |
| 380 | 380 | * Default is array containing 'div' and 'nav'. |
| 381 | 381 | */ |
| 382 | - $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); |
|
| 383 | - if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) { |
|
| 382 | + $allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav')); |
|
| 383 | + if (is_string($args['container']) && in_array($args['container'], $allowed_tags, true)) { |
|
| 384 | 384 | $show_container = true; |
| 385 | - $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"'; |
|
| 386 | - $id = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : ''; |
|
| 385 | + $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr($args['container_class']) . '"' : ' class="menu-fallback-container"'; |
|
| 386 | + $id = $args['container_id'] ? ' id="' . esc_attr($args['container_id']) . '"' : ''; |
|
| 387 | 387 | $fallback_output .= '<' . $args['container'] . $id . $class . '>'; |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | // The fallback menu. |
| 392 | - $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; |
|
| 393 | - $id = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : ''; |
|
| 392 | + $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr($args['menu_class']) . '"' : ' class="menu-fallback-menu"'; |
|
| 393 | + $id = $args['menu_id'] ? ' id="' . esc_attr($args['menu_id']) . '"' : ''; |
|
| 394 | 394 | $fallback_output .= '<ul' . $id . $class . '>'; |
| 395 | - $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>'; |
|
| 395 | + $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>'; |
|
| 396 | 396 | $fallback_output .= '</ul>'; |
| 397 | 397 | |
| 398 | 398 | // Menu container closing tag. |
| 399 | - if ( $show_container ) { |
|
| 399 | + if ($show_container) { |
|
| 400 | 400 | $fallback_output .= '</' . $args['container'] . '>'; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // if $args has 'echo' key and it's true echo, otherwise return. |
| 404 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
| 404 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
| 405 | 405 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 406 | 406 | echo $fallback_output; |
| 407 | 407 | } else { |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | * @param array $args The nav instance arguments. |
| 418 | 418 | * @return array $args The altered nav instance arguments. |
| 419 | 419 | */ |
| 420 | - public function add_schema_to_navbar_ul( $args ) { |
|
| 421 | - if ( isset( $args['items_wrap'] ) ) { |
|
| 420 | + public function add_schema_to_navbar_ul($args) { |
|
| 421 | + if (isset($args['items_wrap'])) { |
|
| 422 | 422 | $wrap = $args['items_wrap']; |
| 423 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 424 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); |
|
| 423 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
| 424 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap); |
|
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | return $args; |
@@ -445,32 +445,32 @@ discard block |
||
| 445 | 445 | * |
| 446 | 446 | * @return array $classes a maybe modified array of classnames. |
| 447 | 447 | */ |
| 448 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
| 448 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
| 449 | 449 | // Loop through $classes array to find linkmod or icon classes. |
| 450 | - foreach ( $classes as $key => $class ) { |
|
| 450 | + foreach ($classes as $key => $class) { |
|
| 451 | 451 | /* |
| 452 | 452 | * If any special classes are found, store the class in it's |
| 453 | 453 | * holder array and and unset the item from $classes. |
| 454 | 454 | */ |
| 455 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
| 455 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
| 456 | 456 | // Test for .disabled or .sr-only classes. |
| 457 | 457 | $linkmod_classes[] = $class; |
| 458 | - unset( $classes[ $key ] ); |
|
| 459 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
| 458 | + unset($classes[$key]); |
|
| 459 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
| 460 | 460 | /* |
| 461 | 461 | * Test for .dropdown-header or .dropdown-divider and a |
| 462 | 462 | * depth greater than 0 - IE inside a dropdown. |
| 463 | 463 | */ |
| 464 | 464 | $linkmod_classes[] = $class; |
| 465 | - unset( $classes[ $key ] ); |
|
| 466 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
| 465 | + unset($classes[$key]); |
|
| 466 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
| 467 | 467 | // Font Awesome. |
| 468 | 468 | $icon_classes[] = $class; |
| 469 | - unset( $classes[ $key ] ); |
|
| 470 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
| 469 | + unset($classes[$key]); |
|
| 470 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
| 471 | 471 | // Glyphicons. |
| 472 | 472 | $icon_classes[] = $class; |
| 473 | - unset( $classes[ $key ] ); |
|
| 473 | + unset($classes[$key]); |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
@@ -487,19 +487,19 @@ discard block |
||
| 487 | 487 | * |
| 488 | 488 | * @return string empty for default, a linkmod type string otherwise. |
| 489 | 489 | */ |
| 490 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
| 490 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
| 491 | 491 | $linkmod_type = ''; |
| 492 | 492 | // Loop through array of linkmod classes to handle their $atts. |
| 493 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 494 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 495 | - if ( ! empty( $link_class ) ) { |
|
| 493 | + if ( ! empty($linkmod_classes)) { |
|
| 494 | + foreach ($linkmod_classes as $link_class) { |
|
| 495 | + if ( ! empty($link_class)) { |
|
| 496 | 496 | |
| 497 | 497 | // Check for special class types and set a flag for them. |
| 498 | - if ( 'dropdown-header' === $link_class ) { |
|
| 498 | + if ('dropdown-header' === $link_class) { |
|
| 499 | 499 | $linkmod_type = 'dropdown-header'; |
| 500 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
| 500 | + } elseif ('dropdown-divider' === $link_class) { |
|
| 501 | 501 | $linkmod_type = 'dropdown-divider'; |
| 502 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
| 502 | + } elseif ('dropdown-item-text' === $link_class) { |
|
| 503 | 503 | $linkmod_type = 'dropdown-item-text'; |
| 504 | 504 | } |
| 505 | 505 | } |
@@ -518,26 +518,26 @@ discard block |
||
| 518 | 518 | * |
| 519 | 519 | * @return array maybe updated array of attributes for item. |
| 520 | 520 | */ |
| 521 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
| 522 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 523 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 524 | - if ( ! empty( $link_class ) ) { |
|
| 521 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
| 522 | + if ( ! empty($linkmod_classes)) { |
|
| 523 | + foreach ($linkmod_classes as $link_class) { |
|
| 524 | + if ( ! empty($link_class)) { |
|
| 525 | 525 | /* |
| 526 | 526 | * Update $atts with a space and the extra classname |
| 527 | 527 | * so long as it's not a sr-only class. |
| 528 | 528 | */ |
| 529 | - if ( 'sr-only' !== $link_class ) { |
|
| 530 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
| 529 | + if ('sr-only' !== $link_class) { |
|
| 530 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
| 531 | 531 | } |
| 532 | 532 | // Check for special class types we need additional handling for. |
| 533 | - if ( 'disabled' === $link_class ) { |
|
| 533 | + if ('disabled' === $link_class) { |
|
| 534 | 534 | // Convert link to '#' and unset open targets. |
| 535 | 535 | $atts['href'] = '#'; |
| 536 | - unset( $atts['target'] ); |
|
| 537 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
| 536 | + unset($atts['target']); |
|
| 537 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
| 538 | 538 | // Store a type flag and unset href and target. |
| 539 | - unset( $atts['href'] ); |
|
| 540 | - unset( $atts['target'] ); |
|
| 539 | + unset($atts['href']); |
|
| 540 | + unset($atts['target']); |
|
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | } |
@@ -553,8 +553,8 @@ discard block |
||
| 553 | 553 | * @param string $text the string of text to be wrapped in a screen reader class. |
| 554 | 554 | * @return string the string wrapped in a span with the class. |
| 555 | 555 | */ |
| 556 | - private function wrap_for_screen_reader( $text = '' ) { |
|
| 557 | - if ( $text ) { |
|
| 556 | + private function wrap_for_screen_reader($text = '') { |
|
| 557 | + if ($text) { |
|
| 558 | 558 | $text = '<span class="sr-only">' . $text . '</span>'; |
| 559 | 559 | } |
| 560 | 560 | return $text; |
@@ -570,17 +570,17 @@ discard block |
||
| 570 | 570 | * |
| 571 | 571 | * @return string a string with the openign tag for the element with attribibutes added. |
| 572 | 572 | */ |
| 573 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
| 573 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
| 574 | 574 | $output = ''; |
| 575 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
| 575 | + if ('dropdown-item-text' === $linkmod_type) { |
|
| 576 | 576 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
| 577 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
| 577 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
| 578 | 578 | /* |
| 579 | 579 | * For a header use a span with the .h6 class instead of a real |
| 580 | 580 | * header tag so that it doesn't confuse screen readers. |
| 581 | 581 | */ |
| 582 | 582 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
| 583 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 583 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 584 | 584 | // This is a divider. |
| 585 | 585 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
| 586 | 586 | } |
@@ -596,15 +596,15 @@ discard block |
||
| 596 | 596 | * |
| 597 | 597 | * @return string a string with the closing tag for this linkmod type. |
| 598 | 598 | */ |
| 599 | - private function linkmod_element_close( $linkmod_type ) { |
|
| 599 | + private function linkmod_element_close($linkmod_type) { |
|
| 600 | 600 | $output = ''; |
| 601 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
| 601 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
| 602 | 602 | /* |
| 603 | 603 | * For a header use a span with the .h6 class instead of a real |
| 604 | 604 | * header tag so that it doesn't confuse screen readers. |
| 605 | 605 | */ |
| 606 | 606 | $output .= '</span>'; |
| 607 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 607 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 608 | 608 | // This is a divider. |
| 609 | 609 | $output .= '</div>'; |
| 610 | 610 | } |
@@ -618,11 +618,11 @@ discard block |
||
| 618 | 618 | * |
| 619 | 619 | * @return array a simple array |
| 620 | 620 | */ |
| 621 | - public function flatten( $array ) { |
|
| 621 | + public function flatten($array) { |
|
| 622 | 622 | $result = array(); |
| 623 | - foreach ( $array as $element ) { |
|
| 624 | - if ( is_array( $element ) ) { |
|
| 625 | - array_push( $result, ...$this->flatten( $element ) ); |
|
| 623 | + foreach ($array as $element) { |
|
| 624 | + if (is_array($element)) { |
|
| 625 | + array_push($result, ...$this->flatten($element)); |
|
| 626 | 626 | } else { |
| 627 | 627 | $result[] = $element; |
| 628 | 628 | } |