megamenu.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. <?php
  2. /*
  3. * Plugin Name: Max Mega Menu
  4. * Plugin URI: https://www.megamenu.com
  5. * Description: An easy to use mega menu plugin. Written the WordPress way.
  6. * Version: 2.5.2
  7. * Author: megamenu.com
  8. * Author URI: https://www.megamenu.com
  9. * License: GPL-2.0+
  10. * Copyright: 2018 Tom Hemsley (https://www.megamenu.com)
  11. */
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit; // disable direct access
  14. }
  15. if ( ! class_exists( 'Mega_Menu' ) ) :
  16. /**
  17. * Main plugin class
  18. */
  19. final class Mega_Menu {
  20. /**
  21. * @var string
  22. */
  23. public $version = '2.5.2';
  24. /**
  25. * @var string
  26. */
  27. public $scss_last_updated = '2.4.1.3';
  28. /**
  29. * Init
  30. *
  31. * @since 1.0
  32. */
  33. public static function init() {
  34. $plugin = new self();
  35. }
  36. /**
  37. * Constructor
  38. *
  39. * @since 1.0
  40. */
  41. public function __construct() {
  42. $this->define_constants();
  43. $this->includes();
  44. add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
  45. add_action( 'admin_init', array( $this, 'install_upgrade_check' ) );
  46. add_action( 'admin_notices', array( $this, 'admin_notices' ) );
  47. add_action( 'widgets_init', array( $this, 'register_widget' ) );
  48. add_filter( 'in_widget_form', array( $this, 'add_notice_to_nav_menu_widget' ) , 10, 3 );
  49. add_action( 'after_setup_theme', array( $this, 'register_nav_menus' ) );
  50. add_filter( 'wp_nav_menu_args', array( $this, 'modify_nav_menu_args' ), 99999 );
  51. add_filter( 'wp_nav_menu', array( $this, 'add_responsive_toggle' ), 10, 2 );
  52. add_filter( 'wp_nav_menu_objects', array( $this, 'add_widgets_to_menu' ), apply_filters("megamenu_wp_nav_menu_objects_priority", 10), 2 );
  53. add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'setup_menu_items' ), 5, 2 );
  54. add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'reorder_menu_items_within_megamenus' ), 6, 2 );
  55. add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'apply_classes_to_menu_items' ), 7, 2 );
  56. add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'set_descriptions_if_enabled' ), 8, 2 );
  57. add_filter( 'body_class', array($this, 'add_megamenu_body_classes'), 10, 1);
  58. add_filter( 'megamenu_nav_menu_css_class', array( $this, 'prefix_menu_classes' ) );
  59. // plugin compatibility
  60. add_filter( 'conditional_menus_theme_location', array( $this, 'conditional_menus_restore_theme_location'), 10, 3 );
  61. add_filter( 'black_studio_tinymce_enable_pages' , array($this, 'megamenu_blackstudio_tinymce' ) );
  62. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts'), 11 );
  63. add_action( 'admin_print_footer_scripts-nav-menus.php', array( $this, 'admin_print_footer_scripts' ) );
  64. add_action( 'admin_print_scripts-nav-menus.php', array( $this, 'admin_print_scripts' ) );
  65. add_action( 'admin_print_styles-nav-menus.php', array( $this, 'admin_print_styles' ) );
  66. add_shortcode( 'maxmenu', array( $this, 'register_shortcode' ) );
  67. add_shortcode( 'maxmegamenu', array( $this, 'register_shortcode' ) );
  68. if ( is_admin() ) {
  69. new Mega_Menu_Nav_Menus();
  70. new Mega_Menu_Widget_Manager();
  71. new Mega_Menu_Menu_Item_Manager();
  72. new Mega_Menu_Settings();
  73. }
  74. if ( class_exists( 'Mega_Menu_Toggle_Blocks' ) ) {
  75. new Mega_Menu_Toggle_Blocks();
  76. }
  77. $mega_menu_style_manager = new Mega_Menu_Style_Manager();
  78. $mega_menu_style_manager->setup_actions();
  79. }
  80. /**
  81. * Add a body class for each active mega menu location.
  82. *
  83. * @since 2.3
  84. * @param array $classes
  85. * @return array
  86. */
  87. public function add_megamenu_body_classes( $classes ) {
  88. $locations = get_nav_menu_locations();
  89. if ( count( $locations ) ) {
  90. foreach ( $locations as $location => $id ) {
  91. if ( has_nav_menu( $location ) && max_mega_menu_is_enabled( $location ) ) {
  92. $classes[] = 'mega-menu-' . str_replace( "_", "-", $location );
  93. }
  94. }
  95. }
  96. return $classes;
  97. }
  98. /**
  99. * Add custom actions to allow enqueuing scripts on specific pages
  100. *
  101. * @since 1.8.3
  102. */
  103. public function admin_enqueue_scripts( $hook ) {
  104. wp_enqueue_style( 'maxmegamenu-global', MEGAMENU_BASE_URL . 'css/admin/global.css', array(), MEGAMENU_VERSION );
  105. if ( ! wp_script_is('maxmegamenu') ) {
  106. if ( 'nav-menus.php' == $hook ) {
  107. // load widget scripts and styles first to allow us to dequeue conflicting colorbox scripts from other plugins
  108. do_action( 'sidebar_admin_setup' );
  109. do_action( 'admin_enqueue_scripts', 'widgets.php' );
  110. do_action( 'megamenu_nav_menus_scripts', $hook );
  111. }
  112. if ( strpos( $hook, 'maxmegamenu' ) !== false ) {
  113. do_action( 'megamenu_admin_scripts', $hook );
  114. }
  115. }
  116. }
  117. /**
  118. * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets.
  119. *
  120. * @since 2.3.7
  121. */
  122. public function admin_print_footer_scripts( $hook ) {
  123. do_action( 'admin_footer-widgets.php' );
  124. }
  125. /**
  126. * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets.
  127. *
  128. * @since 2.3.7
  129. */
  130. public function admin_print_scripts( $hook ) {
  131. do_action( 'admin_print_scripts-widgets.php' );
  132. }
  133. /**
  134. * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets.
  135. *
  136. * @since 2.3.7
  137. */
  138. public function admin_print_styles( $hook ) {
  139. do_action( 'admin_print_styles-widgets.php' );
  140. }
  141. /**
  142. * Register menu locations created within Max Mega Menu.
  143. *
  144. * @since 1.8
  145. */
  146. public function register_nav_menus() {
  147. $locations = get_option('megamenu_locations');
  148. if ( is_array( $locations ) && count( $locations ) ) {
  149. foreach ( $locations as $key => $val ) {
  150. register_nav_menu( $key, $val );
  151. }
  152. }
  153. }
  154. /**
  155. * Black Studio TinyMCE Compatibility.
  156. * Load TinyMCE assets on nav-menus.php page.
  157. *
  158. * @since 1.8
  159. * @param array $pages
  160. * @return array $pages
  161. */
  162. public function megamenu_blackstudio_tinymce( $pages ) {
  163. $pages[] = 'nav-menus.php';
  164. return $pages;
  165. }
  166. /**
  167. * Detect new or updated installations and run actions accordingly.
  168. *
  169. * @since 1.3
  170. */
  171. public function install_upgrade_check() {
  172. $version = get_option( "megamenu_version" );
  173. if ( $version ) {
  174. if ( version_compare( $this->version, $version, '!=' ) ) {
  175. update_option( "megamenu_version", $this->version );
  176. do_action( "megamenu_after_update" );
  177. }
  178. } else {
  179. add_option( "megamenu_version", $this->version );
  180. add_option( "megamenu_initial_version", $this->version );
  181. add_option( "megamenu_multisite_share_themes", 'false' );
  182. do_action( "megamenu_after_install" );
  183. $settings = get_option( "megamenu_settings" );
  184. // set defaults
  185. if ( ! $settings ) {
  186. $settings['prefix'] = 'disabled';
  187. $settings['descriptions'] = 'enabled';
  188. add_option( "megamenu_settings", $settings);
  189. }
  190. }
  191. }
  192. /**
  193. * Register widget
  194. *
  195. * @since 1.7.4
  196. */
  197. public function register_widget() {
  198. register_widget( 'Mega_Menu_Widget' );
  199. }
  200. /**
  201. * Shortcode used to display a menu
  202. *
  203. * @since 1.3
  204. * @return string
  205. */
  206. public function register_shortcode( $atts ) {
  207. if ( ! isset( $atts['location'] ) ) {
  208. return false;
  209. }
  210. if ( has_nav_menu( $atts['location'] ) ) {
  211. return wp_nav_menu( array( 'theme_location' => $atts['location'], 'echo' => false ) );
  212. }
  213. return "<!-- menu not found [maxmegamenu location={$atts['location']}] -->";
  214. }
  215. /**
  216. * Initialise translations
  217. *
  218. * @since 1.0
  219. */
  220. public function load_plugin_textdomain() {
  221. load_plugin_textdomain( 'megamenu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  222. }
  223. /**
  224. * Define Mega Menu constants
  225. *
  226. * @since 1.0
  227. */
  228. private function define_constants() {
  229. define( 'MEGAMENU_VERSION', $this->version );
  230. define( 'MEGAMENU_BASE_URL', trailingslashit( plugins_url( 'megamenu' ) ) );
  231. define( 'MEGAMENU_PATH', plugin_dir_path( __FILE__ ) );
  232. }
  233. /**
  234. * All Mega Menu classes
  235. *
  236. * @since 1.0
  237. */
  238. private function plugin_classes() {
  239. $classes = array(
  240. 'mega_menu_walker' => MEGAMENU_PATH . 'classes/walker.class.php',
  241. 'mega_menu_widget_manager' => MEGAMENU_PATH . 'classes/widget-manager.class.php',
  242. 'mega_menu_menu_item_manager' => MEGAMENU_PATH . 'classes/menu-item-manager.class.php',
  243. 'mega_menu_nav_menus' => MEGAMENU_PATH . 'classes/nav-menus.class.php',
  244. 'mega_menu_style_manager' => MEGAMENU_PATH . 'classes/style-manager.class.php',
  245. 'mega_menu_settings' => MEGAMENU_PATH . 'classes/settings.class.php',
  246. 'mega_menu_widget' => MEGAMENU_PATH . 'classes/widget.class.php',
  247. 'mega_menu_toggle_blocks' => MEGAMENU_PATH . 'classes/toggle-blocks.class.php',
  248. 'scssc' => MEGAMENU_PATH . 'classes/scssc.inc.php'
  249. );
  250. return $classes;
  251. }
  252. /**
  253. * Load required classes
  254. *
  255. * @since 1.0
  256. */
  257. private function includes() {
  258. $autoload_is_disabled = defined( 'MEGAMENU_AUTOLOAD_CLASSES' ) && MEGAMENU_AUTOLOAD_CLASSES === false;
  259. if ( function_exists( "spl_autoload_register" ) && ! $autoload_is_disabled ) {
  260. // >= PHP 5.2 - Use auto loading
  261. if ( function_exists( "__autoload" ) ) {
  262. spl_autoload_register( "__autoload" );
  263. }
  264. spl_autoload_register( array( $this, 'autoload' ) );
  265. } else {
  266. // < PHP5.2 - Require all classes
  267. foreach ( $this->plugin_classes() as $id => $path ) {
  268. if ( is_readable( $path ) && ! class_exists( $id ) ) {
  269. require_once $path;
  270. }
  271. }
  272. }
  273. $template = get_template();
  274. if ($template == 'zerif-pro') {
  275. $template = 'zerif';
  276. }
  277. switch ( $template ) {
  278. case "twentyseventeen":
  279. case "generatepress":
  280. case "twentytwelve":
  281. case "zerif":
  282. if ( is_readable( MEGAMENU_PATH . "integration/{$template}/functions.php" ) ) {
  283. require_once( MEGAMENU_PATH . "integration/{$template}/functions.php" );
  284. }
  285. break;
  286. }
  287. }
  288. /**
  289. * Autoload classes to reduce memory consumption
  290. *
  291. * @since 1.0
  292. * @param string $class
  293. */
  294. public function autoload( $class ) {
  295. $classes = $this->plugin_classes();
  296. $class_name = strtolower( $class );
  297. if ( isset( $classes[ $class_name ] ) && is_readable( $classes[ $class_name ] ) ) {
  298. require_once $classes[ $class_name ];
  299. }
  300. }
  301. /**
  302. * Appends "mega-" to all menu classes.
  303. * This is to help avoid theme CSS conflicts.
  304. *
  305. * @since 1.0
  306. * @param array $classes
  307. * @return array
  308. */
  309. public function prefix_menu_classes( $classes ) {
  310. $return = array();
  311. foreach ( $classes as $class ) {
  312. $return[] = 'mega-' . $class;
  313. }
  314. $settings = get_option( 'megamenu_settings' );
  315. $prefix = isset( $settings['prefix'] ) ? $settings['prefix'] : 'enabled';
  316. if ( $prefix === 'disabled' ) {
  317. // add in custom classes, sans 'mega-' prefix
  318. foreach ( $classes as $class ) {
  319. // custom classes are added before the 'menu-item' class
  320. if ( $class == 'menu-item' ) {
  321. break;
  322. }
  323. if ( in_array( $class, array( 'menu-column', 'menu-row', 'hide-on-mobile', 'hide-on-desktop') ) ) { // these are always prefixed
  324. continue;
  325. }
  326. if ( strpos( $class, "menu-columns-" ) !== FALSE ) { // mega-menu-columns-X-of-Y are always prefixed
  327. continue;
  328. }
  329. $return[] = $class;
  330. }
  331. }
  332. return $return;
  333. }
  334. /**
  335. * Add the html for the responsive toggle box to the menu
  336. *
  337. * @param string $nav_menu
  338. * @param object $args
  339. * @return string
  340. * @since 1.3
  341. */
  342. public function add_responsive_toggle( $nav_menu, $args ) {
  343. // make sure we're working with a Mega Menu
  344. if ( ! is_a( $args->walker, 'Mega_Menu_Walker' ) )
  345. return $nav_menu;
  346. $find = 'class="' . $args->container_class . '">';
  347. $theme_id = mmm_get_theme_id_for_location( $args->theme_location );
  348. $content = "";
  349. $content = apply_filters( "megamenu_toggle_bar_content", $content, $nav_menu, $args, $theme_id );
  350. $replace = $find . '<div class="mega-menu-toggle" tabindex="0">' . $content . '</div>';
  351. return str_replace( $find, $replace, $nav_menu );
  352. }
  353. /**
  354. * Append the widget objects to the menu array before the
  355. * menu is processed by the walker.
  356. *
  357. * @since 1.0
  358. * @param array $items - All menu item objects
  359. * @param object $args
  360. * @return array - Menu objects including widgets
  361. */
  362. public function add_widgets_to_menu( $items, $args ) {
  363. // make sure we're working with a Mega Menu
  364. if ( ! is_a( $args->walker, 'Mega_Menu_Walker' ) ) {
  365. return $items;
  366. }
  367. $items = apply_filters( "megamenu_nav_menu_objects_before", $items, $args );
  368. $widget_manager = new Mega_Menu_Widget_Manager();
  369. $rolling_dummy_id = 999999999;
  370. $items_to_move = array();
  371. foreach ( $items as $item ) {
  372. // populate standard (non-grid) sub menus
  373. if ( $item->depth === 0 && $item->megamenu_settings['type'] == 'megamenu' || ( $item->depth === 1 && $item->parent_submenu_type == 'tabbed' && $item->megamenu_settings['type'] != 'grid' ) ) {
  374. $panel_widgets = $widget_manager->get_widgets_for_menu_id( $item->ID, $args->menu );
  375. if ( ! in_array( 'menu-megamenu', $item->classes ) ) {
  376. $item->classes[] = 'menu-megamenu';
  377. }
  378. if ( count( $panel_widgets ) ) {
  379. $widget_position = 0;
  380. $total_widgets_in_menu = count( $panel_widgets );
  381. $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items );
  382. if ( ! in_array( 'menu-item-has-children', $item->classes ) ) {
  383. $item->classes[] = 'menu-item-has-children';
  384. }
  385. foreach ( $panel_widgets as $widget ) {
  386. $widget_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), array(
  387. 'mega_menu_columns' => absint( $widget['columns'] )
  388. ) );
  389. $menu_item = array(
  390. 'type' => 'widget',
  391. 'parent_submenu_type' => 'megamenu',
  392. 'title' => $widget['id'],
  393. 'content' => $widget_manager->show_widget( $widget['id'] ),
  394. 'menu_item_parent' => $item->ID,
  395. 'db_id' => 0, // This menu item does not have any childen
  396. 'ID' => $widget['id'],
  397. 'menu_order' => $next_order - $total_widgets_in_menu + $widget_position,
  398. 'megamenu_order' => $widget['order'],
  399. 'megamenu_settings' => $widget_settings,
  400. 'depth' => 1,
  401. 'classes' => array(
  402. "menu-item",
  403. "menu-item-type-widget",
  404. "menu-widget-class-" . $widget_manager->get_widget_class( $widget['id'] )
  405. )
  406. );
  407. $items[] = (object) $menu_item;
  408. $widget_position++;
  409. }
  410. }
  411. }
  412. // populate grid sub menus
  413. if ( $item->depth === 0 && $item->megamenu_settings['type'] == 'grid' || ( $item->depth === 1 && $item->parent_submenu_type == 'tabbed' && $item->megamenu_settings['type'] == 'grid' ) ) {
  414. $saved_grid = $widget_manager->get_grid_widgets_and_menu_items_for_menu_id( $item->ID, $args->menu->term_id );
  415. $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items) - 999;
  416. foreach ( $saved_grid as $row => $row_data ) {
  417. $rolling_dummy_id++;
  418. $next_order++;
  419. if ( isset( $row_data['columns'] ) ) {
  420. if ( ! in_array( 'menu-item-has-children', $item->classes ) ) {
  421. $item->classes[] = 'menu-item-has-children';
  422. }
  423. if ( ! in_array( 'menu-megamenu', $item->classes ) ) {
  424. $item->classes[] = 'menu-megamenu';
  425. }
  426. $classes = array("menu-row");
  427. if ( isset( $row_data['meta']['class'] ) ) {
  428. $classes = array_merge( $classes, array_unique( explode( " ", $row_data['meta']['class'] ) ) );
  429. }
  430. $row_item = array(
  431. 'menu_item_parent' => $item->ID,
  432. 'type' => 'mega_row',
  433. 'title' => 'Custom Row',
  434. 'parent_submenu_type' => '',
  435. 'menu_order' => $next_order,
  436. 'depth' => 0,
  437. 'ID' => "{$item->ID}-{$row}",
  438. 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(),
  439. 'db_id' => $rolling_dummy_id,
  440. 'classes' => $classes
  441. );
  442. $items[] = (object) $row_item;
  443. $row_dummy_id = $rolling_dummy_id;
  444. foreach ( $row_data['columns'] as $col => $col_data ) {
  445. $rolling_dummy_id++;
  446. $next_order++;
  447. $classes = array("menu-column");
  448. if ( isset( $col_data['meta']['class'] ) ) {
  449. $classes = array_merge( $classes, array_unique( explode( " ", $col_data['meta']['class'] ) ) );
  450. }
  451. if ( isset( $row_data['meta']['columns'] ) ) {
  452. $row_columns = $row_data['meta']['columns'];
  453. } else {
  454. $row_columns = 12;
  455. }
  456. if ( isset( $col_data['meta']['span'] ) ) {
  457. $classes[] = "menu-columns-{$col_data['meta']['span']}-of-{$row_columns}";
  458. }
  459. if ( isset( $col_data['meta']['hide-on-mobile'] ) && $col_data['meta']['hide-on-mobile'] == 'true' ) {
  460. $classes[] = "hide-on-mobile";
  461. }
  462. if ( isset( $col_data['meta']['hide-on-mobile'] ) && $col_data['meta']['hide-on-desktop'] == 'true' ) {
  463. $classes[] = "hide-on-desktop";
  464. }
  465. $col_item = array(
  466. 'menu_item_parent' => $row_dummy_id,
  467. 'type' => 'mega_column',
  468. 'title' => 'Custom Column',
  469. 'parent_submenu_type' => '',
  470. 'menu_order' => $next_order,
  471. 'depth' => 0,
  472. 'ID' => "{$item->ID}-{$row}-{$col}",
  473. 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(),
  474. 'db_id' => $rolling_dummy_id,
  475. 'classes' => $classes
  476. );
  477. $items[] = (object) $col_item;
  478. if ( isset( $col_data['items'] ) ) {
  479. foreach ( $col_data['items'] as $key => $block ) {
  480. $next_order++;
  481. if ( $block['type'] == 'widget' ) {
  482. $widget_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults() );
  483. $menu_item = array(
  484. 'type' => 'widget',
  485. 'parent_submenu_type' => '',
  486. 'title' => '',
  487. 'content' => $widget_manager->show_widget( $block['id'] ),
  488. 'menu_item_parent' => $rolling_dummy_id,
  489. 'db_id' => 0, // This menu item does not have any childen
  490. 'ID' => $block['id'],
  491. 'menu_order' => $next_order,
  492. 'megamenu_order' => 0,
  493. 'megamenu_settings' => $widget_settings,
  494. 'depth' => 1,
  495. 'classes' => array(
  496. "menu-item",
  497. "menu-item-type-widget",
  498. "menu-widget-class-" . $widget_manager->get_widget_class( $block['id'] )
  499. )
  500. );
  501. $items[] = (object) $menu_item;
  502. } else {
  503. // mark this menu item to be moved into a new position
  504. $items_to_move[$block['id']] = array('new_parent' => $rolling_dummy_id, 'new_order' => $next_order);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. if ( count( $items_to_move ) ) {
  514. foreach ( $items_to_move as $id => $new_parent ) {
  515. $items_to_find[] = $id;
  516. }
  517. foreach ( $items as $item ) {
  518. if ( in_array( $item->ID, $items_to_find ) ) {
  519. $item->menu_item_parent = $items_to_move[ $item->ID ]['new_parent'];
  520. $item->menu_order = $items_to_move[ $item->ID ]['new_order'];
  521. }
  522. }
  523. }
  524. $items = apply_filters( "megamenu_nav_menu_objects_after", $items, $args );
  525. return $items;
  526. }
  527. /**
  528. * Return the menu order of the next sibling menu item.
  529. * Eg, given A as the $item_id, the menu order of D will be returned
  530. * Eg, given B as the $item_id, the menu order of C will be returned
  531. * Eg, given D as the $item_id, the menu order of D + 1000 will be returned
  532. *
  533. * - A
  534. * --- B
  535. * --- C
  536. * - D
  537. *
  538. * @since 2.0
  539. * @param int $item_id
  540. * @param array $items
  541. * @return int
  542. */
  543. private function menu_order_of_next_sibling( $item_id, $menu_item_parent, $items ) {
  544. $get_order_of_next_item = false;
  545. foreach ( $items as $key => $item ) {
  546. if ( $menu_item_parent != $item->menu_item_parent ) {
  547. continue;
  548. }
  549. if ( $item->type == 'widget' ) {
  550. continue;
  551. }
  552. if ( $get_order_of_next_item ) {
  553. return $item->menu_order;
  554. }
  555. if ( $item->ID == $item_id ) {
  556. $get_order_of_next_item = true;
  557. }
  558. if ( isset( $item->menu_order ) ) {
  559. $rolling_last_menu_order = $item->menu_order;
  560. }
  561. }
  562. // there isn't a next sibling
  563. return $rolling_last_menu_order + 1000;
  564. }
  565. /**
  566. * Setup the mega menu settings for each menu item
  567. *
  568. * @since 2.0
  569. * @param array $items - All menu item objects
  570. * @param object $args
  571. * @return array
  572. */
  573. public function setup_menu_items( $items, $args ) {
  574. // apply depth
  575. // @todo work out a better way to do this. Suggestions welcome..!
  576. $parents = array();
  577. foreach ( $items as $key => $item ) {
  578. if ( $item->menu_item_parent == 0 ) {
  579. $parents[] = $item->ID;
  580. $item->depth = 0;
  581. }
  582. }
  583. if ( count( $parents ) ) {
  584. foreach ( $items as $key => $item ) {
  585. if ( in_array( $item->menu_item_parent, $parents ) ) {
  586. $item->depth = 1;
  587. }
  588. }
  589. }
  590. // apply saved metadata to each menu item
  591. foreach ( $items as $item ) {
  592. $saved_settings = array_filter( (array) get_post_meta( $item->ID, '_megamenu', true ) );
  593. $item->megamenu_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $saved_settings );
  594. $item->megamenu_order = isset( $item->megamenu_settings['mega_menu_order'][$item->menu_item_parent] ) ? $item->megamenu_settings['mega_menu_order'][$item->menu_item_parent] : 0;
  595. $item->parent_submenu_type = 'flyout';
  596. if ( isset( $item->menu_order ) ) {
  597. $item->menu_order = $item->menu_order * 1000;
  598. }
  599. // add parent mega menu type
  600. if ( $item->depth == 1 ) {
  601. $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) );
  602. if ( isset( $parent_settings['type'] ) ) {
  603. $item->parent_submenu_type = $parent_settings['type'];
  604. }
  605. }
  606. }
  607. return $items;
  608. }
  609. /**
  610. * Reorder items within the mega menu.
  611. *
  612. * @since 2.0
  613. * @param array $items
  614. * @param object $args
  615. * @return array
  616. */
  617. public function reorder_menu_items_within_megamenus( $items, $args ) {
  618. $new_items = array();
  619. $wpml_lang_items = array();
  620. // reorder menu items within mega menus based on internal ordering
  621. foreach ( $items as $item ) {
  622. // items ordered with 'forced' ordering
  623. if ( property_exists( $item, 'parent_submenu_type' ) && $item->parent_submenu_type == 'megamenu' && property_exists( $item, 'megamenu_order' ) && $item->megamenu_order !== 0 ) {
  624. if ( $parent_menu_item = get_post( $item->menu_item_parent ) ) {
  625. $item->menu_order = $parent_menu_item->menu_order * 1000 + $item->megamenu_order;
  626. }
  627. }
  628. }
  629. foreach ( $items as $item ) {
  630. if ( in_array( 'wpml-ls-item', $item->classes ) ) {
  631. $item->classes[] = 'menu-flyout';
  632. $wpml_lang_items[] = $item;
  633. } else {
  634. $new_items[ $item->menu_order ] = $item;
  635. }
  636. }
  637. ksort( $new_items );
  638. return array_merge( $new_items, $wpml_lang_items );
  639. }
  640. /**
  641. * If descriptions are enabled, create a new 'mega_description' property.
  642. * This is for backwards compatibility for users who have used filters
  643. * to display descriptions
  644. *
  645. * @since 2.3
  646. * @param array $items
  647. * @param array $args
  648. * @return array
  649. */
  650. public function set_descriptions_if_enabled( $items, $args ) {
  651. $settings = get_option( 'megamenu_settings' );
  652. $descriptions = isset( $settings['descriptions'] ) ? $settings['descriptions'] : 'disabled';
  653. if ($descriptions == 'enabled') {
  654. foreach ( $items as $item ) {
  655. if ( property_exists( $item, 'description' ) && strlen( $item->description ) ) {
  656. $item->mega_description = $item->description;
  657. $item->classes[] = 'has-description';
  658. }
  659. }
  660. }
  661. return $items;
  662. }
  663. /**
  664. * Apply column and clear classes to menu items (inc. widgets)
  665. *
  666. * @since 2.0
  667. * @param array $items
  668. * @param array $args
  669. * @return array
  670. */
  671. public function apply_classes_to_menu_items( $items, $args ) {
  672. $parents = array();
  673. foreach ( $items as $item ) {
  674. if ( ! in_array("menu-row", $item->classes) && ! in_array("menu-column", $item->classes) ) {
  675. if ( $item->depth === 0 ) {
  676. $item->classes[] = 'align-' . $item->megamenu_settings['align'];
  677. $item->classes[] = 'menu-' . $item->megamenu_settings['type'];
  678. }
  679. if ( $item->megamenu_settings['hide_arrow'] == 'true' ) {
  680. $item->classes[] = 'hide-arrow';
  681. }
  682. if ( $item->megamenu_settings['icon'] != 'disabled' ) {
  683. $item->classes[] = 'has-icon';
  684. }
  685. if ( $item->megamenu_settings['icon_position'] != 'left' ) {
  686. $item->classes[] = "icon-" . $item->megamenu_settings['icon_position'];
  687. }
  688. if ( $item->megamenu_settings['hide_text'] == 'true' && $item->depth === 0 ) {
  689. $item->classes[] = 'hide-text';
  690. }
  691. if ( $item->megamenu_settings['item_align'] != 'left' && $item->depth === 0 ) {
  692. $item->classes[] = 'item-align-' . $item->megamenu_settings['item_align'];
  693. }
  694. if ( $item->megamenu_settings['hide_on_desktop'] == 'true' ) {
  695. $item->classes[] = 'hide-on-desktop';
  696. }
  697. if ( $item->megamenu_settings['hide_on_mobile'] == 'true' ) {
  698. $item->classes[] = 'hide-on-mobile';
  699. }
  700. if ( $item->megamenu_settings['hide_sub_menu_on_mobile'] == 'true' ) {
  701. $item->classes[] = 'hide-sub-menu-on-mobile';
  702. }
  703. if ( $item->megamenu_settings['disable_link'] == 'true') {
  704. $item->classes[] = 'disable-link';
  705. }
  706. }
  707. // add column classes for second level menu items displayed in mega menus
  708. if ( $item->parent_submenu_type == 'megamenu' ) {
  709. $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) );
  710. $parent_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $parent_settings );
  711. $span = $item->megamenu_settings['mega_menu_columns'];
  712. $total_columns = $parent_settings['panel_columns'];
  713. if ( $total_columns >= $span ) {
  714. $item->classes[] = "menu-columns-{$span}-of-{$total_columns}";
  715. $column_count = $span;
  716. } else {
  717. $item->classes[] = "menu-columns-{$total_columns}-of-{$total_columns}";
  718. $column_count = $total_columns;
  719. }
  720. if ( ! isset( $parents[ $item->menu_item_parent ] ) ) {
  721. $parents[ $item->menu_item_parent ] = $column_count;
  722. } else {
  723. $parents[ $item->menu_item_parent ] = $parents[ $item->menu_item_parent ] + $column_count;
  724. if ( $parents[ $item->menu_item_parent ] > $total_columns ) {
  725. $parents[ $item->menu_item_parent ] = $column_count;
  726. $item->classes[] = 'menu-clear';
  727. }
  728. }
  729. }
  730. }
  731. return $items;
  732. }
  733. /**
  734. * Use the Mega Menu walker to output the menu
  735. * Resets all parameters used in the wp_nav_menu call
  736. * Wraps the menu in mega-menu IDs and classes
  737. *
  738. * @since 1.0
  739. * @param $args array
  740. * @return array
  741. */
  742. public function modify_nav_menu_args( $args ) {
  743. if ( ! isset( $args['theme_location'] ) ) {
  744. return $args;
  745. }
  746. // internal action to use as a counter
  747. do_action('megamenu_instance_counter_' . $args['theme_location']);
  748. $num_times_called = did_action('megamenu_instance_counter_' . $args['theme_location']);
  749. $settings = get_option( 'megamenu_settings' );
  750. $current_theme_location = $args['theme_location'];
  751. $active_instance = isset( $settings['instances'][$current_theme_location] ) ? $settings['instances'][$current_theme_location] : 0;
  752. if ( $active_instance != 0 && $active_instance != $num_times_called ) {
  753. return $args;
  754. }
  755. $locations = get_nav_menu_locations();
  756. if ( isset ( $settings[ $current_theme_location ]['enabled'] ) && $settings[ $current_theme_location ]['enabled'] == true ) {
  757. if ( ! isset( $locations[ $current_theme_location ] ) ) {
  758. return $args;
  759. }
  760. $menu_id = $locations[ $current_theme_location ];
  761. if ( ! $menu_id ) {
  762. return $args;
  763. }
  764. $menu_theme = mmm_get_theme_for_location( $current_theme_location );
  765. $menu_settings = $settings[ $current_theme_location ];
  766. $effect = isset( $menu_settings['effect'] ) ? $menu_settings['effect'] : 'disabled';
  767. // convert Pro JS based effect to CSS3 effect
  768. if ( $effect == 'fadeUp' ) {
  769. $effect = 'fade_up';
  770. }
  771. // as set on the main settings page
  772. $vertical_behaviour = isset( $settings['mobile_behaviour'] ) ? $settings['mobile_behaviour'] : 'standard';
  773. if ( isset( $menu_settings['mobile_behaviour'] ) ) {
  774. $vertical_behaviour = $menu_settings['mobile_behaviour'];
  775. }
  776. // as set on the main settings page
  777. $second_click = isset( $settings['second_click'] ) ? $settings['second_click'] : 'close';
  778. if ( isset( $menu_settings['second_click'] ) ) {
  779. $second_click = $menu_settings['second_click'];
  780. }
  781. $unbind = isset( $settings['unbind'] ) ? $settings['unbind'] : 'enabled';
  782. if ( isset( $menu_settings['unbind'] ) ) {
  783. $unbind = $menu_settings['unbind'];
  784. }
  785. $event = 'hover_intent';
  786. if ( isset( $menu_settings['event'] ) ) {
  787. if ( $menu_settings['event'] == 'hover' ) {
  788. $event = 'hover_intent';
  789. } elseif ( $menu_settings['event'] == 'hover_' ) {
  790. $event = 'hover';
  791. } else {
  792. $event = $menu_settings['event'];
  793. }
  794. }
  795. $mobile_force_width = 'false';
  796. if ( isset( $menu_theme['mobile_menu_force_width'] ) && $menu_theme['mobile_menu_force_width'] == 'on' ) {
  797. if ( isset( $menu_theme['mobile_menu_force_width_selector'] ) ) {
  798. $mobile_force_width = $menu_theme['mobile_menu_force_width_selector'];
  799. } else {
  800. $mobile_force_width = 'body';
  801. }
  802. }
  803. $wrap_attributes = apply_filters("megamenu_wrap_attributes", array(
  804. "id" => '%1$s',
  805. "class" => '%2$s mega-no-js',
  806. "data-event" => $event,
  807. "data-effect" => $effect,
  808. "data-effect-speed" => isset( $menu_settings['effect_speed'] ) ? $menu_settings['effect_speed'] : '200',
  809. "data-effect-mobile" => isset( $menu_settings['effect_mobile'] ) ? $menu_settings['effect_mobile'] : 'disabled',
  810. "data-effect-speed-mobile" => isset( $menu_settings['effect_speed_mobile'] ) ? $menu_settings['effect_speed_mobile'] : '200',
  811. "data-panel-width" => preg_match('/^\d/', $menu_theme['panel_width']) !== 1 ? $menu_theme['panel_width'] : '',
  812. "data-panel-inner-width" => substr( $menu_theme['panel_inner_width'], -1 ) !== '%' ? $menu_theme['panel_inner_width'] : '',
  813. "data-mobile-force-width" => $mobile_force_width,
  814. "data-second-click" => $second_click,
  815. "data-document-click" => 'collapse',
  816. "data-vertical-behaviour" => $vertical_behaviour,
  817. "data-breakpoint" => absint( $menu_theme['responsive_breakpoint'] ),
  818. "data-unbind" => $unbind === "disabled" ? "false" : "true"
  819. ), $menu_id, $menu_settings, $settings, $current_theme_location );
  820. $attributes = "";
  821. foreach( $wrap_attributes as $attribute => $value ) {
  822. if ( strlen( $value ) ) {
  823. $attributes .= " " . $attribute . '="' . esc_attr( $value ) . '"';
  824. }
  825. }
  826. $sanitized_location = str_replace( apply_filters("megamenu_location_replacements", array("-", " ") ), "-", $current_theme_location );
  827. $defaults = array(
  828. 'menu' => wp_get_nav_menu_object( $menu_id ),
  829. 'container' => 'div',
  830. 'container_class' => 'mega-menu-wrap',
  831. 'container_id' => 'mega-menu-wrap-' . $sanitized_location,
  832. 'menu_class' => 'mega-menu max-mega-menu mega-menu-horizontal',
  833. 'menu_id' => 'mega-menu-' . $sanitized_location,
  834. 'fallback_cb' => 'wp_page_menu',
  835. 'before' => '',
  836. 'after' => '',
  837. 'link_before' => '',
  838. 'link_after' => '',
  839. 'items_wrap' => '<ul' . $attributes . '>%3$s</ul>',
  840. 'depth' => 0,
  841. 'walker' => new Mega_Menu_Walker()
  842. );
  843. $args = array_merge( $args, apply_filters( "megamenu_nav_menu_args", $defaults, $menu_id, $current_theme_location ) );
  844. }
  845. return $args;
  846. }
  847. /**
  848. * Display admin notices.
  849. */
  850. public function admin_notices() {
  851. if ( ! $this->is_compatible_wordpress_version() ) :
  852. ?>
  853. <div class="error">
  854. <p><?php _e( 'Max Mega Menu is not compatible with your version of WordPress. Please upgrade WordPress to the latest version or disable Max Mega Menu.', 'megamenu' ); ?></p>
  855. </div>
  856. <?php
  857. endif;
  858. if ( did_action('megamenu_after_install') === 1 ) :
  859. ?>
  860. <?php
  861. endif;
  862. $css_version = get_transient("megamenu_css_version");
  863. $css = get_transient("megamenu_css");
  864. if ( $css && version_compare( $this->scss_last_updated, $css_version, '>' ) ) :
  865. ?>
  866. <div class="updated">
  867. <?php
  868. $clear_cache_url = esc_url( add_query_arg(
  869. array(
  870. 'action' => 'megamenu_clear_css_cache'
  871. ),
  872. wp_nonce_url( admin_url("admin-post.php"), 'megamenu_clear_css_cache' )
  873. ) );
  874. $link = "<a href='{$clear_cache_url}'>" . __( "clear the CSS cache", 'megamenu' ) . "</a>";
  875. ?>
  876. <p><?php echo sprintf( __( 'Max Mega Menu has been updated. Please %s to ensure maximum compatibility with the latest version.', 'megamenu' ), $link); ?></p>
  877. </div>
  878. <?php
  879. endif;
  880. }
  881. /**
  882. * Checks this WordPress installation is v3.8 or above.
  883. * 3.8 is needed for dashicons.
  884. */
  885. public function is_compatible_wordpress_version() {
  886. global $wp_version;
  887. return $wp_version >= 3.8;
  888. }
  889. /**
  890. * Add compatibility for conditional menus plugin
  891. *
  892. * @since 2.2
  893. */
  894. public function conditional_menus_restore_theme_location( $location, $new_args, $old_args ) {
  895. return $old_args['theme_location'];
  896. }
  897. /**
  898. * Add a note to the Navigation Widget to explain that Max Mega Menu will not work with it.
  899. *
  900. * @since 2.5.1
  901. */
  902. public function add_notice_to_nav_menu_widget( $widget, $return, $instance ) {
  903. if ( 'nav_menu' == $widget->id_base ) {
  904. ?>
  905. <p style="font-size: 11px; font-style: italic;">
  906. <?php _e("If you are trying to display Max Mega Menu here, use the 'Max Mega Menu' widget instead.", "megamenu"); ?>
  907. <a href="https://www.megamenu.com/documentation/widget/" target="_blank"><?php _e("More information", "megamenu"); ?></a>
  908. </p>
  909. <?php
  910. }
  911. }
  912. }
  913. add_action( 'plugins_loaded', array( 'Mega_Menu', 'init' ), 10 );
  914. endif;
  915. if ( ! function_exists( 'mmm_get_theme_id_for_location' ) ) {
  916. /**
  917. * @since 2.1
  918. * @param string $location - theme location identifier
  919. */
  920. function mmm_get_theme_id_for_location( $location = false ) {
  921. if ( ! $location ) {
  922. return false;
  923. }
  924. if ( ! has_nav_menu( $location ) ) {
  925. return false;
  926. }
  927. // if a location has been passed, check to see if MMM has been enabled for the location
  928. $settings = get_option( 'megamenu_settings' );
  929. if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) {
  930. return $settings[ $location ]['theme'];
  931. }
  932. return false;
  933. }
  934. }
  935. if ( ! function_exists( 'mmm_get_theme_for_location' ) ) {
  936. /**
  937. * @since 2.0.2
  938. * @param string $location - theme location identifier
  939. */
  940. function mmm_get_theme_for_location( $location = false ) {
  941. if ( ! $location ) {
  942. return false;
  943. }
  944. if ( ! has_nav_menu( $location ) ) {
  945. return false;
  946. }
  947. // if a location has been passed, check to see if MMM has been enabled for the location
  948. $settings = get_option( 'megamenu_settings' );
  949. $style_manager = new Mega_Menu_Style_Manager();
  950. $themes = $style_manager->get_themes();
  951. if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) {
  952. $theme = $settings[ $location ]['theme'];
  953. $menu_theme = isset( $themes[ $theme ] ) ? $themes[ $theme ] : $themes['default'];
  954. return $menu_theme;
  955. }
  956. return $themes['default'];
  957. }
  958. }
  959. if ( ! function_exists( 'max_mega_menu_is_enabled' ) ) {
  960. /**
  961. * Determines if Max Mega Menu has been enabled for a given menu location.
  962. *
  963. * Usage:
  964. *
  965. * Max Mega Menu is enabled:
  966. * function_exists( 'max_mega_menu_is_enabled' )
  967. *
  968. * Max Mega Menu has been enabled for a theme location:
  969. * function_exists( 'max_mega_menu_is_enabled' ) && max_mega_menu_is_enabled( $location )
  970. *
  971. * @since 1.8
  972. * @param string $location - theme location identifier
  973. */
  974. function max_mega_menu_is_enabled( $location = false ) {
  975. if ( ! $location ) {
  976. return true; // the plugin is enabled
  977. }
  978. if ( ! has_nav_menu( $location ) ) {
  979. return false;
  980. }
  981. // if a location has been passed, check to see if MMM has been enabled for the location
  982. $settings = get_option( 'megamenu_settings' );
  983. return is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && $settings[ $location ]['enabled'] == true;
  984. }
  985. }
  986. if ( ! function_exists('max_mega_menu_share_themes_across_multisite') ) {
  987. /*
  988. * In the first version of MMM, themes were (incorrectly) shared between all sites in a multi site network.
  989. * Themes will not be shared across sites for new users installing v2.4.3 onwards, but they will be shared for existing (older) users.
  990. *
  991. * @since 2.3.7
  992. */
  993. function max_mega_menu_share_themes_across_multisite() {
  994. if ( defined('MEGAMENU_SHARE_THEMES_MULTISITE') && MEGAMENU_SHARE_THEMES_MULTISITE === false ) {
  995. return false;
  996. }
  997. if ( defined('MEGAMENU_SHARE_THEMES_MULTISITE') && MEGAMENU_SHARE_THEMES_MULTISITE === true ) {
  998. return true;
  999. }
  1000. if ( get_option('megamenu_multisite_share_themes') === 'false' ) { // only exists if initially installed version is 2.4.3+
  1001. return false;
  1002. }
  1003. return apply_filters( 'megamenu_share_themes_across_multisite', true );
  1004. }
  1005. }
  1006. if ( ! function_exists('max_mega_menu_get_themes') ) {
  1007. /*
  1008. * Return saved themes
  1009. *
  1010. * @since 2.3.7
  1011. */
  1012. function max_mega_menu_get_themes() {
  1013. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1014. return get_option( "megamenu_themes" );
  1015. }
  1016. return get_site_option( "megamenu_themes" );
  1017. }
  1018. }
  1019. if ( ! function_exists('max_mega_menu_save_themes') ) {
  1020. /*
  1021. * Save menu theme
  1022. *
  1023. * @since 2.3.7
  1024. */
  1025. function max_mega_menu_save_themes( $themes ) {
  1026. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1027. return update_option( "megamenu_themes", $themes );
  1028. }
  1029. return update_site_option( "megamenu_themes", $themes );
  1030. }
  1031. }
  1032. if ( ! function_exists('max_mega_menu_save_last_updated_theme') ) {
  1033. /*
  1034. * Save last updated theme
  1035. *
  1036. * @since 2.3.7
  1037. */
  1038. function max_mega_menu_save_last_updated_theme( $theme ) {
  1039. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1040. return update_option( "megamenu_themes_last_updated", $theme );
  1041. }
  1042. return update_site_option( "megamenu_themes_last_updated", $theme );
  1043. }
  1044. }
  1045. if ( ! function_exists('max_mega_menu_get_last_updated_theme') ) {
  1046. /*
  1047. * Return last updated theme
  1048. *
  1049. * @since 2.3.7
  1050. */
  1051. function max_mega_menu_get_last_updated_theme() {
  1052. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1053. return get_option( "megamenu_themes_last_updated" );
  1054. }
  1055. return get_site_option( "megamenu_themes_last_updated" );
  1056. }
  1057. }
  1058. if ( ! function_exists('max_mega_menu_get_toggle_blocks') ) {
  1059. /*
  1060. * Return saved toggle blocks
  1061. *
  1062. * @since 2.3.7
  1063. */
  1064. function max_mega_menu_get_toggle_blocks() {
  1065. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1066. return get_option( "megamenu_toggle_blocks" );
  1067. }
  1068. return get_site_option( "megamenu_toggle_blocks" );
  1069. }
  1070. }
  1071. if ( ! function_exists('max_mega_menu_save_toggle_blocks') ) {
  1072. /*
  1073. * Save toggle blocks
  1074. *
  1075. * @since 2.3.7
  1076. */
  1077. function max_mega_menu_save_toggle_blocks( $saved_blocks ) {
  1078. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1079. return update_option( "megamenu_toggle_blocks", $saved_blocks );
  1080. }
  1081. return update_site_option( "megamenu_toggle_blocks", $saved_blocks );
  1082. }
  1083. }
  1084. if ( ! function_exists('max_mega_menu_delete_themes') ) {
  1085. /*
  1086. * Delete saved themes
  1087. *
  1088. * @since 2.3.7
  1089. */
  1090. function max_mega_menu_delete_themes() {
  1091. if ( ! max_mega_menu_share_themes_across_multisite() ) {
  1092. return delete_option( "megamenu_themes" );
  1093. }
  1094. return delete_site_option( "megamenu_themes" );
  1095. }
  1096. }
  1097. if ( ! function_exists('max_mega_menu_get_active_caching_plugins') ) {
  1098. /**
  1099. * Return list of active caching/CDN/minification plugins
  1100. *
  1101. * @since 2.4
  1102. * @return array
  1103. */
  1104. function max_mega_menu_get_active_caching_plugins() {
  1105. $caching_plugins = apply_filters("megamenu_caching_plugins", array(
  1106. 'litespeed-cache/litespeed-cache.php',
  1107. 'js-css-script-optimizer/js-css-script-optimizer.php',
  1108. 'merge-minify-refresh/merge-minify-refresh.php',
  1109. 'minify-html-markup/minify-html.php',
  1110. 'simple-cache/simple-cache.php',
  1111. 'w3-total-cache/w3-total-cache.php',
  1112. 'wp-fastest-cache/wpFastestCache.php',
  1113. 'wp-speed-of-light/wp-speed-of-light.php',
  1114. 'wp-super-cache/wp-cache.php',
  1115. 'wp-super-minify/wp-super-minify.php',
  1116. 'autoptimize/autoptimize.php',
  1117. 'bwp-minify/bwp-minify.php',
  1118. 'cache-enabler/cache-enabler.php',
  1119. 'cloudflare/cloudflare.php',
  1120. 'comet-cache/comet-cache.php',
  1121. 'css-optimizer/bpminifycss.php',
  1122. 'fast-velocity-minify/fvm.php',
  1123. 'hyper-cache/plugin.php',
  1124. 'remove-query-strings-littlebizzy/remove-query-strings.php',
  1125. 'remove-query-strings-from-static-resources/remove-query-strings.php',
  1126. 'query-strings-remover/query-strings-remover.php',
  1127. 'wp-rocket/wp-rocket.php',
  1128. 'hummingbird-performance/wp-hummingbird.php',
  1129. 'breeze/breeze.php'
  1130. ));
  1131. $active_plugins = array();
  1132. foreach ( $caching_plugins as $plugin_path ) {
  1133. if ( is_plugin_active( $plugin_path ) ) {
  1134. $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
  1135. $active_plugins[] = $plugin_data['Name'];
  1136. }
  1137. }
  1138. return $active_plugins;
  1139. }
  1140. }