1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly |
3
|
|
|
|
4
|
|
|
class Lsx_Bootstrap_Navwalker extends Walker_Nav_Menu { |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @see Walker::start_lvl() |
8
|
|
|
* @since 3.0.0 |
9
|
|
|
* |
10
|
|
|
* @param string $output Passed by reference. Used to append additional content. |
11
|
|
|
* @param int $depth Depth of page. Used for padding. |
12
|
|
|
*/ |
13
|
|
|
public function start_lvl( &$output, $depth = 0, $args = array() ) { |
14
|
|
|
$indent = str_repeat( "\t", $depth ); |
15
|
|
|
$output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n"; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $item Passed by reference. Used to append additional content. |
20
|
|
|
*/ |
21
|
|
|
public function filter_default_pages( &$item ) { |
22
|
|
|
|
23
|
|
|
return $item; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @see Walker::start_el() |
28
|
|
|
* @since 3.0.0 |
29
|
|
|
* |
30
|
|
|
* @param string $output Passed by reference. Used to append additional content. |
31
|
|
|
* @param object $item Menu item data object. |
32
|
|
|
* @param int $depth Depth of menu item. Used for padding. |
33
|
|
|
* @param int $current_page Menu item ID. |
|
|
|
|
34
|
|
|
* @param object $args |
35
|
|
|
*/ |
36
|
|
|
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
37
|
|
|
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* If this is a default menu being called we need to fix |
41
|
|
|
* the item object thats coming through. |
42
|
|
|
*/ |
43
|
|
|
if(!isset($item->title)){ |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Dividers, Headers or Disabled |
49
|
|
|
* ============================= |
50
|
|
|
* Determine whether the item is a Divider, Header, Disabled or regular |
51
|
|
|
* menu item. To prevent errors we use the strcasecmp() function to so a |
52
|
|
|
* comparison that is not case sensitive. The strcasecmp() function returns |
53
|
|
|
* a 0 if the strings are equal. |
54
|
|
|
*/ |
55
|
|
|
if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) { |
56
|
|
|
$output .= $indent . '<li role="presentation" class="divider">'; |
57
|
|
|
} else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) { |
58
|
|
|
$output .= $indent . '<li role="presentation" class="divider">'; |
59
|
|
|
} else if ( strcasecmp( $item->attr_title, 'dropdown-header') == 0 && $depth === 1 ) { |
60
|
|
|
$output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title ); |
61
|
|
|
} else if ( strcasecmp($item->attr_title, 'disabled' ) == 0 ) { |
62
|
|
|
$output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>'; |
63
|
|
|
} else { |
64
|
|
|
|
65
|
|
|
$class_names = $value = ''; |
|
|
|
|
66
|
|
|
|
67
|
|
|
$classes = empty( $item->classes ) ? array() : (array) $item->classes; |
68
|
|
|
$classes[] = 'menu-item-' . $item->ID; |
69
|
|
|
|
70
|
|
|
$classes = apply_filters( 'lsx_nav_menu_css_class', array_filter( $classes ), $item, $args , $depth ); |
71
|
|
|
|
72
|
|
|
$class_names = join( ' ', $classes ); |
73
|
|
|
|
74
|
|
|
if ( $args->has_children ) |
75
|
|
|
$class_names .= ' dropdown'; |
76
|
|
|
|
77
|
|
|
if ( in_array( 'current-menu-item', $classes ) ) |
78
|
|
|
$class_names .= ' active'; |
79
|
|
|
|
80
|
|
|
if ( in_array( 'current-menu-parent', $classes ) ) |
81
|
|
|
$class_names .= ' active'; |
82
|
|
|
|
83
|
|
|
//Check if this is ment to be a "social" type menu |
84
|
|
|
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
85
|
|
|
|
86
|
|
|
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); |
87
|
|
|
$id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
88
|
|
|
|
89
|
|
|
$output .= $indent . '<li' . $id . $value . $class_names .'>'; |
90
|
|
|
|
91
|
|
|
$atts = array(); |
92
|
|
|
$atts['title'] = ! empty( $item->title ) ? $item->title : ''; |
93
|
|
|
$atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
94
|
|
|
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
95
|
|
|
|
96
|
|
|
// If item has_children add atts to a. |
97
|
|
|
if ( $args->has_children ) { |
98
|
|
|
$atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
99
|
|
|
$atts['data-toggle'] = 'dropdown'; |
100
|
|
|
$atts['class'] = 'dropdown-toggle'; |
101
|
|
|
$atts['aria-haspopup'] = 'true'; |
102
|
|
|
} else { |
103
|
|
|
$atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
107
|
|
|
|
108
|
|
|
$attributes = ''; |
109
|
|
|
foreach ( $atts as $attr => $value ) { |
110
|
|
|
if ( ! empty( $value ) ) { |
111
|
|
|
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
112
|
|
|
$attributes .= ' ' . $attr . '="' . $value . '"'; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$item_output = $args->before; |
117
|
|
|
|
118
|
|
|
/* |
119
|
|
|
* Glyphicons |
120
|
|
|
* =========== |
121
|
|
|
* Since the the menu item is NOT a Divider or Header we check the see |
122
|
|
|
* if there is a value in the attr_title property. If the attr_title |
123
|
|
|
* property is NOT null we apply it as the class name for the glyphicon. |
124
|
|
|
*/ |
125
|
|
|
if ( ! empty( $item->attr_title ) ) { |
126
|
|
|
$item_output .= '<a'. $attributes .'"><span class="glyphicon ' . esc_attr( $item->attr_title ) . '"></span> '; |
127
|
|
|
} else { |
128
|
|
|
$item_output .= '<a'. $attributes .'>'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; |
132
|
|
|
$item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; |
133
|
|
|
$item_output .= $args->after; |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Traverse elements to create list from elements. |
143
|
|
|
* |
144
|
|
|
* Display one element if the element doesn't have any children otherwise, |
145
|
|
|
* display the element and its children. Will only traverse up to the max |
146
|
|
|
* depth and no ignore elements under that depth. |
147
|
|
|
* |
148
|
|
|
* This method shouldn't be called directly, use the walk() method instead. |
149
|
|
|
* |
150
|
|
|
* @see Walker::start_el() |
151
|
|
|
* @since 2.5.0 |
152
|
|
|
* |
153
|
|
|
* @param object $element Data object |
154
|
|
|
* @param array $children_elements List of elements to continue traversing. |
155
|
|
|
* @param int $max_depth Max depth to traverse. |
156
|
|
|
* @param int $depth Depth of current element. |
157
|
|
|
* @param array $args |
158
|
|
|
* @param string $output Passed by reference. Used to append additional content. |
159
|
|
|
* @return null Null on failure with no changes to parameters. |
160
|
|
|
*/ |
161
|
|
|
public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
162
|
|
|
if ( ! $element ) |
163
|
|
|
return; |
164
|
|
|
|
165
|
|
|
$id_field = $this->db_fields['id']; |
166
|
|
|
|
167
|
|
|
// Display this element. |
168
|
|
|
if ( is_object( $args[0] ) ) |
169
|
|
|
$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); |
170
|
|
|
|
171
|
|
|
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Menu Fallback |
176
|
|
|
* ============= |
177
|
|
|
* If this function is assigned to the wp_nav_menu's fallback_cb variable |
178
|
|
|
* and a manu has not been assigned to the theme location in the WordPress |
179
|
|
|
* menu manager the function with display nothing to a non-logged in user, |
180
|
|
|
* and will add a link to the WordPress menu manager if logged in as an admin. |
181
|
|
|
* |
182
|
|
|
* @param array $args passed from the wp_nav_menu function. |
183
|
|
|
* |
184
|
|
|
*/ |
185
|
|
|
public static function fallback( $args ) { |
186
|
|
|
if ( current_user_can( 'manage_options' ) ) { |
187
|
|
|
|
188
|
|
|
extract( $args ); |
189
|
|
|
|
190
|
|
|
$fb_output = null; |
191
|
|
|
|
192
|
|
|
if ( $container ) { |
193
|
|
|
$fb_output = '<' . $container; |
194
|
|
|
|
195
|
|
|
if ( $container_id ) |
196
|
|
|
$fb_output .= ' id="' . $container_id . '"'; |
197
|
|
|
|
198
|
|
|
if ( $container_class ) |
199
|
|
|
$fb_output .= ' class="' . $container_class . '"'; |
200
|
|
|
|
201
|
|
|
$fb_output .= '>'; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$fb_output .= '<ul'; |
205
|
|
|
|
206
|
|
|
if ( $menu_id ) |
207
|
|
|
$fb_output .= ' id="' . $menu_id . '"'; |
208
|
|
|
|
209
|
|
|
if ( $menu_class ) |
210
|
|
|
$fb_output .= ' class="' . $menu_class . '"'; |
211
|
|
|
|
212
|
|
|
$fb_output .= '>'; |
213
|
|
|
$fb_output .= '<li><a href="' . admin_url( 'nav-menus.php' ) . '">'.__('Add a menu','lsx').'</a></li>'; |
214
|
|
|
$fb_output .= '</ul>'; |
215
|
|
|
|
216
|
|
|
if ( $container ) |
217
|
|
|
$fb_output .= '</' . $container . '>'; |
218
|
|
|
|
219
|
|
|
echo wp_kses_post( $fb_output ); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Add in our custom classes to the menus |
227
|
|
|
*/ |
228
|
|
|
function wpml_nav_language_switcher_fix( $items , $args ) { |
|
|
|
|
229
|
|
|
$items = str_replace('menu-item-language-current','menu-item-language-current dropdown',$items); |
230
|
|
|
$items = str_replace('submenu-languages','submenu-languages dropdown-menu',$items); |
231
|
|
|
return $items; |
232
|
|
|
} |
233
|
|
|
add_filter( 'wp_nav_menu_items', 'wpml_nav_language_switcher_fix', 10, 2 ); |
234
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.