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