@@ -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 role=\"menu\">{$n}"; |
| 96 | 96 | } |
@@ -109,23 +109,23 @@ 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 | /* |
| 131 | 131 | * Initialize some holder variables to store specially handled item |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | * NOTE: linkmod and icon class arrays are passed by reference and |
| 141 | 141 | * are maybe modified before being used later in this function. |
| 142 | 142 | */ |
| 143 | - $classes = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
| 143 | + $classes = self::separate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
| 144 | 144 | |
| 145 | 145 | // Join any icon classes plucked from $classes into a string. |
| 146 | - $icon_class_string = join( ' ', $icon_classes ); |
|
| 146 | + $icon_class_string = join(' ', $icon_classes); |
|
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * Filters the arguments for a single nav menu item. |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @var WP_Nav_Menu_Args |
| 158 | 158 | */ |
| 159 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
| 159 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
| 160 | 160 | |
| 161 | 161 | // Add .dropdown or .active classes where they are needed. |
| 162 | - if ( isset( $args->has_children ) && $args->has_children ) { |
|
| 162 | + if (isset($args->has_children) && $args->has_children) { |
|
| 163 | 163 | $classes[] = 'dropdown'; |
| 164 | 164 | } |
| 165 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
| 165 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
| 166 | 166 | $classes[] = 'active'; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | $classes[] = 'nav-item'; |
| 172 | 172 | |
| 173 | 173 | // Allow filtering the classes. |
| 174 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
| 174 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
| 175 | 175 | |
| 176 | 176 | // Form a string of classes in format: class="class_names". |
| 177 | - $class_names = join( ' ', $classes ); |
|
| 178 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 177 | + $class_names = join(' ', $classes); |
|
| 178 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Filters the ID applied to a menu item's list item element. |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 189 | 189 | * @param int $depth Depth of menu item. Used for padding. |
| 190 | 190 | */ |
| 191 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
| 192 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
| 191 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
| 192 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
| 193 | 193 | |
| 194 | 194 | $output .= $indent . '<li ' . $id . $class_names . '>'; |
| 195 | 195 | |
@@ -200,20 +200,20 @@ discard block |
||
| 200 | 200 | * Set title from item to the $atts array - if title is empty then |
| 201 | 201 | * default to item title. |
| 202 | 202 | */ |
| 203 | - if ( empty( $item->attr_title ) ) { |
|
| 204 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
| 203 | + if (empty($item->attr_title)) { |
|
| 204 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
| 205 | 205 | } else { |
| 206 | 206 | $atts['title'] = $item->attr_title; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
| 210 | - if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
|
| 209 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
| 210 | + if ('_blank' === $item->target && empty($item->xfn)) { |
|
| 211 | 211 | $atts['rel'] = 'noopener noreferrer'; |
| 212 | 212 | } else { |
| 213 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
| 213 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
| 214 | 214 | } |
| 215 | 215 | // If the item has_children add atts to <a>. |
| 216 | - if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
| 216 | + if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) { |
|
| 217 | 217 | $atts['href'] = '#'; |
| 218 | 218 | $atts['data-toggle'] = 'dropdown'; |
| 219 | 219 | $atts['aria-haspopup'] = 'true'; |
@@ -221,13 +221,13 @@ discard block |
||
| 221 | 221 | $atts['class'] = 'dropdown-toggle nav-link'; |
| 222 | 222 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
| 223 | 223 | } else { |
| 224 | - if ( true === $this->has_schema ) { |
|
| 224 | + if (true === $this->has_schema) { |
|
| 225 | 225 | $atts['itemprop'] = 'url'; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
| 228 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
| 229 | 229 | // For items in dropdowns use .dropdown-item instead of .nav-link. |
| 230 | - if ( $depth > 0 ) { |
|
| 230 | + if ($depth > 0) { |
|
| 231 | 231 | $atts['class'] = 'dropdown-item'; |
| 232 | 232 | } else { |
| 233 | 233 | $atts['class'] = 'nav-link'; |
@@ -237,33 +237,33 @@ discard block |
||
| 237 | 237 | $atts['aria-current'] = $item->current ? 'page' : ''; |
| 238 | 238 | |
| 239 | 239 | // Update atts of this item based on any custom linkmod classes. |
| 240 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
| 240 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
| 241 | 241 | |
| 242 | 242 | // Allow filtering of the $atts array before using it. |
| 243 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
| 243 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
| 244 | 244 | |
| 245 | 245 | // Build a string of html containing all the atts for the item. |
| 246 | 246 | $attributes = ''; |
| 247 | - foreach ( $atts as $attr => $value ) { |
|
| 248 | - if ( ! empty( $value ) ) { |
|
| 249 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
| 247 | + foreach ($atts as $attr => $value) { |
|
| 248 | + if ( ! empty($value)) { |
|
| 249 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
| 250 | 250 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Set a typeflag to easily test if this is a linkmod or not. |
| 255 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
| 255 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
| 256 | 256 | |
| 257 | 257 | // START appending the internal item contents to the output. |
| 258 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
| 258 | + $item_output = isset($args->before) ? $args->before : ''; |
|
| 259 | 259 | |
| 260 | 260 | /* |
| 261 | 261 | * This is the start of the internal nav item. Depending on what |
| 262 | 262 | * kind of linkmod we have we may need different wrapper elements. |
| 263 | 263 | */ |
| 264 | - if ( '' !== $linkmod_type ) { |
|
| 264 | + if ('' !== $linkmod_type) { |
|
| 265 | 265 | // Is linkmod, output the required element opener. |
| 266 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
| 266 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
| 267 | 267 | } else { |
| 268 | 268 | // With no link mod type set this must be a standard <a> tag. |
| 269 | 269 | $item_output .= '<a' . $attributes . '>'; |
@@ -275,13 +275,13 @@ discard block |
||
| 275 | 275 | * output inside of the item before the $title (the link text). |
| 276 | 276 | */ |
| 277 | 277 | $icon_html = ''; |
| 278 | - if ( ! empty( $icon_class_string ) ) { |
|
| 278 | + if ( ! empty($icon_class_string)) { |
|
| 279 | 279 | // Append an <i> with the icon classes to what is output before links. |
| 280 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
| 280 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** This filter is documented in wp-includes/post-template.php */ |
| 284 | - $title = apply_filters( 'the_title', esc_html( $item->title ), $item->ID ); |
|
| 284 | + $title = apply_filters('the_title', esc_html($item->title), $item->ID); |
|
| 285 | 285 | |
| 286 | 286 | /** |
| 287 | 287 | * Filters a menu item's title. |
@@ -293,36 +293,36 @@ discard block |
||
| 293 | 293 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 294 | 294 | * @param int $depth Depth of menu item. Used for padding. |
| 295 | 295 | */ |
| 296 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
| 296 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
| 297 | 297 | |
| 298 | 298 | // If the .sr-only class was set apply to the nav items text only. |
| 299 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
| 300 | - $title = self::wrap_for_screen_reader( $title ); |
|
| 301 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
| 302 | - foreach ( $keys_to_unset as $k ) { |
|
| 303 | - unset( $linkmod_classes[ $k ] ); |
|
| 299 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
| 300 | + $title = self::wrap_for_screen_reader($title); |
|
| 301 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
| 302 | + foreach ($keys_to_unset as $k) { |
|
| 303 | + unset($linkmod_classes[$k]); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Put the item contents into $output. |
| 308 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 308 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 309 | 309 | |
| 310 | 310 | /* |
| 311 | 311 | * This is the end of the internal nav item. We need to close the |
| 312 | 312 | * correct element depending on the type of link or link mod. |
| 313 | 313 | */ |
| 314 | - if ( '' !== $linkmod_type ) { |
|
| 314 | + if ('' !== $linkmod_type) { |
|
| 315 | 315 | // Is linkmod, output the required closing element. |
| 316 | - $item_output .= self::linkmod_element_close( $linkmod_type ); |
|
| 316 | + $item_output .= self::linkmod_element_close($linkmod_type); |
|
| 317 | 317 | } else { |
| 318 | 318 | // With no link mod type set this must be a standard <a> tag. |
| 319 | 319 | $item_output .= '</a>'; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
| 322 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
| 323 | 323 | |
| 324 | 324 | // END appending the internal item contents to the output. |
| 325 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
| 325 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -347,17 +347,17 @@ discard block |
||
| 347 | 347 | * @param string $output Used to append additional content (passed by reference). |
| 348 | 348 | * @return void |
| 349 | 349 | */ |
| 350 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
| 351 | - if ( ! is_object( $element ) ) { |
|
| 350 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
| 351 | + if ( ! is_object($element)) { |
|
| 352 | 352 | return; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | $id_field = $this->db_fields['id']; |
| 356 | 356 | // Display this element. |
| 357 | - if ( is_object( $args[0] ) ) { |
|
| 358 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); |
|
| 357 | + if (is_object($args[0])) { |
|
| 358 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); |
|
| 359 | 359 | } |
| 360 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
| 360 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | * @param array $args passed from the wp_nav_menu function. |
| 372 | 372 | * @return string|void |
| 373 | 373 | */ |
| 374 | - public static function fallback( $args ) { |
|
| 375 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
| 374 | + public static function fallback($args) { |
|
| 375 | + if ( ! current_user_can('edit_theme_options')) { |
|
| 376 | 376 | return; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -386,30 +386,30 @@ discard block |
||
| 386 | 386 | // Initialize var to store fallback html. |
| 387 | 387 | $fallback_output = ''; |
| 388 | 388 | |
| 389 | - if ( $container ) { |
|
| 390 | - $fallback_output .= '<' . esc_attr( $container ); |
|
| 391 | - if ( $container_id ) { |
|
| 392 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
| 389 | + if ($container) { |
|
| 390 | + $fallback_output .= '<' . esc_attr($container); |
|
| 391 | + if ($container_id) { |
|
| 392 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
| 393 | 393 | } |
| 394 | - if ( $container_class ) { |
|
| 395 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
| 394 | + if ($container_class) { |
|
| 395 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
| 396 | 396 | } |
| 397 | 397 | $fallback_output .= '>'; |
| 398 | 398 | } |
| 399 | 399 | $fallback_output .= '<ul'; |
| 400 | - if ( $menu_id ) { |
|
| 401 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
| 402 | - if ( $menu_class ) { |
|
| 403 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
| 400 | + if ($menu_id) { |
|
| 401 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
| 402 | + if ($menu_class) { |
|
| 403 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
| 404 | 404 | $fallback_output .= '>'; |
| 405 | - $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>'; |
|
| 405 | + $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>'; |
|
| 406 | 406 | $fallback_output .= '</ul>'; |
| 407 | - if ( $container ) { |
|
| 408 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
| 407 | + if ($container) { |
|
| 408 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // If $args has 'echo' key and it's true echo, otherwise return. |
| 412 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
| 412 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
| 413 | 413 | echo $fallback_output; // WPCS: XSS OK. |
| 414 | 414 | return; |
| 415 | 415 | } |
@@ -425,10 +425,10 @@ discard block |
||
| 425 | 425 | * @param array $args The nav instance arguments. |
| 426 | 426 | * @return array $args The altered nav instance arguments. |
| 427 | 427 | */ |
| 428 | - public function add_schema_to_navbar_ul( $args ) { |
|
| 428 | + public function add_schema_to_navbar_ul($args) { |
|
| 429 | 429 | $wrap = $args['items_wrap']; |
| 430 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 431 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); |
|
| 430 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
| 431 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | return $args; |
@@ -452,32 +452,32 @@ discard block |
||
| 452 | 452 | * |
| 453 | 453 | * @return array $classes a maybe modified array of classnames. |
| 454 | 454 | */ |
| 455 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
| 455 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
| 456 | 456 | // Loop through $classes array to find linkmod or icon classes. |
| 457 | - foreach ( $classes as $key => $class ) { |
|
| 457 | + foreach ($classes as $key => $class) { |
|
| 458 | 458 | /* |
| 459 | 459 | * If any special classes are found, store the class in it's |
| 460 | 460 | * holder array and and unset the item from $classes. |
| 461 | 461 | */ |
| 462 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
| 462 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
| 463 | 463 | // Test for .disabled or .sr-only classes. |
| 464 | 464 | $linkmod_classes[] = $class; |
| 465 | - unset( $classes[ $key ] ); |
|
| 466 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
| 465 | + unset($classes[$key]); |
|
| 466 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
| 467 | 467 | /* |
| 468 | 468 | * Test for .dropdown-header or .dropdown-divider and a |
| 469 | 469 | * depth greater than 0 - IE inside a dropdown. |
| 470 | 470 | */ |
| 471 | 471 | $linkmod_classes[] = $class; |
| 472 | - unset( $classes[ $key ] ); |
|
| 473 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
| 472 | + unset($classes[$key]); |
|
| 473 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
| 474 | 474 | // Font Awesome. |
| 475 | 475 | $icon_classes[] = $class; |
| 476 | - unset( $classes[ $key ] ); |
|
| 477 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
| 476 | + unset($classes[$key]); |
|
| 477 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
| 478 | 478 | // Glyphicons. |
| 479 | 479 | $icon_classes[] = $class; |
| 480 | - unset( $classes[ $key ] ); |
|
| 480 | + unset($classes[$key]); |
|
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | |
@@ -494,19 +494,19 @@ discard block |
||
| 494 | 494 | * |
| 495 | 495 | * @return string empty for default, a linkmod type string otherwise. |
| 496 | 496 | */ |
| 497 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
| 497 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
| 498 | 498 | $linkmod_type = ''; |
| 499 | 499 | // Loop through array of linkmod classes to handle their $atts. |
| 500 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 501 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 502 | - if ( ! empty( $link_class ) ) { |
|
| 500 | + if ( ! empty($linkmod_classes)) { |
|
| 501 | + foreach ($linkmod_classes as $link_class) { |
|
| 502 | + if ( ! empty($link_class)) { |
|
| 503 | 503 | |
| 504 | 504 | // Check for special class types and set a flag for them. |
| 505 | - if ( 'dropdown-header' === $link_class ) { |
|
| 505 | + if ('dropdown-header' === $link_class) { |
|
| 506 | 506 | $linkmod_type = 'dropdown-header'; |
| 507 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
| 507 | + } elseif ('dropdown-divider' === $link_class) { |
|
| 508 | 508 | $linkmod_type = 'dropdown-divider'; |
| 509 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
| 509 | + } elseif ('dropdown-item-text' === $link_class) { |
|
| 510 | 510 | $linkmod_type = 'dropdown-item-text'; |
| 511 | 511 | } |
| 512 | 512 | } |
@@ -525,26 +525,26 @@ discard block |
||
| 525 | 525 | * |
| 526 | 526 | * @return array maybe updated array of attributes for item. |
| 527 | 527 | */ |
| 528 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
| 529 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 530 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 531 | - if ( ! empty( $link_class ) ) { |
|
| 528 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
| 529 | + if ( ! empty($linkmod_classes)) { |
|
| 530 | + foreach ($linkmod_classes as $link_class) { |
|
| 531 | + if ( ! empty($link_class)) { |
|
| 532 | 532 | /* |
| 533 | 533 | * Update $atts with a space and the extra classname |
| 534 | 534 | * so long as it's not a sr-only class. |
| 535 | 535 | */ |
| 536 | - if ( 'sr-only' !== $link_class ) { |
|
| 537 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
| 536 | + if ('sr-only' !== $link_class) { |
|
| 537 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
| 538 | 538 | } |
| 539 | 539 | // Check for special class types we need additional handling for. |
| 540 | - if ( 'disabled' === $link_class ) { |
|
| 540 | + if ('disabled' === $link_class) { |
|
| 541 | 541 | // Convert link to '#' and unset open targets. |
| 542 | 542 | $atts['href'] = '#'; |
| 543 | - unset( $atts['target'] ); |
|
| 544 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
| 543 | + unset($atts['target']); |
|
| 544 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
| 545 | 545 | // Store a type flag and unset href and target. |
| 546 | - unset( $atts['href'] ); |
|
| 547 | - unset( $atts['target'] ); |
|
| 546 | + unset($atts['href']); |
|
| 547 | + unset($atts['target']); |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | } |
@@ -560,8 +560,8 @@ discard block |
||
| 560 | 560 | * @param string $text the string of text to be wrapped in a screen reader class. |
| 561 | 561 | * @return string the string wrapped in a span with the class. |
| 562 | 562 | */ |
| 563 | - private function wrap_for_screen_reader( $text = '' ) { |
|
| 564 | - if ( $text ) { |
|
| 563 | + private function wrap_for_screen_reader($text = '') { |
|
| 564 | + if ($text) { |
|
| 565 | 565 | $text = '<span class="sr-only">' . $text . '</span>'; |
| 566 | 566 | } |
| 567 | 567 | return $text; |
@@ -577,17 +577,17 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @return string a string with the openign tag for the element with attribibutes added. |
| 579 | 579 | */ |
| 580 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
| 580 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
| 581 | 581 | $output = ''; |
| 582 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
| 582 | + if ('dropdown-item-text' === $linkmod_type) { |
|
| 583 | 583 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
| 584 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
| 584 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
| 585 | 585 | /* |
| 586 | 586 | * For a header use a span with the .h6 class instead of a real |
| 587 | 587 | * header tag so that it doesn't confuse screen readers. |
| 588 | 588 | */ |
| 589 | 589 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
| 590 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 590 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 591 | 591 | // This is a divider. |
| 592 | 592 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
| 593 | 593 | } |
@@ -603,15 +603,15 @@ discard block |
||
| 603 | 603 | * |
| 604 | 604 | * @return string a string with the closing tag for this linkmod type. |
| 605 | 605 | */ |
| 606 | - private function linkmod_element_close( $linkmod_type ) { |
|
| 606 | + private function linkmod_element_close($linkmod_type) { |
|
| 607 | 607 | $output = ''; |
| 608 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
| 608 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
| 609 | 609 | /* |
| 610 | 610 | * For a header use a span with the .h6 class instead of a real |
| 611 | 611 | * header tag so that it doesn't confuse screen readers. |
| 612 | 612 | */ |
| 613 | 613 | $output .= '</span>'; |
| 614 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 614 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 615 | 615 | // This is a divider. |
| 616 | 616 | $output .= '</div>'; |
| 617 | 617 | } |