@@ -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 |