PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.4
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.4
4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / modules / megamenu / walker-nav-menu.php
elementskit-lite / modules / megamenu Last commit date
assets 1 day ago views 1 day ago api.php 1 day ago init.php 1 day ago options.php 4 years ago walker-nav-menu.php 1 day ago
walker-nav-menu.php
364 lines
1 <?php
2 namespace ElementsKit_Lite;
3
4 use \ElementsKit_Lite\Modules\Megamenu\Init;
5 use \ElementsKit_Lite\Libs\Framework\Attr;
6
7 class ElementsKit_Menu_Walker extends \Walker_Nav_Menu {
8
9 public $menu_Settings;
10
11 /**
12 * ID of the item most recently opened by start_el().
13 *
14 * The walker visits a parent before descending into its children, so this
15 * holds the parent's ID when start_lvl() runs for that submenu. It lets the
16 * panel carry an id for the parent link's aria-controls to point at, without
17 * altering any markup that already existed.
18 *
19 * @var int
20 */
21 private $ekit_parent_item_id = 0;
22
23 // custom methods
24 public function get_item_meta( $menu_item_id ) {
25 $meta_key = Init::$menuitem_settings_key;
26 $data = get_post_meta( $menu_item_id, $meta_key, true );
27 $data = (array) json_decode( $data );
28
29 $default = array(
30 'menu_id' => null,
31 'menu_has_child' => '',
32 'menu_enable' => 0,
33 'menu_icon' => '',
34 'menu_icon_color' => '',
35 'menu_badge_text' => '',
36 'menu_badge_color' => '',
37 'menu_badge_background' => '',
38 'mobile_submenu_content_type' => 'builder_content',
39 'vertical_megamenu_position_type' => 'relative_position',
40 'vertical_menu_width' => '',
41 'megamenu_width_type' => 'default_width',
42 'megamenu_ajax_load' => 'no',
43 );
44 return array_merge( $default, $data );
45 }
46
47 public function is_megamenu( $menu_slug ) {
48 $menu_obj = wp_get_nav_menu_object($menu_slug);
49 $menu_slug = ( ( ( gettype( $menu_obj ) == 'object' ) && ( isset( $menu_obj->slug ) ) ) ? $menu_obj->slug : $menu_slug );
50
51 $cache_key = 'elementskit_megamenu_data_' . $menu_slug;
52 $cached = wp_cache_get( $cache_key );
53 if ( false !== $cached ) {
54 return $cached;
55 }
56
57 $return = 0;
58
59 $modules_all = \ElementsKit_Lite\Config\Module_List::instance()->get_list();
60 $modules_active = \ElementsKit_Lite\Libs\Framework\Classes\Utils::instance()->get_option( 'module_list', $modules_all );
61 $modules_active = ( ! isset( $modules_active[0] ) ? array_keys( $modules_active ) : $modules_active );
62
63 $settings = Attr::instance()->utils->get_option( Init::$megamenu_settings_key, array() );
64 $term = get_term_by( 'slug', $menu_slug, 'nav_menu' );
65
66 if ( in_array( 'megamenu', $modules_active )
67 && isset( $term->term_id )
68 && isset( $settings[ 'menu_location_' . $term->term_id ] )
69 && $settings[ 'menu_location_' . $term->term_id ]['is_enabled'] == '1' ) {
70
71 $return = 1;
72 }
73
74 wp_cache_set( $cache_key, $return );
75 return $return;
76 }
77
78 public function is_megamenu_item( $item_meta, $menu ) {
79 if ( $this->is_megamenu( $menu ) == 1 && $item_meta['menu_enable'] == 1 && class_exists( 'Elementor\Plugin' ) ) {
80 return true;
81 }
82 return false;
83 }
84
85 /**
86 * Starts the list before the elements are added.
87 *
88 * @see Walker::start_lvl()
89 *
90 * @since 3.0.0
91 *
92 * @param string $output Passed by reference. Used to append additional content.
93 * @param int $depth Depth of menu item. Used for padding.
94 * @param array $args An array of arguments. @see wp_nav_menu()
95 */
96 public function start_lvl( &$output, $depth = 0, $args = array() ) {
97 $indent = str_repeat( "\t", $depth );
98 $submenu_id = $this->ekit_parent_item_id
99 ? ' id="ekit-submenu-' . esc_attr( $this->ekit_parent_item_id ) . '"'
100 : '';
101 $output .= "\n$indent<ul class=\"elementskit-dropdown elementskit-submenu-panel\"$submenu_id>\n";
102 }
103 /**
104 * Ends the list of after the elements are added.
105 *
106 * @see Walker::end_lvl()
107 *
108 * @since 3.0.0
109 *
110 * @param string $output Passed by reference. Used to append additional content.
111 * @param int $depth Depth of menu item. Used for padding.
112 * @param array $args An array of arguments. @see wp_nav_menu()
113 */
114 public function end_lvl( &$output, $depth = 0, $args = array() ) {
115 $indent = str_repeat( "\t", $depth );
116 $output .= "$indent</ul>\n";
117 }
118 /**
119 * Start the element output.
120 *
121 * @see Walker::start_el()
122 *
123 * @since 3.0.0
124 *
125 * @param string $output Passed by reference. Used to append additional content.
126 * @param object $item Menu item data object.
127 * @param int $depth Depth of menu item. Used for padding.
128 * @param array $args An array of arguments. @see wp_nav_menu()
129 * @param int $id Current item ID.
130 */
131 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
132 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
133 $classes = empty( $item->classes ) ? array() : (array) $item->classes;
134 $classes[] = 'menu-item-' . $item->ID;
135
136 /**
137 * Filter the CSS class(es) applied to a menu item's list item element.
138 *
139 * @since 3.0.0
140 * @since 4.1.0 The `$depth` parameter was added.
141 *
142 * @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
143 * @param object $item The current menu item.
144 * @param array $args An array of {@see wp_nav_menu()} arguments.
145 * @param int $depth Depth of menu item. Used for padding.
146 */
147 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
148 // New
149 $class_names .= ' nav-item';
150 $item_meta = $this->get_item_meta( $item->ID );
151 $is_megamenu_item = $this->is_megamenu_item( $item_meta, $args->menu );
152
153 if ( in_array( 'menu-item-has-children', $classes ) || $is_megamenu_item == true ) {
154 $class_names .= ' elementskit-dropdown-has ' . $item_meta['vertical_megamenu_position_type'] . ' elementskit-dropdown-menu-' . $item_meta['megamenu_width_type'] . '';
155 }
156
157 if ( $is_megamenu_item == true ) {
158 $class_names .= ' elementskit-megamenu-has';
159 }
160
161 if ( $item_meta['mobile_submenu_content_type'] == 'builder_content' ) {
162 $class_names .= ' elementskit-mobile-builder-content';
163 }
164
165 if ( in_array( 'current-menu-item', $classes ) ) {
166 $class_names .= ' active';
167 }
168
169 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
170
171 /**
172 * Filter the ID applied to a menu item's list item element.
173 *
174 * @since 3.0.1
175 * @since 4.1.0 The `$depth` parameter was added.
176 *
177 * @param string $menu_id The ID that is applied to the menu item's `<li>` element.
178 * @param object $item The current menu item.
179 * @param array $args An array of {@see wp_nav_menu()} arguments.
180 * @param int $depth Depth of menu item. Used for padding.
181 */
182 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
183 $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
184 // New
185 $data_attr = '';
186 switch ( $item_meta['megamenu_width_type'] ) {
187 case 'default_width':
188 $data_attr = esc_attr( ' data-vertical-menu=750px' );
189 break;
190
191 case 'full_width':
192 $data_attr = ' data-vertical-menu=""';
193 break;
194
195 case 'custom_width':
196 $data_attr = $item_meta['vertical_menu_width'] === '' ? esc_attr( ' data-vertical-menu=750px' ) : esc_attr( ' data-vertical-menu=' . $item_meta['vertical_menu_width'] . '' );
197 break;
198
199 default:
200 $data_attr = esc_attr( ' data-vertical-menu=750px' );
201 break;
202 }
203 //
204 $output .= $indent . '<li' . $id . $class_names . $data_attr . '>';
205 $atts = array();
206 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
207 $atts['target'] = ! empty( $item->target ) ? $item->target : '';
208 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
209 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
210
211 $submenu_indicator = '';
212
213 // New
214 if ( $depth === 0 ) {
215 $atts['class'] = 'ekit-menu-nav-link';
216 }
217 if ( $depth === 0 && in_array( 'menu-item-has-children', $classes ) ) {
218 $atts['class'] .= ' ekit-menu-dropdown-toggle';
219 }
220 if ( in_array( 'menu-item-has-children', $classes ) || $is_megamenu_item == true ) {
221 // Use an if statement to conditionally display the submenu indicator icon
222 if(!empty($args->submenu_indicator_icon)) {
223 $submenu_indicator .= $args->submenu_indicator_icon;
224 } else {
225 $submenu_indicator .= '<i class="icon icon-down-arrow1 elementskit-submenu-indicator" aria-hidden="true"></i>';
226 }
227 }
228 if ( $depth > 0 ) {
229 $manual_class = array_values( $classes )[0] . ' ' . 'dropdown-item';
230 $atts ['class'] = $manual_class;
231 }
232 if ( in_array( 'current-menu-item', $item->classes ) ) {
233 $atts['class'] .= ' active';
234 }
235
236 // Announce that this link opens a panel, and whether it is currently open.
237 // A mega menu item points at the panel end_el() emits; a plain parent item
238 // points at the <ul> start_lvl() emits. Added before the
239 // nav_menu_link_attributes filter so a theme can still override them.
240 $this->ekit_parent_item_id = $item->ID;
241
242 // end_el() only emits the mega panel at depth 0, so only point at it there —
243 // otherwise aria-controls would reference an id that is never rendered.
244 if ( $is_megamenu_item == true && $depth === 0 ) {
245 $atts['aria-haspopup'] = 'true';
246 $atts['aria-expanded'] = 'false';
247 $atts['aria-controls'] = 'ekit-megamenu-panel-' . $item->ID;
248 } elseif ( in_array( 'menu-item-has-children', $classes ) ) {
249 $atts['aria-haspopup'] = 'true';
250 $atts['aria-expanded'] = 'false';
251 $atts['aria-controls'] = 'ekit-submenu-' . $item->ID;
252 }
253
254 //
255 /**
256 * Filter the HTML attributes applied to a menu item's anchor element.
257 *
258 * @since 3.6.0
259 * @since 4.1.0 The `$depth` parameter was added.
260 *
261 * @param array $atts {
262 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
263 *
264 * @type string $title Title attribute.
265 * @type string $target Target attribute.
266 * @type string $rel The rel attribute.
267 * @type string $href The href attribute.
268 * }
269 * @param object $item The current menu item.
270 * @param array $args An array of {@see wp_nav_menu()} arguments.
271 * @param int $depth Depth of menu item. Used for padding.
272 */
273 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
274 $attributes = '';
275 foreach ( $atts as $attr => $value ) {
276 if ( ! empty( $value ) ) {
277 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
278 $attributes .= ' ' . $attr . '="' . $value . '"';
279 }
280 }
281 $item_output = $args->before;
282 // New
283
284 //
285 $item_output .= '<a' . $attributes . '>';
286
287 if ( $this->is_megamenu( $args->menu ) == 1 ) {
288 // add badge text
289 if ( $item_meta['menu_badge_text'] != '' ) {
290 $badge_background = sanitize_hex_color( $item_meta['menu_badge_background'] );
291 $badge_color = sanitize_hex_color( $item_meta['menu_badge_color'] );
292 $badge_style = 'background:' . $badge_background . '; color:' . $badge_color;
293 $badge_carret_style = 'border-top-color:' . $badge_background;
294 $item_output .= '<span style="' . esc_attr( $badge_style ) . '" class="ekit-menu-badge">' . esc_html( $item_meta['menu_badge_text'] ) . '<i style="' . esc_attr( $badge_carret_style ) . '" class="ekit-menu-badge-arrow"></i></span>';
295 }
296
297 // add menu icon & style
298 if ( $item_meta['menu_icon'] != '' ) {
299 $icon_style = 'color:' . sanitize_hex_color( $item_meta['menu_icon_color'] );
300 $item_output .= '<i class="ekit-menu-icon ' . esc_attr( $item_meta['menu_icon'] ) . '" style="' . esc_attr( $icon_style ) . '" aria-hidden="true"></i>';
301 }
302 }
303
304 /** This filter is documented in wp-includes/post-template.php */
305 $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
306 $item_output .= $submenu_indicator . '</a>';
307 $item_output .= $args->after;
308 /**
309 * Filter a menu item's starting output.
310 *
311 * The menu item's starting output only includes `$args->before`, the opening `<a>`,
312 * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
313 * no filter for modifying the opening and closing `<li>` for a menu item.
314 *
315 * @since 3.0.0
316 *
317 * @param string $item_output The menu item's starting HTML output.
318 * @param object $item Menu item data object.
319 * @param int $depth Depth of menu item. Used for padding.
320 * @param array $args An array of {@see wp_nav_menu()} arguments.
321 */
322 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
323 }
324 /**
325 * Ends the element output, if needed.
326 *
327 * @see Walker::end_el()
328 *
329 * @since 3.0.0
330 *
331 * @param string $output Passed by reference. Used to append additional content.
332 * @param object $item Page data object. Not used.
333 * @param int $depth Depth of page. Not Used.
334 * @param array $args An array of arguments. @see wp_nav_menu()
335 */
336 public function end_el( &$output, $item, $depth = 0, $args = array() ) {
337 if ( $depth === 0 ) {
338 if ( $this->is_megamenu( $args->menu ) == 1 ) {
339 $item_meta = $this->get_item_meta( $item->ID );
340 if ( $item_meta['menu_enable'] == 1 && class_exists( 'Elementor\Plugin' ) ) {
341 $builder_post_title = 'dynamic-content-megamenu-menuitem' . $item->ID;
342 $builder_post = Utils::get_page_by_title( $builder_post_title, 'elementskit_content' );
343 $output .= '<div class="elementskit-megamenu-panel" id="ekit-megamenu-panel-' . esc_attr( $item->ID ) . '">';
344 if ( $builder_post != null ) {
345 $mega_menu_output = \ElementsKit_Lite\Utils::render_elementor_content( $builder_post->ID );
346
347 // if ajax load is enable and not elementor editor mode
348 if(!empty($item_meta['megamenu_ajax_load']) && $item_meta['megamenu_ajax_load'] == 'yes') {
349 $mega_menu_output = sprintf('<div class="megamenu-ajax-load" data-id="%1$s"></div>', $builder_post->ID);
350 }
351
352 $output .= $mega_menu_output;
353 } else {
354 $output .= esc_html__( 'No content found', 'elementskit-lite' );
355 }
356
357 $output .= '</div>';
358 }
359 }
360 $output .= "</li>\n";
361 }
362 }
363 }
364