@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) return; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | class Lsx_Bootstrap_Navwalker extends Walker_Nav_Menu { |
5 | 5 | |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | * @param string $output Passed by reference. Used to append additional content. |
11 | 11 | * @param int $depth Depth of page. Used for padding. |
12 | 12 | */ |
13 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
14 | - $indent = str_repeat( "\t", $depth ); |
|
13 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
14 | + $indent = str_repeat("\t", $depth); |
|
15 | 15 | $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $item Passed by reference. Used to append additional content. |
20 | 20 | */ |
21 | - public function filter_default_pages( &$item ) { |
|
21 | + public function filter_default_pages(&$item) { |
|
22 | 22 | |
23 | 23 | return $item; |
24 | 24 | } |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | * @param int $current_page Menu item ID. |
34 | 34 | * @param object $args |
35 | 35 | */ |
36 | - public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
37 | - $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
|
36 | + public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
|
37 | + $indent = ($depth) ? str_repeat("\t", $depth) : ''; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * If this is a default menu being called we need to fix |
41 | 41 | * the item object thats coming through. |
42 | 42 | */ |
43 | - if(!isset($item->title)){ |
|
43 | + if ( ! isset($item->title)) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
@@ -52,63 +52,63 @@ discard block |
||
52 | 52 | * comparison that is not case sensitive. The strcasecmp() function returns |
53 | 53 | * a 0 if the strings are equal. |
54 | 54 | */ |
55 | - if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) { |
|
55 | + if (strcasecmp($item->attr_title, 'divider') == 0 && $depth === 1) { |
|
56 | 56 | $output .= $indent . '<li role="presentation" class="divider">'; |
57 | - } else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) { |
|
57 | + } else if (strcasecmp($item->title, 'divider') == 0 && $depth === 1) { |
|
58 | 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>'; |
|
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 | 63 | } else { |
64 | 64 | |
65 | 65 | $class_names = $value = ''; |
66 | 66 | |
67 | - $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
|
67 | + $classes = empty($item->classes) ? array() : (array) $item->classes; |
|
68 | 68 | $classes[] = 'menu-item-' . $item->ID; |
69 | 69 | |
70 | - $classes = apply_filters( 'lsx_nav_menu_css_class', array_filter( $classes ), $item, $args , $depth ); |
|
70 | + $classes = apply_filters('lsx_nav_menu_css_class', array_filter($classes), $item, $args, $depth); |
|
71 | 71 | |
72 | - $class_names = join( ' ', $classes ); |
|
72 | + $class_names = join(' ', $classes); |
|
73 | 73 | |
74 | - if ( $args->has_children ) |
|
74 | + if ($args->has_children) |
|
75 | 75 | $class_names .= ' dropdown'; |
76 | 76 | |
77 | - if ( in_array( 'current-menu-item', $classes ) ) |
|
77 | + if (in_array('current-menu-item', $classes)) |
|
78 | 78 | $class_names .= ' active'; |
79 | 79 | |
80 | - if ( in_array( 'current-menu-parent', $classes ) ) |
|
80 | + if (in_array('current-menu-parent', $classes)) |
|
81 | 81 | $class_names .= ' active'; |
82 | 82 | |
83 | 83 | //Check if this is ment to be a "social" type menu |
84 | - $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
|
84 | + $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; |
|
85 | 85 | |
86 | - $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); |
|
87 | - $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
|
86 | + $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args); |
|
87 | + $id = $id ? ' id="' . esc_attr($id) . '"' : ''; |
|
88 | 88 | |
89 | - $output .= $indent . '<li' . $id . $value . $class_names .'>'; |
|
89 | + $output .= $indent . '<li' . $id . $value . $class_names . '>'; |
|
90 | 90 | |
91 | 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 : ''; |
|
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 | 95 | |
96 | 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'; |
|
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 | 102 | } else { |
103 | - $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
|
103 | + $atts['href'] = ! empty($item->url) ? $item->url : ''; |
|
104 | 104 | } |
105 | 105 | |
106 | - $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); |
|
106 | + $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args); |
|
107 | 107 | |
108 | 108 | $attributes = ''; |
109 | - foreach ( $atts as $attr => $value ) { |
|
110 | - if ( ! empty( $value ) ) { |
|
111 | - $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
|
109 | + foreach ($atts as $attr => $value) { |
|
110 | + if ( ! empty($value)) { |
|
111 | + $value = ('href' === $attr) ? esc_url($value) : esc_attr($value); |
|
112 | 112 | $attributes .= ' ' . $attr . '="' . $value . '"'; |
113 | 113 | } |
114 | 114 | } |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | * if there is a value in the attr_title property. If the attr_title |
123 | 123 | * property is NOT null we apply it as the class name for the glyphicon. |
124 | 124 | */ |
125 | - if ( ! empty( $item->attr_title ) ) { |
|
126 | - $item_output .= '<a'. $attributes .'"><span class="glyphicon ' . esc_attr( $item->attr_title ) . '"></span> '; |
|
125 | + if ( ! empty($item->attr_title)) { |
|
126 | + $item_output .= '<a' . $attributes . '"><span class="glyphicon ' . esc_attr($item->attr_title) . '"></span> '; |
|
127 | 127 | } else { |
128 | - $item_output .= '<a'. $attributes .'>'; |
|
128 | + $item_output .= '<a' . $attributes . '>'; |
|
129 | 129 | } |
130 | 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>'; |
|
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 | 133 | $item_output .= $args->after; |
134 | 134 | |
135 | 135 | |
136 | 136 | |
137 | - $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); |
|
137 | + $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | * @param string $output Passed by reference. Used to append additional content. |
159 | 159 | * @return null Null on failure with no changes to parameters. |
160 | 160 | */ |
161 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
|
162 | - if ( ! $element ) |
|
161 | + public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { |
|
162 | + if ( ! $element) |
|
163 | 163 | return; |
164 | 164 | |
165 | 165 | $id_field = $this->db_fields['id']; |
166 | 166 | |
167 | 167 | // Display this element. |
168 | - if ( is_object( $args[0] ) ) |
|
169 | - $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); |
|
168 | + if (is_object($args[0])) |
|
169 | + $args[0]->has_children = ! empty($children_elements[$element->$id_field]); |
|
170 | 170 | |
171 | - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
|
171 | + parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * @param array $args passed from the wp_nav_menu function. |
183 | 183 | * |
184 | 184 | */ |
185 | - public static function fallback( $args ) { |
|
186 | - if ( current_user_can( 'manage_options' ) ) { |
|
185 | + public static function fallback($args) { |
|
186 | + if (current_user_can('manage_options')) { |
|
187 | 187 | $fb_output = null; |
188 | 188 | |
189 | - if ( $args['container'] ) { |
|
189 | + if ($args['container']) { |
|
190 | 190 | $fb_output = '<' . $args['container']; |
191 | 191 | |
192 | - if ( $args['container_id'] ) |
|
192 | + if ($args['container_id']) |
|
193 | 193 | $fb_output .= ' id="' . $args['container_id'] . '"'; |
194 | 194 | |
195 | - if ( $args['container_class'] ) |
|
195 | + if ($args['container_class']) |
|
196 | 196 | $fb_output .= ' class="' . $args['container_class'] . '"'; |
197 | 197 | |
198 | 198 | $fb_output .= '>'; |
@@ -200,20 +200,20 @@ discard block |
||
200 | 200 | |
201 | 201 | $fb_output .= '<ul'; |
202 | 202 | |
203 | - if ( $args['menu_id'] ) |
|
203 | + if ($args['menu_id']) |
|
204 | 204 | $fb_output .= ' id="' . $args['menu_id'] . '"'; |
205 | 205 | |
206 | - if ( $args['menu_class'] ) |
|
206 | + if ($args['menu_class']) |
|
207 | 207 | $fb_output .= ' class="' . $args['menu_class'] . '"'; |
208 | 208 | |
209 | 209 | $fb_output .= '>'; |
210 | - $fb_output .= '<li><a href="' . admin_url( 'nav-menus.php' ) . '">' . esc_html__( 'Add a menu', 'lsx' ) . '</a></li>'; |
|
210 | + $fb_output .= '<li><a href="' . admin_url('nav-menus.php') . '">' . esc_html__('Add a menu', 'lsx') . '</a></li>'; |
|
211 | 211 | $fb_output .= '</ul>'; |
212 | 212 | |
213 | - if ( $args['container'] ) |
|
213 | + if ($args['container']) |
|
214 | 214 | $fb_output .= '</' . $args['container'] . '>'; |
215 | 215 | |
216 | - echo wp_kses_post( $fb_output ); |
|
216 | + echo wp_kses_post($fb_output); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * Add in our custom classes to the menus |
224 | 224 | */ |
225 | -function wpml_nav_language_switcher_fix( $items , $args ) { |
|
226 | - $items = str_replace('menu-item-language-current','menu-item-language-current dropdown',$items); |
|
227 | - $items = str_replace('submenu-languages','submenu-languages dropdown-menu',$items); |
|
225 | +function wpml_nav_language_switcher_fix($items, $args) { |
|
226 | + $items = str_replace('menu-item-language-current', 'menu-item-language-current dropdown', $items); |
|
227 | + $items = str_replace('submenu-languages', 'submenu-languages dropdown-menu', $items); |
|
228 | 228 | return $items; |
229 | 229 | } |
230 | -add_filter( 'wp_nav_menu_items', 'wpml_nav_language_switcher_fix', 10, 2 ); |
|
230 | +add_filter('wp_nav_menu_items', 'wpml_nav_language_switcher_fix', 10, 2); |