PluginProbe
QuadMenu – Mega Menu / 2.0.5
QuadMenu – Mega Menu v2.0.5
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / quadmenu.php

quadmenu.php in QuadMenu – Mega Menu 2.0.5, at quadmenu.php

630 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Plugin Name: QuadMenu
5 * Plugin URI: https://quadmenu.com
6 * Description: The best drag & drop WordPress Mega Menu plugin which allow you to create Tabs Menus & Carousel Menus.
7 * Version: 2.0.5
8 * Author: Mega Menu
9 * Author URI: https://quadmenu.com
10 * Copyright: 2018 QuadMenu (https://quadmenu.com)
11 * Text Domain: quadmenu
12 */
13
14 if (!defined('ABSPATH')) {
15 die('-1');
16 }
17
18 define('QUADMENU_PLUGIN_NAME', 'QuadMenu');
19 define('QUADMENU_PLUGIN_VERSION', '2.0.5');
20 define('QUADMENU_PLUGIN_FILE', __FILE__);
21 define('QUADMENU_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR);
22 define('QUADMENU_PLUGIN_URL', plugin_dir_url(QUADMENU_PLUGIN_FILE));
23 define('QUADMENU_PLUGIN_BASENAME', plugin_basename(QUADMENU_PLUGIN_FILE));
24 define('QUADMENU_PREFIX', 'quadmenu');
25 define('QUADMENU_WORDPRESS_URL', 'https://wordpress.org/plugins/quadmenu/');
26 define('QUADMENU_REVIEW_URL', 'https://wordpress.org/support/plugin/quadmenu/reviews/?filter=5#new-post');
27 define('QUADMENU_DEMO_URL', 'https://quadmenu.com/?utm_source=quadmenu_admin');
28 define('QUADMENU_PURCHASE_URL', QUADMENU_DEMO_URL);
29 define('QUADMENU_SUPPORT_URL', 'https://quadmenu.com/account/support/?utm_source=quadmenu_admin');
30 define('QUADMENU_DOCUMENTATION_URL', 'https://quadmenu.com/documentation/?utm_source=quadmenu_admin');
31 define('QUADMENU_GROUP_URL', 'https://www.facebook.com/groups/quadlayers');
32 define('QUADMENU_DB_THEME', '_quadmenu_theme');
33 define('QUADMENU_DB_ITEM', '_menu_item_quadmenu');
34 define('QUADMENU_DEV', false);
35 define('QUADMENU_COMPILE', true);
36 //Pro compatibility
37 define('QUADMENU_DOMAIN', 'quadmenu');
38 define('QUADMENU_PATH', QUADMENU_PLUGIN_DIR);
39 define('QUADMENU_DEMO', QUADMENU_DEMO_URL);
40
41 if (!class_exists('QuadMenu')) :
42
43 final class QuadMenu
44 {
45
46 private $prefix = '#quadmenu-';
47 private static $instance;
48 private $registered_icons;
49 private $registered_icons_names;
50 public $selected_icons;
51
52 public static function instance()
53 {
54 if (!isset(self::$instance)) {
55 self::$instance = new QuadMenu;
56 self::$instance->constants();
57 self::$instance->config();
58 self::$instance->includes();
59 self::$instance->compatibility();
60 self::$instance->hooks();
61 self::$instance->errors();
62 }
63 return self::$instance;
64 }
65
66 private function config()
67 {
68 require_once QUADMENU_PLUGIN_DIR . 'includes/configuration.php';
69 }
70
71 private function compatibility()
72 {
73 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/woocommerce.php';
74 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/polylang.php';
75 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/vc.php';
76 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/elementor.php';
77 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/beaver.php';
78 require_once QUADMENU_PLUGIN_DIR . 'includes/3rd/divi.php';
79 require_once QUADMENU_PLUGIN_DIR . 'includes/widget.php';
80 }
81
82 private function hooks()
83 {
84
85 add_filter('wp_get_nav_menu_items', array($this, 'remove_nav_menu_item'), 20, 3);
86 add_filter('wp_setup_nav_menu_item', array($this, 'setup_nav_menu_item_options'), 90);
87 add_filter('quadmenu_setup_nav_menu_item', array($this, 'setup_nav_menu_item_parents'), 5);
88 add_filter('quadmenu_setup_nav_menu_item', array($this, 'setup_nav_menu_item_validation'), 10);
89
90 add_action('init', array($this, 'register_sidebar'));
91 add_action('init', array($this, 'register_icons'), -35);
92 add_action('init', array($this, 'admin'), -25);
93 add_action('init', array($this, 'compiler'), -20);
94 add_action('init', array($this, 'locations'), -15);
95 add_action('init', array($this, 'init'), -10);
96 add_action('init', array($this, 'frontend'), -5);
97 add_action('admin_init', array($this, 'navmenu'));
98
99 add_action('plugins_loaded', array($this, 'i18n'));
100 }
101
102 public function register_sidebar()
103 {
104
105 register_sidebar(
106 array(
107 'id' => 'quadmenu-widgets',
108 'name' => esc_html__('QuadMenu Widgets', 'quadmenu'),
109 'description' => esc_html__('Do not manually edit this sidebar.', 'quadmenu')
110 )
111 );
112 }
113
114 function register_icons()
115 {
116
117 foreach (apply_filters('quadmenu_register_icons', array()) as $id => $settings) {
118
119 //if (!wp_style_is($id, $list = 'registered')) {
120 // wp_register_style($id, $settings['url']);
121 // }
122
123 $settings['ID'] = $id;
124
125 $this->registered_icons[$id] = (object) $settings;
126
127 $this->registered_icons_names[$id] = $settings['name'];
128 }
129 }
130
131 function registered_icons()
132 {
133 return (object) $this->registered_icons;
134 }
135
136 function registered_icons_names()
137 {
138 return $this->registered_icons_names;
139 }
140
141 function selected_icons()
142 {
143
144 global $quadmenu;
145
146 $this->selected_icons = $this->registered_icons()->dashicons;
147
148 if (!empty($quadmenu['styles_icons']) && isset($this->registered_icons()->{$quadmenu['styles_icons']})) {
149 $this->selected_icons = $this->registered_icons()->{$quadmenu['styles_icons']};
150 }
151
152 if (!wp_style_is($this->selected_icons->ID, $list = 'registered')) {
153 wp_register_style($this->selected_icons->ID, $this->selected_icons->url);
154 }
155
156 return $this->selected_icons;
157 }
158
159
160 /* function selected_icons() {
161
162 global $quadmenu;
163
164 if (empty($quadmenu['styles_icons'])) {
165 self::$selected_icons = $this->registered_icons()->dashicons;
166 }
167
168 if (empty($this->registered_icons()->{$quadmenu['styles_icons']})) {
169 self::$selected_icons = $this->registered_icons()->dashicons;
170 }
171
172 self::$selected_icons = $this->registered_icons()->{$quadmenu['styles_icons']};
173
174 if (!wp_style_is(self::$selected_icons->ID, $list = 'registered')) {
175 wp_register_style(self::$selected_icons->ID, self::$selected_icons->url);
176 }
177
178 return self::$selected_icons;
179 } */
180
181 private function theme()
182 {
183
184 $theme = get_stylesheet();
185
186 $theme = preg_replace('/[^a-zA-Z0-9_\-]/', '', $theme);
187
188 return $theme;
189 }
190
191 private function constants()
192 {
193
194 $upload_dir = wp_upload_dir();
195
196 define('QUADMENU_DB_OPTIONS', "quadmenu_{$this->theme()}");
197
198 define('QUADMENU_DB_THEMES', "quadmenu_{$this->theme()}_themes");
199
200 define('QUADMENU_DB_LOCATIONS', "quadmenu_{$this->theme()}_locations");
201
202 define('QUADMENU_UPLOAD_DIR', trailingslashit("{$upload_dir['basedir']}/{$this->theme()}"));
203
204 define('QUADMENU_UPLOAD_URL', set_url_scheme(trailingslashit("{$upload_dir['baseurl']}/{$this->theme()}")));
205
206 define('QUADMENU_PANEL', apply_filters('quadmenu_hook_menu_panel', 'quadmenu_options'));
207
208 // Compatibility
209 define('QUADMENU_PATH_CSS', QUADMENU_UPLOAD_DIR);
210 define('QUADMENU_URL_CSS', QUADMENU_UPLOAD_URL);
211 define('QUADMENU_OPTIONS', QUADMENU_DB_OPTIONS);
212 define('QUADMENU_THEMES', QUADMENU_DB_THEMES);
213 define('QUADMENU_LOCATIONS', QUADMENU_DB_LOCATIONS);
214 }
215
216 private function includes()
217 {
218
219 require_once QUADMENU_PLUGIN_DIR . 'includes/functions.php';
220
221 require_once QUADMENU_PLUGIN_DIR . 'includes/import.php';
222
223 require_once QUADMENU_PLUGIN_DIR . 'includes/activation.php';
224
225 require_once QUADMENU_PLUGIN_DIR . 'includes/panel.php';
226 }
227
228 public function admin()
229 {
230 require_once QUADMENU_PLUGIN_DIR . 'includes/admin.php';
231 require_once QUADMENU_PLUGIN_DIR . 'includes/panel/welcome.php';
232 require_once QUADMENU_PLUGIN_DIR . 'includes/panel/system.php';
233 require_once QUADMENU_PLUGIN_DIR . 'includes/panel/options.php';
234 require_once QUADMENU_PLUGIN_DIR . 'includes/panel/suggestions.php';
235 require_once QUADMENU_PLUGIN_DIR . 'includes/panel/premium.php';
236 }
237
238 public function locations()
239 {
240 require_once QUADMENU_PLUGIN_DIR . 'includes/locations.php';
241 }
242
243 public function init()
244 {
245 require_once QUADMENU_PLUGIN_DIR . 'includes/themes.php';
246 require_once QUADMENU_PLUGIN_DIR . 'includes/options.php';
247 require_once QUADMENU_PLUGIN_DIR . 'includes/redux.php';
248 require_once QUADMENU_PLUGIN_DIR . 'includes/icons.php';
249 }
250
251 public function compiler()
252 {
253
254 if (!is_admin() && !is_customize_preview())
255 return;
256
257 require_once QUADMENU_PLUGIN_DIR . 'includes/compiler.php';
258 }
259
260 function nav_menu_selected_id()
261 {
262
263 if (wp_doing_ajax() && isset($_REQUEST['menu_id'])) {
264 return (int) $_REQUEST['menu_id'];
265 }
266
267 $nav_menus = wp_get_nav_menus(array('orderby' => 'name'));
268
269 $menu_count = count($nav_menus);
270
271 // Get recently edited nav menu
272 $recently_edited = (int) get_user_option('nav_menu_recently_edited');
273
274 $nav_menu_selected_id = isset($_REQUEST['menu']) ? (int) $_REQUEST['menu'] : 0;
275
276 // Are we on the add new screen?
277 $add_new_screen = (isset($_REQUEST['menu']) && 0 == $_REQUEST['menu']) ? true : false;
278
279 $page_count = wp_count_posts('page');
280
281 $one_theme_location_no_menus = (1 == count(get_registered_nav_menus()) && !$add_new_screen && empty($nav_menus) && !empty($page_count->publish)) ? true : false;
282
283 if (empty($recently_edited) && is_nav_menu($nav_menu_selected_id))
284 $recently_edited = $nav_menu_selected_id;
285
286 // Use $recently_edited if none are selected.
287 if (empty($nav_menu_selected_id) && !isset($_REQUEST['menu']) && is_nav_menu($recently_edited))
288 $nav_menu_selected_id = $recently_edited;
289
290 // On deletion of menu, if another menu exists, show it.
291 if (!$add_new_screen && 0 < $menu_count && isset($_REQUEST['action']) && 'delete' == $_REQUEST['action'])
292 $nav_menu_selected_id = $nav_menus[0]->term_id;
293
294 // Set $nav_menu_selected_id to 0 if no menus.
295 if ($one_theme_location_no_menus) {
296 $nav_menu_selected_id = 0;
297 } elseif (empty($nav_menu_selected_id) && !empty($nav_menus) && !$add_new_screen) {
298 // if we have no selection yet, and we have menus, set to the first one in the list.
299 $nav_menu_selected_id = $nav_menus[0]->term_id;
300 }
301
302 return $nav_menu_selected_id;
303 }
304
305 function is_quadmenu($nav_menu_selected_id = false)
306 {
307
308 global $quadmenu_active_locations;
309
310 if (!$menu_locations = isset($_REQUEST['menu-locations']) && is_array($_REQUEST['menu-locations']) ? $_REQUEST['menu-locations'] : get_nav_menu_locations()) {
311 return false;
312 }
313
314 if (!$nav_menu_selected_id = $this->nav_menu_selected_id()) {
315 return false;
316 }
317
318 // chek if this menu id is in the theme locations
319 if (!in_array(sanitize_key($nav_menu_selected_id), $menu_locations)) {
320 return false;
321 }
322
323 if (count(array_intersect(array_keys($menu_locations, $nav_menu_selected_id), array_keys((array) $quadmenu_active_locations))) > 0) {
324 return true;
325 }
326
327 return false;
328 }
329
330 function is_quadmenu_location($location = false)
331 {
332
333 global $quadmenu_active_locations;
334
335 if (!empty($quadmenu_active_locations[$location])) {
336 return true;
337 }
338
339 return false;
340 }
341
342 public function navmenu()
343 {
344
345 if (is_quadmenu()) {
346
347 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/settings.php';
348 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/walker/widgets.php';
349 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/walker/columns.php';
350 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/walker/mega.php';
351 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/walker/defaults.php';
352 require_once QUADMENU_PLUGIN_DIR . 'includes/backend/ajax.php';
353 }
354 }
355
356 public function frontend()
357 {
358
359 //if (is_admin())
360 // return;
361
362 require_once QUADMENU_PLUGIN_DIR . 'includes/frontend/frontend.php';
363 require_once QUADMENU_PLUGIN_DIR . 'includes/frontend/integration.php';
364 require_once QUADMENU_PLUGIN_DIR . 'includes/frontend/items.php';
365 }
366
367 public function setup_nav_menu_item_options($item)
368 {
369
370 //if (empty($item->quadmenu)) {
371 if (isset($item->ID)) {
372
373 $saved_settings = (array) get_post_meta($item->ID, QUADMENU_DB_ITEM, true);
374
375 foreach ($saved_settings as $key => $value) {
376 $item->{$key} = $value;
377 }
378
379 return apply_filters('quadmenu_setup_nav_menu_item', $item);
380 }
381 //}
382
383 return $item;
384 }
385
386 public function setup_nav_menu_item_parents($item)
387 {
388
389 global $wp_registered_widgets;
390
391 $items = QuadMenu_Configuration::custom_nav_menu_items();
392
393 // Quadmenu
394 // -----------------------------------------------------------------
395
396 if (strpos($item->url, $this->prefix) !== false) {
397 $item->quadmenu = str_replace($this->prefix, '', $item->url);
398 }
399
400 if (isset($item->quadmenu)) {
401 if (!empty($items->{$item->quadmenu}->label)) {
402 $item->type_label = '[' . $items->{$item->quadmenu}->label . ']';
403 }
404 }
405
406 if (isset($item->quadmenu) && $item->object == 'custom') {
407 $item->object = $item->quadmenu;
408 }
409
410 if (!isset($item->quadmenu)) {
411 $item->quadmenu = $item->type;
412 }
413
414 // Replace quadmenu with object if defined
415 // -----------------------------------------------------------------
416
417 if (isset($items->{$item->object})) {
418 $item->quadmenu = $item->object;
419 }
420
421 // Replace quadmenu with object post_archive
422 // -----------------------------------------------------------------
423 if ($item->type === 'post_type_archive' && isset($items->{$item->object . '_archive'})) {
424 $item->quadmenu = $item->object . '_archive';
425 }
426
427 // Parent
428 // -----------------------------------------------------------------
429 if (empty($item->quadmenu_menu_item_parent)) {
430 if (!empty($item->menu_item_parent)) {
431
432 $parent_obj = QuadMenu::wp_setup_nav_menu_item($item->menu_item_parent);
433
434 if (isset($parent_obj->type)) {
435 //brokes the subitems
436 //if (!empty($parent_obj->quadmenu)) {
437 if (isset($parent_obj->quadmenu) && $parent_obj->type === 'custom') {
438 $item->quadmenu_menu_item_parent = $parent_obj->quadmenu;
439 } else {
440 // post_type taxonomy post_type_archive parents
441 $item->quadmenu_menu_item_parent = $parent_obj->type;
442 }
443 }
444 } else {
445 $item->quadmenu_menu_item_parent = 'main';
446 }
447 }
448
449 // Validation
450 // -----------------------------------------------------------------
451
452 if (!empty($items->{$item->quadmenu}->parent)) {
453
454 $item->quadmenu_allowed_parents = $items->{$item->quadmenu}->parent;
455
456 // Main
457 // -----------------------------------------------------------------
458 if (!is_array($item->quadmenu_allowed_parents) && $item->quadmenu_allowed_parents === 'main') {
459 $item->menu_item_parent = 0;
460 $item->quadmenu_menu_item_parent = 'main';
461 }
462
463 // Invalid
464 // -----------------------------------------------------------------
465 if (is_array($item->quadmenu_allowed_parents) && !in_array($item->quadmenu_menu_item_parent, $item->quadmenu_allowed_parents)) {
466 $item->_invalid = true;
467 }
468
469 // Invalid
470 // -----------------------------------------------------------------
471 if (!is_array($item->quadmenu_allowed_parents) && $item->quadmenu_allowed_parents != $item->quadmenu_menu_item_parent) {
472 $item->_invalid = true;
473 }
474 } else {
475 $item->quadmenu_allowed_parents = 'all';
476 }
477
478 if ($item->quadmenu == 'widget' && (empty($item->widget_id) || !isset($wp_registered_widgets[$item->widget_id]))) {
479 $item->_invalid = true;
480 }
481
482 return $item;
483 }
484
485 static function wp_setup_nav_menu_item($ID)
486 {
487
488 $item_obj = wp_cache_get("wp_setup_nav_menu_item_{$ID}", 'quadmenu');
489
490 if ($item_obj === false) {
491
492 $item_obj = get_post($ID);
493
494 if (!empty($item_obj->ID)) {
495 $item_obj = wp_setup_nav_menu_item($item_obj);
496 }
497
498 wp_cache_set("wp_setup_nav_menu_item_{$ID}", $item_obj, 'quadmenu');
499 }
500
501 return $item_obj;
502 }
503
504 function setup_nav_menu_item_validation($item)
505 {
506
507 if (isset($item->target) && $item->target === 'on') {
508 $item->target = '_blank';
509 }
510
511 if (isset($item->target) && $item->target === 'off') {
512 $item->target = '';
513 }
514
515 if (isset($item->columns)) {
516
517 //var_dump($item->columns);
518
519 $item->columns = array_diff(array_filter((array) $item->columns), array('off'));
520 }
521
522 return $item;
523 }
524
525 public function remove_nav_menu_item($items, $menu, $args)
526 {
527
528 if (is_quadmenu()) {
529
530 foreach ($items as $key => $item) {
531
532 if (!wp_doing_ajax()) {
533
534 // Remove invalid items in frontend
535 if (!is_admin() && $item->_invalid) {
536 unset($items[$key]);
537 }
538
539 // Remove valid quadmenu items
540 if (is_admin() && !$item->_invalid && in_array(sanitize_key($item->quadmenu_menu_item_parent), apply_filters('quadmenu_remove_nav_menu_item', array('column', 'mega', 'login')))) {
541 unset($items[$key]);
542 }
543
544 // Remove invalid items without parent
545 if (is_admin() && $item->_invalid && !$item->quadmenu_menu_item_parent) {
546 unset($items[$key]);
547 }
548 }
549 }
550 }
551
552 return $items;
553 }
554
555 public function edit_nav_menu_walker($menu_id)
556 {
557 return 'QuadMenu_Walker_Nav_Menu_Edit';
558 }
559
560 function i18n()
561 {
562 load_plugin_textdomain('quadmenu', false, QUADMENU_PLUGIN_DIR . '/languages');
563 }
564
565 public static function taburl($id = 0)
566 {
567 return admin_url('admin.php?page=' . QUADMENU_PANEL . '&tab=' . $id);
568 }
569
570 public static function isMin()
571 {
572 $min = '';
573
574 if (false == QUADMENU_DEV) {
575 $min = '.min';
576 }
577
578 return $min;
579 }
580
581 public static function send_json_success($json)
582 {
583 if (ob_get_contents())
584 ob_clean();
585
586 wp_send_json_success($json);
587 }
588
589 public static function send_json_error($json)
590 {
591 if (ob_get_contents())
592 ob_clean();
593
594 wp_send_json_error($json);
595 }
596
597 private function errors()
598 {
599
600 if (!QUADMENU_DEV)
601 return;
602
603 ini_set('error_reporting', E_ALL);
604 ini_set('display_errors', 1);
605 ini_set('display_startup_errors', 1);
606 }
607 }
608
609 endif; // End if class_exists check
610
611 if (!function_exists('_QuadMenu')) {
612
613 function _QuadMenu()
614 {
615 return QuadMenu::instance();
616 }
617
618 _QuadMenu();
619 }
620
621 if (!function_exists('is_quadmenu_location')) {
622
623 function is_quadmenu_location($location = false)
624 {
625 return QuadMenu::instance()->is_quadmenu_location($location);
626 }
627 }
628
629 register_activation_hook(__FILE__, array('QuadMenu_Activation', 'activation'));
630