Version Description
- Refactor: Improve method to determine the depth of a menu item (when loading menu item options in back end)
Download this release
Release Info
Developer | megamenu |
Plugin | Max Mega Menu |
Version | 2.7.7 |
Comparing to | |
See all releases |
Code changes from version 2.7.6 to 2.7.7
- classes/menu-item-manager.class.php +40 -8
- js/admin.js +12 -33
- megamenu.php +20 -8
- readme.txt +5 -1
classes/menu-item-manager.class.php
CHANGED
@@ -48,19 +48,45 @@ class Mega_Menu_Menu_Item_Manager {
|
|
48 |
$this->menu_id = $this->get_menu_id_for_menu_item_id( $this->menu_item_id );
|
49 |
$this->menu_item_objects = wp_get_nav_menu_items( $this->menu_id );
|
50 |
$this->menu_item_title = $this->get_title_for_menu_item_id( $this->menu_item_id, $this->menu_item_objects );
|
51 |
-
|
52 |
-
if ( isset( $_POST['menu_item_depth'] ) ) {
|
53 |
-
$this->menu_item_depth = absint( $_POST['menu_item_depth'] );
|
54 |
-
}
|
55 |
-
|
56 |
$saved_settings = array_filter( (array) get_post_meta( $this->menu_item_id, '_megamenu', true ) );
|
57 |
$this->menu_item_meta = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $saved_settings );
|
58 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
//
|
62 |
-
// $this->menu_id = absint( $_POST['menu_id'] );
|
63 |
-
//}
|
64 |
}
|
65 |
|
66 |
|
@@ -136,6 +162,12 @@ class Mega_Menu_Menu_Item_Manager {
|
|
136 |
|
137 |
$response['title'] = $this->menu_item_title;
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
$response = apply_filters( "megamenu_tabs", $response, $this->menu_item_id, $this->menu_id, $this->menu_item_depth, $this->menu_item_meta );
|
140 |
|
141 |
if ( ob_get_contents() ) ob_clean(); // remove any warnings or output from other plugins which may corrupt the response
|
48 |
$this->menu_id = $this->get_menu_id_for_menu_item_id( $this->menu_item_id );
|
49 |
$this->menu_item_objects = wp_get_nav_menu_items( $this->menu_id );
|
50 |
$this->menu_item_title = $this->get_title_for_menu_item_id( $this->menu_item_id, $this->menu_item_objects );
|
51 |
+
$this->menu_item_depth = $this->get_menu_item_depth( $this->menu_item_id, $this->menu_item_objects );
|
|
|
|
|
|
|
|
|
52 |
$saved_settings = array_filter( (array) get_post_meta( $this->menu_item_id, '_megamenu', true ) );
|
53 |
$this->menu_item_meta = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $saved_settings );
|
54 |
}
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Get the depth for a menu item ID
|
59 |
+
*
|
60 |
+
* @since 2.7.7
|
61 |
+
* @param int $menu_item_id
|
62 |
+
* @param array $menu_item_objects
|
63 |
+
* @return int
|
64 |
+
*/
|
65 |
+
public function get_menu_item_depth( $menu_item_id, $menu_item_objects ) {
|
66 |
+
$parents = array();
|
67 |
+
|
68 |
+
foreach ( $menu_item_objects as $key => $item ) {
|
69 |
+
if ( $item->menu_item_parent == 0 ) {
|
70 |
+
|
71 |
+
if ( $item->ID == $menu_item_id ) {
|
72 |
+
return 0; // top level item
|
73 |
+
}
|
74 |
+
|
75 |
+
$parents[] = $item->ID;
|
76 |
+
}
|
77 |
+
}
|
78 |
|
79 |
+
if ( count( $parents ) ) {
|
80 |
+
foreach ( $menu_item_objects as $key => $item ) {
|
81 |
+
if ( in_array( $item->menu_item_parent, $parents ) ) {
|
82 |
+
if ( $item->ID == $menu_item_id ) {
|
83 |
+
return 1; // second level item
|
84 |
+
}
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
|
89 |
+
return 2; // third level item or above
|
|
|
|
|
90 |
}
|
91 |
|
92 |
|
162 |
|
163 |
$response['title'] = $this->menu_item_title;
|
164 |
|
165 |
+
$response['active_tab'] = "mega_menu";
|
166 |
+
|
167 |
+
if ( $this->menu_item_depth > 0 ) {
|
168 |
+
$response['active_tab'] = "general_settings";
|
169 |
+
}
|
170 |
+
|
171 |
$response = apply_filters( "megamenu_tabs", $response, $this->menu_item_id, $this->menu_id, $this->menu_item_depth, $this->menu_item_meta );
|
172 |
|
173 |
if ( ob_get_contents() ) ob_clean(); // remove any warnings or output from other plugins which may corrupt the response
|
js/admin.js
CHANGED
@@ -68,9 +68,7 @@
|
|
68 |
data: {
|
69 |
action: "mm_get_lightbox_html",
|
70 |
_wpnonce: megamenu.nonce,
|
71 |
-
menu_item_id: panel.settings.menu_item_id
|
72 |
-
menu_item_depth: panel.settings.menu_item_depth,
|
73 |
-
menu_id: panel.settings.menu_id
|
74 |
},
|
75 |
cache: false,
|
76 |
beforeSend: function() {
|
@@ -88,18 +86,16 @@
|
|
88 |
var json = $.parseJSON(response.data);
|
89 |
|
90 |
var header_container = $("<div />").addClass("mm_header_container");
|
91 |
-
|
92 |
var title = $("<div />").addClass("mm_title");
|
93 |
-
|
94 |
var saving = $("<div class='mm_saving'>" + megamenu.saving + "</div>");
|
95 |
|
96 |
header_container.append(title).append(saving);
|
97 |
|
|
|
98 |
var tabs_container = $("<div class='mm_tab_container' />");
|
99 |
-
|
100 |
var content_container = $("<div class='mm_content_container' />");
|
101 |
|
102 |
-
if (
|
103 |
content_container.html(response);
|
104 |
}
|
105 |
|
@@ -110,6 +106,11 @@
|
|
110 |
return;
|
111 |
}
|
112 |
|
|
|
|
|
|
|
|
|
|
|
113 |
var content = $("<div />").addClass("mm_content").addClass(idx).html(this.content).hide();
|
114 |
|
115 |
// bind save button action
|
@@ -196,12 +197,6 @@
|
|
196 |
content.show();
|
197 |
});
|
198 |
|
199 |
-
if ((panel.settings.menu_item_depth == 0 && idx == "mega_menu") ||
|
200 |
-
(panel.settings.menu_item_depth > 0 && idx == "general_settings")) {
|
201 |
-
content.show();
|
202 |
-
tab.addClass("active");
|
203 |
-
}
|
204 |
-
|
205 |
tabs_container.append(tab);
|
206 |
|
207 |
$(".mm_tab_horizontal", content).on("click", function() {
|
@@ -235,7 +230,9 @@
|
|
235 |
content_container.append(content);
|
236 |
});
|
237 |
|
238 |
-
$("
|
|
|
|
|
239 |
$("#cboxLoadedContent").css({
|
240 |
"width": "100%",
|
241 |
"height": "100%",
|
@@ -1153,12 +1150,6 @@
|
|
1153 |
jQuery(function($) {
|
1154 |
"use strict";
|
1155 |
|
1156 |
-
$(".menu").on("click", ".megamenu_launch", function(e) {
|
1157 |
-
e.preventDefault();
|
1158 |
-
|
1159 |
-
$(this).megaMenu();
|
1160 |
-
});
|
1161 |
-
|
1162 |
$("#megamenu_accordion").accordion({
|
1163 |
heightStyle: "content",
|
1164 |
collapsible: true,
|
@@ -1183,16 +1174,9 @@ jQuery(function($) {
|
|
1183 |
$("#menu-to-edit li.menu-item").each(function() {
|
1184 |
|
1185 |
var menu_item = $(this);
|
1186 |
-
var menu_id = $("input#menu").val();
|
1187 |
-
var title = menu_item.find(".menu-item-title").text();
|
1188 |
|
1189 |
menu_item.data("megamenu_has_button", "true");
|
1190 |
|
1191 |
-
// fix for Jupiter theme
|
1192 |
-
if (!title) {
|
1193 |
-
title = menu_item.find(".item-title").text();
|
1194 |
-
}
|
1195 |
-
|
1196 |
var id = parseInt(menu_item.attr("id").match(/[0-9]+/)[0], 10);
|
1197 |
|
1198 |
var button = $("<span>").addClass("mm_launch")
|
@@ -1205,13 +1189,8 @@ jQuery(function($) {
|
|
1205 |
return;
|
1206 |
}
|
1207 |
|
1208 |
-
var depth = menu_item.attr("class").match(/\menu-item-depth-(\d+)\b/)[1];
|
1209 |
-
|
1210 |
$(this).megaMenu({
|
1211 |
-
menu_item_id: id
|
1212 |
-
menu_item_title: 0, // title, // 2.7.5: detect using PHP
|
1213 |
-
menu_item_depth: depth,
|
1214 |
-
menu_id: 0 ///menu_id // 2.7.5: detect using PHP
|
1215 |
});
|
1216 |
});
|
1217 |
|
68 |
data: {
|
69 |
action: "mm_get_lightbox_html",
|
70 |
_wpnonce: megamenu.nonce,
|
71 |
+
menu_item_id: panel.settings.menu_item_id
|
|
|
|
|
72 |
},
|
73 |
cache: false,
|
74 |
beforeSend: function() {
|
86 |
var json = $.parseJSON(response.data);
|
87 |
|
88 |
var header_container = $("<div />").addClass("mm_header_container");
|
|
|
89 |
var title = $("<div />").addClass("mm_title");
|
|
|
90 |
var saving = $("<div class='mm_saving'>" + megamenu.saving + "</div>");
|
91 |
|
92 |
header_container.append(title).append(saving);
|
93 |
|
94 |
+
var active_tab = "mega_menu";
|
95 |
var tabs_container = $("<div class='mm_tab_container' />");
|
|
|
96 |
var content_container = $("<div class='mm_content_container' />");
|
97 |
|
98 |
+
if (json === null) {
|
99 |
content_container.html(response);
|
100 |
}
|
101 |
|
106 |
return;
|
107 |
}
|
108 |
|
109 |
+
if (idx === "active_tab") {
|
110 |
+
active_tab = (this);
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
|
114 |
var content = $("<div />").addClass("mm_content").addClass(idx).html(this.content).hide();
|
115 |
|
116 |
// bind save button action
|
197 |
content.show();
|
198 |
});
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
tabs_container.append(tab);
|
201 |
|
202 |
$(".mm_tab_horizontal", content).on("click", function() {
|
230 |
content_container.append(content);
|
231 |
});
|
232 |
|
233 |
+
$(".mm_tab." + active_tab + ":first", tabs_container).click();
|
234 |
+
|
235 |
+
$("#cboxLoadedContent").append(header_container).append(tabs_container).append(content_container);
|
236 |
$("#cboxLoadedContent").css({
|
237 |
"width": "100%",
|
238 |
"height": "100%",
|
1150 |
jQuery(function($) {
|
1151 |
"use strict";
|
1152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1153 |
$("#megamenu_accordion").accordion({
|
1154 |
heightStyle: "content",
|
1155 |
collapsible: true,
|
1174 |
$("#menu-to-edit li.menu-item").each(function() {
|
1175 |
|
1176 |
var menu_item = $(this);
|
|
|
|
|
1177 |
|
1178 |
menu_item.data("megamenu_has_button", "true");
|
1179 |
|
|
|
|
|
|
|
|
|
|
|
1180 |
var id = parseInt(menu_item.attr("id").match(/[0-9]+/)[0], 10);
|
1181 |
|
1182 |
var button = $("<span>").addClass("mm_launch")
|
1189 |
return;
|
1190 |
}
|
1191 |
|
|
|
|
|
1192 |
$(this).megaMenu({
|
1193 |
+
menu_item_id: id
|
|
|
|
|
|
|
1194 |
});
|
1195 |
});
|
1196 |
|
megamenu.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Max Mega Menu
|
5 |
* Plugin URI: https://www.megamenu.com
|
6 |
* Description: An easy to use mega menu plugin. Written the WordPress way.
|
7 |
-
* Version: 2.7.
|
8 |
* Author: megamenu.com
|
9 |
* Author URI: https://www.megamenu.com
|
10 |
* License: GPL-2.0+
|
@@ -36,7 +36,7 @@ final class Mega_Menu {
|
|
36 |
/**
|
37 |
* @var string
|
38 |
*/
|
39 |
-
public $version = '2.7.
|
40 |
|
41 |
|
42 |
/**
|
@@ -78,6 +78,7 @@ final class Mega_Menu {
|
|
78 |
add_filter( 'wp_nav_menu', array( $this, 'add_responsive_toggle' ), 10, 2 );
|
79 |
|
80 |
add_filter( 'wp_nav_menu_objects', array( $this, 'add_widgets_to_menu' ), apply_filters("megamenu_wp_nav_menu_objects_priority", 10), 2 );
|
|
|
81 |
add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'setup_menu_items' ), 5, 2 );
|
82 |
add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'reorder_menu_items_within_megamenus' ), 6, 2 );
|
83 |
add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'apply_classes_to_menu_items' ), 7, 2 );
|
@@ -761,17 +762,14 @@ final class Mega_Menu {
|
|
761 |
|
762 |
|
763 |
/**
|
764 |
-
*
|
765 |
*
|
766 |
-
* @since 2.
|
767 |
* @param array $items - All menu item objects
|
768 |
* @param object $args
|
769 |
* @return array
|
770 |
*/
|
771 |
-
public function
|
772 |
-
|
773 |
-
// apply depth
|
774 |
-
// @todo work out a better way to do this. Suggestions welcome..!
|
775 |
$parents = array();
|
776 |
|
777 |
foreach ( $items as $key => $item ) {
|
@@ -789,6 +787,20 @@ final class Mega_Menu {
|
|
789 |
}
|
790 |
}
|
791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
792 |
// apply saved metadata to each menu item
|
793 |
foreach ( $items as $item ) {
|
794 |
$saved_settings = array_filter( (array) get_post_meta( $item->ID, '_megamenu', true ) );
|
4 |
* Plugin Name: Max Mega Menu
|
5 |
* Plugin URI: https://www.megamenu.com
|
6 |
* Description: An easy to use mega menu plugin. Written the WordPress way.
|
7 |
+
* Version: 2.7.7
|
8 |
* Author: megamenu.com
|
9 |
* Author URI: https://www.megamenu.com
|
10 |
* License: GPL-2.0+
|
36 |
/**
|
37 |
* @var string
|
38 |
*/
|
39 |
+
public $version = '2.7.7';
|
40 |
|
41 |
|
42 |
/**
|
78 |
add_filter( 'wp_nav_menu', array( $this, 'add_responsive_toggle' ), 10, 2 );
|
79 |
|
80 |
add_filter( 'wp_nav_menu_objects', array( $this, 'add_widgets_to_menu' ), apply_filters("megamenu_wp_nav_menu_objects_priority", 10), 2 );
|
81 |
+
add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'apply_depth_to_menu_items' ), 5, 2 );
|
82 |
add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'setup_menu_items' ), 5, 2 );
|
83 |
add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'reorder_menu_items_within_megamenus' ), 6, 2 );
|
84 |
add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'apply_classes_to_menu_items' ), 7, 2 );
|
762 |
|
763 |
|
764 |
/**
|
765 |
+
* Determine if menu item is a top level item or a second level item
|
766 |
*
|
767 |
+
* @since 2.7.7
|
768 |
* @param array $items - All menu item objects
|
769 |
* @param object $args
|
770 |
* @return array
|
771 |
*/
|
772 |
+
public function apply_depth_to_menu_items( $items, $args ) {
|
|
|
|
|
|
|
773 |
$parents = array();
|
774 |
|
775 |
foreach ( $items as $key => $item ) {
|
787 |
}
|
788 |
}
|
789 |
|
790 |
+
return $items;
|
791 |
+
}
|
792 |
+
|
793 |
+
|
794 |
+
/**
|
795 |
+
* Setup the mega menu settings for each menu item
|
796 |
+
*
|
797 |
+
* @since 2.0
|
798 |
+
* @param array $items - All menu item objects
|
799 |
+
* @param object $args
|
800 |
+
* @return array
|
801 |
+
*/
|
802 |
+
public function setup_menu_items( $items, $args ) {
|
803 |
+
|
804 |
// apply saved metadata to each menu item
|
805 |
foreach ( $items as $item ) {
|
806 |
$saved_settings = array_filter( (array) get_post_meta( $item->ID, '_megamenu', true ) );
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: megamenu
|
|
3 |
Tags: menu, megamenu, mega menu, navigation, widget, dropdown menu, drag and drop, mobile, responsive, retina, theme editor, widget, shortcode, sidebar, icons, dashicons
|
4 |
Requires at least: 4.9
|
5 |
Tested up to: 5.4
|
6 |
-
Stable tag: 2.7.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -133,6 +133,10 @@ See https://www.megamenu.com for more screenshots
|
|
133 |
|
134 |
== Changelog ==
|
135 |
|
|
|
|
|
|
|
|
|
136 |
= 2.7.6 =
|
137 |
|
138 |
* Fix: Revert "Refactor: Improve method to determine the depth of a menu item", causing infinite loop on some installations
|
3 |
Tags: menu, megamenu, mega menu, navigation, widget, dropdown menu, drag and drop, mobile, responsive, retina, theme editor, widget, shortcode, sidebar, icons, dashicons
|
4 |
Requires at least: 4.9
|
5 |
Tested up to: 5.4
|
6 |
+
Stable tag: 2.7.6
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
133 |
|
134 |
== Changelog ==
|
135 |
|
136 |
+
= 2.7.7 =
|
137 |
+
|
138 |
+
* Refactor: Improve method to determine the depth of a menu item (when loading menu item options in back end)
|
139 |
+
|
140 |
= 2.7.6 =
|
141 |
|
142 |
* Fix: Revert "Refactor: Improve method to determine the depth of a menu item", causing infinite loop on some installations
|