PluginProbe
EasyMega / 1.0.3
EasyMega v1.0.3
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.3, at easymega.php

205 lines 9.6 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.3
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 'disable_css' => 0, // Do not load plugin css
36 'parent_level' => 0, // Default parent Level
37 'content_right' => 0, //Content right
38 'content_left' => 0, //Content left
39 'margin_top' => 0, //Content left
40 'animation' => '', //Animation
41 'child_li' => '', // Use ul li for menu item children
42 );
43 $support = get_theme_support('megamenu-wp');
44 if (is_array($support) && !empty($support)) {
45 $sp = current($support);
46 if ( ! $feature ) {
47 return wp_parse_args($sp, $options);
48 }
49 if (is_array($sp)) {
50 if (isset($sp[$feature])) {
51 return $sp[$feature];
52 } else {
53 return false;
54 }
55 }
56 }
57 if ( $feature ) {
58 return false;
59 }
60 return wp_parse_args($default, $options);
61 }
62 function scripts()
63 {
64 $support = $this->get_theme_support();
65 if ( ! $support['disable_css'] ) {
66 wp_enqueue_style('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'style.css');
67 }
68 wp_enqueue_script('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'assets/js/megamenu-wp.js', array('jquery'), '1.0.1', true);
69 $args = array(
70 'ajax_url' => admin_url('admin-ajax.php'),
71 'loading_icon' => apply_filters('megamenu_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>'),
72 'theme_support' => $support
73 );
74 if (!$args['theme_support']['mobile_mod']) {
75 $args['theme_support']['mobile_mod'] = absint(get_theme_mod('mega_mobile_break_points', 720));
76 }
77 if (!$args['theme_support']['disable_auto_css']) {
78 $args['theme_support']['disable_auto_css'] = absint(get_theme_mod('mega_disable_css', false));
79 }
80 if ( $support['parent_level'] ) {
81 $args['mega_parent_level'] = absint( $support['parent_level'] );
82 } else {
83 $args['mega_parent_level'] = absint(get_theme_mod('mega_parent_level'));
84 }
85 if ( $support['content_left'] ) {
86 $args['mega_content_left'] = floatval( $support['content_left'] );
87 } else {
88 $args['mega_content_left'] = floatval(get_theme_mod('mega_content_left'));
89 }
90 if ( $support['content_right'] ) {
91 $args['mega_content_right'] = floatval( $support['content_right'] );
92 } else {
93 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
94 }
95 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
96 if ( ! $support['animation'] ) {
97 $args['animation'] = get_theme_mod('mega_animation');
98 if (!$args['animation']) { // shift-up, shift-down, shift-left, shift-right, fade, flip, animation-none
99 $args['animation'] = 'shift-up';
100 }
101 } else {
102 $args['animation'] = $support['animation'];
103 }
104 wp_localize_script('megamenu-wp', 'MegamenuWp', apply_filters( 'megamenu_wp_localize_script_args', $args ) );
105 if ( $support['margin_top'] ) {
106 $margin_top = $support['margin_top'] ;
107 } else {
108 $margin_top = get_theme_mod('mega_content_margin_top');
109 }
110 $margin_top = floatval($margin_top);
111 $css = '.megamenu-wp-desktop #megamenu-wp-page .megamenu-wp .mega-item .mega-content li.mega-content-li { margin-top: ' . $margin_top . 'px; }';
112 wp_add_inline_style('megamenu-wp', $css);
113 }
114 static function get_template($template)
115 {
116 $template_folders = array(
117 get_stylesheet_directory() . '/', // Child theme
118 get_stylesheet_directory() . '/templates/', // child theme
119 get_template_directory() . '/', // Parent theme
120 get_template_directory() . '/templates/', // Parent theme
121 MAGAZINE_MEGA_MENU_PATH . 'templates/' // Plugin
122 );
123
124 foreach ($template_folders as $folder) {
125 $file = $folder . $template;
126 if (file_exists($file)) {
127 return apply_filters('megamenuwp_get_nav_template', $file, $template);
128 }
129 }
130 return apply_filters('megamenuwp_get_nav_template', false, $template);
131 }
132 static function get_previewing_data($key, $default = null)
133 {
134 if (!isset($GLOBALS['_customized_decode']) || !is_array($GLOBALS['_customized_decode'])) {
135 return $default;
136 }
137 if (is_array($key)) {
138 if (isset($GLOBALS['_customized_decode'][$key[0]]) && is_array($GLOBALS['_customized_decode'][$key[0]])) {
139 if ($GLOBALS['_customized_decode'][$key[0]][$key[1]]) {
140 return $GLOBALS['_customized_decode'][$key[0]][$key[1]];
141 }
142 }
143 } else {
144 if (isset($GLOBALS['_customized_decode'][$key])) {
145 return $GLOBALS['_customized_decode'][$key];
146 }
147 }
148 return $default;
149 }
150 static function is_mega_nav_active($nav_id)
151 {
152 if (isset($GLOBALS['_mega_menu_enable_' . $nav_id])) {
153 return $GLOBALS['_mega_menu_enable_' . $nav_id];
154 }
155 $key = 'nav_menu[' . $nav_id . ']';
156 if (MegaMenu_WP::is_preview(array($key, 'mega_enable'))) {
157 $mega_enable = MegaMenu_WP::get_previewing_data(array($key, 'mega_enable'));
158 } else {
159 $mega_enable = get_term_meta($nav_id, '_mega_enable', true);
160 }
161 $GLOBALS['_mega_menu_enable_' . $nav_id] = $mega_enable;
162 return $GLOBALS['_mega_menu_enable_' . $nav_id];
163 }
164 static function is_preview($key_check = false)
165 {
166 if (is_customize_preview()) {
167 if (isset($_POST['wp_customize']) && $_POST['wp_customize'] == 'on') {
168 if (!isset($GLOBALS['_customized_decode'])) {
169 if (isset($_POST['customized'])) {
170 $GLOBALS['_customized_decode'] = json_decode(wp_unslash($_POST['customized']), true);
171 } else {
172 $GLOBALS['_customized_decode'] = array();
173 }
174 }
175 if ($key_check) {
176 if (is_array($key_check)) {
177 if (isset($GLOBALS['_customized_decode'] [$key_check[0]])) {
178 return isset($GLOBALS['_customized_decode'][$key_check[0]] [$key_check[1]]);
179 }
180 } else {
181 return isset($GLOBALS['_customized_decode'][$key_check]);
182 }
183 }
184 }
185 }
186 return false;
187 }
188 static function ajax_load_posts()
189 {
190 $args = MegaMenu_WP_Menu_Item::get_post_query_args($_REQUEST);
191 $content = MegaMenu_WP_Menu_Item::posts_content($args);
192 wp_send_json_success($content);
193 die();
194 }
195 }
196 }
197 function MegaMenu_WP__Init() {
198 if ( ! defined( 'MAGAZINE_MEGA_MENU_PATH' ) ) {
199 define('MAGAZINE_MEGA_MENU_URL', trailingslashit(plugins_url('', __FILE__)));
200 define('MAGAZINE_MEGA_MENU_PATH', trailingslashit(dirname(__FILE__)));
201 $GLOBALS['MegaMenu_WP'] = new MegaMenu_WP();
202 }
203 }
204 add_action( 'init', 'MegaMenu_WP__Init', 35 );
205