@@ -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,10 +147,10 @@ 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 = self::separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
| 150 | + $classes = self::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 | /** |
| 156 | 156 | * Filters the arguments for a single nav menu item. |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @var WP_Nav_Menu_Args |
| 165 | 165 | */ |
| 166 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
| 166 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
| 167 | 167 | |
| 168 | 168 | // Add .dropdown or .active classes where they are needed. |
| 169 | - if ( $this->has_children ) { |
|
| 169 | + if ($this->has_children) { |
|
| 170 | 170 | $classes[] = 'dropdown'; |
| 171 | 171 | } |
| 172 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
| 172 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
| 173 | 173 | $classes[] = 'active'; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | $classes[] = 'nav-item'; |
| 179 | 179 | |
| 180 | 180 | // Allow filtering the classes. |
| 181 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
| 181 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
| 182 | 182 | |
| 183 | 183 | // Form a string of classes in format: class="class_names". |
| 184 | - $class_names = join( ' ', $classes ); |
|
| 185 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 184 | + $class_names = join(' ', $classes); |
|
| 185 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Filters the ID applied to a menu item's list item element. |
@@ -195,23 +195,23 @@ discard block |
||
| 195 | 195 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 196 | 196 | * @param int $depth Depth of menu item. Used for padding. |
| 197 | 197 | */ |
| 198 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
| 199 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
| 198 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
| 199 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
| 200 | 200 | |
| 201 | 201 | $output .= $indent . '<li ' . $id . $class_names . '>'; |
| 202 | 202 | |
| 203 | 203 | // Initialize array for holding the $atts for the link item. |
| 204 | 204 | $atts = array(); |
| 205 | - $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
|
| 206 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
| 207 | - if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
|
| 205 | + $atts['title'] = ! empty($item->attr_title) ? $item->attr_title : ''; |
|
| 206 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
| 207 | + if ('_blank' === $item->target && empty($item->xfn)) { |
|
| 208 | 208 | $atts['rel'] = 'noopener noreferrer'; |
| 209 | 209 | } else { |
| 210 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
| 210 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // If the item has_children add atts to <a>. |
| 214 | - if ( $this->has_children && 0 === $depth ) { |
|
| 214 | + if ($this->has_children && 0 === $depth) { |
|
| 215 | 215 | $atts['href'] = '#'; |
| 216 | 216 | $atts['data-toggle'] = 'dropdown'; |
| 217 | 217 | $atts['aria-haspopup'] = 'true'; |
@@ -219,13 +219,13 @@ discard block |
||
| 219 | 219 | $atts['class'] = 'dropdown-toggle nav-link'; |
| 220 | 220 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
| 221 | 221 | } else { |
| 222 | - if ( true === $this->has_schema ) { |
|
| 222 | + if (true === $this->has_schema) { |
|
| 223 | 223 | $atts['itemprop'] = 'url'; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
| 226 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
| 227 | 227 | // For items in dropdowns use .dropdown-item instead of .nav-link. |
| 228 | - if ( $depth > 0 ) { |
|
| 228 | + if ($depth > 0) { |
|
| 229 | 229 | $atts['class'] = 'dropdown-item'; |
| 230 | 230 | } else { |
| 231 | 231 | $atts['class'] = 'nav-link'; |
@@ -235,33 +235,33 @@ discard block |
||
| 235 | 235 | $atts['aria-current'] = $item->current ? 'page' : ''; |
| 236 | 236 | |
| 237 | 237 | // Update atts of this item based on any custom linkmod classes. |
| 238 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
| 238 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
| 239 | 239 | |
| 240 | 240 | // Allow filtering of the $atts array before using it. |
| 241 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
| 241 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
| 242 | 242 | |
| 243 | 243 | // Build a string of html containing all the atts for the item. |
| 244 | 244 | $attributes = ''; |
| 245 | - foreach ( $atts as $attr => $value ) { |
|
| 246 | - if ( ! empty( $value ) ) { |
|
| 247 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
| 245 | + foreach ($atts as $attr => $value) { |
|
| 246 | + if ( ! empty($value)) { |
|
| 247 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
| 248 | 248 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Set a typeflag to easily test if this is a linkmod or not. |
| 253 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
| 253 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
| 254 | 254 | |
| 255 | 255 | // START appending the internal item contents to the output. |
| 256 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
| 256 | + $item_output = isset($args->before) ? $args->before : ''; |
|
| 257 | 257 | |
| 258 | 258 | /* |
| 259 | 259 | * This is the start of the internal nav item. Depending on what |
| 260 | 260 | * kind of linkmod we have we may need different wrapper elements. |
| 261 | 261 | */ |
| 262 | - if ( '' !== $linkmod_type ) { |
|
| 262 | + if ('' !== $linkmod_type) { |
|
| 263 | 263 | // Is linkmod, output the required element opener. |
| 264 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
| 264 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
| 265 | 265 | } else { |
| 266 | 266 | // With no link mod type set this must be a standard <a> tag. |
| 267 | 267 | $item_output .= '<a' . $attributes . '>'; |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | * output inside of the item before the $title (the link text). |
| 274 | 274 | */ |
| 275 | 275 | $icon_html = ''; |
| 276 | - if ( ! empty( $icon_class_string ) ) { |
|
| 276 | + if ( ! empty($icon_class_string)) { |
|
| 277 | 277 | // Append an <i> with the icon classes to what is output before links. |
| 278 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
| 278 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** This filter is documented in wp-includes/post-template.php */ |
| 282 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
| 282 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | 285 | * Filters a menu item's title. |
@@ -291,36 +291,36 @@ discard block |
||
| 291 | 291 | * @param WP_Nav_Menu_Args $args An object of wp_nav_menu() arguments. |
| 292 | 292 | * @param int $depth Depth of menu item. Used for padding. |
| 293 | 293 | */ |
| 294 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
| 294 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
| 295 | 295 | |
| 296 | 296 | // If the .sr-only class was set apply to the nav items text only. |
| 297 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
| 298 | - $title = self::wrap_for_screen_reader( $title ); |
|
| 299 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true ); |
|
| 300 | - foreach ( $keys_to_unset as $k ) { |
|
| 301 | - unset( $linkmod_classes[ $k ] ); |
|
| 297 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
| 298 | + $title = self::wrap_for_screen_reader($title); |
|
| 299 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only', true); |
|
| 300 | + foreach ($keys_to_unset as $k) { |
|
| 301 | + unset($linkmod_classes[$k]); |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // Put the item contents into $output. |
| 306 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 306 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 307 | 307 | |
| 308 | 308 | /* |
| 309 | 309 | * This is the end of the internal nav item. We need to close the |
| 310 | 310 | * correct element depending on the type of link or link mod. |
| 311 | 311 | */ |
| 312 | - if ( '' !== $linkmod_type ) { |
|
| 312 | + if ('' !== $linkmod_type) { |
|
| 313 | 313 | // Is linkmod, output the required closing element. |
| 314 | - $item_output .= self::linkmod_element_close( $linkmod_type ); |
|
| 314 | + $item_output .= self::linkmod_element_close($linkmod_type); |
|
| 315 | 315 | } else { |
| 316 | 316 | // With no link mod type set this must be a standard <a> tag. |
| 317 | 317 | $item_output .= '</a>'; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
| 320 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
| 321 | 321 | |
| 322 | 322 | // END appending the internal item contents to the output. |
| 323 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
| 323 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @param array $args passed from the wp_nav_menu function. |
| 335 | 335 | * @return string|void String when echo is false. |
| 336 | 336 | */ |
| 337 | - public static function fallback( $args ) { |
|
| 338 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
| 337 | + public static function fallback($args) { |
|
| 338 | + if ( ! current_user_can('edit_theme_options')) { |
|
| 339 | 339 | return; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | // Menu container opening tag. |
| 346 | 346 | $show_container = false; |
| 347 | - if ( $args['container'] ) { |
|
| 347 | + if ($args['container']) { |
|
| 348 | 348 | /** |
| 349 | 349 | * Filters the list of HTML tags that are valid for use as menu containers. |
| 350 | 350 | * |
@@ -353,29 +353,29 @@ discard block |
||
| 353 | 353 | * @param array $tags The acceptable HTML tags for use as menu containers. |
| 354 | 354 | * Default is array containing 'div' and 'nav'. |
| 355 | 355 | */ |
| 356 | - $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); |
|
| 357 | - if ( is_string( $args['container'] ) && in_array( $args['container'], $allowed_tags, true ) ) { |
|
| 356 | + $allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav')); |
|
| 357 | + if (is_string($args['container']) && in_array($args['container'], $allowed_tags, true)) { |
|
| 358 | 358 | $show_container = true; |
| 359 | - $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr( $args['container_class'] ) . '"' : ' class="menu-fallback-container"'; |
|
| 360 | - $id = $args['container_id'] ? ' id="' . esc_attr( $args['container_id'] ) . '"' : ''; |
|
| 359 | + $class = $args['container_class'] ? ' class="menu-fallback-container ' . esc_attr($args['container_class']) . '"' : ' class="menu-fallback-container"'; |
|
| 360 | + $id = $args['container_id'] ? ' id="' . esc_attr($args['container_id']) . '"' : ''; |
|
| 361 | 361 | $fallback_output .= '<' . $args['container'] . $id . $class . '>'; |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // The fallback menu. |
| 366 | - $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr( $args['menu_class'] ) . '"' : ' class="menu-fallback-menu"'; |
|
| 367 | - $id = $args['menu_id'] ? ' id="' . esc_attr( $args['menu_id'] ) . '"' : ''; |
|
| 366 | + $class = $args['menu_class'] ? ' class="menu-fallback-menu ' . esc_attr($args['menu_class']) . '"' : ' class="menu-fallback-menu"'; |
|
| 367 | + $id = $args['menu_id'] ? ' id="' . esc_attr($args['menu_id']) . '"' : ''; |
|
| 368 | 368 | $fallback_output .= '<ul' . $id . $class . '>'; |
| 369 | - $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>'; |
|
| 369 | + $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>'; |
|
| 370 | 370 | $fallback_output .= '</ul>'; |
| 371 | 371 | |
| 372 | 372 | // Menu container closing tag. |
| 373 | - if ( $show_container ) { |
|
| 373 | + if ($show_container) { |
|
| 374 | 374 | $fallback_output .= '</' . $args['container'] . '>'; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // if $args has 'echo' key and it's true echo, otherwise return. |
| 378 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
| 378 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
| 379 | 379 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 380 | 380 | echo $fallback_output; |
| 381 | 381 | } else { |
@@ -391,10 +391,10 @@ discard block |
||
| 391 | 391 | * @param array $args The nav instance arguments. |
| 392 | 392 | * @return array $args The altered nav instance arguments. |
| 393 | 393 | */ |
| 394 | - public function add_schema_to_navbar_ul( $args ) { |
|
| 394 | + public function add_schema_to_navbar_ul($args) { |
|
| 395 | 395 | $wrap = $args['items_wrap']; |
| 396 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 397 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap ); |
|
| 396 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
| 397 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', ' itemscope itemtype="http://www.schema.org/SiteNavigationElement"$0', $wrap); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | return $args; |
@@ -418,32 +418,32 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * @return array $classes a maybe modified array of classnames. |
| 420 | 420 | */ |
| 421 | - private function separate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
| 421 | + private function separate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
| 422 | 422 | // Loop through $classes array to find linkmod or icon classes. |
| 423 | - foreach ( $classes as $key => $class ) { |
|
| 423 | + foreach ($classes as $key => $class) { |
|
| 424 | 424 | /* |
| 425 | 425 | * If any special classes are found, store the class in it's |
| 426 | 426 | * holder array and and unset the item from $classes. |
| 427 | 427 | */ |
| 428 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
| 428 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
| 429 | 429 | // Test for .disabled or .sr-only classes. |
| 430 | 430 | $linkmod_classes[] = $class; |
| 431 | - unset( $classes[ $key ] ); |
|
| 432 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
| 431 | + unset($classes[$key]); |
|
| 432 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
| 433 | 433 | /* |
| 434 | 434 | * Test for .dropdown-header or .dropdown-divider and a |
| 435 | 435 | * depth greater than 0 - IE inside a dropdown. |
| 436 | 436 | */ |
| 437 | 437 | $linkmod_classes[] = $class; |
| 438 | - unset( $classes[ $key ] ); |
|
| 439 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
| 438 | + unset($classes[$key]); |
|
| 439 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
| 440 | 440 | // Font Awesome. |
| 441 | 441 | $icon_classes[] = $class; |
| 442 | - unset( $classes[ $key ] ); |
|
| 443 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
| 442 | + unset($classes[$key]); |
|
| 443 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
| 444 | 444 | // Glyphicons. |
| 445 | 445 | $icon_classes[] = $class; |
| 446 | - unset( $classes[ $key ] ); |
|
| 446 | + unset($classes[$key]); |
|
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |
@@ -460,19 +460,19 @@ discard block |
||
| 460 | 460 | * |
| 461 | 461 | * @return string empty for default, a linkmod type string otherwise. |
| 462 | 462 | */ |
| 463 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
| 463 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
| 464 | 464 | $linkmod_type = ''; |
| 465 | 465 | // Loop through array of linkmod classes to handle their $atts. |
| 466 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 467 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 468 | - if ( ! empty( $link_class ) ) { |
|
| 466 | + if ( ! empty($linkmod_classes)) { |
|
| 467 | + foreach ($linkmod_classes as $link_class) { |
|
| 468 | + if ( ! empty($link_class)) { |
|
| 469 | 469 | |
| 470 | 470 | // Check for special class types and set a flag for them. |
| 471 | - if ( 'dropdown-header' === $link_class ) { |
|
| 471 | + if ('dropdown-header' === $link_class) { |
|
| 472 | 472 | $linkmod_type = 'dropdown-header'; |
| 473 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
| 473 | + } elseif ('dropdown-divider' === $link_class) { |
|
| 474 | 474 | $linkmod_type = 'dropdown-divider'; |
| 475 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
| 475 | + } elseif ('dropdown-item-text' === $link_class) { |
|
| 476 | 476 | $linkmod_type = 'dropdown-item-text'; |
| 477 | 477 | } |
| 478 | 478 | } |
@@ -491,26 +491,26 @@ discard block |
||
| 491 | 491 | * |
| 492 | 492 | * @return array maybe updated array of attributes for item. |
| 493 | 493 | */ |
| 494 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
| 495 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 496 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 497 | - if ( ! empty( $link_class ) ) { |
|
| 494 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
| 495 | + if ( ! empty($linkmod_classes)) { |
|
| 496 | + foreach ($linkmod_classes as $link_class) { |
|
| 497 | + if ( ! empty($link_class)) { |
|
| 498 | 498 | /* |
| 499 | 499 | * Update $atts with a space and the extra classname |
| 500 | 500 | * so long as it's not a sr-only class. |
| 501 | 501 | */ |
| 502 | - if ( 'sr-only' !== $link_class ) { |
|
| 503 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
| 502 | + if ('sr-only' !== $link_class) { |
|
| 503 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
| 504 | 504 | } |
| 505 | 505 | // Check for special class types we need additional handling for. |
| 506 | - if ( 'disabled' === $link_class ) { |
|
| 506 | + if ('disabled' === $link_class) { |
|
| 507 | 507 | // Convert link to '#' and unset open targets. |
| 508 | 508 | $atts['href'] = '#'; |
| 509 | - unset( $atts['target'] ); |
|
| 510 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
| 509 | + unset($atts['target']); |
|
| 510 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
| 511 | 511 | // Store a type flag and unset href and target. |
| 512 | - unset( $atts['href'] ); |
|
| 513 | - unset( $atts['target'] ); |
|
| 512 | + unset($atts['href']); |
|
| 513 | + unset($atts['target']); |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | } |
@@ -526,8 +526,8 @@ discard block |
||
| 526 | 526 | * @param string $text the string of text to be wrapped in a screen reader class. |
| 527 | 527 | * @return string the string wrapped in a span with the class. |
| 528 | 528 | */ |
| 529 | - private function wrap_for_screen_reader( $text = '' ) { |
|
| 530 | - if ( $text ) { |
|
| 529 | + private function wrap_for_screen_reader($text = '') { |
|
| 530 | + if ($text) { |
|
| 531 | 531 | $text = '<span class="sr-only">' . $text . '</span>'; |
| 532 | 532 | } |
| 533 | 533 | return $text; |
@@ -543,17 +543,17 @@ discard block |
||
| 543 | 543 | * |
| 544 | 544 | * @return string a string with the openign tag for the element with attribibutes added. |
| 545 | 545 | */ |
| 546 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
| 546 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
| 547 | 547 | $output = ''; |
| 548 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
| 548 | + if ('dropdown-item-text' === $linkmod_type) { |
|
| 549 | 549 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
| 550 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
| 550 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
| 551 | 551 | /* |
| 552 | 552 | * For a header use a span with the .h6 class instead of a real |
| 553 | 553 | * header tag so that it doesn't confuse screen readers. |
| 554 | 554 | */ |
| 555 | 555 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
| 556 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 556 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 557 | 557 | // This is a divider. |
| 558 | 558 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
| 559 | 559 | } |
@@ -569,15 +569,15 @@ discard block |
||
| 569 | 569 | * |
| 570 | 570 | * @return string a string with the closing tag for this linkmod type. |
| 571 | 571 | */ |
| 572 | - private function linkmod_element_close( $linkmod_type ) { |
|
| 572 | + private function linkmod_element_close($linkmod_type) { |
|
| 573 | 573 | $output = ''; |
| 574 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
| 574 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
| 575 | 575 | /* |
| 576 | 576 | * For a header use a span with the .h6 class instead of a real |
| 577 | 577 | * header tag so that it doesn't confuse screen readers. |
| 578 | 578 | */ |
| 579 | 579 | $output .= '</span>'; |
| 580 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 580 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 581 | 581 | // This is a divider. |
| 582 | 582 | $output .= '</div>'; |
| 583 | 583 | } |
@@ -591,11 +591,11 @@ discard block |
||
| 591 | 591 | * |
| 592 | 592 | * @return array a simple array |
| 593 | 593 | */ |
| 594 | - public function flatten( $array ) { |
|
| 594 | + public function flatten($array) { |
|
| 595 | 595 | $result = array(); |
| 596 | - foreach ( $array as $element ) { |
|
| 597 | - if ( is_array( $element ) ) { |
|
| 598 | - array_push( $result, ...$this->flatten( $element ) ); |
|
| 596 | + foreach ($array as $element) { |
|
| 597 | + if (is_array($element)) { |
|
| 598 | + array_push($result, ...$this->flatten($element)); |
|
| 599 | 599 | } else { |
| 600 | 600 | $result[] = $element; |
| 601 | 601 | } |