PluginProbe
EasyMega / 1.0.1
EasyMega v1.0.1
trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.9 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9
easymega / easymega.php

easymega.php in EasyMega 1.0.1, at easymega.php

191 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: EasyMega
4 Plugin URI: https://www.famethemes.com
5 Description: Add mega menu for WordPress
6 Author: famethemes, shrimp2t
7 Author URI: https://www.famethemes.com
8 Version: 1.0.1
9 Text Domain: megamenu-wp
10 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 */
12 if ( ! class_exists( 'MegaMenu_WP' ) ) {
13 class MegaMenu_WP
14 {
15 function __construct()
16 {
17 include MAGAZINE_MEGA_MENU_PATH . 'inc/admin.php';
18 include MAGAZINE_MEGA_MENU_PATH . 'inc/class-mega-item.php';
19 include MAGAZINE_MEGA_MENU_PATH . 'inc/menu.php';
20 include MAGAZINE_MEGA_MENU_PATH . 'inc/settings.php';
21 if (is_admin()) {
22 }
23 if (!is_admin()) {
24 add_action('wp_enqueue_scripts', array($this, 'scripts'), 3);
25 }
26 add_action('wp_ajax_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
27 add_action('wp_ajax_nopriv_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
28 add_filter('widget_text', 'do_shortcode');
29 }
30 static function get_theme_support($feature = null, $default = null)
31 {
32 $options = array(
33 'mobile_mod' => 0, // Break point when toggle mobile mod
34 'disable_auto_css' => 0, // Do not apply auto css
35 'parent_level' => 0, // Default parent Level
36 'content_right' => 0, //Content right
37 'content_left' => 0, //Content left
38 'animation' => '', //Animation
39 );
40 $support = get_theme_support('megamenu-wp');
41 if (is_array($support) && !empty($support)) {
42 $sp = current($support);
43 if (!$feature) {
44 return wp_parse_args($sp, $options);
45 }
46 if (is_array($sp)) {
47 if (isset($sp[$feature])) {
48 return $sp[$feature];
49 }
50 }
51 }
52 return wp_parse_args($default, $options);
53 }
54 function scripts()
55 {
56 wp_enqueue_style('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'style.css');
57 wp_enqueue_script('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'assets/js/megamenu-wp.js', array('jquery'), '1.0.1', true);
58 $support = $this->get_theme_support();
59 $args = array(
60 'ajax_url' => admin_url('admin-ajax.php'),
61 'loading_icon' => apply_filters('megamenu_wp_loading_icon', '<div class="spinner"><div class="uil-squares-css" style="transform:scale(0.4);"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div></div>'),
62 'theme_support' => $support
63 );
64 if (!$args['theme_support']['mobile_mod']) {
65 $args['theme_support']['mobile_mod'] = absint(get_theme_mod('mega_mobile_break_points', 720));
66 }
67 if (!$args['theme_support']['disable_auto_css']) {
68 $args['theme_support']['disable_auto_css'] = absint(get_theme_mod('mega_disable_css', false));
69 }
70 if ( $support['parent_level'] ) {
71 $args['mega_parent_level'] = absint( $support['parent_level'] );
72 } else {
73 $args['mega_parent_level'] = absint(get_theme_mod('mega_parent_level'));
74 }
75 if ( $support['content_left'] ) {
76 $args['mega_content_left'] = absint( $support['content_left'] );
77 } else {
78 $args['mega_content_left'] = absint(get_theme_mod('mega_content_left'));
79 }
80 if ( $support['content_right'] ) {
81 $args['mega_content_right'] = absint( $support['content_right'] );
82 } else {
83 $args['mega_content_right'] = absint(get_theme_mod('mega_content_right'));
84 }
85 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
86 if ( ! $support['animation'] ) {
87 $args['animation'] = get_theme_mod('mega_animation');
88 if (!$args['animation']) { // shift-up, shift-down, shift-left, shift-right, fade, flip, animation-none
89 $args['animation'] = 'shift-up';
90 }
91 } else {
92 $args['animation'] = $support['animation'];
93 }
94 wp_localize_script('megamenu-wp', 'MegamenuWp', $args);
95 $margin_top = get_theme_mod('mega_content_margin_top');
96 $margin_top = floatval($margin_top);
97 $css = '.megamenu-wp-desktop #megamenu-wp-page .megamenu-wp .mega-item .mega-content li.mega-content-li { margin-top: ' . $margin_top . 'px; }';
98 wp_add_inline_style('megamenu-wp', $css);
99 }
100 static function get_template($template)
101 {
102 $template_folders = array(
103 get_stylesheet_directory() . '/', // Child theme
104 get_stylesheet_directory() . '/templates/', // child theme
105 get_template_directory() . '/', // Parent theme
106 get_template_directory() . '/templates/', // Parent theme
107 MAGAZINE_MEGA_MENU_PATH . 'templates/' // Plugin
108 );
109
110 foreach ($template_folders as $folder) {
111 $file = $folder . $template;
112 if (file_exists($file)) {
113 return apply_filters('megamenuwp_get_nav_template', $file, $template);
114 }
115 }
116 return apply_filters('megamenuwp_get_nav_template', false, $template);
117 }
118 static function get_previewing_data($key, $default = null)
119 {
120 if (!isset($GLOBALS['_customized_decode']) || !is_array($GLOBALS['_customized_decode'])) {
121 return $default;
122 }
123 if (is_array($key)) {
124 if (isset($GLOBALS['_customized_decode'][$key[0]]) && is_array($GLOBALS['_customized_decode'][$key[0]])) {
125 if ($GLOBALS['_customized_decode'][$key[0]][$key[1]]) {
126 return $GLOBALS['_customized_decode'][$key[0]][$key[1]];
127 }
128 }
129 } else {
130 if (isset($GLOBALS['_customized_decode'][$key])) {
131 return $GLOBALS['_customized_decode'][$key];
132 }
133 }
134 return $default;
135 }
136 static function is_mega_nav_active($nav_id)
137 {
138 if (isset($GLOBALS['_mega_menu_enable_' . $nav_id])) {
139 return $GLOBALS['_mega_menu_enable_' . $nav_id];
140 }
141 $key = 'nav_menu[' . $nav_id . ']';
142 if (MegaMenu_WP::is_preview(array($key, 'mega_enable'))) {
143 $mega_enable = MegaMenu_WP::get_previewing_data(array($key, 'mega_enable'));
144 } else {
145 $mega_enable = get_term_meta($nav_id, '_mega_enable', true);
146 }
147 $GLOBALS['_mega_menu_enable_' . $nav_id] = $mega_enable;
148 return $GLOBALS['_mega_menu_enable_' . $nav_id];
149 }
150 static function is_preview($key_check = false)
151 {
152 if (is_customize_preview()) {
153 if (isset($_POST['wp_customize']) && $_POST['wp_customize'] == 'on') {
154 if (!isset($GLOBALS['_customized_decode'])) {
155 if (isset($_POST['customized'])) {
156 $GLOBALS['_customized_decode'] = json_decode(wp_unslash($_POST['customized']), true);
157 } else {
158 $GLOBALS['_customized_decode'] = array();
159 }
160 }
161 if ($key_check) {
162 if (is_array($key_check)) {
163 if (isset($GLOBALS['_customized_decode'] [$key_check[0]])) {
164 return isset($GLOBALS['_customized_decode'][$key_check[0]] [$key_check[1]]);
165 }
166 } else {
167 return isset($GLOBALS['_customized_decode'][$key_check]);
168 }
169 }
170 }
171 }
172 return false;
173 }
174 static function ajax_load_posts()
175 {
176 $args = MegaMenu_WP_Menu_Item::get_post_query_args($_REQUEST);
177 $content = MegaMenu_WP_Menu_Item::posts_content($args);
178 wp_send_json_success($content);
179 die();
180 }
181 }
182 }
183 function MegaMenu_WP__Init() {
184 if ( ! defined( 'MAGAZINE_MEGA_MENU_PATH' ) ) {
185 define('MAGAZINE_MEGA_MENU_URL', trailingslashit(plugins_url('', __FILE__)));
186 define('MAGAZINE_MEGA_MENU_PATH', trailingslashit(dirname(__FILE__)));
187 $GLOBALS['MegaMenu_WP'] = new MegaMenu_WP();
188 }
189 }
190 add_action( 'init', 'MegaMenu_WP__Init', 35 );
191