-
Notifications
You must be signed in to change notification settings - Fork 8
/
hooks.php
126 lines (107 loc) · 3.33 KB
/
hooks.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php if (!defined('FW')) die('Forbidden');
/**
* @param array $args
* @return array
* @internal
*/
function _filter_fw_ext_mega_menu_wp_nav_menu_args($args) {
// nav-menu-template.php L271
// $args['menu'] = ...
// nav-menu-template.php L363
// $args['menu_id'] = 'xxx-menu-id';
// $args['menu_class'] = 'xxx-menu-class';
// nav-menu-template.php L311
// $args['container'] = 'xxx-container'; // should be in apply_filters('wp_nav_menu_container_allowedtags')
// $args['container_id'] = 'xxx-container-id';
// $args['container_class'] = 'xxx-container-class';
// nav-menu-template.php L151
// $args['before'] = 'xxx-before';
// $args['after'] = 'xxx-after';
// $args['link_before'] = 'xxx-link-before';
// $args['link_after'] = 'xxx-link-after';
// nav-menu-template.php L405
// $args['items_wrap'] = '<ul id="%1$s" class="%2$s">%3$s</ul>';
$args['walker'] = new FW_Ext_Mega_Menu_Walker();
return $args;
}
add_filter('wp_nav_menu_args', '_filter_fw_ext_mega_menu_wp_nav_menu_args');
/**
* Just for removing FW_Ext_Mega_Menu_Walker set in the previous
* filter when the fallback menu is in action.
* @param array $args
* @return array
* @internal
*/
function _filter_fw_ext_mega_menu_wp_page_menu_args($args) {
if ($args['walker'] instanceof FW_Ext_Mega_Menu_Walker) {
$args['walker'] = '';
}
return $args;
}
add_filter('wp_page_menu_args', '_filter_fw_ext_mega_menu_wp_page_menu_args');
/**
* @param [WP_Post] $sorted_menu_items
* @param $args
* @return array
* @internal
*/
function _filter_fw_ext_mega_menu_wp_nav_menu_objects($sorted_menu_items, $args) {
// <li id="menu-item-1234" class="menu-item menu-item-type-post_type ... mega-menu">
// ....
// </li>
$mega_menu = array();
foreach ($sorted_menu_items as $item) {
if ($item->menu_item_parent == 0 && fw_ext_mega_menu_get_meta($item, 'enabled')) {
$mega_menu[$item->ID] = true;
}
}
foreach ($sorted_menu_items as $item) {
if (isset($mega_menu[$item->ID])) {
$item->classes[] = 'menu-item-has-mega-menu';
}
if (isset($mega_menu[$item->menu_item_parent])) {
$item->classes[] = 'mega-menu-col';
}
if (fw_ext_mega_menu_get_meta($item, 'icon')) {
$item->classes[] = 'menu-item-has-icon';
}
}
return $sorted_menu_items;
}
add_filter('wp_nav_menu_objects', '_filter_fw_ext_mega_menu_wp_nav_menu_objects', 10, 2);
/**
* nav-menu-template.php L174
* Walker_Nav_Menu::start_el
*
* @param $item_output
* @param $item
* @param $depth
* @param $args
* @return string
* @internal
*/
function _filter_fw_ext_mega_menu_walker_nav_menu_start_el($item_output, $item, $depth, $args) {
/** @since 1.1.3 */
if (apply_filters('fw:ext:megamenu:start_el_item_content:disable', false, $item)) {
return $item_output;
}
if (!fw_ext_mega_menu_is_mm_item($item)) {
return $item_output;
}
// <li>
// {{ item_output }}
// <div>{{ item.description }}</div>
// <div class="mega-menu">
// <ul class="sub-menu"></ul>
// </div>
// </li>
if ($depth > 0 && fw_ext_mega_menu_get_meta($item, 'title-off')) {
$item_output = '';
}
// Note that raw description is stored in post_content field.
if ($depth > 0 && trim($item->post_content)) {
$item_output .= '<div>' . do_shortcode($item->post_content) . '</div>';
}
return $item_output;
}
add_filter('walker_nav_menu_start_el', '_filter_fw_ext_mega_menu_walker_nav_menu_start_el', 10, 4);