Beispiel #1
0
 /**
  * Constructor
  *
  * @since 1.0
  */
 public function __construct()
 {
     $this->define_constants();
     $this->includes();
     add_action('init', array($this, 'load_plugin_textdomain'));
     add_action('admin_init', array($this, 'install_upgrade_check'));
     add_action('admin_notices', array($this, 'admin_notices'));
     add_action('widgets_init', array($this, 'register_widget'));
     add_action('after_setup_theme', array($this, 'register_nav_menus'));
     add_filter('wp_nav_menu_args', array($this, 'modify_nav_menu_args'), 9999);
     add_filter('wp_nav_menu', array($this, 'add_responsive_toggle'), 10, 2);
     add_filter('wp_nav_menu_objects', array($this, 'add_widgets_to_menu'), 10, 2);
     add_filter('megamenu_nav_menu_objects_before', array($this, 'setup_menu_items'), 5, 2);
     add_filter('megamenu_nav_menu_objects_after', array($this, 'reorder_menu_items_within_megamenus'), 6, 2);
     add_filter('megamenu_nav_menu_objects_after', array($this, 'apply_classes_to_menu_items'), 7, 2);
     add_filter('megamenu_nav_menu_css_class', array($this, 'prefix_menu_classes'));
     add_filter('black_studio_tinymce_enable_pages', array($this, 'megamenu_blackstudio_tinymce'));
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 11);
     // add 'go pro' link to plugin options
     $plugin = plugin_basename(__FILE__);
     add_filter("plugin_action_links_{$plugin}", array($this, 'upgrade_to_pro_link'));
     add_shortcode('maxmenu', array($this, 'register_shortcode'));
     add_shortcode('maxmegamenu', array($this, 'register_shortcode'));
     if (is_admin()) {
         new Mega_Menu_Nav_Menus();
         new Mega_Menu_Widget_Manager();
         new Mega_Menu_Menu_Item_Manager();
         new Mega_Menu_Settings();
     }
     if (class_exists('Mega_Menu_Toggle_Blocks')) {
         new Mega_Menu_Toggle_Blocks();
     }
     $mega_menu_style_manager = new Mega_Menu_Style_Manager();
     $mega_menu_style_manager->setup_actions();
 }
 /**
  * Return default menu toggle block settings
  *
  * @since 2.1
  * @return array
  */
 private function get_default_menu_toggle_block($theme_id = 'default')
 {
     $style_manager = new Mega_Menu_Style_Manager();
     $themes = $style_manager->get_themes();
     $menu_theme = isset($themes[$theme_id]) ? $themes[$theme_id] : $themes['default'];
     $defaults = array('type' => 'menu_toggle', 'align' => 'right', 'closed_text' => isset($menu_theme['responsive_text']) ? $menu_theme['responsive_text'] : "MENU", 'open_text' => isset($menu_theme['responsive_text']) ? $menu_theme['responsive_text'] : "MENU", 'closed_icon' => 'dash-f333', 'open_icon' => 'dash-f153', 'icon_position' => 'after', 'text_color' => isset($menu_theme['toggle_font_color']) ? $menu_theme['toggle_font_color'] : '#fff', 'icon_color' => isset($menu_theme['toggle_font_color']) ? $menu_theme['toggle_font_color'] : '#fff');
     return $defaults;
 }
