PluginProbe
EasyMega / 1.1.7
EasyMega v1.1.7
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.1.7, at easymega.php

284 lines 10.1 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: The EasyMega plugin helps you create mega menu easily, beautifully in any themes. Using the lightweight live Customizer system.
6 Author: famethemes
7 Author URI: https://www.famethemes.com
8 Version: 1.1.7
9 Text Domain: easymega
10 License: GPLv2 or later
11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
12 */
13
14
15
16
17 if (! class_exists('EasyMega')) {
18 class EasyMega
19 {
20
21 function __construct()
22 {
23 include EASYMEGA_PATH . 'inc/admin.php';
24 include EASYMEGA_PATH . 'inc/class-mega-item.php';
25 include EASYMEGA_PATH . 'inc/menu.php';
26 include EASYMEGA_PATH . 'inc/settings.php';
27 include EASYMEGA_PATH . 'inc/theme-supports.php';
28
29 if (is_admin()) {
30 include EASYMEGA_PATH . 'inc/dashboard.php';
31 }
32 if (! is_admin()) {
33 add_action('wp_enqueue_scripts', array($this, 'scripts'), 3);
34 }
35
36 add_action('wp_ajax_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
37 add_action('wp_ajax_nopriv_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
38 add_filter('widget_text', 'do_shortcode');
39 }
40
41 static function get_theme_support($feature = null, $default = null)
42 {
43 $options = array(
44 'mobile_mod' => 0, // Break point when toggle mobile mod
45 'disable_auto_css' => 0, // Do not apply auto css
46 'disable_css' => 0, // Do not load plugin css
47 'parent_level' => 0, // Default parent Level
48 'content_right' => 0, // Content right
49 'content_left' => 0, // Content left
50 'margin_top' => 0, // Content left
51 'animation' => '', // Animation
52 'child_li' => '', // Use ul li for menu item children
53 'ul_css' => '', // Css of child mega `ul.mega-content` element
54 'li_css' => '', // Css of child mega `ul.mega-conten li.mega-content-li` element
55 );
56
57 $support = apply_filters('easymega_wp_get_theme_support_args', get_theme_support('easymega'));
58
59 if (is_array($support) && ! empty($support)) {
60 $sp = current($support);
61 if (! $feature) {
62 $sp = wp_parse_args($sp, $default);
63 return apply_filters('easymega_wp_get_theme_support', $sp, $feature, $sp);
64 }
65
66 if (is_array($sp)) {
67 if (isset($sp[$feature])) {
68 return apply_filters('easymega_wp_get_theme_support', $sp[$feature], $feature, $sp);
69 } else {
70 return apply_filters('easymega_wp_get_theme_support', false, $feature, $options);
71 }
72 }
73 }
74
75 if ($feature) {
76 return apply_filters('easymega_wp_get_theme_support', false, $feature, $options);
77 }
78 return apply_filters('easymega_wp_get_theme_support', wp_parse_args($default, $options), $feature, $options);
79 }
80
81 static function get_pro_url()
82 {
83 return apply_filters('megamenuwp-pro-url', 'https://www.famethemes.com/plugins/easymega-pro/');
84 }
85
86 function scripts()
87 {
88 $support = $this->get_theme_support();
89 if (! isset($support['disable_css']) || ! $support['disable_css']) {
90 $css_file = EASYMEGA_PATH . 'assets/css/style.css';
91 if (file_exists($css_file)) {
92 $v = filemtime($css_file);
93 wp_enqueue_style('easymega', EASYMEGA_URL . 'assets/css/style.css', false, $v);
94 }
95 }
96 $js_file = EASYMEGA_PATH . 'assets/js/easymega-wp.js';
97 $v = filemtime($js_file);
98 wp_enqueue_script('easymega', EASYMEGA_URL . 'assets/js/easymega-wp.js', array('jquery'), $v, true);
99
100 $args = array(
101 'ajax_url' => admin_url('admin-ajax.php'),
102 'loading_icon' => apply_filters('easymega_wp_loading_icon', '<div class="mega-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>'),
103 'theme_support' => $support,
104 );
105
106 if (! $args['theme_support']['mobile_mod']) {
107 $args['theme_support']['mobile_mod'] = absint(get_theme_mod('mega_mobile_break_points', 720));
108 }
109
110 if (! isset($args['theme_support']['disable_auto_css']) || ! $args['theme_support']['disable_auto_css']) {
111 $args['theme_support']['disable_auto_css'] = absint(get_theme_mod('mega_disable_css', false));
112 }
113
114 if (isset($support['parent_level']) && $support['parent_level']) {
115 $args['mega_parent_level'] = absint($support['parent_level']);
116 } else {
117 $args['mega_parent_level'] = absint(get_theme_mod('mega_parent_level'));
118 }
119
120 if (isset($support['content_left']) && $support['content_left']) {
121 $args['mega_content_left'] = floatval($support['content_left']);
122 } else {
123 $args['mega_content_left'] = floatval(get_theme_mod('mega_content_left'));
124 }
125
126 if (isset($support['content_right']) && $support['content_right']) {
127 $args['mega_content_right'] = floatval($support['content_right']);
128 } else {
129 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
130 }
131
132 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
133
134 if (! isset($support['animation']) || ! $support['animation']) {
135 $args['animation'] = get_theme_mod('mega_animation');
136 if (! $args['animation']) { // shift-up, shift-down, shift-left, shift-right, fade, flip, animation-none
137 $args['animation'] = 'shift-up';
138 }
139 } else {
140 $args['animation'] = $support['animation'];
141 }
142
143 wp_localize_script('easymega', 'MegamenuWp', apply_filters('easymega_wp_localize_script_args', $args));
144
145 if ($support['margin_top']) {
146 $margin_top = $support['margin_top'];
147 } else {
148 $margin_top = get_theme_mod('mega_content_margin_top');
149 }
150
151 $margin_top = floatval($margin_top);
152 $css = '.easymega-wp-desktop #easymega-wp-page .easymega-wp .mega-item .mega-content li.mega-content-li { margin-top: ' . $margin_top . 'px; }';
153 if (isset($support['ul_css']) && $support['ul_css']) {
154 $css .= '.easymega-wp-desktop #easymega-wp-page .easymega-wp .mega-item .mega-content li.mega-content-li{ ' . $support['ul_css'] . ' }';
155 }
156
157 if (isset($support['li_css']) && $support['li_css']) {
158 $css .= '.easymega-wp-desktop .easymega-wp .mega-item .mega-content li.mega-content-li{ ' . $support['li_css'] . ' }';
159 }
160
161 if (isset($support['custom_css'])) {
162 $css .= $support['custom_css'];
163 }
164
165 wp_add_inline_style('easymega', $css);
166 }
167
168 static function get_template($template)
169 {
170 $template_folders = array(
171 get_stylesheet_directory() . '/', // Child theme
172 get_stylesheet_directory() . '/templates/', // child theme
173 get_template_directory() . '/', // Parent theme
174 get_template_directory() . '/templates/', // Parent theme
175 EASYMEGA_PATH . 'templates/', // Plugin
176 );
177
178
179
180 foreach ($template_folders as $folder) {
181 $file = $folder . $template;
182 if (file_exists($file)) {
183 return apply_filters('easymega_get_nav_template', $file, $template);
184 }
185 }
186
187 return apply_filters('easymega_get_nav_template', false, $template);
188 }
189
190 static function get_previewing_data($key, $default = null)
191 {
192 if (! isset($GLOBALS['_customized_decode']) || ! is_array($GLOBALS['_customized_decode'])) {
193 return $default;
194 }
195 if (is_array($key)) {
196 if (isset($GLOBALS['_customized_decode'][$key[0]]) && is_array($GLOBALS['_customized_decode'][$key[0]])) {
197 if ($GLOBALS['_customized_decode'][$key[0]][$key[1]]) {
198 return $GLOBALS['_customized_decode'][$key[0]][$key[1]];
199 }
200 }
201 } else {
202 if (isset($GLOBALS['_customized_decode'][$key])) {
203 return $GLOBALS['_customized_decode'][$key];
204 }
205 }
206
207 return $default;
208 }
209
210 static function is_mega_nav_active($nav_id)
211 {
212 if (isset($GLOBALS['_mega_menu_enable_' . $nav_id])) {
213 return $GLOBALS['_mega_menu_enable_' . $nav_id];
214 }
215
216 $key = 'nav_menu[' . $nav_id . ']';
217 if (self::is_preview(array($key, 'mega_enable'))) {
218 $mega_enable = self::get_previewing_data(array($key, 'mega_enable'));
219 } else {
220 $mega_enable = get_term_meta($nav_id, '_mega_enable', true);
221 }
222
223 $GLOBALS['_mega_menu_enable_' . $nav_id] = $mega_enable;
224 return $GLOBALS['_mega_menu_enable_' . $nav_id];
225 }
226
227 static function is_preview($key_check = false)
228 {
229 if (is_customize_preview()) {
230 if (isset($_POST['wp_customize']) && $_POST['wp_customize'] == 'on') { // phpcs:ignore WordPress.Security.NonceVerification.Missing
231 if (! isset($GLOBALS['_customized_decode'])) {
232 if (isset($_POST['customized'])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
233 $GLOBALS['_customized_decode'] = json_decode(wp_unslash($_POST['customized']), true); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
234 } else {
235 $GLOBALS['_customized_decode'] = array();
236 }
237 }
238
239 if ($key_check) {
240 if (is_array($key_check)) {
241 if (isset($GLOBALS['_customized_decode'][$key_check[0]])) {
242 return isset($GLOBALS['_customized_decode'][$key_check[0]][$key_check[1]]);
243 }
244 } else {
245 return isset($GLOBALS['_customized_decode'][$key_check]);
246 }
247 }
248 }
249 }
250 return false;
251 }
252
253 static function ajax_load_posts()
254 {
255 $args = EasyMega_Menu_Item::get_post_query_args($_REQUEST); // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended
256 $content = EasyMega_Menu_Item::posts_content($args);
257 wp_send_json_success($content);
258 die();
259 }
260 }
261 }
262
263
264
265 function EasyMega__Init()
266 {
267 if (! defined('EASYMEGA_PATH')) {
268 define('EASYMEGA_URL', trailingslashit(plugins_url('', __FILE__)));
269 define('EASYMEGA_PATH', trailingslashit(dirname(__FILE__)));
270 $GLOBALS['EasyMega'] = new EasyMega();
271 }
272 }
273 add_action('init', 'EasyMega__Init', 35);
274
275
276 function easymega_activation_redirect($plugin)
277 {
278 if ($plugin == plugin_basename(__FILE__)) {
279 wp_redirect(admin_url('options-general.php?page=easymega'));
280 die();
281 }
282 }
283 add_action('activated_plugin', 'easymega_activation_redirect');
284