@@ -28,24 +28,24 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class WP_Bootstrap_Navwalker extends Walker_Nav_Menu { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Whether the items_wrap contains schema microdata or not. |
|
| 33 | - * |
|
| 34 | - * @since 4.2.0 |
|
| 35 | - * @var type bool |
|
| 36 | - */ |
|
| 37 | - private $has_schema = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Ensure the items_wrap argument contains microdata. |
|
| 41 | - * |
|
| 42 | - * @since 4.2.0 |
|
| 43 | - */ |
|
| 44 | - public function __construct() { |
|
| 45 | - if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { |
|
| 46 | - add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); |
|
| 47 | - } |
|
| 48 | - } |
|
| 31 | + /** |
|
| 32 | + * Whether the items_wrap contains schema microdata or not. |
|
| 33 | + * |
|
| 34 | + * @since 4.2.0 |
|
| 35 | + * @var type bool |
|
| 36 | + */ |
|
| 37 | + private $has_schema = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Ensure the items_wrap argument contains microdata. |
|
| 41 | + * |
|
| 42 | + * @since 4.2.0 |
|
| 43 | + */ |
|
| 44 | + public function __construct() { |
|
| 45 | + if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { |
|
| 46 | + add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Starts the list before the elements are added. |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
| 124 | 124 | |
| 125 | 125 | if ( strpos( $args->items_wrap, 'itemscope' ) !== false && $this->has_schema === false ) { |
| 126 | - $this->has_schema = true; |
|
| 127 | - $args->link_before = '<span itemprop="name">' . $args->link_before; |
|
| 128 | - $args->link_after .= '</span>'; |
|
| 129 | - } |
|
| 126 | + $this->has_schema = true; |
|
| 127 | + $args->link_before = '<span itemprop="name">' . $args->link_before; |
|
| 128 | + $args->link_after .= '</span>'; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
| 132 | 132 | |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
| 216 | 216 | } else { |
| 217 | 217 | if ( $this->has_schema === true ) { |
| 218 | - $atts['itemprop'] = 'url'; |
|
| 219 | - } |
|
| 218 | + $atts['itemprop'] = 'url'; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | 221 | $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
| 222 | 222 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
@@ -409,21 +409,21 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | - * Filter to ensure the items_Wrap argument contains microdata. |
|
| 413 | - * |
|
| 414 | - * @since 4.2.0 |
|
| 415 | - * |
|
| 416 | - * @param array $args The nav instance arguments. |
|
| 417 | - * @return array $args The altered nav instance arguments. |
|
| 418 | - */ |
|
| 419 | - public function add_schema_to_navbar_ul( $args ) { |
|
| 420 | - $wrap = $args['items_wrap']; |
|
| 421 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 422 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return $args; |
|
| 426 | - } |
|
| 412 | + * Filter to ensure the items_Wrap argument contains microdata. |
|
| 413 | + * |
|
| 414 | + * @since 4.2.0 |
|
| 415 | + * |
|
| 416 | + * @param array $args The nav instance arguments. |
|
| 417 | + * @return array $args The altered nav instance arguments. |
|
| 418 | + */ |
|
| 419 | + public function add_schema_to_navbar_ul( $args ) { |
|
| 420 | + $wrap = $args['items_wrap']; |
|
| 421 | + if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 422 | + $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return $args; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | /** |
| 429 | 429 | * Find any custom linkmod or icon classes and store in their holder |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | /* Check if Class Exists. */ |
| 23 | -if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) { |
|
| 23 | +if ( ! class_exists('WP_Bootstrap_Navwalker')) { |
|
| 24 | 24 | /** |
| 25 | 25 | * WP_Bootstrap_Navwalker class. |
| 26 | 26 | * |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @since 4.2.0 |
| 43 | 43 | */ |
| 44 | 44 | public function __construct() { |
| 45 | - if ( ! has_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ) ) { |
|
| 46 | - add_filter( 'wp_nav_menu_args', [ $this, 'add_schema_to_navbar_ul' ] ); |
|
| 45 | + if ( ! has_filter('wp_nav_menu_args', [$this, 'add_schema_to_navbar_ul'])) { |
|
| 46 | + add_filter('wp_nav_menu_args', [$this, 'add_schema_to_navbar_ul']); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -58,17 +58,17 @@ discard block |
||
| 58 | 58 | * @param int $depth Depth of menu item. Used for padding. |
| 59 | 59 | * @param stdClass $args An object of wp_nav_menu() arguments. |
| 60 | 60 | */ |
| 61 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
| 62 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 61 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
| 62 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
| 63 | 63 | $t = ''; |
| 64 | 64 | $n = ''; |
| 65 | 65 | } else { |
| 66 | 66 | $t = "\t"; |
| 67 | 67 | $n = "\n"; |
| 68 | 68 | } |
| 69 | - $indent = str_repeat( $t, $depth ); |
|
| 69 | + $indent = str_repeat($t, $depth); |
|
| 70 | 70 | // Default class to add to the file. |
| 71 | - $classes = array( 'dropdown-menu' ); |
|
| 71 | + $classes = array('dropdown-menu'); |
|
| 72 | 72 | /** |
| 73 | 73 | * Filters the CSS class(es) applied to a menu list element. |
| 74 | 74 | * |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @param stdClass $args An object of `wp_nav_menu()` arguments. |
| 79 | 79 | * @param int $depth Depth of menu item. Used for padding. |
| 80 | 80 | */ |
| 81 | - $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
|
| 82 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 81 | + $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth)); |
|
| 82 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 83 | 83 | /** |
| 84 | 84 | * The `.dropdown-menu` container needs to have a labelledby |
| 85 | 85 | * attribute which points to it's trigger link. |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | $labelledby = ''; |
| 91 | 91 | // find all links with an id in the output. |
| 92 | - preg_match_all( '/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches ); |
|
| 92 | + preg_match_all('/(<a.*?id=\"|\')(.*?)\"|\'.*?>/im', $output, $matches); |
|
| 93 | 93 | // with pointer at end of array check if we got an ID match. |
| 94 | - if ( end( $matches[2] ) ) { |
|
| 94 | + if (end($matches[2])) { |
|
| 95 | 95 | // build a string to use as aria-labelledby. |
| 96 | - $labelledby = 'aria-labelledby="' . end( $matches[2] ) . '"'; |
|
| 96 | + $labelledby = 'aria-labelledby="' . end($matches[2]) . '"'; |
|
| 97 | 97 | } |
| 98 | 98 | $output .= "{$n}{$indent}<ul$class_names $labelledby role=\"menu\">{$n}"; |
| 99 | 99 | } |
@@ -112,23 +112,23 @@ discard block |
||
| 112 | 112 | * @param stdClass $args An object of wp_nav_menu() arguments. |
| 113 | 113 | * @param int $id Current item ID. |
| 114 | 114 | */ |
| 115 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
| 116 | - if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { |
|
| 115 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
| 116 | + if (isset($args->item_spacing) && 'discard' === $args->item_spacing) { |
|
| 117 | 117 | $t = ''; |
| 118 | 118 | $n = ''; |
| 119 | 119 | } else { |
| 120 | 120 | $t = "\t"; |
| 121 | 121 | $n = "\n"; |
| 122 | 122 | } |
| 123 | - $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; |
|
| 123 | + $indent = ($depth) ? str_repeat($t, $depth) : ''; |
|
| 124 | 124 | |
| 125 | - if ( strpos( $args->items_wrap, 'itemscope' ) !== false && $this->has_schema === false ) { |
|
| 125 | + if (strpos($args->items_wrap, 'itemscope') !== false && $this->has_schema === false) { |
|
| 126 | 126 | $this->has_schema = true; |
| 127 | 127 | $args->link_before = '<span itemprop="name">' . $args->link_before; |
| 128 | 128 | $args->link_after .= '</span>'; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
| 131 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
| 132 | 132 | |
| 133 | 133 | // Initialize some holder variables to store specially handled item |
| 134 | 134 | // wrappers and icons. |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | * NOTE: linkmod and icon class arrays are passed by reference and |
| 142 | 142 | * are maybe modified before being used later in this function. |
| 143 | 143 | */ |
| 144 | - $classes = self::seporate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth ); |
|
| 144 | + $classes = self::seporate_linkmods_and_icons_from_classes($classes, $linkmod_classes, $icon_classes, $depth); |
|
| 145 | 145 | |
| 146 | 146 | // Join any icon classes plucked from $classes into a string. |
| 147 | - $icon_class_string = join( ' ', $icon_classes ); |
|
| 147 | + $icon_class_string = join(' ', $icon_classes); |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * Filters the arguments for a single nav menu item. |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | * @param WP_Post $item Menu item data object. |
| 156 | 156 | * @param int $depth Depth of menu item. Used for padding. |
| 157 | 157 | */ |
| 158 | - $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
|
| 158 | + $args = apply_filters('nav_menu_item_args', $args, $item, $depth); |
|
| 159 | 159 | |
| 160 | 160 | // Add .dropdown or .active classes where they are needed. |
| 161 | - if ( isset( $args->has_children ) && $args->has_children ) { |
|
| 161 | + if (isset($args->has_children) && $args->has_children) { |
|
| 162 | 162 | $classes[] = 'dropdown'; |
| 163 | 163 | } |
| 164 | - if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) { |
|
| 164 | + if (in_array('current-menu-item', $classes, true) || in_array('current-menu-parent', $classes, true)) { |
|
| 165 | 165 | $classes[] = 'active'; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | $classes[] = 'nav-item'; |
| 171 | 171 | |
| 172 | 172 | // Allow filtering the classes. |
| 173 | - $classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ); |
|
| 173 | + $classes = apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
| 174 | 174 | |
| 175 | 175 | // Form a string of classes in format: class="class_names". |
| 176 | - $class_names = join( ' ', $classes ); |
|
| 177 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
| 176 | + $class_names = join(' ', $classes); |
|
| 177 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * Filters the ID applied to a menu item's list item element. |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * @param stdClass $args An object of wp_nav_menu() arguments. |
| 188 | 188 | * @param int $depth Depth of menu item. Used for padding. |
| 189 | 189 | */ |
| 190 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
|
| 191 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
| 190 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth); |
|
| 191 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
| 192 | 192 | |
| 193 | 193 | $output .= $indent . '<li ' . $id . $class_names . '>'; |
| 194 | 194 | |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | // Set title from item to the $atts array - if title is empty then |
| 199 | 199 | // default to item title. |
| 200 | - if ( empty( $item->attr_title ) ) { |
|
| 201 | - $atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : ''; |
|
| 200 | + if (empty($item->attr_title)) { |
|
| 201 | + $atts['title'] = ! empty($item->title) ? strip_tags($item->title) : ''; |
|
| 202 | 202 | } else { |
| 203 | 203 | $atts['title'] = $item->attr_title; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
|
| 207 | - $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
|
| 206 | + $atts['target'] = ! empty($item->target) ? $item->target : ''; |
|
| 207 | + $atts['rel'] = ! empty($item->xfn) ? $item->xfn : ''; |
|
| 208 | 208 | // If item has_children add atts to <a>. |
| 209 | - if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) { |
|
| 209 | + if (isset($args->has_children) && $args->has_children && 0 === $depth && $args->depth > 1) { |
|
| 210 | 210 | $atts['href'] = '#'; |
| 211 | 211 | $atts['data-toggle'] = 'dropdown'; |
| 212 | 212 | $atts['aria-haspopup'] = 'true'; |
@@ -214,13 +214,13 @@ discard block |
||
| 214 | 214 | $atts['class'] = 'dropdown-toggle nav-link'; |
| 215 | 215 | $atts['id'] = 'menu-item-dropdown-' . $item->ID; |
| 216 | 216 | } else { |
| 217 | - if ( $this->has_schema === true ) { |
|
| 217 | + if ($this->has_schema === true) { |
|
| 218 | 218 | $atts['itemprop'] = 'url'; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $atts['href'] = ! empty( $item->url ) ? $item->url : '#'; |
|
| 221 | + $atts['href'] = ! empty($item->url) ? $item->url : '#'; |
|
| 222 | 222 | // Items in dropdowns use .dropdown-item instead of .nav-link. |
| 223 | - if ( $depth > 0 ) { |
|
| 223 | + if ($depth > 0) { |
|
| 224 | 224 | $atts['class'] = 'dropdown-item'; |
| 225 | 225 | } else { |
| 226 | 226 | $atts['class'] = 'nav-link'; |
@@ -228,16 +228,16 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // update atts of this item based on any custom linkmod classes. |
| 231 | - $atts = self::update_atts_for_linkmod_type( $atts, $linkmod_classes ); |
|
| 231 | + $atts = self::update_atts_for_linkmod_type($atts, $linkmod_classes); |
|
| 232 | 232 | |
| 233 | 233 | // Allow filtering of the $atts array before using it. |
| 234 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
|
| 234 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth); |
|
| 235 | 235 | |
| 236 | 236 | // Build a string of html containing all the atts for the item. |
| 237 | 237 | $attributes = ''; |
| 238 | - foreach ( $atts as $attr => $value ) { |
|
| 239 | - if ( ! empty( $value ) ) { |
|
| 240 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
| 238 | + foreach ($atts as $attr => $value) { |
|
| 239 | + if ( ! empty($value)) { |
|
| 240 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
| 241 | 241 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -245,19 +245,19 @@ discard block |
||
| 245 | 245 | /** |
| 246 | 246 | * Set a typeflag to easily test if this is a linkmod or not. |
| 247 | 247 | */ |
| 248 | - $linkmod_type = self::get_linkmod_type( $linkmod_classes ); |
|
| 248 | + $linkmod_type = self::get_linkmod_type($linkmod_classes); |
|
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | 251 | * START appending the internal item contents to the output. |
| 252 | 252 | */ |
| 253 | - $item_output = isset( $args->before ) ? $args->before : ''; |
|
| 253 | + $item_output = isset($args->before) ? $args->before : ''; |
|
| 254 | 254 | /** |
| 255 | 255 | * This is the start of the internal nav item. Depending on what |
| 256 | 256 | * kind of linkmod we have we may need different wrapper elements. |
| 257 | 257 | */ |
| 258 | - if ( '' !== $linkmod_type ) { |
|
| 258 | + if ('' !== $linkmod_type) { |
|
| 259 | 259 | // is linkmod, output the required element opener. |
| 260 | - $item_output .= self::linkmod_element_open( $linkmod_type, $attributes ); |
|
| 260 | + $item_output .= self::linkmod_element_open($linkmod_type, $attributes); |
|
| 261 | 261 | } else { |
| 262 | 262 | // With no link mod type set this must be a standard <a> tag. |
| 263 | 263 | $item_output .= '<a' . $attributes . '>'; |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | * output inside of the item before the $title (the link text). |
| 270 | 270 | */ |
| 271 | 271 | $icon_html = ''; |
| 272 | - if ( ! empty( $icon_class_string ) ) { |
|
| 272 | + if ( ! empty($icon_class_string)) { |
|
| 273 | 273 | // append an <i> with the icon classes to what is output before links. |
| 274 | - $icon_html = '<i class="' . esc_attr( $icon_class_string ) . '" aria-hidden="true"></i> '; |
|
| 274 | + $icon_html = '<i class="' . esc_attr($icon_class_string) . '" aria-hidden="true"></i> '; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** This filter is documented in wp-includes/post-template.php */ |
| 278 | - $title = apply_filters( 'the_title', $item->title, $item->ID ); |
|
| 278 | + $title = apply_filters('the_title', $item->title, $item->ID); |
|
| 279 | 279 | |
| 280 | 280 | /** |
| 281 | 281 | * Filters a menu item's title. |
@@ -287,39 +287,39 @@ discard block |
||
| 287 | 287 | * @param stdClass $args An object of wp_nav_menu() arguments. |
| 288 | 288 | * @param int $depth Depth of menu item. Used for padding. |
| 289 | 289 | */ |
| 290 | - $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
|
| 290 | + $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth); |
|
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | 293 | * If the .sr-only class was set apply to the nav items text only. |
| 294 | 294 | */ |
| 295 | - if ( in_array( 'sr-only', $linkmod_classes, true ) ) { |
|
| 296 | - $title = self::wrap_for_screen_reader( $title ); |
|
| 297 | - $keys_to_unset = array_keys( $linkmod_classes, 'sr-only' ); |
|
| 298 | - foreach ( $keys_to_unset as $k ) { |
|
| 299 | - unset( $linkmod_classes[ $k ] ); |
|
| 295 | + if (in_array('sr-only', $linkmod_classes, true)) { |
|
| 296 | + $title = self::wrap_for_screen_reader($title); |
|
| 297 | + $keys_to_unset = array_keys($linkmod_classes, 'sr-only'); |
|
| 298 | + foreach ($keys_to_unset as $k) { |
|
| 299 | + unset($linkmod_classes[$k]); |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // Put the item contents into $output. |
| 304 | - $item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 304 | + $item_output .= isset($args->link_before) ? $args->link_before . $icon_html . $title . $args->link_after : ''; |
|
| 305 | 305 | /** |
| 306 | 306 | * This is the end of the internal nav item. We need to close the |
| 307 | 307 | * correct element depending on the type of link or link mod. |
| 308 | 308 | */ |
| 309 | - if ( '' !== $linkmod_type ) { |
|
| 309 | + if ('' !== $linkmod_type) { |
|
| 310 | 310 | // is linkmod, output the required element opener. |
| 311 | - $item_output .= self::linkmod_element_close( $linkmod_type, $attributes ); |
|
| 311 | + $item_output .= self::linkmod_element_close($linkmod_type, $attributes); |
|
| 312 | 312 | } else { |
| 313 | 313 | // With no link mod type set this must be a standard <a> tag. |
| 314 | 314 | $item_output .= '</a>'; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $item_output .= isset( $args->after ) ? $args->after : ''; |
|
| 317 | + $item_output .= isset($args->after) ? $args->after : ''; |
|
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | 320 | * END appending the internal item contents to the output. |
| 321 | 321 | */ |
| 322 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
| 322 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
| 323 | 323 | |
| 324 | 324 | } |
| 325 | 325 | |
@@ -344,14 +344,14 @@ discard block |
||
| 344 | 344 | * @param array $args An array of arguments. |
| 345 | 345 | * @param string $output Used to append additional content (passed by reference). |
| 346 | 346 | */ |
| 347 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
| 348 | - if ( ! $element ) { |
|
| 347 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
| 348 | + if ( ! $element) { |
|
| 349 | 349 | return; } |
| 350 | 350 | $id_field = $this->db_fields['id']; |
| 351 | 351 | // Display this element. |
| 352 | - if ( is_object( $args[0] ) ) { |
|
| 353 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); } |
|
| 354 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
| 352 | + if (is_object($args[0])) { |
|
| 353 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); } |
|
| 354 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | * @param array $args passed from the wp_nav_menu function. |
| 366 | 366 | */ |
| 367 | - public static function fallback( $args ) { |
|
| 368 | - if ( current_user_can( 'edit_theme_options' ) ) { |
|
| 367 | + public static function fallback($args) { |
|
| 368 | + if (current_user_can('edit_theme_options')) { |
|
| 369 | 369 | |
| 370 | 370 | /* Get Arguments. */ |
| 371 | 371 | $container = $args['container']; |
@@ -377,30 +377,30 @@ discard block |
||
| 377 | 377 | // initialize var to store fallback html. |
| 378 | 378 | $fallback_output = ''; |
| 379 | 379 | |
| 380 | - if ( $container ) { |
|
| 381 | - $fallback_output .= '<' . esc_attr( $container ); |
|
| 382 | - if ( $container_id ) { |
|
| 383 | - $fallback_output .= ' id="' . esc_attr( $container_id ) . '"'; |
|
| 380 | + if ($container) { |
|
| 381 | + $fallback_output .= '<' . esc_attr($container); |
|
| 382 | + if ($container_id) { |
|
| 383 | + $fallback_output .= ' id="' . esc_attr($container_id) . '"'; |
|
| 384 | 384 | } |
| 385 | - if ( $container_class ) { |
|
| 386 | - $fallback_output .= ' class="' . esc_attr( $container_class ) . '"'; |
|
| 385 | + if ($container_class) { |
|
| 386 | + $fallback_output .= ' class="' . esc_attr($container_class) . '"'; |
|
| 387 | 387 | } |
| 388 | 388 | $fallback_output .= '>'; |
| 389 | 389 | } |
| 390 | 390 | $fallback_output .= '<ul'; |
| 391 | - if ( $menu_id ) { |
|
| 392 | - $fallback_output .= ' id="' . esc_attr( $menu_id ) . '"'; } |
|
| 393 | - if ( $menu_class ) { |
|
| 394 | - $fallback_output .= ' class="' . esc_attr( $menu_class ) . '"'; } |
|
| 391 | + if ($menu_id) { |
|
| 392 | + $fallback_output .= ' id="' . esc_attr($menu_id) . '"'; } |
|
| 393 | + if ($menu_class) { |
|
| 394 | + $fallback_output .= ' class="' . esc_attr($menu_class) . '"'; } |
|
| 395 | 395 | $fallback_output .= '>'; |
| 396 | - $fallback_output .= '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="' . esc_attr__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '">' . esc_html__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '</a></li>'; |
|
| 396 | + $fallback_output .= '<li><a href="' . esc_url(admin_url('nav-menus.php')) . '" title="' . esc_attr__('Add a menu', 'wp-bootstrap-navwalker') . '">' . esc_html__('Add a menu', 'wp-bootstrap-navwalker') . '</a></li>'; |
|
| 397 | 397 | $fallback_output .= '</ul>'; |
| 398 | - if ( $container ) { |
|
| 399 | - $fallback_output .= '</' . esc_attr( $container ) . '>'; |
|
| 398 | + if ($container) { |
|
| 399 | + $fallback_output .= '</' . esc_attr($container) . '>'; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | // if $args has 'echo' key and it's true echo, otherwise return. |
| 403 | - if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
|
| 403 | + if (array_key_exists('echo', $args) && $args['echo']) { |
|
| 404 | 404 | echo $fallback_output; // WPCS: XSS OK. |
| 405 | 405 | } else { |
| 406 | 406 | return $fallback_output; |
@@ -416,10 +416,10 @@ discard block |
||
| 416 | 416 | * @param array $args The nav instance arguments. |
| 417 | 417 | * @return array $args The altered nav instance arguments. |
| 418 | 418 | */ |
| 419 | - public function add_schema_to_navbar_ul( $args ) { |
|
| 419 | + public function add_schema_to_navbar_ul($args) { |
|
| 420 | 420 | $wrap = $args['items_wrap']; |
| 421 | - if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) { |
|
| 422 | - $args['items_wrap'] = preg_replace( '/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap ); |
|
| 421 | + if (strpos($wrap, 'SiteNavigationElement') === false) { |
|
| 422 | + $args['items_wrap'] = preg_replace('/(>).*>?\%3\$s/', " itemscope itemtype=\"http://www.schema.org/SiteNavigationElement\"$0", $wrap); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | return $args; |
@@ -443,28 +443,28 @@ discard block |
||
| 443 | 443 | * |
| 444 | 444 | * @return array $classes a maybe modified array of classnames. |
| 445 | 445 | */ |
| 446 | - private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_classes, &$icon_classes, $depth ) { |
|
| 446 | + private function seporate_linkmods_and_icons_from_classes($classes, &$linkmod_classes, &$icon_classes, $depth) { |
|
| 447 | 447 | // Loop through $classes array to find linkmod or icon classes. |
| 448 | - foreach ( $classes as $key => $class ) { |
|
| 448 | + foreach ($classes as $key => $class) { |
|
| 449 | 449 | // If any special classes are found, store the class in it's |
| 450 | 450 | // holder array and and unset the item from $classes. |
| 451 | - if ( preg_match( '/^disabled|^sr-only/i', $class ) ) { |
|
| 451 | + if (preg_match('/^disabled|^sr-only/i', $class)) { |
|
| 452 | 452 | // Test for .disabled or .sr-only classes. |
| 453 | 453 | $linkmod_classes[] = $class; |
| 454 | - unset( $classes[ $key ] ); |
|
| 455 | - } elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) && $depth > 0 ) { |
|
| 454 | + unset($classes[$key]); |
|
| 455 | + } elseif (preg_match('/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class) && $depth > 0) { |
|
| 456 | 456 | // Test for .dropdown-header or .dropdown-divider and a |
| 457 | 457 | // depth greater than 0 - IE inside a dropdown. |
| 458 | 458 | $linkmod_classes[] = $class; |
| 459 | - unset( $classes[ $key ] ); |
|
| 460 | - } elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) { |
|
| 459 | + unset($classes[$key]); |
|
| 460 | + } elseif (preg_match('/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class)) { |
|
| 461 | 461 | // Font Awesome. |
| 462 | 462 | $icon_classes[] = $class; |
| 463 | - unset( $classes[ $key ] ); |
|
| 464 | - } elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) { |
|
| 463 | + unset($classes[$key]); |
|
| 464 | + } elseif (preg_match('/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class)) { |
|
| 465 | 465 | // Glyphicons. |
| 466 | 466 | $icon_classes[] = $class; |
| 467 | - unset( $classes[ $key ] ); |
|
| 467 | + unset($classes[$key]); |
|
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | |
@@ -481,19 +481,19 @@ discard block |
||
| 481 | 481 | * |
| 482 | 482 | * @return string empty for default, a linkmod type string otherwise. |
| 483 | 483 | */ |
| 484 | - private function get_linkmod_type( $linkmod_classes = array() ) { |
|
| 484 | + private function get_linkmod_type($linkmod_classes = array()) { |
|
| 485 | 485 | $linkmod_type = ''; |
| 486 | 486 | // Loop through array of linkmod classes to handle their $atts. |
| 487 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 488 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 489 | - if ( ! empty( $link_class ) ) { |
|
| 487 | + if ( ! empty($linkmod_classes)) { |
|
| 488 | + foreach ($linkmod_classes as $link_class) { |
|
| 489 | + if ( ! empty($link_class)) { |
|
| 490 | 490 | |
| 491 | 491 | // check for special class types and set a flag for them. |
| 492 | - if ( 'dropdown-header' === $link_class ) { |
|
| 492 | + if ('dropdown-header' === $link_class) { |
|
| 493 | 493 | $linkmod_type = 'dropdown-header'; |
| 494 | - } elseif ( 'dropdown-divider' === $link_class ) { |
|
| 494 | + } elseif ('dropdown-divider' === $link_class) { |
|
| 495 | 495 | $linkmod_type = 'dropdown-divider'; |
| 496 | - } elseif ( 'dropdown-item-text' === $link_class ) { |
|
| 496 | + } elseif ('dropdown-item-text' === $link_class) { |
|
| 497 | 497 | $linkmod_type = 'dropdown-item-text'; |
| 498 | 498 | } |
| 499 | 499 | } |
@@ -512,24 +512,24 @@ discard block |
||
| 512 | 512 | * |
| 513 | 513 | * @return array maybe updated array of attributes for item. |
| 514 | 514 | */ |
| 515 | - private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) { |
|
| 516 | - if ( ! empty( $linkmod_classes ) ) { |
|
| 517 | - foreach ( $linkmod_classes as $link_class ) { |
|
| 518 | - if ( ! empty( $link_class ) ) { |
|
| 515 | + private function update_atts_for_linkmod_type($atts = array(), $linkmod_classes = array()) { |
|
| 516 | + if ( ! empty($linkmod_classes)) { |
|
| 517 | + foreach ($linkmod_classes as $link_class) { |
|
| 518 | + if ( ! empty($link_class)) { |
|
| 519 | 519 | // update $atts with a space and the extra classname... |
| 520 | 520 | // so long as it's not a sr-only class. |
| 521 | - if ( 'sr-only' !== $link_class ) { |
|
| 522 | - $atts['class'] .= ' ' . esc_attr( $link_class ); |
|
| 521 | + if ('sr-only' !== $link_class) { |
|
| 522 | + $atts['class'] .= ' ' . esc_attr($link_class); |
|
| 523 | 523 | } |
| 524 | 524 | // check for special class types we need additional handling for. |
| 525 | - if ( 'disabled' === $link_class ) { |
|
| 525 | + if ('disabled' === $link_class) { |
|
| 526 | 526 | // Convert link to '#' and unset open targets. |
| 527 | 527 | $atts['href'] = '#'; |
| 528 | - unset( $atts['target'] ); |
|
| 529 | - } elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) { |
|
| 528 | + unset($atts['target']); |
|
| 529 | + } elseif ('dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class) { |
|
| 530 | 530 | // Store a type flag and unset href and target. |
| 531 | - unset( $atts['href'] ); |
|
| 532 | - unset( $atts['target'] ); |
|
| 531 | + unset($atts['href']); |
|
| 532 | + unset($atts['target']); |
|
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -545,8 +545,8 @@ discard block |
||
| 545 | 545 | * @param string $text the string of text to be wrapped in a screen reader class. |
| 546 | 546 | * @return string the string wrapped in a span with the class. |
| 547 | 547 | */ |
| 548 | - private function wrap_for_screen_reader( $text = '' ) { |
|
| 549 | - if ( $text ) { |
|
| 548 | + private function wrap_for_screen_reader($text = '') { |
|
| 549 | + if ($text) { |
|
| 550 | 550 | $text = '<span class="sr-only">' . $text . '</span>'; |
| 551 | 551 | } |
| 552 | 552 | return $text; |
@@ -562,15 +562,15 @@ discard block |
||
| 562 | 562 | * |
| 563 | 563 | * @return string a string with the openign tag for the element with attribibutes added. |
| 564 | 564 | */ |
| 565 | - private function linkmod_element_open( $linkmod_type, $attributes = '' ) { |
|
| 565 | + private function linkmod_element_open($linkmod_type, $attributes = '') { |
|
| 566 | 566 | $output = ''; |
| 567 | - if ( 'dropdown-item-text' === $linkmod_type ) { |
|
| 567 | + if ('dropdown-item-text' === $linkmod_type) { |
|
| 568 | 568 | $output .= '<span class="dropdown-item-text"' . $attributes . '>'; |
| 569 | - } elseif ( 'dropdown-header' === $linkmod_type ) { |
|
| 569 | + } elseif ('dropdown-header' === $linkmod_type) { |
|
| 570 | 570 | // For a header use a span with the .h6 class instead of a real |
| 571 | 571 | // header tag so that it doesn't confuse screen readers. |
| 572 | 572 | $output .= '<span class="dropdown-header h6"' . $attributes . '>'; |
| 573 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 573 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 574 | 574 | // this is a divider. |
| 575 | 575 | $output .= '<div class="dropdown-divider"' . $attributes . '>'; |
| 576 | 576 | } |
@@ -586,13 +586,13 @@ discard block |
||
| 586 | 586 | * |
| 587 | 587 | * @return string a string with the closing tag for this linkmod type. |
| 588 | 588 | */ |
| 589 | - private function linkmod_element_close( $linkmod_type ) { |
|
| 589 | + private function linkmod_element_close($linkmod_type) { |
|
| 590 | 590 | $output = ''; |
| 591 | - if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) { |
|
| 591 | + if ('dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type) { |
|
| 592 | 592 | // For a header use a span with the .h6 class instead of a real |
| 593 | 593 | // header tag so that it doesn't confuse screen readers. |
| 594 | 594 | $output .= '</span>'; |
| 595 | - } elseif ( 'dropdown-divider' === $linkmod_type ) { |
|
| 595 | + } elseif ('dropdown-divider' === $linkmod_type) { |
|
| 596 | 596 | // this is a divider. |
| 597 | 597 | $output .= '</div>'; |
| 598 | 598 | } |