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