PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.4
Easy Elements for Elementor – Addons & Website Templates v1.4.4
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.4.4, at widgets/navigation-menu/menu-walker.php

138 lines 6.0 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
23 // Mega menu (Elementor template) ke o has_children hisebe treat kori,
24 // jate dropdown icon, submenu class ar aria attributes thik moto add hoy.
25 $has_megamenu_template = false;
26 if ( function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_megamenu_builder' ) ) {
27 $mm_template_id = get_post_meta( $item->ID, 'easyel__menu_item_elementor_template', true );
28 if ( ! empty( $mm_template_id ) ) $has_megamenu_template = true;
29 }
30 $has_children_or_megamenu = $args->has_children || $has_megamenu_template;
31
32 $submenu = $has_children_or_megamenu ? ' eel-has-submenu' : '';
33
34 if ( 0 === $depth ) array_push( $classes, 'parent' );
35 if ( $has_children_or_megamenu ) array_push( $classes, 'menu-item-has-children' );
36
37 // last-item logic
38 $is_last_item = false;
39 $menu_last_item_setting = isset( $args->menu_last_item ) ? $args->menu_last_item : '';
40 if ( $depth === 0 ) {
41 $menu_items = wp_get_nav_menu_items( $args->menu );
42 if ( $menu_items && is_array( $menu_items ) ) {
43 $top_level_items = array_filter( $menu_items, fn($menu_item) => $menu_item->menu_item_parent == 0 );
44 $last_top_level_item = end( $top_level_items );
45 if ( $last_top_level_item && $last_top_level_item->ID === $item->ID ) $is_last_item = true;
46 }
47 }
48 if ( $is_last_item && $menu_last_item_setting === 'cta' ) $classes[] = 'last-item';
49
50 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
51 $filtered_classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
52 if ( ! is_array( $filtered_classes ) ) $filtered_classes = array_filter( $classes );
53
54
55 $class_names = ' class="' . esc_attr( join( ' ', $filtered_classes ) ) . $submenu . ' eel-creative-menu"';
56
57 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
58 $value = apply_filters( 'nav_menu_li_values', $value );
59
60 $output .= $indent . '<li id="menu-item-' . $item->ID . '"' . $value . $class_names . '>';
61
62 // anchor attributes
63 if ( isset( $item->target ) && '_blank' === $item->target && isset( $item->xfn ) && false === strpos( $item->xfn, 'noopener' ) ) $rel_xfn = ' noopener';
64 if ( isset( $item->target ) && '_blank' === $item->target && isset( $item->xfn ) && empty( $item->xfn ) ) $rel_blank = 'rel="noopener"';
65
66 $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
67 $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
68 $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . $rel_xfn . '"' : '' . $rel_blank;
69 $attributes .= ! empty( $item->url ) ? ' href="' . esc_url( $item->url ) . '"' : '';
70 if ( $has_children_or_megamenu ) $attributes .= ' aria-haspopup="true" aria-expanded="false"';
71
72 $atts = apply_filters( 'Easyel_Menu_Walker_nav_menu_attrs', $attributes );
73
74 $item_output = $args->before;
75 $item_output .= '<a' . $atts;
76 if ( 0 === $depth ) {
77 $anchor_class = 'eel-menu-item';
78 if ( $is_last_item && $menu_last_item_setting === 'cta' ) $anchor_class .= ' elementor-button';
79 $item_output .= ' class="' . $anchor_class . '"';
80 } else {
81 $item_output .= in_array( 'current-menu-item', $classes ) ? ' class="eel-sub-menu-item eel-sub-menu-item-active"' : ' class="eel-sub-menu-item"';
82 }
83 $item_output .= '>';
84 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
85 $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
86 $item_output .= '</a>';
87 $item_output .= $args->after;
88
89 if ( function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_megamenu_builder' ) ) {
90 if ( class_exists( '\Elementor\Plugin' ) && ! \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
91 $template_id = get_post_meta( $item->ID, 'easyel__menu_item_elementor_template', true );
92 if ( ! empty( $template_id ) ) {
93 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
94 $css_file = new \Elementor\Core\Files\CSS\Post( $template_id );
95 $css_file->enqueue();
96 }
97 $template_content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id );
98 if ( $template_content ) {
99 $item_output .= '<ul class="easyel--elementor-template-mega-menu easyel-mega--current sub-menu">' . $template_content . '</ul>';
100 }
101 }
102 }
103 }
104
105 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
106 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
107 }
108
109 /**
110 * Start level (submenu)
111 */
112 public function start_lvl( &$output, $depth = 0, $args = [] ) {
113 $indent = str_repeat( "\t", $depth );
114 $submenu_class = 'sub-menu';
115 if ( $depth > 0 ) $submenu_class .= ' sub-sub-menu';
116 $output .= "\n" . $indent . '<ul class="' . $submenu_class . '">' . "\n";
117 }
118
119 /**
120 * End level (submenu)
121 */
122 public function end_lvl( &$output, $depth = 0, $args = [] ) {
123 $indent = str_repeat( "\t", $depth );
124 $output .= $indent . "</ul>\n";
125 }
126
127 /**
128 * Display element (children check)
129 */
130 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
131 $id_field = $this->db_fields['id'];
132 if ( is_object( $args[0] ) ) {
133 $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
134 }
135 return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
136 }
137 }
138