PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.9
Easy Elements for Elementor – Addons & Website Templates v1.3.9
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / navigation-menu / menu-walker.php

menu-walker.php in Easy Elements for Elementor – Addons & Website Templates 1.3.9, at widgets/navigation-menu/menu-walker.php

128 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class Easyel_Menu_Walker extends \Walker_Nav_Menu {
7
8 /**
9 * Start element
10 */
11 public function start_el( &$output, $item, $depth = 0, $args = [], $id = 0 ) {
12
13 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
14 $args = (object) $args;
15
16 $class_names = '';
17 $value = '';
18 $rel_xfn = '';
19 $rel_blank = '';
20
21 $classes = ! empty( $item->classes ) && is_array( $item->classes ) ? $item->classes : [];
22 $submenu = $args->has_children ? ' eel-has-submenu' : '';
23
24 if ( 0 === $depth ) array_push( $classes, 'parent' );
25 if ( $args->has_children ) array_push( $classes, 'menu-item-has-children' );
26
27 // last-item logic
28 $is_last_item = false;
29 $menu_last_item_setting = isset( $args->menu_last_item ) ? $args->menu_last_item : '';
30 if ( $depth === 0 ) {
31 $menu_items = wp_get_nav_menu_items( $args->menu );
32 if ( $menu_items && is_array( $menu_items ) ) {
33 $top_level_items = array_filter( $menu_items, fn($menu_item) => $menu_item->menu_item_parent == 0 );
34 $last_top_level_item = end( $top_level_items );
35 if ( $last_top_level_item && $last_top_level_item->ID === $item->ID ) $is_last_item = true;
36 }
37 }
38 if ( $is_last_item && $menu_last_item_setting === 'cta' ) $classes[] = 'last-item';
39
40 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
41 $filtered_classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
42 if ( ! is_array( $filtered_classes ) ) $filtered_classes = array_filter( $classes );
43
44
45 $class_names = ' class="' . esc_attr( join( ' ', $filtered_classes ) ) . $submenu . ' eel-creative-menu"';
46
47 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
48 $value = apply_filters( 'nav_menu_li_values', $value );
49
50 $output .= $indent . '<li id="menu-item-' . $item->ID . '"' . $value . $class_names . '>';
51
52 // anchor attributes
53 if ( isset( $item->target ) && '_blank' === $item->target && isset( $item->xfn ) && false === strpos( $item->xfn, 'noopener' ) ) $rel_xfn = ' noopener';
54 if ( isset( $item->target ) && '_blank' === $item->target && isset( $item->xfn ) && empty( $item->xfn ) ) $rel_blank = 'rel="noopener"';
55
56 $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
57 $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
58 $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . $rel_xfn . '"' : '' . $rel_blank;
59 $attributes .= ! empty( $item->url ) ? ' href="' . esc_url( $item->url ) . '"' : '';
60 if ( $args->has_children ) $attributes .= ' aria-haspopup="true" aria-expanded="false"';
61
62 $atts = apply_filters( 'Easyel_Menu_Walker_nav_menu_attrs', $attributes );
63
64 $item_output = $args->before;
65 $item_output .= '<a' . $atts;
66 if ( 0 === $depth ) {
67 $anchor_class = 'eel-menu-item';
68 if ( $is_last_item && $menu_last_item_setting === 'cta' ) $anchor_class .= ' elementor-button';
69 $item_output .= ' class="' . $anchor_class . '"';
70 } else {
71 $item_output .= in_array( 'current-menu-item', $classes ) ? ' class="eel-sub-menu-item eel-sub-menu-item-active"' : ' class="eel-sub-menu-item"';
72 }
73 $item_output .= '>';
74 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
75 $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
76 $item_output .= '</a>';
77 $item_output .= $args->after;
78
79 // ---------------------------
80 // Elementor Mega Menu Injection
81 // ---------------------------
82
83 if ( function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_megamenu_builder' ) ) {
84 if ( class_exists( '\Elementor\Plugin' ) && ! \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
85 $template_id = get_post_meta( $item->ID, 'easyel__menu_item_elementor_template', true );
86 if ( $template_id !== false ) {
87 $template_content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id );
88 if ( $template_content ) {
89 $item_output .= '<ul class="easyel--elementor-template-mega-menu easyel-mega--current sub-menu">' . $template_content . '</ul>';
90 }
91 }
92 }
93 }
94
95 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
96 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
97 }
98
99 /**
100 * Start level (submenu)
101 */
102 public function start_lvl( &$output, $depth = 0, $args = [] ) {
103 $indent = str_repeat( "\t", $depth );
104 $submenu_class = 'sub-menu';
105 if ( $depth > 0 ) $submenu_class .= ' sub-sub-menu';
106 $output .= "\n" . $indent . '<ul class="' . $submenu_class . '">' . "\n";
107 }
108
109 /**
110 * End level (submenu)
111 */
112 public function end_lvl( &$output, $depth = 0, $args = [] ) {
113 $indent = str_repeat( "\t", $depth );
114 $output .= $indent . "</ul>\n";
115 }
116
117 /**
118 * Display element (children check)
119 */
120 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
121 $id_field = $this->db_fields['id'];
122 if ( is_object( $args[0] ) ) {
123 $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
124 }
125 return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
126 }
127 }
128