LSX_Nav_Walker::check_current()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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' ) ) {
11
	exit;
12
}
13
14
if ( ! class_exists( 'Walker_Nav_Menu' ) ) {
15
	return;
16
}
17
18
if ( ! class_exists( 'LSX_Nav_Walker' ) ) :
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function check_current()
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
38
			return preg_match( '/^(current[-_])|active|dropdown$/', $classes );
39
		}
40
41
		function start_lvl( &$output, $depth = 0, $args = array() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function start_lvl()
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
42
			$output .= "\n<ul class=\"dropdown-menu\">\n";
43
		}
44
45
		function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function start_el()
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
46
			$item_html = '';
47
48
			if ( isset( $item->title ) ) {
49
				parent::start_el( $item_html, $item, $depth, $args );
50
51
				if ( $item->is_dropdown && ( 0 === $depth ) ) {
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"' ) ) {
55
					$item_html = preg_replace( '/<a[^>]*>.*?<\/a>/iU', '', $item_html );
56
				} elseif ( stristr( $item_html, 'li class="dropdown-header"' ) ) {
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
		}
64
65
		function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Documentation introduced by
Missing doc comment for function display_element()
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
66
			$element->is_dropdown = ( ( ! empty( $children_elements[ $element->ID ] ) && ( ( $depth + 1 ) < $max_depth || ( 0 === $max_depth ) ) ) );
67
68
			if ( $element->is_dropdown ) {
69
				if ( $depth > 0 ) {
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
		}
78
79
	}
80
81
endif;
82