| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Mega Menu Plugin for WordPress |
| 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.0.7 |
| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
if ( ! class_exists( 'MegaMenu_WP' ) ) { |
| 17 |
class MegaMenu_WP |
| 18 |
{ |
| 19 |
function __construct() |
| 20 |
{ |
| 21 |
|
| 22 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/admin.php'; |
| 23 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/class-mega-item.php'; |
| 24 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/menu.php'; |
| 25 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/settings.php'; |
| 26 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/theme-supports.php'; |
| 27 |
|
| 28 |
if (is_admin()) { |
| 29 |
include MAGAZINE_MEGA_MENU_PATH . 'inc/dashboard.php'; |
| 30 |
} |
| 31 |
if (!is_admin()) { |
| 32 |
add_action('wp_enqueue_scripts', array($this, 'scripts'), 3); |
| 33 |
} |
| 34 |
|
| 35 |
add_action('wp_ajax_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts')); |
| 36 |
add_action('wp_ajax_nopriv_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts')); |
| 37 |
add_filter('widget_text', 'do_shortcode'); |
| 38 |
} |
| 39 |
|
| 40 |
static function get_theme_support($feature = null, $default = null) |
| 41 |
{ |
| 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( 'megamenu_wp_get_theme_support_args', get_theme_support('megamenu-wp') ); |
| 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( 'megamenu_wp_get_theme_support', $sp, $feature, $sp ); |
| 64 |
} |
| 65 |
|
| 66 |
if ( is_array( $sp ) ) { |
| 67 |
if (isset($sp[$feature])) { |
| 68 |
return apply_filters( 'megamenu_wp_get_theme_support', $sp[$feature], $feature, $sp ); |
| 69 |
} else { |
| 70 |
return apply_filters( 'megamenu_wp_get_theme_support', false, $feature, $options ); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
if ( $feature ) { |
| 76 |
return apply_filters( 'megamenu_wp_get_theme_support', false, $feature, $options ); |
| 77 |
} |
| 78 |
return apply_filters( 'megamenu_wp_get_theme_support', wp_parse_args( $default, $options), $feature, $options ); |
| 79 |
} |
| 80 |
|
| 81 |
static function get_pro_url( ){ |
| 82 |
return apply_filters( 'megamenuwp-pro-url', 'https://www.famethemes.com/plugins/easymega-pro/' ); |
| 83 |
} |
| 84 |
|
| 85 |
function scripts() |
| 86 |
{ |
| 87 |
$support = $this->get_theme_support(); |
| 88 |
if ( ! $support['disable_css'] ) { |
| 89 |
wp_enqueue_style('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'style.css'); |
| 90 |
} |
| 91 |
wp_enqueue_script('megamenu-wp', MAGAZINE_MEGA_MENU_URL . 'assets/js/megamenu-wp.js', array('jquery'), '1.0.1', true); |
| 92 |
|
| 93 |
$args = array( |
| 94 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 95 |
'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>'), |
| 96 |
'theme_support' => $support |
| 97 |
); |
| 98 |
|
| 99 |
if (!$args['theme_support']['mobile_mod']) { |
| 100 |
$args['theme_support']['mobile_mod'] = absint(get_theme_mod('mega_mobile_break_points', 720)); |
| 101 |
} |
| 102 |
|
| 103 |
if (!$args['theme_support']['disable_auto_css']) { |
| 104 |
$args['theme_support']['disable_auto_css'] = absint(get_theme_mod('mega_disable_css', false)); |
| 105 |
} |
| 106 |
|
| 107 |
if ( $support['parent_level'] ) { |
| 108 |
$args['mega_parent_level'] = absint( $support['parent_level'] ); |
| 109 |
} else { |
| 110 |
$args['mega_parent_level'] = absint(get_theme_mod('mega_parent_level')); |
| 111 |
} |
| 112 |
|
| 113 |
if ( $support['content_left'] ) { |
| 114 |
$args['mega_content_left'] = floatval( $support['content_left'] ); |
| 115 |
} else { |
| 116 |
$args['mega_content_left'] = floatval(get_theme_mod('mega_content_left')); |
| 117 |
} |
| 118 |
|
| 119 |
if ( $support['content_right'] ) { |
| 120 |
$args['mega_content_right'] = floatval( $support['content_right'] ); |
| 121 |
} else { |
| 122 |
$args['mega_content_right'] = floatval(get_theme_mod('mega_content_right')); |
| 123 |
} |
| 124 |
|
| 125 |
$args['mega_content_right'] = floatval(get_theme_mod('mega_content_right')); |
| 126 |
|
| 127 |
if ( ! $support['animation'] ) { |
| 128 |
$args['animation'] = get_theme_mod('mega_animation'); |
| 129 |
if (!$args['animation']) { // shift-up, shift-down, shift-left, shift-right, fade, flip, animation-none |
| 130 |
$args['animation'] = 'shift-up'; |
| 131 |
} |
| 132 |
} else { |
| 133 |
$args['animation'] = $support['animation']; |
| 134 |
} |
| 135 |
|
| 136 |
wp_localize_script('megamenu-wp', 'MegamenuWp', apply_filters( 'megamenu_wp_localize_script_args', $args ) ); |
| 137 |
|
| 138 |
if ( $support['margin_top'] ) { |
| 139 |
$margin_top = $support['margin_top'] ; |
| 140 |
} else { |
| 141 |
$margin_top = get_theme_mod('mega_content_margin_top'); |
| 142 |
} |
| 143 |
|
| 144 |
$margin_top = floatval($margin_top); |
| 145 |
$css = '.megamenu-wp-desktop #megamenu-wp-page .megamenu-wp .mega-item .mega-content li.mega-content-li { margin-top: ' . $margin_top . 'px; }'; |
| 146 |
if ( $support['ul_css'] ) { |
| 147 |
$css .= '.megamenu-wp-desktop #megamenu-wp-page .megamenu-wp .mega-item .mega-content li.mega-content-li{ '. $support['ul_css'].' }'; |
| 148 |
} |
| 149 |
|
| 150 |
if ( $support['li_css'] ) { |
| 151 |
$css .= '.megamenu-wp-desktop .megamenu-wp .mega-item .mega-content li.mega-content-li{ '. $support['li_css'].' }'; |
| 152 |
} |
| 153 |
|
| 154 |
if ( isset( $support['custom_css'] ) ) { |
| 155 |
$css .= $support['custom_css']; |
| 156 |
} |
| 157 |
|
| 158 |
wp_add_inline_style('megamenu-wp', $css); |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
static function get_template($template) |
| 163 |
{ |
| 164 |
|
| 165 |
$template_folders = array( |
| 166 |
get_stylesheet_directory() . '/', // Child theme |
| 167 |
get_stylesheet_directory() . '/templates/', // child theme |
| 168 |
get_template_directory() . '/', // Parent theme |
| 169 |
get_template_directory() . '/templates/', // Parent theme |
| 170 |
MAGAZINE_MEGA_MENU_PATH . 'templates/' // Plugin |
| 171 |
); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
foreach ($template_folders as $folder) { |
| 176 |
$file = $folder . $template; |
| 177 |
if (file_exists($file)) { |
| 178 |
return apply_filters('megamenuwp_get_nav_template', $file, $template); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
return apply_filters('megamenuwp_get_nav_template', false, $template); |
| 183 |
} |
| 184 |
|
| 185 |
static function get_previewing_data($key, $default = null) |
| 186 |
{ |
| 187 |
if (!isset($GLOBALS['_customized_decode']) || !is_array($GLOBALS['_customized_decode'])) { |
| 188 |
return $default; |
| 189 |
} |
| 190 |
if (is_array($key)) { |
| 191 |
if (isset($GLOBALS['_customized_decode'][$key[0]]) && is_array($GLOBALS['_customized_decode'][$key[0]])) { |
| 192 |
if ($GLOBALS['_customized_decode'][$key[0]][$key[1]]) { |
| 193 |
return $GLOBALS['_customized_decode'][$key[0]][$key[1]]; |
| 194 |
} |
| 195 |
} |
| 196 |
} else { |
| 197 |
if (isset($GLOBALS['_customized_decode'][$key])) { |
| 198 |
return $GLOBALS['_customized_decode'][$key]; |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
return $default; |
| 203 |
} |
| 204 |
|
| 205 |
static function is_mega_nav_active($nav_id) |
| 206 |
{ |
| 207 |
|
| 208 |
if (isset($GLOBALS['_mega_menu_enable_' . $nav_id])) { |
| 209 |
return $GLOBALS['_mega_menu_enable_' . $nav_id]; |
| 210 |
} |
| 211 |
|
| 212 |
$key = 'nav_menu[' . $nav_id . ']'; |
| 213 |
if (MegaMenu_WP::is_preview(array($key, 'mega_enable'))) { |
| 214 |
$mega_enable = MegaMenu_WP::get_previewing_data(array($key, 'mega_enable')); |
| 215 |
} else { |
| 216 |
$mega_enable = get_term_meta($nav_id, '_mega_enable', true); |
| 217 |
} |
| 218 |
|
| 219 |
$GLOBALS['_mega_menu_enable_' . $nav_id] = $mega_enable; |
| 220 |
return $GLOBALS['_mega_menu_enable_' . $nav_id]; |
| 221 |
} |
| 222 |
|
| 223 |
static function is_preview($key_check = false) |
| 224 |
{ |
| 225 |
if (is_customize_preview()) { |
| 226 |
if (isset($_POST['wp_customize']) && $_POST['wp_customize'] == 'on') { |
| 227 |
if (!isset($GLOBALS['_customized_decode'])) { |
| 228 |
if (isset($_POST['customized'])) { |
| 229 |
$GLOBALS['_customized_decode'] = json_decode(wp_unslash($_POST['customized']), true); |
| 230 |
} else { |
| 231 |
$GLOBALS['_customized_decode'] = array(); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if ($key_check) { |
| 236 |
if (is_array($key_check)) { |
| 237 |
if (isset($GLOBALS['_customized_decode'] [$key_check[0]])) { |
| 238 |
return isset($GLOBALS['_customized_decode'][$key_check[0]] [$key_check[1]]); |
| 239 |
} |
| 240 |
} else { |
| 241 |
return isset($GLOBALS['_customized_decode'][$key_check]); |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
return false; |
| 247 |
} |
| 248 |
|
| 249 |
static function ajax_load_posts() |
| 250 |
{ |
| 251 |
$args = MegaMenu_WP_Menu_Item::get_post_query_args($_REQUEST); |
| 252 |
$content = MegaMenu_WP_Menu_Item::posts_content($args); |
| 253 |
wp_send_json_success($content); |
| 254 |
die(); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
function MegaMenu_WP__Init() { |
| 262 |
if ( ! defined( 'MAGAZINE_MEGA_MENU_PATH' ) ) { |
| 263 |
define('MAGAZINE_MEGA_MENU_URL', trailingslashit(plugins_url('', __FILE__))); |
| 264 |
define('MAGAZINE_MEGA_MENU_PATH', trailingslashit(dirname(__FILE__))); |
| 265 |
$GLOBALS['MegaMenu_WP'] = new MegaMenu_WP(); |
| 266 |
} |
| 267 |
} |
| 268 |
add_action( 'init', 'MegaMenu_WP__Init', 35 ); |
| 269 |
|
| 270 |
|
| 271 |
function megamenuwp_activation_redirect( $plugin ) { |
| 272 |
if( $plugin == plugin_basename( __FILE__ ) ) { |
| 273 |
exit( wp_redirect( admin_url( 'options-general.php?page=megamenu-wp' ) ) ); |
| 274 |
} |
| 275 |
} |
| 276 |
add_action( 'activated_plugin', 'megamenuwp_activation_redirect' ); |
| 277 |
|
| 278 |
|
| 279 |
|