lightspeeddevelopment /
lsx
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * LSX functions and definitions - Navigation Walker. |
||
| 4 | * |
||
| 5 | * @package lsx |
||
| 6 | * @subpackage navigation |
||
| 7 | * @category bootstrap-walker |
||
| 8 | */ |
||
| 9 | |||
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 11 | exit; |
||
| 12 | } |
||
| 13 | |||
| 14 | if ( ! class_exists( 'Walker_Nav_Menu' ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 15 | return; |
||
| 16 | } |
||
| 17 | |||
| 18 | if ( ! class_exists( 'LSX_Nav_Walker' ) ) : |
||
|
0 ignored issues
–
show
|
|||
| 19 | |||
| 20 | /** |
||
| 21 | * Cleaner walker for wp_nav_menu() |
||
| 22 | * |
||
| 23 | * Walker_Nav_Menu (WordPress default) example output: |
||
| 24 | * <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li> |
||
| 25 | * <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l |
||
| 26 | * |
||
| 27 | * LSX_Nav_Walker example output: |
||
| 28 | * <li class="menu-home"><a href="/">Home</a></li> |
||
| 29 | * <li class="menu-sample-page"><a href="/sample-page/">Sample Page</a></li> |
||
| 30 | * |
||
| 31 | * @package lsx |
||
| 32 | * @subpackage navigation |
||
| 33 | * @category bootstrap-walker |
||
| 34 | */ |
||
| 35 | class LSX_Nav_Walker extends Walker_Nav_Menu { |
||
| 36 | |||
| 37 | function check_current( $classes ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
check_current.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 38 | return preg_match( '/^(current[-_])|active|dropdown$/', $classes ); |
||
| 39 | } |
||
|
0 ignored issues
–
show
|
|||
| 40 | |||
| 41 | function start_lvl( &$output, $depth = 0, $args = array() ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
start_lvl.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 42 | $output .= "\n<ul class=\"dropdown-menu\">\n"; |
||
| 43 | } |
||
|
0 ignored issues
–
show
|
|||
| 44 | |||
| 45 | function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
start_el.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 46 | $item_html = ''; |
||
| 47 | |||
| 48 | if ( isset( $item->title ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 49 | parent::start_el( $item_html, $item, $depth, $args ); |
||
| 50 | |||
| 51 | if ( $item->is_dropdown && ( 0 === $depth ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 52 | $item_html = str_replace( '<a', '<a class="dropdown-toggle" data-target="#"', $item_html ); |
||
| 53 | $item_html = str_replace( '</a>', ' <b class="caret"></b></a>', $item_html ); |
||
| 54 | } elseif ( stristr( $item_html, 'li class="divider"' ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 55 | $item_html = preg_replace( '/<a[^>]*>.*?<\/a>/iU', '', $item_html ); |
||
| 56 | } elseif ( stristr( $item_html, 'li class="dropdown-header"' ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 57 | $item_html = preg_replace( '/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html ); |
||
| 58 | } |
||
| 59 | |||
| 60 | $item_html = apply_filters( 'lsx_wp_nav_menu_item', $item_html ); |
||
| 61 | $output .= $item_html; |
||
| 62 | } |
||
| 63 | } |
||
|
0 ignored issues
–
show
|
|||
| 64 | |||
| 65 | function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
display_element.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 66 | $element->is_dropdown = ( ( ! empty( $children_elements[ $element->ID ] ) && ( ( $depth + 1 ) < $max_depth || ( 0 === $max_depth ) ) ) ); |
||
| 67 | |||
| 68 | if ( $element->is_dropdown ) { |
||
|
0 ignored issues
–
show
|
|||
| 69 | if ( $depth > 0 ) { |
||
|
0 ignored issues
–
show
|
|||
| 70 | $element->classes[] = 'dropdown-submenu'; |
||
| 71 | } else { |
||
| 72 | $element->classes[] = 'dropdown'; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
||
| 77 | } |
||
|
0 ignored issues
–
show
|
|||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | endif; |
||
| 82 |