forked from bigvoodoo/bvi-mega-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalker-nav-mega-menu.php
93 lines (75 loc) · 2.93 KB
/
walker-nav-mega-menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Create HTML list of Mega Menu items.
* @see Walker_Nav_Menu
* @see Walker
* @author firejdl
*/
class Walker_Nav_Mega_Menu extends Walker_Nav_Menu {
/**
* @see Walker::$tree_type
*/
var $tree_type = array('mega_menu');
/**
* @see Walker::$db_fields
*/
var $db_fields = array(
'parent' => 'parent_id',
'id' => 'ID',
);
/**
* Overrides Walker_Nav_Menu::start_el() to display some of our special stuffs.
*
* @see Walker_Nav_Menu::start_el()
* @see Walker::start_el()
* @see Walker::walk()
*/
function start_el(&$output, $item, $depth = 0, $args = array(), $current_object_id = 0) {
global $post;
$indent = ($depth) ? str_repeat("\t", $depth) : '';
$class_names = '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
$classes[] = 'menu-item-depth-' . $depth;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
$id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args);
$id = $id ? ' id="' . esc_attr($id) . '"' : '';
$output .= $indent . '<li' . $id . $class_names .'>';
$item_output = '';
if ($item->post_id || isset($item->url)) {
if ($item->post_id) {
$url = get_permalink($item->post_id);
} else {
$url = $item->url;
}
$attributes = '';
$attributes .= ! empty($url) ? ' href="' . esc_attr($url ) .'"' : '';
$attributes .= ! empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) .'"' : '';
$attributes .= ! empty($item->target) ? ' target="' . esc_attr($item->target ) .'"' : '';
$attributes .= ! empty($item->xfn) ? ' rel="' . esc_attr($item->xfn ) .'"' : '';
if($depth == 0) {
$attributes .= ' aria-haspopup="true" aria-expanded="false"';
}
$item_output = '<a'. $attributes .'>' . $args->link_before . apply_filters('the_title', $item->post_title, $item->ID) . $args->link_after . '</a>';
if($depth == 0 && !empty($args->aria_button) && $args->aria_button == true) {
$item_output .= '<button class="aria-button"><span></span></button>';
}
} else if ($item->type == 'shortcode') {
$item_output = do_shortcode(htmlspecialchars_decode($item->post_title, ENT_QUOTES));
} else if (isset($item->post_title)) {
$item_output = '<span>'.$item->post_title.'</span>';
}
$item_output = $args->before . $item_output . $args->after;
if(!empty($args->mega_wrapper) && $depth == 0) {
$item_output .= $args->mega_wrapper;
}
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
function end_el(&$output, $item, $depth = 0, $args = array()) {
$output .= apply_filters('walker_nav_menu_end_el', '', $item, $depth, $args);
if(!empty($args->mega_wrapper_end) && $depth == 0) {
$output .= $args->mega_wrapper_end;
}
parent::end_el($output, $item, $depth, $args);
}
}