Passed
Push — master ( e51c9a...41921a )
by Chris
04:16
created

includes/classes/class-lsx-nav-walker.php (35 issues)

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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
11
	exit;
12
}
13
14
if ( ! class_exists( 'Walker_Nav_Menu' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
15
	return;
16
}
17
18
if ( ! class_exists( 'LSX_Nav_Walker' ) ) :
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
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...
Expected 2 blank lines before function; 1 found
Loading history...
38
			return preg_match( '/^(current[-_])|active|dropdown$/', $classes );
39
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
40
41
		function start_lvl( &$output, $depth = 0, $args = array() ) {
0 ignored issues
show
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
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
44
45
		function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
0 ignored issues
show
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 ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
49
				parent::start_el( $item_html, $item, $depth, $args );
50
51
				if ( $item->is_dropdown && ( 0 === $depth ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
55
					$item_html = preg_replace( '/<a[^>]*>.*?<\/a>/iU', '', $item_html );
56
				} elseif ( stristr( $item_html, 'li class="dropdown-header"' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
64
65
		function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
0 ignored issues
show
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 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
69
				if ( $depth > 0 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
78
79
	}
80
81
endif;
82