Beispiel #3
0
 /**
  * Retrieve the enabled Google Fonts from the settings
  *
  * @since 1.0
  */
 public function set_enabled_fonts()
 {
     $settings = get_option("megamenu_settings");
     if (!is_array($settings)) {
         return;
     }
     if (!class_exists('Mega_Menu_Style_Manager')) {
         return;
     }
     $style_manager = new Mega_Menu_Style_Manager();
     $google_fonts = $this->google_fonts();
     foreach ($settings as $location => $settings) {
         if (isset($settings['enabled']) && has_nav_menu($location)) {
             $theme_id = isset($settings['theme']) ? $settings['theme'] : 'default';
             $all_themes = $style_manager->get_themes();
             $theme_settings = isset($all_themes[$theme_id]) ? $all_themes[$theme_id] : $all_themes['default'];
             foreach ($theme_settings as $theme_setting => $value) {
                 if (in_array($value, $google_fonts)) {
                     $this->enabled_fonts[$value] = $value;
                 }
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Use the Mega Menu walker to output the menu
  * Resets all parameters used in the wp_nav_menu call
  * Wraps the menu in mega-menu IDs and classes
  *
  * @since 1.0
  * @param $args array
  * @return array
  */
 public function modify_nav_menu_args($args)
 {
     $settings = get_option('megamenu_settings');
     $current_theme_location = $args['theme_location'];
     $locations = get_nav_menu_locations();
     if (isset($settings[$current_theme_location]['enabled']) && $settings[$current_theme_location]['enabled'] == true) {
         if (!isset($locations[$current_theme_location])) {
             return $args;
         }
         $menu_id = $locations[$current_theme_location];
         if (!$menu_id) {
             return $args;
         }
         $style_manager = new Mega_Menu_Style_Manager();
         $themes = $style_manager->get_themes();
         $menu_theme = isset($themes[$settings[$current_theme_location]['theme']]) ? $themes[$settings[$current_theme_location]['theme']] : $themes['default'];
         $menu_settings = $settings[$current_theme_location];
         $wrap_attributes = apply_filters("megamenu_wrap_attributes", array("id" => '%1$s', "class" => '%2$s mega-no-js', "data-event" => isset($menu_settings['event']) ? $menu_settings['event'] : 'hover', "data-effect" => isset($menu_settings['effect']) ? $menu_settings['effect'] : 'disabled', "data-panel-width" => preg_match('/^\\d/', $menu_theme['panel_width']) !== 1 ? $menu_theme['panel_width'] : '', "data-second-click" => isset($settings['second_click']) ? $settings['second_click'] : 'close', "data-mobile-behaviour" => isset($settings['mobile_behaviour']) ? $settings['mobile_behaviour'] : 'standard', "data-breakpoint" => absint($menu_theme['responsive_breakpoint'])), $menu_id, $menu_settings, $settings, $current_theme_location);
         $attributes = "";
         foreach ($wrap_attributes as $attribute => $value) {
             if (strlen($value)) {
                 $attributes .= " " . $attribute . '="' . $value . '"';
             }
         }
         $sanitized_location = str_replace(apply_filters("megamenu_location_replacements", array("-", " ")), "-", $current_theme_location);
         $defaults = array('menu' => $menu_id, 'container' => 'div', 'container_class' => 'mega-menu-wrap', 'container_id' => 'mega-menu-wrap-' . $sanitized_location, 'menu_class' => 'mega-menu mega-menu-horizontal', 'menu_id' => 'mega-menu-' . $sanitized_location, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul' . $attributes . '>%3$s</ul>', 'depth' => 0, 'walker' => new Mega_Menu_Walker());
         $args = array_merge($args, apply_filters("megamenu_nav_menu_args", $defaults, $menu_id, $current_theme_location));
     }
     return $args;
 }
Beispiel #5
0
        /**
         * Print the list of Mega Menu settings
         *
         * @since 1.0
         */
        public function settings_table($location, $settings)
        {
            ?>
        <table>
            <tr>
                <td><?php 
            _e("Enable", "megamenu");
            ?>
</td>
                <td>
                    <input type='checkbox' class='megamenu_enabled' name='megamenu_meta[<?php 
            echo $location;
            ?>
][enabled]' value='1' <?php 
            checked(isset($settings[$location]['enabled']));
            ?>
 />
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Event", "megamenu");
            ?>
</td>
                <td>
                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][event]'>
                        <option value='hover' <?php 
            selected(isset($settings[$location]['event']) && $settings[$location]['event'] == 'hover');
            ?>
><?php 
            _e("Hover", "megamenu");
            ?>
</option>
                        <option value='click' <?php 
            selected(isset($settings[$location]['event']) && $settings[$location]['event'] == 'click');
            ?>
><?php 
            _e("Click", "megamenu");
            ?>
</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Effect", "megamenu");
            ?>
</td>
                <td>
                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][effect]'>
                    <?php 
            $selected = isset($settings[$location]['effect']) ? $settings[$location]['effect'] : 'disabled';
            $options = apply_filters("megamenu_effects", array("disabled" => array('label' => __("None", "megamenu"), 'selected' => $selected == 'disabled'), "fade" => array('label' => __("Fade", "megamenu"), 'selected' => $selected == 'fade'), "slide" => array('label' => __("Slide", "megamenu"), 'selected' => $selected == 'slide')), $selected);
            foreach ($options as $key => $value) {
                ?>
<option value='<?php 
                echo $key;
                ?>
' <?php 
                selected($value['selected']);
                ?>
><?php 
                echo $value['label'];
                ?>
</option><?php 
            }
            ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Theme", "megamenu");
            ?>
</td>
                <td>

                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][theme]'>
                        <?php 
            $style_manager = new Mega_Menu_Style_Manager();
            $themes = $style_manager->get_themes();
            $selected_theme = isset($settings[$location]['theme']) ? $settings[$location]['theme'] : 'default';
            foreach ($themes as $key => $theme) {
                echo "<option value='{$key}' " . selected($selected_theme, $key) . ">{$theme['title']}</option>";
            }
            ?>
                    </select>
                </td>
            </tr>

            <?php 
            do_action('megamenu_settings_table', $location, $settings);
            ?>
        </table>
        <?php 
        }
Beispiel #6
0
 /**
  * Display messages to the user
  *
  * @since 1.0
  */
 public function print_messages()
 {
     $this->init();
     $style_manager = new Mega_Menu_Style_Manager();
     $menu_id = 0;
     $menus = get_registered_nav_menus();
     if (count($menus)) {
         $locations = get_nav_menu_locations();
         foreach ($menus as $location => $description) {
             if (isset($locations[$location])) {
                 $menu_id = $locations[$location];
                 continue;
             }
         }
     }
     $test = $style_manager->generate_css_for_location('test', $this->active_theme, $menu_id);
     if (is_wp_error($test)) {
         echo "<p class='fail'>" . $test->get_error_message() . "</p>";
     }
     if (isset($_GET['deleted']) && $_GET['deleted'] == 'false') {
         echo "<p class='fail'>" . __("Failed to delete theme. The theme is in use by a menu.", "megamenu") . "</p>";
     }
     if (isset($_GET['regenerate_css']) && $_GET['regenerate_css'] == 'true') {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("CSS cache cleared and CSS regenerated", "megamenu") . "</p>";
     }
     if (isset($_GET['delete_data']) && $_GET['delete_data'] == 'true') {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("All plugin data removed", "megamenu") . "</p>";
     }
     if (isset($_GET['deleted']) && $_GET['deleted'] == 'true') {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Theme Deleted", "megamenu") . "</p>";
     }
     if (isset($_GET['duplicated'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Theme Duplicated", "megamenu") . "</p>";
     }
     if (isset($_GET['saved'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Changes Saved", "megamenu") . "</p>";
     }
     if (isset($_GET['reverted'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Theme Reverted", "megamenu") . "</p>";
     }
     if (isset($_GET['created'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("New Theme Created", "megamenu") . "</p>";
     }
     if (isset($_GET['add_location'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("New Menu Location Created", "megamenu") . "</p>";
     }
     if (isset($_GET['delete_location'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Menu Location Deleted", "megamenu") . "</p>";
     }
     if (isset($_GET['theme_imported']) && $_GET['theme_imported'] == 'true') {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Theme Imported", "megamenu") . "</p>";
     }
     if (isset($_GET['theme_imported']) && $_GET['theme_imported'] == 'false') {
         echo "<p class='fail'>" . __("Theme Import Failed", "megamenu") . "</p>";
     }
     if (isset($_POST['theme_export'])) {
         echo "<p class='success'><i class='dashicons dashicons-yes'></i>" . __("Theme Exported", "megamenu") . "</p>";
     }
     do_action("megamenu_print_messages");
 }
Beispiel #7
0
 /**
  * Regenerate the CSS for the menu's. The generated CSS is then cached.
  *
  * @since 1.2
  */
 public function regenerate_css()
 {
     $style_manager = new Mega_Menu_Style_Manager();
     $style_manager->empty_cache();
 }
 /**
  * Lists the available themes
  *
  * @since 1.0
  */
 public function theme_selector()
 {
     $list_items = "";
     foreach ($this->themes as $id => $theme) {
         $class = $id == $this->id ? 'mega_active' : '';
         $style_manager = new Mega_Menu_Style_Manager();
         $test = $style_manager->generate_css_for_location('tmp-location', $theme, 0);
         $error = is_wp_error($test) ? 'error' : '';
         $list_items .= "<li class='{$class} {$error}'><a href='" . admin_url("themes.php?page=megamenu_theme_editor&theme={$id}") . "'>{$theme['title']}</a></li>";
     }
     return $list_items;
 }
Beispiel #9
0
        /**
         * Print the list of Mega Menu settings
         *
         * @since 1.0
         */
        public function settings_table($location, $settings)
        {
            ?>
        <table>
            <tr>
                <td><?php 
            _e("Enable", "megamenu");
            ?>
</td>
                <td>
                    <input type='checkbox' name='megamenu_meta[<?php 
            echo $location;
            ?>
][enabled]' value='1' <?php 
            checked(isset($settings[$location]['enabled']));
            ?>
 />
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Event", "megamenu");
            ?>
</td>
                <td>
                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][event]'>
                        <option value='hover' <?php 
            selected(isset($settings[$location]['event']) && $settings[$location]['event'] == 'hover');
            ?>
><?php 
            _e("Hover", "megamenu");
            ?>
</option>
                        <option value='click' <?php 
            selected(isset($settings[$location]['event']) && $settings[$location]['event'] == 'click');
            ?>
><?php 
            _e("Click", "megamenu");
            ?>
</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Effect", "megamenu");
            ?>
</td>
                <td>
                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][effect]'>
                        <option value='disabled' <?php 
            selected(isset($settings[$location]['effect']) && $settings[$location]['effect'] == 'disabled');
            ?>
><?php 
            _e("None", "megamenu");
            ?>
</option>
                        <option value='fade' <?php 
            selected(isset($settings[$location]['effect']) && $settings[$location]['effect'] == 'fade');
            ?>
><?php 
            _e("Fade", "megamenu");
            ?>
</option>
                        <option value='slide' <?php 
            selected(isset($settings[$location]['effect']) && $settings[$location]['effect'] == 'slide');
            ?>
><?php 
            _e("Slide", "megamenu");
            ?>
</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><?php 
            _e("Theme", "megamenu");
            ?>
</td>
                <td>

                    <select name='megamenu_meta[<?php 
            echo $location;
            ?>
][theme]'>
                        <?php 
            $style_manager = new Mega_Menu_Style_Manager();
            $themes = $style_manager->get_themes();
            foreach ($themes as $key => $theme) {
                echo "<option value='{$key}' " . selected($settings[$location]['theme'], $key) . ">{$theme['title']}</option>";
            }
            ?>
                    </select>
                </td>
            </tr>

            <?php 
            do_action('megamenu_settings_table', $location, $settings);
            ?>
        </table>
        <?php 
        }