@@ -1,1195 +1,1195 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Style_Manager' ) ) : |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * |
|
| 11 | - */ |
|
| 12 | - final class Mega_Menu_Style_Manager { |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * |
|
| 16 | - */ |
|
| 17 | - var $settings = array(); |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Constructor |
|
| 22 | - * |
|
| 23 | - * @since 1.0 |
|
| 24 | - */ |
|
| 25 | - public function __construct() { |
|
| 26 | - $this->settings = get_option( 'megamenu_settings' ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Setup actions |
|
| 32 | - * |
|
| 33 | - * @since 1.0 |
|
| 34 | - */ |
|
| 35 | - public function setup_actions() { |
|
| 36 | - add_action( 'megamenu_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 37 | - add_action( 'megamenu_enqueue_styles', array( $this, 'enqueue_styles' ) ); |
|
| 38 | - |
|
| 39 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 40 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999 ); |
|
| 41 | - add_action( 'wp_head', array( $this, 'head_css' ), 9999 ); |
|
| 42 | - add_action( 'megamenu_delete_cache', array( $this, 'delete_cache' ) ); |
|
| 43 | - add_action( 'megamenu_delete_cache', array( $this, 'clear_external_caches' ) ); |
|
| 44 | - add_action( 'after_switch_theme', array( $this, 'delete_cache' ) ); |
|
| 45 | - |
|
| 46 | - add_action( 'megamenu_head_css', array( $this, 'head_css' ), 999 ); |
|
| 47 | - |
|
| 48 | - // PolyLang |
|
| 49 | - if ( function_exists( 'pll_current_language' ) ) { |
|
| 50 | - add_filter( 'megamenu_css_transient_key', array( $this, 'polylang_transient_key' ) ); |
|
| 51 | - add_filter( 'megamenu_css_filename', array( $this, 'polylang_css_filename' ) ); |
|
| 52 | - add_action( 'megamenu_after_delete_cache', array( $this, 'polylang_delete_cache' ) ); |
|
| 53 | - } elseif ( defined( 'ICL_LANGUAGE_CODE' ) ) { // WPML |
|
| 54 | - add_filter( 'megamenu_css_transient_key', array( $this, 'wpml_transient_key' ) ); |
|
| 55 | - add_filter( 'megamenu_css_filename', array( $this, 'wpml_css_filename' ) ); |
|
| 56 | - add_action( 'megamenu_after_delete_cache', array( $this, 'wpml_delete_cache' ) ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - add_filter( 'megamenu_scripts_in_footer', array( $this, 'scripts_in_footer' ) ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Determines whether to load JavaScript in footer or not, based on the configured option. |
|
| 65 | - * |
|
| 66 | - * @since 2.9 |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - function scripts_in_footer() { |
|
| 70 | - if ( isset( $this->settings['js'] ) && $this->settings['js'] == 'head' ) { |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return true; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Clear plugin caches when CSS is updated or menu settings are changed |
|
| 80 | - */ |
|
| 81 | - public function clear_external_caches() { |
|
| 82 | - // Breeze: https://wordpress.org/plugins/breeze/ |
|
| 83 | - do_action( 'breeze_clear_all_cache' ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Return the default menu theme |
|
| 89 | - */ |
|
| 90 | - public function get_default_theme() { |
|
| 91 | - return apply_filters( |
|
| 92 | - 'megamenu_default_theme', |
|
| 93 | - array( |
|
| 94 | - 'title' => __( 'Default', 'megamenu' ), |
|
| 95 | - 'container_background_from' => '#222', |
|
| 96 | - 'container_background_to' => '#222', |
|
| 97 | - 'container_padding_left' => '0px', |
|
| 98 | - 'container_padding_right' => '0px', |
|
| 99 | - 'container_padding_top' => '0px', |
|
| 100 | - 'container_padding_bottom' => '0px', |
|
| 101 | - 'container_border_radius_top_left' => '0px', |
|
| 102 | - 'container_border_radius_top_right' => '0px', |
|
| 103 | - 'container_border_radius_bottom_left' => '0px', |
|
| 104 | - 'container_border_radius_bottom_right' => '0px', |
|
| 105 | - 'arrow_up' => 'dash-f142', |
|
| 106 | - 'arrow_down' => 'dash-f140', |
|
| 107 | - 'arrow_left' => 'dash-f141', |
|
| 108 | - 'arrow_right' => 'dash-f139', |
|
| 109 | - 'font_size' => '14px', // deprecated |
|
| 110 | - 'font_color' => '#666', // deprecated |
|
| 111 | - 'font_family' => 'inherit', // deprecated |
|
| 112 | - 'menu_item_align' => 'left', |
|
| 113 | - 'menu_item_background_from' => 'rgba(0,0,0,0)', |
|
| 114 | - 'menu_item_background_to' => 'rgba(0,0,0,0)', |
|
| 115 | - 'menu_item_background_hover_from' => '#333', |
|
| 116 | - 'menu_item_background_hover_to' => '#333', |
|
| 117 | - 'menu_item_spacing' => '0px', |
|
| 118 | - 'menu_item_link_font' => 'inherit', |
|
| 119 | - 'menu_item_link_font_size' => '14px', |
|
| 120 | - 'menu_item_link_height' => '40px', |
|
| 121 | - 'menu_item_link_color' => '#ffffff', |
|
| 122 | - 'menu_item_link_weight' => 'normal', |
|
| 123 | - 'menu_item_link_text_transform' => 'none', |
|
| 124 | - 'menu_item_link_text_decoration' => 'none', |
|
| 125 | - 'menu_item_link_text_align' => 'left', |
|
| 126 | - 'menu_item_link_color_hover' => '#ffffff', |
|
| 127 | - 'menu_item_link_weight_hover' => 'normal', |
|
| 128 | - 'menu_item_link_text_decoration_hover' => 'none', |
|
| 129 | - 'menu_item_link_padding_left' => '10px', |
|
| 130 | - 'menu_item_link_padding_right' => '10px', |
|
| 131 | - 'menu_item_link_padding_top' => '0px', |
|
| 132 | - 'menu_item_link_padding_bottom' => '0px', |
|
| 133 | - 'menu_item_link_border_radius_top_left' => '0px', |
|
| 134 | - 'menu_item_link_border_radius_top_right' => '0px', |
|
| 135 | - 'menu_item_link_border_radius_bottom_left' => '0px', |
|
| 136 | - 'menu_item_link_border_radius_bottom_right' => '0px', |
|
| 137 | - 'menu_item_border_color' => '#fff', |
|
| 138 | - 'menu_item_border_left' => '0px', |
|
| 139 | - 'menu_item_border_right' => '0px', |
|
| 140 | - 'menu_item_border_top' => '0px', |
|
| 141 | - 'menu_item_border_bottom' => '0px', |
|
| 142 | - 'menu_item_border_color_hover' => '#fff', |
|
| 143 | - 'menu_item_highlight_current' => 'on', |
|
| 144 | - 'menu_item_divider' => 'off', |
|
| 145 | - 'menu_item_divider_color' => 'rgba(255, 255, 255, 0.1)', |
|
| 146 | - 'menu_item_divider_glow_opacity' => '0.1', |
|
| 147 | - 'panel_background_from' => '#f1f1f1', |
|
| 148 | - 'panel_background_to' => '#f1f1f1', |
|
| 149 | - 'panel_width' => '100%', |
|
| 150 | - 'panel_inner_width' => '100%', |
|
| 151 | - 'panel_border_color' => '#fff', |
|
| 152 | - 'panel_border_left' => '0px', |
|
| 153 | - 'panel_border_right' => '0px', |
|
| 154 | - 'panel_border_top' => '0px', |
|
| 155 | - 'panel_border_bottom' => '0px', |
|
| 156 | - 'panel_border_radius_top_left' => '0px', |
|
| 157 | - 'panel_border_radius_top_right' => '0px', |
|
| 158 | - 'panel_border_radius_bottom_left' => '0px', |
|
| 159 | - 'panel_border_radius_bottom_right' => '0px', |
|
| 160 | - 'panel_header_color' => '#555', |
|
| 161 | - 'panel_header_text_transform' => 'uppercase', |
|
| 162 | - 'panel_header_text_align' => 'left', |
|
| 163 | - 'panel_header_font' => 'inherit', |
|
| 164 | - 'panel_header_font_size' => '16px', |
|
| 165 | - 'panel_header_font_weight' => 'bold', |
|
| 166 | - 'panel_header_text_decoration' => 'none', |
|
| 167 | - 'panel_header_padding_top' => '0px', |
|
| 168 | - 'panel_header_padding_right' => '0px', |
|
| 169 | - 'panel_header_padding_bottom' => '5px', |
|
| 170 | - 'panel_header_padding_left' => '0px', |
|
| 171 | - 'panel_header_margin_top' => '0px', |
|
| 172 | - 'panel_header_margin_right' => '0px', |
|
| 173 | - 'panel_header_margin_bottom' => '0px', |
|
| 174 | - 'panel_header_margin_left' => '0px', |
|
| 175 | - 'panel_header_border_color' => 'rgba(0,0,0,0)', |
|
| 176 | - 'panel_header_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 177 | - 'panel_header_border_left' => '0px', |
|
| 178 | - 'panel_header_border_right' => '0px', |
|
| 179 | - 'panel_header_border_top' => '0px', |
|
| 180 | - 'panel_header_border_bottom' => '0px', |
|
| 181 | - 'panel_padding_left' => '0px', |
|
| 182 | - 'panel_padding_right' => '0px', |
|
| 183 | - 'panel_padding_top' => '0px', |
|
| 184 | - 'panel_padding_bottom' => '0px', |
|
| 185 | - 'panel_widget_padding_left' => '15px', |
|
| 186 | - 'panel_widget_padding_right' => '15px', |
|
| 187 | - 'panel_widget_padding_top' => '15px', |
|
| 188 | - 'panel_widget_padding_bottom' => '15px', |
|
| 189 | - 'panel_font_size' => 'font_size', |
|
| 190 | - 'panel_font_color' => 'font_color', |
|
| 191 | - 'panel_font_family' => 'font_family', |
|
| 192 | - 'panel_second_level_font_color' => 'panel_header_color', |
|
| 193 | - 'panel_second_level_font_color_hover' => 'panel_header_color', |
|
| 194 | - 'panel_second_level_text_transform' => 'panel_header_text_transform', |
|
| 195 | - 'panel_second_level_text_align' => 'left', |
|
| 196 | - 'panel_second_level_font' => 'panel_header_font', |
|
| 197 | - 'panel_second_level_font_size' => 'panel_header_font_size', |
|
| 198 | - 'panel_second_level_font_weight' => 'panel_header_font_weight', |
|
| 199 | - 'panel_second_level_font_weight_hover' => 'panel_header_font_weight', |
|
| 200 | - 'panel_second_level_text_decoration' => 'panel_header_text_decoration', |
|
| 201 | - 'panel_second_level_text_decoration_hover' => 'panel_header_text_decoration', |
|
| 202 | - 'panel_second_level_background_hover_from' => 'rgba(0,0,0,0)', |
|
| 203 | - 'panel_second_level_background_hover_to' => 'rgba(0,0,0,0)', |
|
| 204 | - 'panel_second_level_padding_left' => '0px', |
|
| 205 | - 'panel_second_level_padding_right' => '0px', |
|
| 206 | - 'panel_second_level_padding_top' => '0px', |
|
| 207 | - 'panel_second_level_padding_bottom' => '0px', |
|
| 208 | - 'panel_second_level_margin_left' => '0px', |
|
| 209 | - 'panel_second_level_margin_right' => '0px', |
|
| 210 | - 'panel_second_level_margin_top' => '0px', |
|
| 211 | - 'panel_second_level_margin_bottom' => '0px', |
|
| 212 | - 'panel_second_level_border_color' => 'rgba(0,0,0,0)', |
|
| 213 | - 'panel_second_level_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 214 | - 'panel_second_level_border_left' => '0px', |
|
| 215 | - 'panel_second_level_border_right' => '0px', |
|
| 216 | - 'panel_second_level_border_top' => '0px', |
|
| 217 | - 'panel_second_level_border_bottom' => '0px', |
|
| 218 | - 'panel_third_level_font_color' => 'panel_font_color', |
|
| 219 | - 'panel_third_level_font_color_hover' => 'panel_font_color', |
|
| 220 | - 'panel_third_level_text_transform' => 'none', |
|
| 221 | - 'panel_third_level_text_align' => 'left', |
|
| 222 | - 'panel_third_level_font' => 'panel_font_family', |
|
| 223 | - 'panel_third_level_font_size' => 'panel_font_size', |
|
| 224 | - 'panel_third_level_font_weight' => 'normal', |
|
| 225 | - 'panel_third_level_font_weight_hover' => 'normal', |
|
| 226 | - 'panel_third_level_text_decoration' => 'none', |
|
| 227 | - 'panel_third_level_text_decoration_hover' => 'none', |
|
| 228 | - 'panel_third_level_background_hover_from' => 'rgba(0,0,0,0)', |
|
| 229 | - 'panel_third_level_background_hover_to' => 'rgba(0,0,0,0)', |
|
| 230 | - 'panel_third_level_padding_left' => '0px', |
|
| 231 | - 'panel_third_level_padding_right' => '0px', |
|
| 232 | - 'panel_third_level_padding_top' => '0px', |
|
| 233 | - 'panel_third_level_padding_bottom' => '0px', |
|
| 234 | - 'panel_third_level_margin_left' => '0px', |
|
| 235 | - 'panel_third_level_margin_right' => '0px', |
|
| 236 | - 'panel_third_level_margin_top' => '0px', |
|
| 237 | - 'panel_third_level_margin_bottom' => '0px', |
|
| 238 | - 'panel_third_level_border_color' => 'rgba(0,0,0,0)', |
|
| 239 | - 'panel_third_level_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 240 | - 'panel_third_level_border_left' => '0px', |
|
| 241 | - 'panel_third_level_border_right' => '0px', |
|
| 242 | - 'panel_third_level_border_top' => '0px', |
|
| 243 | - 'panel_third_level_border_bottom' => '0px', |
|
| 244 | - 'flyout_width' => '250px', |
|
| 245 | - 'flyout_menu_background_from' => '#f1f1f1', |
|
| 246 | - 'flyout_menu_background_to' => '#f1f1f1', |
|
| 247 | - 'flyout_border_color' => '#ffffff', |
|
| 248 | - 'flyout_border_left' => '0px', |
|
| 249 | - 'flyout_border_right' => '0px', |
|
| 250 | - 'flyout_border_top' => '0px', |
|
| 251 | - 'flyout_border_bottom' => '0px', |
|
| 252 | - 'flyout_border_radius_top_left' => '0px', |
|
| 253 | - 'flyout_border_radius_top_right' => '0px', |
|
| 254 | - 'flyout_border_radius_bottom_left' => '0px', |
|
| 255 | - 'flyout_border_radius_bottom_right' => '0px', |
|
| 256 | - 'flyout_menu_item_divider' => 'off', |
|
| 257 | - 'flyout_menu_item_divider_color' => 'rgba(255, 255, 255, 0.1)', |
|
| 258 | - 'flyout_padding_top' => '0px', |
|
| 259 | - 'flyout_padding_right' => '0px', |
|
| 260 | - 'flyout_padding_bottom' => '0px', |
|
| 261 | - 'flyout_padding_left' => '0px', |
|
| 262 | - 'flyout_link_padding_left' => '10px', |
|
| 263 | - 'flyout_link_padding_right' => '10px', |
|
| 264 | - 'flyout_link_padding_top' => '0px', |
|
| 265 | - 'flyout_link_padding_bottom' => '0px', |
|
| 266 | - 'flyout_link_weight' => 'normal', |
|
| 267 | - 'flyout_link_weight_hover' => 'normal', |
|
| 268 | - 'flyout_link_height' => '35px', |
|
| 269 | - 'flyout_link_text_decoration' => 'none', |
|
| 270 | - 'flyout_link_text_decoration_hover' => 'none', |
|
| 271 | - 'flyout_background_from' => '#f1f1f1', |
|
| 272 | - 'flyout_background_to' => '#f1f1f1', |
|
| 273 | - 'flyout_background_hover_from' => '#dddddd', |
|
| 274 | - 'flyout_background_hover_to' => '#dddddd', |
|
| 275 | - 'flyout_link_size' => 'font_size', |
|
| 276 | - 'flyout_link_color' => 'font_color', |
|
| 277 | - 'flyout_link_color_hover' => 'font_color', |
|
| 278 | - 'flyout_link_family' => 'font_family', |
|
| 279 | - 'flyout_link_text_transform' => 'none', |
|
| 280 | - 'responsive_breakpoint' => '768px', |
|
| 281 | - 'responsive_text' => 'MENU', // deprecated |
|
| 282 | - 'line_height' => '1.7', |
|
| 283 | - 'z_index' => '999', |
|
| 284 | - 'shadow' => 'off', |
|
| 285 | - 'shadow_horizontal' => '0px', |
|
| 286 | - 'shadow_vertical' => '0px', |
|
| 287 | - 'shadow_blur' => '5px', |
|
| 288 | - 'shadow_spread' => '0px', |
|
| 289 | - 'shadow_color' => 'rgba(0, 0, 0, 0.1)', |
|
| 290 | - 'transitions' => 'off', |
|
| 291 | - 'resets' => 'off', |
|
| 292 | - 'mobile_columns' => '1', |
|
| 293 | - 'toggle_background_from' => 'container_background_from', |
|
| 294 | - 'toggle_background_to' => 'container_background_to', |
|
| 295 | - 'toggle_font_color' => 'rgb(221, 221, 221)', // deprecated |
|
| 296 | - 'toggle_bar_height' => '40px', |
|
| 297 | - 'toggle_bar_border_radius_top_left' => '2px', |
|
| 298 | - 'toggle_bar_border_radius_top_right' => '2px', |
|
| 299 | - 'toggle_bar_border_radius_bottom_left' => '2px', |
|
| 300 | - 'toggle_bar_border_radius_bottom_right' => '2px', |
|
| 301 | - 'mobile_menu_padding_left' => '0px', |
|
| 302 | - 'mobile_menu_padding_right' => '0px', |
|
| 303 | - 'mobile_menu_padding_top' => '0px', |
|
| 304 | - 'mobile_menu_padding_bottom' => '0px', |
|
| 305 | - 'mobile_menu_item_height' => '40px', |
|
| 306 | - 'mobile_menu_overlay' => 'off', |
|
| 307 | - 'mobile_menu_force_width' => 'off', |
|
| 308 | - 'mobile_menu_force_width_selector' => 'body', |
|
| 309 | - 'mobile_background_from' => 'container_background_from', |
|
| 310 | - 'mobile_background_to' => 'container_background_to', |
|
| 311 | - 'mobile_menu_item_link_font_size' => 'menu_item_link_font_size', |
|
| 312 | - 'mobile_menu_item_link_color' => 'menu_item_link_color', |
|
| 313 | - 'mobile_menu_item_link_text_align' => 'menu_item_link_text_align', |
|
| 314 | - 'mobile_menu_item_link_color_hover' => 'menu_item_link_color_hover', |
|
| 315 | - 'mobile_menu_item_background_hover_from' => 'menu_item_background_hover_from', |
|
| 316 | - 'mobile_menu_item_background_hover_to' => 'menu_item_background_hover_to', |
|
| 317 | - 'mobile_menu_off_canvas_width' => '300px', |
|
| 318 | - 'disable_mobile_toggle' => 'off', |
|
| 319 | - 'custom_css' => '/** Push menu onto new line **/ |
|
| 9 | + /** |
|
| 10 | + * |
|
| 11 | + */ |
|
| 12 | + final class Mega_Menu_Style_Manager { |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * |
|
| 16 | + */ |
|
| 17 | + var $settings = array(); |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Constructor |
|
| 22 | + * |
|
| 23 | + * @since 1.0 |
|
| 24 | + */ |
|
| 25 | + public function __construct() { |
|
| 26 | + $this->settings = get_option( 'megamenu_settings' ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Setup actions |
|
| 32 | + * |
|
| 33 | + * @since 1.0 |
|
| 34 | + */ |
|
| 35 | + public function setup_actions() { |
|
| 36 | + add_action( 'megamenu_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 37 | + add_action( 'megamenu_enqueue_styles', array( $this, 'enqueue_styles' ) ); |
|
| 38 | + |
|
| 39 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 40 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999 ); |
|
| 41 | + add_action( 'wp_head', array( $this, 'head_css' ), 9999 ); |
|
| 42 | + add_action( 'megamenu_delete_cache', array( $this, 'delete_cache' ) ); |
|
| 43 | + add_action( 'megamenu_delete_cache', array( $this, 'clear_external_caches' ) ); |
|
| 44 | + add_action( 'after_switch_theme', array( $this, 'delete_cache' ) ); |
|
| 45 | + |
|
| 46 | + add_action( 'megamenu_head_css', array( $this, 'head_css' ), 999 ); |
|
| 47 | + |
|
| 48 | + // PolyLang |
|
| 49 | + if ( function_exists( 'pll_current_language' ) ) { |
|
| 50 | + add_filter( 'megamenu_css_transient_key', array( $this, 'polylang_transient_key' ) ); |
|
| 51 | + add_filter( 'megamenu_css_filename', array( $this, 'polylang_css_filename' ) ); |
|
| 52 | + add_action( 'megamenu_after_delete_cache', array( $this, 'polylang_delete_cache' ) ); |
|
| 53 | + } elseif ( defined( 'ICL_LANGUAGE_CODE' ) ) { // WPML |
|
| 54 | + add_filter( 'megamenu_css_transient_key', array( $this, 'wpml_transient_key' ) ); |
|
| 55 | + add_filter( 'megamenu_css_filename', array( $this, 'wpml_css_filename' ) ); |
|
| 56 | + add_action( 'megamenu_after_delete_cache', array( $this, 'wpml_delete_cache' ) ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + add_filter( 'megamenu_scripts_in_footer', array( $this, 'scripts_in_footer' ) ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Determines whether to load JavaScript in footer or not, based on the configured option. |
|
| 65 | + * |
|
| 66 | + * @since 2.9 |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + function scripts_in_footer() { |
|
| 70 | + if ( isset( $this->settings['js'] ) && $this->settings['js'] == 'head' ) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return true; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Clear plugin caches when CSS is updated or menu settings are changed |
|
| 80 | + */ |
|
| 81 | + public function clear_external_caches() { |
|
| 82 | + // Breeze: https://wordpress.org/plugins/breeze/ |
|
| 83 | + do_action( 'breeze_clear_all_cache' ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Return the default menu theme |
|
| 89 | + */ |
|
| 90 | + public function get_default_theme() { |
|
| 91 | + return apply_filters( |
|
| 92 | + 'megamenu_default_theme', |
|
| 93 | + array( |
|
| 94 | + 'title' => __( 'Default', 'megamenu' ), |
|
| 95 | + 'container_background_from' => '#222', |
|
| 96 | + 'container_background_to' => '#222', |
|
| 97 | + 'container_padding_left' => '0px', |
|
| 98 | + 'container_padding_right' => '0px', |
|
| 99 | + 'container_padding_top' => '0px', |
|
| 100 | + 'container_padding_bottom' => '0px', |
|
| 101 | + 'container_border_radius_top_left' => '0px', |
|
| 102 | + 'container_border_radius_top_right' => '0px', |
|
| 103 | + 'container_border_radius_bottom_left' => '0px', |
|
| 104 | + 'container_border_radius_bottom_right' => '0px', |
|
| 105 | + 'arrow_up' => 'dash-f142', |
|
| 106 | + 'arrow_down' => 'dash-f140', |
|
| 107 | + 'arrow_left' => 'dash-f141', |
|
| 108 | + 'arrow_right' => 'dash-f139', |
|
| 109 | + 'font_size' => '14px', // deprecated |
|
| 110 | + 'font_color' => '#666', // deprecated |
|
| 111 | + 'font_family' => 'inherit', // deprecated |
|
| 112 | + 'menu_item_align' => 'left', |
|
| 113 | + 'menu_item_background_from' => 'rgba(0,0,0,0)', |
|
| 114 | + 'menu_item_background_to' => 'rgba(0,0,0,0)', |
|
| 115 | + 'menu_item_background_hover_from' => '#333', |
|
| 116 | + 'menu_item_background_hover_to' => '#333', |
|
| 117 | + 'menu_item_spacing' => '0px', |
|
| 118 | + 'menu_item_link_font' => 'inherit', |
|
| 119 | + 'menu_item_link_font_size' => '14px', |
|
| 120 | + 'menu_item_link_height' => '40px', |
|
| 121 | + 'menu_item_link_color' => '#ffffff', |
|
| 122 | + 'menu_item_link_weight' => 'normal', |
|
| 123 | + 'menu_item_link_text_transform' => 'none', |
|
| 124 | + 'menu_item_link_text_decoration' => 'none', |
|
| 125 | + 'menu_item_link_text_align' => 'left', |
|
| 126 | + 'menu_item_link_color_hover' => '#ffffff', |
|
| 127 | + 'menu_item_link_weight_hover' => 'normal', |
|
| 128 | + 'menu_item_link_text_decoration_hover' => 'none', |
|
| 129 | + 'menu_item_link_padding_left' => '10px', |
|
| 130 | + 'menu_item_link_padding_right' => '10px', |
|
| 131 | + 'menu_item_link_padding_top' => '0px', |
|
| 132 | + 'menu_item_link_padding_bottom' => '0px', |
|
| 133 | + 'menu_item_link_border_radius_top_left' => '0px', |
|
| 134 | + 'menu_item_link_border_radius_top_right' => '0px', |
|
| 135 | + 'menu_item_link_border_radius_bottom_left' => '0px', |
|
| 136 | + 'menu_item_link_border_radius_bottom_right' => '0px', |
|
| 137 | + 'menu_item_border_color' => '#fff', |
|
| 138 | + 'menu_item_border_left' => '0px', |
|
| 139 | + 'menu_item_border_right' => '0px', |
|
| 140 | + 'menu_item_border_top' => '0px', |
|
| 141 | + 'menu_item_border_bottom' => '0px', |
|
| 142 | + 'menu_item_border_color_hover' => '#fff', |
|
| 143 | + 'menu_item_highlight_current' => 'on', |
|
| 144 | + 'menu_item_divider' => 'off', |
|
| 145 | + 'menu_item_divider_color' => 'rgba(255, 255, 255, 0.1)', |
|
| 146 | + 'menu_item_divider_glow_opacity' => '0.1', |
|
| 147 | + 'panel_background_from' => '#f1f1f1', |
|
| 148 | + 'panel_background_to' => '#f1f1f1', |
|
| 149 | + 'panel_width' => '100%', |
|
| 150 | + 'panel_inner_width' => '100%', |
|
| 151 | + 'panel_border_color' => '#fff', |
|
| 152 | + 'panel_border_left' => '0px', |
|
| 153 | + 'panel_border_right' => '0px', |
|
| 154 | + 'panel_border_top' => '0px', |
|
| 155 | + 'panel_border_bottom' => '0px', |
|
| 156 | + 'panel_border_radius_top_left' => '0px', |
|
| 157 | + 'panel_border_radius_top_right' => '0px', |
|
| 158 | + 'panel_border_radius_bottom_left' => '0px', |
|
| 159 | + 'panel_border_radius_bottom_right' => '0px', |
|
| 160 | + 'panel_header_color' => '#555', |
|
| 161 | + 'panel_header_text_transform' => 'uppercase', |
|
| 162 | + 'panel_header_text_align' => 'left', |
|
| 163 | + 'panel_header_font' => 'inherit', |
|
| 164 | + 'panel_header_font_size' => '16px', |
|
| 165 | + 'panel_header_font_weight' => 'bold', |
|
| 166 | + 'panel_header_text_decoration' => 'none', |
|
| 167 | + 'panel_header_padding_top' => '0px', |
|
| 168 | + 'panel_header_padding_right' => '0px', |
|
| 169 | + 'panel_header_padding_bottom' => '5px', |
|
| 170 | + 'panel_header_padding_left' => '0px', |
|
| 171 | + 'panel_header_margin_top' => '0px', |
|
| 172 | + 'panel_header_margin_right' => '0px', |
|
| 173 | + 'panel_header_margin_bottom' => '0px', |
|
| 174 | + 'panel_header_margin_left' => '0px', |
|
| 175 | + 'panel_header_border_color' => 'rgba(0,0,0,0)', |
|
| 176 | + 'panel_header_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 177 | + 'panel_header_border_left' => '0px', |
|
| 178 | + 'panel_header_border_right' => '0px', |
|
| 179 | + 'panel_header_border_top' => '0px', |
|
| 180 | + 'panel_header_border_bottom' => '0px', |
|
| 181 | + 'panel_padding_left' => '0px', |
|
| 182 | + 'panel_padding_right' => '0px', |
|
| 183 | + 'panel_padding_top' => '0px', |
|
| 184 | + 'panel_padding_bottom' => '0px', |
|
| 185 | + 'panel_widget_padding_left' => '15px', |
|
| 186 | + 'panel_widget_padding_right' => '15px', |
|
| 187 | + 'panel_widget_padding_top' => '15px', |
|
| 188 | + 'panel_widget_padding_bottom' => '15px', |
|
| 189 | + 'panel_font_size' => 'font_size', |
|
| 190 | + 'panel_font_color' => 'font_color', |
|
| 191 | + 'panel_font_family' => 'font_family', |
|
| 192 | + 'panel_second_level_font_color' => 'panel_header_color', |
|
| 193 | + 'panel_second_level_font_color_hover' => 'panel_header_color', |
|
| 194 | + 'panel_second_level_text_transform' => 'panel_header_text_transform', |
|
| 195 | + 'panel_second_level_text_align' => 'left', |
|
| 196 | + 'panel_second_level_font' => 'panel_header_font', |
|
| 197 | + 'panel_second_level_font_size' => 'panel_header_font_size', |
|
| 198 | + 'panel_second_level_font_weight' => 'panel_header_font_weight', |
|
| 199 | + 'panel_second_level_font_weight_hover' => 'panel_header_font_weight', |
|
| 200 | + 'panel_second_level_text_decoration' => 'panel_header_text_decoration', |
|
| 201 | + 'panel_second_level_text_decoration_hover' => 'panel_header_text_decoration', |
|
| 202 | + 'panel_second_level_background_hover_from' => 'rgba(0,0,0,0)', |
|
| 203 | + 'panel_second_level_background_hover_to' => 'rgba(0,0,0,0)', |
|
| 204 | + 'panel_second_level_padding_left' => '0px', |
|
| 205 | + 'panel_second_level_padding_right' => '0px', |
|
| 206 | + 'panel_second_level_padding_top' => '0px', |
|
| 207 | + 'panel_second_level_padding_bottom' => '0px', |
|
| 208 | + 'panel_second_level_margin_left' => '0px', |
|
| 209 | + 'panel_second_level_margin_right' => '0px', |
|
| 210 | + 'panel_second_level_margin_top' => '0px', |
|
| 211 | + 'panel_second_level_margin_bottom' => '0px', |
|
| 212 | + 'panel_second_level_border_color' => 'rgba(0,0,0,0)', |
|
| 213 | + 'panel_second_level_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 214 | + 'panel_second_level_border_left' => '0px', |
|
| 215 | + 'panel_second_level_border_right' => '0px', |
|
| 216 | + 'panel_second_level_border_top' => '0px', |
|
| 217 | + 'panel_second_level_border_bottom' => '0px', |
|
| 218 | + 'panel_third_level_font_color' => 'panel_font_color', |
|
| 219 | + 'panel_third_level_font_color_hover' => 'panel_font_color', |
|
| 220 | + 'panel_third_level_text_transform' => 'none', |
|
| 221 | + 'panel_third_level_text_align' => 'left', |
|
| 222 | + 'panel_third_level_font' => 'panel_font_family', |
|
| 223 | + 'panel_third_level_font_size' => 'panel_font_size', |
|
| 224 | + 'panel_third_level_font_weight' => 'normal', |
|
| 225 | + 'panel_third_level_font_weight_hover' => 'normal', |
|
| 226 | + 'panel_third_level_text_decoration' => 'none', |
|
| 227 | + 'panel_third_level_text_decoration_hover' => 'none', |
|
| 228 | + 'panel_third_level_background_hover_from' => 'rgba(0,0,0,0)', |
|
| 229 | + 'panel_third_level_background_hover_to' => 'rgba(0,0,0,0)', |
|
| 230 | + 'panel_third_level_padding_left' => '0px', |
|
| 231 | + 'panel_third_level_padding_right' => '0px', |
|
| 232 | + 'panel_third_level_padding_top' => '0px', |
|
| 233 | + 'panel_third_level_padding_bottom' => '0px', |
|
| 234 | + 'panel_third_level_margin_left' => '0px', |
|
| 235 | + 'panel_third_level_margin_right' => '0px', |
|
| 236 | + 'panel_third_level_margin_top' => '0px', |
|
| 237 | + 'panel_third_level_margin_bottom' => '0px', |
|
| 238 | + 'panel_third_level_border_color' => 'rgba(0,0,0,0)', |
|
| 239 | + 'panel_third_level_border_color_hover' => 'rgba(0,0,0,0)', |
|
| 240 | + 'panel_third_level_border_left' => '0px', |
|
| 241 | + 'panel_third_level_border_right' => '0px', |
|
| 242 | + 'panel_third_level_border_top' => '0px', |
|
| 243 | + 'panel_third_level_border_bottom' => '0px', |
|
| 244 | + 'flyout_width' => '250px', |
|
| 245 | + 'flyout_menu_background_from' => '#f1f1f1', |
|
| 246 | + 'flyout_menu_background_to' => '#f1f1f1', |
|
| 247 | + 'flyout_border_color' => '#ffffff', |
|
| 248 | + 'flyout_border_left' => '0px', |
|
| 249 | + 'flyout_border_right' => '0px', |
|
| 250 | + 'flyout_border_top' => '0px', |
|
| 251 | + 'flyout_border_bottom' => '0px', |
|
| 252 | + 'flyout_border_radius_top_left' => '0px', |
|
| 253 | + 'flyout_border_radius_top_right' => '0px', |
|
| 254 | + 'flyout_border_radius_bottom_left' => '0px', |
|
| 255 | + 'flyout_border_radius_bottom_right' => '0px', |
|
| 256 | + 'flyout_menu_item_divider' => 'off', |
|
| 257 | + 'flyout_menu_item_divider_color' => 'rgba(255, 255, 255, 0.1)', |
|
| 258 | + 'flyout_padding_top' => '0px', |
|
| 259 | + 'flyout_padding_right' => '0px', |
|
| 260 | + 'flyout_padding_bottom' => '0px', |
|
| 261 | + 'flyout_padding_left' => '0px', |
|
| 262 | + 'flyout_link_padding_left' => '10px', |
|
| 263 | + 'flyout_link_padding_right' => '10px', |
|
| 264 | + 'flyout_link_padding_top' => '0px', |
|
| 265 | + 'flyout_link_padding_bottom' => '0px', |
|
| 266 | + 'flyout_link_weight' => 'normal', |
|
| 267 | + 'flyout_link_weight_hover' => 'normal', |
|
| 268 | + 'flyout_link_height' => '35px', |
|
| 269 | + 'flyout_link_text_decoration' => 'none', |
|
| 270 | + 'flyout_link_text_decoration_hover' => 'none', |
|
| 271 | + 'flyout_background_from' => '#f1f1f1', |
|
| 272 | + 'flyout_background_to' => '#f1f1f1', |
|
| 273 | + 'flyout_background_hover_from' => '#dddddd', |
|
| 274 | + 'flyout_background_hover_to' => '#dddddd', |
|
| 275 | + 'flyout_link_size' => 'font_size', |
|
| 276 | + 'flyout_link_color' => 'font_color', |
|
| 277 | + 'flyout_link_color_hover' => 'font_color', |
|
| 278 | + 'flyout_link_family' => 'font_family', |
|
| 279 | + 'flyout_link_text_transform' => 'none', |
|
| 280 | + 'responsive_breakpoint' => '768px', |
|
| 281 | + 'responsive_text' => 'MENU', // deprecated |
|
| 282 | + 'line_height' => '1.7', |
|
| 283 | + 'z_index' => '999', |
|
| 284 | + 'shadow' => 'off', |
|
| 285 | + 'shadow_horizontal' => '0px', |
|
| 286 | + 'shadow_vertical' => '0px', |
|
| 287 | + 'shadow_blur' => '5px', |
|
| 288 | + 'shadow_spread' => '0px', |
|
| 289 | + 'shadow_color' => 'rgba(0, 0, 0, 0.1)', |
|
| 290 | + 'transitions' => 'off', |
|
| 291 | + 'resets' => 'off', |
|
| 292 | + 'mobile_columns' => '1', |
|
| 293 | + 'toggle_background_from' => 'container_background_from', |
|
| 294 | + 'toggle_background_to' => 'container_background_to', |
|
| 295 | + 'toggle_font_color' => 'rgb(221, 221, 221)', // deprecated |
|
| 296 | + 'toggle_bar_height' => '40px', |
|
| 297 | + 'toggle_bar_border_radius_top_left' => '2px', |
|
| 298 | + 'toggle_bar_border_radius_top_right' => '2px', |
|
| 299 | + 'toggle_bar_border_radius_bottom_left' => '2px', |
|
| 300 | + 'toggle_bar_border_radius_bottom_right' => '2px', |
|
| 301 | + 'mobile_menu_padding_left' => '0px', |
|
| 302 | + 'mobile_menu_padding_right' => '0px', |
|
| 303 | + 'mobile_menu_padding_top' => '0px', |
|
| 304 | + 'mobile_menu_padding_bottom' => '0px', |
|
| 305 | + 'mobile_menu_item_height' => '40px', |
|
| 306 | + 'mobile_menu_overlay' => 'off', |
|
| 307 | + 'mobile_menu_force_width' => 'off', |
|
| 308 | + 'mobile_menu_force_width_selector' => 'body', |
|
| 309 | + 'mobile_background_from' => 'container_background_from', |
|
| 310 | + 'mobile_background_to' => 'container_background_to', |
|
| 311 | + 'mobile_menu_item_link_font_size' => 'menu_item_link_font_size', |
|
| 312 | + 'mobile_menu_item_link_color' => 'menu_item_link_color', |
|
| 313 | + 'mobile_menu_item_link_text_align' => 'menu_item_link_text_align', |
|
| 314 | + 'mobile_menu_item_link_color_hover' => 'menu_item_link_color_hover', |
|
| 315 | + 'mobile_menu_item_background_hover_from' => 'menu_item_background_hover_from', |
|
| 316 | + 'mobile_menu_item_background_hover_to' => 'menu_item_background_hover_to', |
|
| 317 | + 'mobile_menu_off_canvas_width' => '300px', |
|
| 318 | + 'disable_mobile_toggle' => 'off', |
|
| 319 | + 'custom_css' => '/** Push menu onto new line **/ |
|
| 320 | 320 | #{$wrap} { |
| 321 | 321 | clear: both; |
| 322 | 322 | }', |
| 323 | - ) |
|
| 324 | - ); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * |
|
| 330 | - * @since 1.0 |
|
| 331 | - */ |
|
| 332 | - public function default_themes() { |
|
| 323 | + ) |
|
| 324 | + ); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * |
|
| 330 | + * @since 1.0 |
|
| 331 | + */ |
|
| 332 | + public function default_themes() { |
|
| 333 | 333 | |
| 334 | - $themes['default'] = $this->get_default_theme(); |
|
| 335 | - |
|
| 336 | - return apply_filters( 'megamenu_themes', $themes ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Merge the saved themes (from options table) into array of complete themes |
|
| 341 | - * |
|
| 342 | - * @since 2.1 |
|
| 343 | - */ |
|
| 344 | - private function merge_in_saved_themes( $all_themes ) { |
|
| 345 | - |
|
| 346 | - if ( $saved_themes = max_mega_menu_get_themes() ) { |
|
| 347 | - foreach ( $saved_themes as $key => $settings ) { |
|
| 348 | - if ( isset( $all_themes[ $key ] ) ) { |
|
| 349 | - // merge modifications to default themes |
|
| 350 | - $all_themes[ $key ] = array_merge( $all_themes[ $key ], $saved_themes[ $key ] ); |
|
| 351 | - } else { |
|
| 352 | - // add in new themes |
|
| 353 | - $all_themes[ $key ] = $settings; |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $all_themes; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Populate all themes with all keys from the default theme |
|
| 364 | - * |
|
| 365 | - * @since 2.1 |
|
| 366 | - */ |
|
| 367 | - private function ensure_all_themes_have_all_default_theme_settings( $all_themes ) { |
|
| 368 | - |
|
| 369 | - $default_theme = $this->get_default_theme(); |
|
| 370 | - |
|
| 371 | - $themes = array(); |
|
| 372 | - |
|
| 373 | - foreach ( $all_themes as $theme_id => $theme ) { |
|
| 374 | - $themes[ $theme_id ] = array_merge( $default_theme, $theme ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return $themes; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * For backwards compatibility, copy old settings into new values |
|
| 383 | - * |
|
| 384 | - * @since 2.1 |
|
| 385 | - */ |
|
| 386 | - private function process_theme_replacements( $all_themes ) { |
|
| 387 | - |
|
| 388 | - foreach ( $all_themes as $key => $settings ) { |
|
| 389 | - // process replacements |
|
| 390 | - foreach ( $settings as $var => $val ) { |
|
| 391 | - if ( ! is_array( $val ) && isset( $all_themes[ $key ][ $val ] ) ) { |
|
| 392 | - $all_themes[ $key ][ $var ] = $all_themes[ $key ][ $val ]; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - return $all_themes; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Return a filtered list of themes |
|
| 403 | - * |
|
| 404 | - * @since 1.0 |
|
| 405 | - * @return array |
|
| 406 | - */ |
|
| 407 | - public function get_themes() { |
|
| 408 | - |
|
| 409 | - $default_themes = $this->default_themes(); |
|
| 410 | - |
|
| 411 | - $all_themes = $this->merge_in_saved_themes( $default_themes ); |
|
| 412 | - $all_themes = $this->ensure_all_themes_have_all_default_theme_settings( $all_themes ); |
|
| 413 | - $all_themes = $this->process_theme_replacements( $all_themes ); |
|
| 414 | - |
|
| 415 | - uasort( $all_themes, array( $this, 'sort_by_title' ) ); |
|
| 416 | - |
|
| 417 | - return $all_themes; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Sorts a 2d array by the 'title' key |
|
| 423 | - * |
|
| 424 | - * @since 1.0 |
|
| 425 | - * @param array $a |
|
| 426 | - * @param array $b |
|
| 427 | - */ |
|
| 428 | - private function sort_by_title( $a, $b ) { |
|
| 429 | - return strcmp( $a['title'], $b['title'] ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * |
|
| 435 | - * |
|
| 436 | - * @since 1.3.1 |
|
| 437 | - * @return bool |
|
| 438 | - */ |
|
| 439 | - private function is_debug_mode() { |
|
| 440 | - return ( defined( 'MEGAMENU_DEBUG' ) && MEGAMENU_DEBUG === true ); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Return the menu CSS for use in inline CSS block. Use the cache if possible. |
|
| 446 | - * |
|
| 447 | - * @since 1.3.1 |
|
| 448 | - */ |
|
| 449 | - public function get_css() { |
|
| 450 | - |
|
| 451 | - if ( ( $css = $this->get_cached_css() ) && ! $this->is_debug_mode() ) { |
|
| 452 | - return $css; |
|
| 453 | - } else { |
|
| 454 | - return $this->generate_css(); |
|
| 455 | - } |
|
| 456 | - } |
|
| 334 | + $themes['default'] = $this->get_default_theme(); |
|
| 335 | + |
|
| 336 | + return apply_filters( 'megamenu_themes', $themes ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Merge the saved themes (from options table) into array of complete themes |
|
| 341 | + * |
|
| 342 | + * @since 2.1 |
|
| 343 | + */ |
|
| 344 | + private function merge_in_saved_themes( $all_themes ) { |
|
| 345 | + |
|
| 346 | + if ( $saved_themes = max_mega_menu_get_themes() ) { |
|
| 347 | + foreach ( $saved_themes as $key => $settings ) { |
|
| 348 | + if ( isset( $all_themes[ $key ] ) ) { |
|
| 349 | + // merge modifications to default themes |
|
| 350 | + $all_themes[ $key ] = array_merge( $all_themes[ $key ], $saved_themes[ $key ] ); |
|
| 351 | + } else { |
|
| 352 | + // add in new themes |
|
| 353 | + $all_themes[ $key ] = $settings; |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $all_themes; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Populate all themes with all keys from the default theme |
|
| 364 | + * |
|
| 365 | + * @since 2.1 |
|
| 366 | + */ |
|
| 367 | + private function ensure_all_themes_have_all_default_theme_settings( $all_themes ) { |
|
| 368 | + |
|
| 369 | + $default_theme = $this->get_default_theme(); |
|
| 370 | + |
|
| 371 | + $themes = array(); |
|
| 372 | + |
|
| 373 | + foreach ( $all_themes as $theme_id => $theme ) { |
|
| 374 | + $themes[ $theme_id ] = array_merge( $default_theme, $theme ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return $themes; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * For backwards compatibility, copy old settings into new values |
|
| 383 | + * |
|
| 384 | + * @since 2.1 |
|
| 385 | + */ |
|
| 386 | + private function process_theme_replacements( $all_themes ) { |
|
| 387 | + |
|
| 388 | + foreach ( $all_themes as $key => $settings ) { |
|
| 389 | + // process replacements |
|
| 390 | + foreach ( $settings as $var => $val ) { |
|
| 391 | + if ( ! is_array( $val ) && isset( $all_themes[ $key ][ $val ] ) ) { |
|
| 392 | + $all_themes[ $key ][ $var ] = $all_themes[ $key ][ $val ]; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + return $all_themes; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Return a filtered list of themes |
|
| 403 | + * |
|
| 404 | + * @since 1.0 |
|
| 405 | + * @return array |
|
| 406 | + */ |
|
| 407 | + public function get_themes() { |
|
| 408 | + |
|
| 409 | + $default_themes = $this->default_themes(); |
|
| 410 | + |
|
| 411 | + $all_themes = $this->merge_in_saved_themes( $default_themes ); |
|
| 412 | + $all_themes = $this->ensure_all_themes_have_all_default_theme_settings( $all_themes ); |
|
| 413 | + $all_themes = $this->process_theme_replacements( $all_themes ); |
|
| 414 | + |
|
| 415 | + uasort( $all_themes, array( $this, 'sort_by_title' ) ); |
|
| 416 | + |
|
| 417 | + return $all_themes; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Sorts a 2d array by the 'title' key |
|
| 423 | + * |
|
| 424 | + * @since 1.0 |
|
| 425 | + * @param array $a |
|
| 426 | + * @param array $b |
|
| 427 | + */ |
|
| 428 | + private function sort_by_title( $a, $b ) { |
|
| 429 | + return strcmp( $a['title'], $b['title'] ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * |
|
| 435 | + * |
|
| 436 | + * @since 1.3.1 |
|
| 437 | + * @return bool |
|
| 438 | + */ |
|
| 439 | + private function is_debug_mode() { |
|
| 440 | + return ( defined( 'MEGAMENU_DEBUG' ) && MEGAMENU_DEBUG === true ); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Return the menu CSS for use in inline CSS block. Use the cache if possible. |
|
| 446 | + * |
|
| 447 | + * @since 1.3.1 |
|
| 448 | + */ |
|
| 449 | + public function get_css() { |
|
| 450 | + |
|
| 451 | + if ( ( $css = $this->get_cached_css() ) && ! $this->is_debug_mode() ) { |
|
| 452 | + return $css; |
|
| 453 | + } else { |
|
| 454 | + return $this->generate_css(); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | 458 | |
| 459 | - /** |
|
| 460 | - * Generate and cache the CSS for our menus. |
|
| 461 | - * The CSS is compiled by scssphp using the file located in /css/megamenu.scss |
|
| 462 | - * |
|
| 463 | - * @since 1.0 |
|
| 464 | - * @return string |
|
| 465 | - * @param boolean $debug_mode (prints error messages to the CSS when enabled) |
|
| 466 | - */ |
|
| 467 | - public function generate_css() { |
|
| 468 | - |
|
| 469 | - if ( function_exists( 'wp_raise_memory_limit' ) ) { |
|
| 470 | - wp_raise_memory_limit(); // attempt to raise memory limit to 256MB |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // the settings may have changed since the class was instantiated, |
|
| 474 | - // reset them here |
|
| 475 | - $this->settings = get_option( 'megamenu_settings' ); |
|
| 476 | - |
|
| 477 | - if ( ! $this->settings ) { |
|
| 478 | - return '/** CSS Generation Failed. No menu settings found **/'; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - $css = ''; |
|
| 482 | - |
|
| 483 | - foreach ( $this->settings as $location => $settings ) { |
|
| 484 | - if ( isset( $settings['enabled'] ) && has_nav_menu( $location ) ) { |
|
| 485 | - $theme = $this->get_theme_settings_for_location( $location ); |
|
| 486 | - $menu_id = $this->get_menu_id_for_location( $location ); |
|
| 487 | - $compiled_css = $this->generate_css_for_location( $location, $theme, $menu_id ); |
|
| 488 | - |
|
| 489 | - if ( ! is_wp_error( $compiled_css ) ) { |
|
| 490 | - $css .= $compiled_css; |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ( strlen( $css ) ) { |
|
| 496 | - $scss_location = 'core'; |
|
| 497 | - |
|
| 498 | - foreach ( $this->get_possible_scss_file_locations() as $path ) { |
|
| 499 | - if ( file_exists( $path ) && $path !== $this->get_default_scss_file_location() ) { |
|
| 500 | - $scss_location = 'custom'; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $css = '/** ' . date( 'l jS F Y H:i:s e' ) . " ({$scss_location}) **/\n/** THIS FILE IS AUTOMATICALLY GENERATED - DO NOT MAKE MANUAL EDITS! **/\n/** Custom CSS should be added to Mega Menu > Menu Themes > Custom Styling **/\n\n.mega-menu-last-modified-" . time() . " { content: '" . date( 'l jS F Y H:i:s e' ) . "'; }\n\n" . $css; |
|
| 505 | - |
|
| 506 | - $css = apply_filters( 'megamenu_compiled_css', $css ); |
|
| 507 | - |
|
| 508 | - $this->set_cached_css( $css ); |
|
| 509 | - |
|
| 510 | - if ( $this->get_css_output_method() == 'fs' ) { |
|
| 511 | - $this->save_to_filesystem( $css ); |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $css; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Saves the generated CSS to the uploads folder |
|
| 521 | - * |
|
| 522 | - * @since 1.6.1 |
|
| 523 | - */ |
|
| 524 | - private function save_to_filesystem( $css ) { |
|
| 525 | - global $wp_filesystem; |
|
| 526 | - |
|
| 527 | - if ( ! $wp_filesystem ) { |
|
| 528 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $upload_dir = wp_upload_dir(); |
|
| 532 | - $filename = $this->get_css_filename(); |
|
| 533 | - |
|
| 534 | - $dir = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/'; |
|
| 535 | - |
|
| 536 | - WP_Filesystem( false, $upload_dir['basedir'], true ); |
|
| 537 | - |
|
| 538 | - if ( ! $wp_filesystem->is_dir( $dir ) ) { |
|
| 539 | - $wp_filesystem->mkdir( $dir ); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if ( ! $wp_filesystem->put_contents( $dir . $filename, $css ) ) { |
|
| 543 | - // File write failed. |
|
| 544 | - // Update CSS output option to 'head' to stop us from attempting to regenerate the CSS on every request. |
|
| 545 | - $settings = get_option( 'megamenu_settings' ); |
|
| 546 | - $settings['css'] = 'head'; |
|
| 547 | - update_option( 'megamenu_settings', $settings ); |
|
| 548 | - $this->settings = get_option( 'megamenu_settings' ); |
|
| 549 | - |
|
| 550 | - // set a far expiration date to prevent transient from being autoloaded |
|
| 551 | - $hundred_years_in_seconds = 3153600000; |
|
| 552 | - set_transient( 'megamenu_failed_to_write_css_to_filesystem', 'true', $hundred_years_in_seconds ); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Return an array of all the possible file path locations for the SCSS file |
|
| 560 | - * @since 2.2.3 |
|
| 561 | - * @return array |
|
| 562 | - */ |
|
| 563 | - private function get_possible_scss_file_locations() { |
|
| 564 | - return apply_filters( |
|
| 565 | - 'megamenu_scss_locations', |
|
| 566 | - array( |
|
| 567 | - trailingslashit( get_stylesheet_directory() ) . trailingslashit( 'megamenu' ) . 'megamenu.scss', // child theme |
|
| 568 | - trailingslashit( get_template_directory() ) . trailingslashit( 'megamenu' ) . 'megamenu.scss', // parent theme |
|
| 569 | - $this->get_default_scss_file_location(), |
|
| 570 | - ) |
|
| 571 | - ); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Return the default SCSS file path |
|
| 577 | - * |
|
| 578 | - * @since 2.2.3 |
|
| 579 | - * @return string |
|
| 580 | - */ |
|
| 581 | - private function get_default_scss_file_location() { |
|
| 582 | - return MEGAMENU_PATH . trailingslashit( 'css' ) . 'megamenu.scss'; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Return the path to the megamenu.scss file, look for custom files before |
|
| 588 | - * loading the core version. |
|
| 589 | - * |
|
| 590 | - * @since 1.0 |
|
| 591 | - * @return string |
|
| 592 | - */ |
|
| 593 | - private function load_scss_file() { |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * *** IMPORTANT NOTICE *** |
|
| 597 | - * |
|
| 598 | - * Allowing users to create their own versions of megamenu.scss was a poor design decision. |
|
| 599 | - * |
|
| 600 | - * The bundled SCSS file and the plugin code work in perfect harmony. |
|
| 601 | - * |
|
| 602 | - * When a user (or theme developer) creates their own copy of megamenu.scss it |
|
| 603 | - * _will_ become outdated as the plugin is updated and the menu HTML changes. |
|
| 604 | - * |
|
| 605 | - * Instead of using a custom SCSS file, override only the absolute minimum CSS in the |
|
| 606 | - * Mega Menu > Menu Themes > Custom Styling section. |
|
| 607 | - */ |
|
| 608 | - $scss = file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'mixin.scss' ); |
|
| 609 | - $scss .= file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'reset.scss' ); |
|
| 610 | - |
|
| 611 | - $locations = $this->get_possible_scss_file_locations(); |
|
| 612 | - |
|
| 613 | - foreach ( $locations as $path ) { |
|
| 614 | - |
|
| 615 | - if ( file_exists( $path ) ) { |
|
| 616 | - |
|
| 617 | - $scss .= file_get_contents( $path ); |
|
| 618 | - //break; |
|
| 619 | - // |
|
| 620 | - // @todo: add a break here. This is a known bug but some users may be relying on it. |
|
| 621 | - // Add warning message to plugin to alert users about not using custom megamenu.scss files |
|
| 622 | - // then fix the bug in a later release. |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - $scss .= file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'compatibility.scss' ); |
|
| 627 | - |
|
| 628 | - return apply_filters( 'megamenu_load_scss_file_contents', $scss ); |
|
| 629 | - |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Before a theme is saved, attempt to generate the CSS to ensure it passes as valid SCSS |
|
| 634 | - * |
|
| 635 | - * @param array $theme |
|
| 636 | - */ |
|
| 637 | - public function test_theme_compilation( $theme ) { |
|
| 638 | - $menu_id = 0; |
|
| 639 | - |
|
| 640 | - $menus = get_registered_nav_menus(); |
|
| 641 | - |
|
| 642 | - if ( count( $menus ) ) { |
|
| 643 | - $locations = get_nav_menu_locations(); |
|
| 644 | - |
|
| 645 | - foreach ( $menus as $location => $description ) { |
|
| 646 | - if ( isset( $locations[ $location ] ) ) { |
|
| 647 | - $menu_id = $locations[ $location ]; |
|
| 648 | - continue; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return $this->generate_css_for_location( 'test', $theme, $menu_id ); |
|
| 654 | - |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Compiles raw SCSS into CSS for a particular menu location. |
|
| 660 | - * |
|
| 661 | - * @since 1.3 |
|
| 662 | - * @return mixed |
|
| 663 | - * @param array $settings |
|
| 664 | - * @param string $location |
|
| 665 | - */ |
|
| 666 | - public function generate_css_for_location( $location, $theme, $menu_id ) { |
|
| 667 | - |
|
| 668 | - if ( is_readable( MEGAMENU_PATH . 'classes/scssc.inc.php' ) && ! class_exists( 'scssc' ) ) { |
|
| 669 | - include_once MEGAMENU_PATH . 'classes/scssc.inc.php'; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - $scssc = new scssc(); |
|
| 673 | - $scssc->setFormatter( 'scss_formatter' ); |
|
| 674 | - |
|
| 675 | - $import_paths = apply_filters( |
|
| 676 | - 'megamenu_scss_import_paths', |
|
| 677 | - array( |
|
| 678 | - trailingslashit( get_stylesheet_directory() ) . trailingslashit( 'megamenu' ), |
|
| 679 | - trailingslashit( get_stylesheet_directory() ), |
|
| 680 | - trailingslashit( get_template_directory() ) . trailingslashit( 'megamenu' ), |
|
| 681 | - trailingslashit( get_template_directory() ), |
|
| 682 | - trailingslashit( WP_PLUGIN_DIR ), |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - |
|
| 686 | - foreach ( $import_paths as $path ) { |
|
| 687 | - $scssc->addImportPath( $path ); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - try { |
|
| 691 | - return $scssc->compile( $this->get_complete_scss_for_location( $location, $theme, $menu_id ) ); |
|
| 692 | - } catch ( Exception $e ) { |
|
| 693 | - $message = __( 'Warning: CSS compilation failed. Please check your changes or revert the theme.', 'megamenu' ); |
|
| 694 | - |
|
| 695 | - return new WP_Error( 'scss_compile_fail', $message . '<br /><br />' . $e->getMessage() ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - } |
|
| 459 | + /** |
|
| 460 | + * Generate and cache the CSS for our menus. |
|
| 461 | + * The CSS is compiled by scssphp using the file located in /css/megamenu.scss |
|
| 462 | + * |
|
| 463 | + * @since 1.0 |
|
| 464 | + * @return string |
|
| 465 | + * @param boolean $debug_mode (prints error messages to the CSS when enabled) |
|
| 466 | + */ |
|
| 467 | + public function generate_css() { |
|
| 468 | + |
|
| 469 | + if ( function_exists( 'wp_raise_memory_limit' ) ) { |
|
| 470 | + wp_raise_memory_limit(); // attempt to raise memory limit to 256MB |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // the settings may have changed since the class was instantiated, |
|
| 474 | + // reset them here |
|
| 475 | + $this->settings = get_option( 'megamenu_settings' ); |
|
| 476 | + |
|
| 477 | + if ( ! $this->settings ) { |
|
| 478 | + return '/** CSS Generation Failed. No menu settings found **/'; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + $css = ''; |
|
| 482 | + |
|
| 483 | + foreach ( $this->settings as $location => $settings ) { |
|
| 484 | + if ( isset( $settings['enabled'] ) && has_nav_menu( $location ) ) { |
|
| 485 | + $theme = $this->get_theme_settings_for_location( $location ); |
|
| 486 | + $menu_id = $this->get_menu_id_for_location( $location ); |
|
| 487 | + $compiled_css = $this->generate_css_for_location( $location, $theme, $menu_id ); |
|
| 488 | + |
|
| 489 | + if ( ! is_wp_error( $compiled_css ) ) { |
|
| 490 | + $css .= $compiled_css; |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ( strlen( $css ) ) { |
|
| 496 | + $scss_location = 'core'; |
|
| 497 | + |
|
| 498 | + foreach ( $this->get_possible_scss_file_locations() as $path ) { |
|
| 499 | + if ( file_exists( $path ) && $path !== $this->get_default_scss_file_location() ) { |
|
| 500 | + $scss_location = 'custom'; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $css = '/** ' . date( 'l jS F Y H:i:s e' ) . " ({$scss_location}) **/\n/** THIS FILE IS AUTOMATICALLY GENERATED - DO NOT MAKE MANUAL EDITS! **/\n/** Custom CSS should be added to Mega Menu > Menu Themes > Custom Styling **/\n\n.mega-menu-last-modified-" . time() . " { content: '" . date( 'l jS F Y H:i:s e' ) . "'; }\n\n" . $css; |
|
| 505 | + |
|
| 506 | + $css = apply_filters( 'megamenu_compiled_css', $css ); |
|
| 507 | + |
|
| 508 | + $this->set_cached_css( $css ); |
|
| 509 | + |
|
| 510 | + if ( $this->get_css_output_method() == 'fs' ) { |
|
| 511 | + $this->save_to_filesystem( $css ); |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $css; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Saves the generated CSS to the uploads folder |
|
| 521 | + * |
|
| 522 | + * @since 1.6.1 |
|
| 523 | + */ |
|
| 524 | + private function save_to_filesystem( $css ) { |
|
| 525 | + global $wp_filesystem; |
|
| 526 | + |
|
| 527 | + if ( ! $wp_filesystem ) { |
|
| 528 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $upload_dir = wp_upload_dir(); |
|
| 532 | + $filename = $this->get_css_filename(); |
|
| 533 | + |
|
| 534 | + $dir = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/'; |
|
| 535 | + |
|
| 536 | + WP_Filesystem( false, $upload_dir['basedir'], true ); |
|
| 537 | + |
|
| 538 | + if ( ! $wp_filesystem->is_dir( $dir ) ) { |
|
| 539 | + $wp_filesystem->mkdir( $dir ); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if ( ! $wp_filesystem->put_contents( $dir . $filename, $css ) ) { |
|
| 543 | + // File write failed. |
|
| 544 | + // Update CSS output option to 'head' to stop us from attempting to regenerate the CSS on every request. |
|
| 545 | + $settings = get_option( 'megamenu_settings' ); |
|
| 546 | + $settings['css'] = 'head'; |
|
| 547 | + update_option( 'megamenu_settings', $settings ); |
|
| 548 | + $this->settings = get_option( 'megamenu_settings' ); |
|
| 549 | + |
|
| 550 | + // set a far expiration date to prevent transient from being autoloaded |
|
| 551 | + $hundred_years_in_seconds = 3153600000; |
|
| 552 | + set_transient( 'megamenu_failed_to_write_css_to_filesystem', 'true', $hundred_years_in_seconds ); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Return an array of all the possible file path locations for the SCSS file |
|
| 560 | + * @since 2.2.3 |
|
| 561 | + * @return array |
|
| 562 | + */ |
|
| 563 | + private function get_possible_scss_file_locations() { |
|
| 564 | + return apply_filters( |
|
| 565 | + 'megamenu_scss_locations', |
|
| 566 | + array( |
|
| 567 | + trailingslashit( get_stylesheet_directory() ) . trailingslashit( 'megamenu' ) . 'megamenu.scss', // child theme |
|
| 568 | + trailingslashit( get_template_directory() ) . trailingslashit( 'megamenu' ) . 'megamenu.scss', // parent theme |
|
| 569 | + $this->get_default_scss_file_location(), |
|
| 570 | + ) |
|
| 571 | + ); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Return the default SCSS file path |
|
| 577 | + * |
|
| 578 | + * @since 2.2.3 |
|
| 579 | + * @return string |
|
| 580 | + */ |
|
| 581 | + private function get_default_scss_file_location() { |
|
| 582 | + return MEGAMENU_PATH . trailingslashit( 'css' ) . 'megamenu.scss'; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Return the path to the megamenu.scss file, look for custom files before |
|
| 588 | + * loading the core version. |
|
| 589 | + * |
|
| 590 | + * @since 1.0 |
|
| 591 | + * @return string |
|
| 592 | + */ |
|
| 593 | + private function load_scss_file() { |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * *** IMPORTANT NOTICE *** |
|
| 597 | + * |
|
| 598 | + * Allowing users to create their own versions of megamenu.scss was a poor design decision. |
|
| 599 | + * |
|
| 600 | + * The bundled SCSS file and the plugin code work in perfect harmony. |
|
| 601 | + * |
|
| 602 | + * When a user (or theme developer) creates their own copy of megamenu.scss it |
|
| 603 | + * _will_ become outdated as the plugin is updated and the menu HTML changes. |
|
| 604 | + * |
|
| 605 | + * Instead of using a custom SCSS file, override only the absolute minimum CSS in the |
|
| 606 | + * Mega Menu > Menu Themes > Custom Styling section. |
|
| 607 | + */ |
|
| 608 | + $scss = file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'mixin.scss' ); |
|
| 609 | + $scss .= file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'reset.scss' ); |
|
| 610 | + |
|
| 611 | + $locations = $this->get_possible_scss_file_locations(); |
|
| 612 | + |
|
| 613 | + foreach ( $locations as $path ) { |
|
| 614 | + |
|
| 615 | + if ( file_exists( $path ) ) { |
|
| 616 | + |
|
| 617 | + $scss .= file_get_contents( $path ); |
|
| 618 | + //break; |
|
| 619 | + // |
|
| 620 | + // @todo: add a break here. This is a known bug but some users may be relying on it. |
|
| 621 | + // Add warning message to plugin to alert users about not using custom megamenu.scss files |
|
| 622 | + // then fix the bug in a later release. |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + $scss .= file_get_contents( MEGAMENU_PATH . trailingslashit( 'css' ) . 'compatibility.scss' ); |
|
| 627 | + |
|
| 628 | + return apply_filters( 'megamenu_load_scss_file_contents', $scss ); |
|
| 629 | + |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Before a theme is saved, attempt to generate the CSS to ensure it passes as valid SCSS |
|
| 634 | + * |
|
| 635 | + * @param array $theme |
|
| 636 | + */ |
|
| 637 | + public function test_theme_compilation( $theme ) { |
|
| 638 | + $menu_id = 0; |
|
| 639 | + |
|
| 640 | + $menus = get_registered_nav_menus(); |
|
| 641 | + |
|
| 642 | + if ( count( $menus ) ) { |
|
| 643 | + $locations = get_nav_menu_locations(); |
|
| 644 | + |
|
| 645 | + foreach ( $menus as $location => $description ) { |
|
| 646 | + if ( isset( $locations[ $location ] ) ) { |
|
| 647 | + $menu_id = $locations[ $location ]; |
|
| 648 | + continue; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return $this->generate_css_for_location( 'test', $theme, $menu_id ); |
|
| 654 | + |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Compiles raw SCSS into CSS for a particular menu location. |
|
| 660 | + * |
|
| 661 | + * @since 1.3 |
|
| 662 | + * @return mixed |
|
| 663 | + * @param array $settings |
|
| 664 | + * @param string $location |
|
| 665 | + */ |
|
| 666 | + public function generate_css_for_location( $location, $theme, $menu_id ) { |
|
| 667 | + |
|
| 668 | + if ( is_readable( MEGAMENU_PATH . 'classes/scssc.inc.php' ) && ! class_exists( 'scssc' ) ) { |
|
| 669 | + include_once MEGAMENU_PATH . 'classes/scssc.inc.php'; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + $scssc = new scssc(); |
|
| 673 | + $scssc->setFormatter( 'scss_formatter' ); |
|
| 674 | + |
|
| 675 | + $import_paths = apply_filters( |
|
| 676 | + 'megamenu_scss_import_paths', |
|
| 677 | + array( |
|
| 678 | + trailingslashit( get_stylesheet_directory() ) . trailingslashit( 'megamenu' ), |
|
| 679 | + trailingslashit( get_stylesheet_directory() ), |
|
| 680 | + trailingslashit( get_template_directory() ) . trailingslashit( 'megamenu' ), |
|
| 681 | + trailingslashit( get_template_directory() ), |
|
| 682 | + trailingslashit( WP_PLUGIN_DIR ), |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + |
|
| 686 | + foreach ( $import_paths as $path ) { |
|
| 687 | + $scssc->addImportPath( $path ); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + try { |
|
| 691 | + return $scssc->compile( $this->get_complete_scss_for_location( $location, $theme, $menu_id ) ); |
|
| 692 | + } catch ( Exception $e ) { |
|
| 693 | + $message = __( 'Warning: CSS compilation failed. Please check your changes or revert the theme.', 'megamenu' ); |
|
| 694 | + |
|
| 695 | + return new WP_Error( 'scss_compile_fail', $message . '<br /><br />' . $e->getMessage() ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | 700 | |
| 701 | - /** |
|
| 702 | - * Generates a SCSS string which includes the variables for a menu theme, |
|
| 703 | - * for a particular menu location. |
|
| 704 | - * |
|
| 705 | - * @since 1.3 |
|
| 706 | - * @return string |
|
| 707 | - * @param string $theme |
|
| 708 | - * @param string $location |
|
| 709 | - * @param int $menu_id |
|
| 710 | - */ |
|
| 711 | - private function get_complete_scss_for_location( $location, $theme, $menu_id ) { |
|
| 701 | + /** |
|
| 702 | + * Generates a SCSS string which includes the variables for a menu theme, |
|
| 703 | + * for a particular menu location. |
|
| 704 | + * |
|
| 705 | + * @since 1.3 |
|
| 706 | + * @return string |
|
| 707 | + * @param string $theme |
|
| 708 | + * @param string $location |
|
| 709 | + * @param int $menu_id |
|
| 710 | + */ |
|
| 711 | + private function get_complete_scss_for_location( $location, $theme, $menu_id ) { |
|
| 712 | 712 | |
| 713 | - $sanitized_location = str_replace( apply_filters( 'megamenu_location_replacements', array( '-', ' ' ) ), '-', $location ); |
|
| 713 | + $sanitized_location = str_replace( apply_filters( 'megamenu_location_replacements', array( '-', ' ' ) ), '-', $location ); |
|
| 714 | 714 | |
| 715 | - $wrap_selector = apply_filters( 'megamenu_scss_wrap_selector', "#mega-menu-wrap-{$sanitized_location}", $menu_id, $location ); |
|
| 716 | - $menu_selector = apply_filters( 'megamenu_scss_menu_selector', "#mega-menu-{$sanitized_location}", $menu_id, $location ); |
|
| 715 | + $wrap_selector = apply_filters( 'megamenu_scss_wrap_selector', "#mega-menu-wrap-{$sanitized_location}", $menu_id, $location ); |
|
| 716 | + $menu_selector = apply_filters( 'megamenu_scss_menu_selector', "#mega-menu-{$sanitized_location}", $menu_id, $location ); |
|
| 717 | 717 | |
| 718 | - $vars['wrap'] = "'$wrap_selector'"; |
|
| 719 | - $vars['menu'] = "'$menu_selector'"; |
|
| 720 | - $vars['location'] = "'$sanitized_location'"; |
|
| 721 | - $vars['menu_id'] = "'$menu_id'"; |
|
| 722 | - $vars['elementor_pro_active'] = 'false'; |
|
| 723 | - $vars['arrow_font'] = 'dashicons'; |
|
| 724 | - $vars['arrow_font_weight'] = 'normal'; |
|
| 718 | + $vars['wrap'] = "'$wrap_selector'"; |
|
| 719 | + $vars['menu'] = "'$menu_selector'"; |
|
| 720 | + $vars['location'] = "'$sanitized_location'"; |
|
| 721 | + $vars['menu_id'] = "'$menu_id'"; |
|
| 722 | + $vars['elementor_pro_active'] = 'false'; |
|
| 723 | + $vars['arrow_font'] = 'dashicons'; |
|
| 724 | + $vars['arrow_font_weight'] = 'normal'; |
|
| 725 | 725 | |
| 726 | - $current_theme = wp_get_theme(); |
|
| 727 | - $theme_id = $current_theme->template; |
|
| 726 | + $current_theme = wp_get_theme(); |
|
| 727 | + $theme_id = $current_theme->template; |
|
| 728 | 728 | |
| 729 | - $vars['wp_theme'] = strtolower( str_replace( array( '.', ' ' ), '_', $theme_id ) ); |
|
| 730 | - |
|
| 731 | - if ( empty( $vars['wp_theme'] ) ) { |
|
| 732 | - $vars['wp_theme'] = 'unknown'; |
|
| 733 | - } |
|
| 729 | + $vars['wp_theme'] = strtolower( str_replace( array( '.', ' ' ), '_', $theme_id ) ); |
|
| 730 | + |
|
| 731 | + if ( empty( $vars['wp_theme'] ) ) { |
|
| 732 | + $vars['wp_theme'] = 'unknown'; |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | - if ( ! function_exists( 'is_plugin_active' ) ) { |
|
| 736 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
| 737 | - } |
|
| 735 | + if ( ! function_exists( 'is_plugin_active' ) ) { |
|
| 736 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'elementor-pro/elementor-pro.php' ) ) { |
|
| 740 | - $vars['elementor_pro_active'] = 'true'; |
|
| 741 | - } |
|
| 739 | + if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'elementor-pro/elementor-pro.php' ) ) { |
|
| 740 | + $vars['elementor_pro_active'] = 'true'; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | - $settings = $this->get_menu_settings_for_location( $location ); |
|
| 743 | + $settings = $this->get_menu_settings_for_location( $location ); |
|
| 744 | 744 | |
| 745 | - if ( isset( $settings['effect_speed'] ) && absint( $settings['effect_speed'] ) > 0 ) { |
|
| 746 | - $effect_speed = absint( $settings['effect_speed'] ) . 'ms'; |
|
| 747 | - } else { |
|
| 748 | - $effect_speed = '200ms'; |
|
| 749 | - } |
|
| 745 | + if ( isset( $settings['effect_speed'] ) && absint( $settings['effect_speed'] ) > 0 ) { |
|
| 746 | + $effect_speed = absint( $settings['effect_speed'] ) . 'ms'; |
|
| 747 | + } else { |
|
| 748 | + $effect_speed = '200ms'; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - $vars['effect_speed'] = $effect_speed; |
|
| 751 | + $vars['effect_speed'] = $effect_speed; |
|
| 752 | 752 | |
| 753 | - if ( isset( $settings['effect_speed_mobile'] ) && absint( $settings['effect_speed_mobile'] ) > 0 ) { |
|
| 754 | - $effect_speed_mobile = absint( $settings['effect_speed_mobile'] ) . 'ms'; |
|
| 755 | - } else { |
|
| 756 | - $effect_speed_mobile = '200ms'; |
|
| 757 | - } |
|
| 753 | + if ( isset( $settings['effect_speed_mobile'] ) && absint( $settings['effect_speed_mobile'] ) > 0 ) { |
|
| 754 | + $effect_speed_mobile = absint( $settings['effect_speed_mobile'] ) . 'ms'; |
|
| 755 | + } else { |
|
| 756 | + $effect_speed_mobile = '200ms'; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - $vars['effect_speed_mobile'] = $effect_speed_mobile; |
|
| 759 | + $vars['effect_speed_mobile'] = $effect_speed_mobile; |
|
| 760 | 760 | |
| 761 | - if ( isset( $settings['effect_mobile'] ) ) { |
|
| 762 | - $effect_mobile = $settings['effect_mobile']; |
|
| 763 | - } else { |
|
| 764 | - $effect_mobile = 'disabled'; |
|
| 765 | - } |
|
| 761 | + if ( isset( $settings['effect_mobile'] ) ) { |
|
| 762 | + $effect_mobile = $settings['effect_mobile']; |
|
| 763 | + } else { |
|
| 764 | + $effect_mobile = 'disabled'; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - $vars['effect_mobile'] = $effect_mobile; |
|
| 767 | + $vars['effect_mobile'] = $effect_mobile; |
|
| 768 | 768 | |
| 769 | - foreach ( $theme as $name => $value ) { |
|
| 769 | + foreach ( $theme as $name => $value ) { |
|
| 770 | 770 | |
| 771 | - if ( in_array( $name, array( 'arrow_up', 'arrow_down', 'arrow_left', 'arrow_right' ) ) ) { |
|
| 771 | + if ( in_array( $name, array( 'arrow_up', 'arrow_down', 'arrow_left', 'arrow_right' ) ) ) { |
|
| 772 | 772 | |
| 773 | - $parts = explode( '-', $value ); |
|
| 774 | - $code = end( $parts ); |
|
| 773 | + $parts = explode( '-', $value ); |
|
| 774 | + $code = end( $parts ); |
|
| 775 | 775 | |
| 776 | - $arrow_icon = $code == 'disabled' ? "''" : "'\\" . $code . "'"; |
|
| 776 | + $arrow_icon = $code == 'disabled' ? "''" : "'\\" . $code . "'"; |
|
| 777 | 777 | |
| 778 | - $vars[ $name ] = $arrow_icon; |
|
| 778 | + $vars[ $name ] = $arrow_icon; |
|
| 779 | 779 | |
| 780 | - continue; |
|
| 781 | - } |
|
| 780 | + continue; |
|
| 781 | + } |
|
| 782 | 782 | |
| 783 | - if ( in_array( $name, array( 'menu_item_link_font', 'panel_font_family', 'panel_header_font', 'panel_second_level_font', 'panel_third_level_font', 'panel_third_level_font', 'flyout_link_family', 'tabbed_link_family' ) ) ) { |
|
| 783 | + if ( in_array( $name, array( 'menu_item_link_font', 'panel_font_family', 'panel_header_font', 'panel_second_level_font', 'panel_third_level_font', 'panel_third_level_font', 'flyout_link_family', 'tabbed_link_family' ) ) ) { |
|
| 784 | 784 | |
| 785 | - $vars[ $name ] = "'" . stripslashes( htmlspecialchars_decode( $value ) ) . "'"; |
|
| 785 | + $vars[ $name ] = "'" . stripslashes( htmlspecialchars_decode( $value ) ) . "'"; |
|
| 786 | 786 | |
| 787 | - // find font names that end with/contain a number, e.g. Baloo 2, and add extra quotes so that they still retain quotes when CSS is compiled. |
|
| 788 | - $font_name_with_single_quotes = $vars[ $name ]; |
|
| 789 | - $font_name_with_no_quotes = str_replace( "'", "", $font_name_with_single_quotes ); |
|
| 790 | - $font_name_parts = explode( " ", $font_name_with_no_quotes ); |
|
| 787 | + // find font names that end with/contain a number, e.g. Baloo 2, and add extra quotes so that they still retain quotes when CSS is compiled. |
|
| 788 | + $font_name_with_single_quotes = $vars[ $name ]; |
|
| 789 | + $font_name_with_no_quotes = str_replace( "'", "", $font_name_with_single_quotes ); |
|
| 790 | + $font_name_parts = explode( " ", $font_name_with_no_quotes ); |
|
| 791 | 791 | |
| 792 | - if ( is_array( $font_name_parts) ) { |
|
| 793 | - foreach ( $font_name_parts as $part ) { |
|
| 794 | - if ( is_numeric ($part) ) { |
|
| 795 | - $vars[ $name ] = "\"{$font_name_with_single_quotes}\""; |
|
| 796 | - continue; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 792 | + if ( is_array( $font_name_parts) ) { |
|
| 793 | + foreach ( $font_name_parts as $part ) { |
|
| 794 | + if ( is_numeric ($part) ) { |
|
| 795 | + $vars[ $name ] = "\"{$font_name_with_single_quotes}\""; |
|
| 796 | + continue; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | - continue; |
|
| 802 | - } |
|
| 801 | + continue; |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - if ( in_array( $name, array( 'responsive_text' ) ) ) { |
|
| 804 | + if ( in_array( $name, array( 'responsive_text' ) ) ) { |
|
| 805 | 805 | |
| 806 | - if ( strlen( $value ) ) { |
|
| 807 | - $vars[ $name ] = "'" . do_shortcode( $value ) . "'"; |
|
| 808 | - } else { |
|
| 809 | - $vars[ $name ] = "''"; |
|
| 810 | - } |
|
| 806 | + if ( strlen( $value ) ) { |
|
| 807 | + $vars[ $name ] = "'" . do_shortcode( $value ) . "'"; |
|
| 808 | + } else { |
|
| 809 | + $vars[ $name ] = "''"; |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - continue; |
|
| 813 | - } |
|
| 812 | + continue; |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | - if ( in_array( $name, array( 'panel_width', 'panel_inner_width', 'mobile_menu_force_width_selector' ) ) ) { |
|
| 816 | - if ( preg_match( '/^\d/', $value ) !== 1 ) { // doesn't start with number (jQuery selector) |
|
| 817 | - $vars[ $name ] = '100%'; |
|
| 818 | - continue; |
|
| 819 | - } |
|
| 820 | - } |
|
| 815 | + if ( in_array( $name, array( 'panel_width', 'panel_inner_width', 'mobile_menu_force_width_selector' ) ) ) { |
|
| 816 | + if ( preg_match( '/^\d/', $value ) !== 1 ) { // doesn't start with number (jQuery selector) |
|
| 817 | + $vars[ $name ] = '100%'; |
|
| 818 | + continue; |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | 821 | |
| 822 | - if ( $name != 'custom_css' ) { |
|
| 823 | - $vars[ $name ] = $value; |
|
| 824 | - } |
|
| 825 | - } |
|
| 822 | + if ( $name != 'custom_css' ) { |
|
| 823 | + $vars[ $name ] = $value; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | - // Non-standard characters in the title will break CSS compilation, unset it here as it's not needed. |
|
| 828 | - if ( isset( $vars['title'] ) ) { |
|
| 829 | - unset( $vars['title'] ); |
|
| 830 | - } |
|
| 827 | + // Non-standard characters in the title will break CSS compilation, unset it here as it's not needed. |
|
| 828 | + if ( isset( $vars['title'] ) ) { |
|
| 829 | + unset( $vars['title'] ); |
|
| 830 | + } |
|
| 831 | 831 | |
| 832 | - $vars = apply_filters( 'megamenu_scss_variables', $vars, $location, $theme, $menu_id, $this->get_theme_id_for_location( $location ) ); |
|
| 832 | + $vars = apply_filters( 'megamenu_scss_variables', $vars, $location, $theme, $menu_id, $this->get_theme_id_for_location( $location ) ); |
|
| 833 | 833 | |
| 834 | - $scss = ''; |
|
| 834 | + $scss = ''; |
|
| 835 | 835 | |
| 836 | - foreach ( $vars as $name => $value ) { |
|
| 837 | - $scss .= '$' . $name . ': ' . $value . ";\n"; |
|
| 838 | - } |
|
| 836 | + foreach ( $vars as $name => $value ) { |
|
| 837 | + $scss .= '$' . $name . ': ' . $value . ";\n"; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - $scss .= $this->load_scss_file(); |
|
| 840 | + $scss .= $this->load_scss_file(); |
|
| 841 | 841 | |
| 842 | - $scss .= stripslashes( html_entity_decode( $theme['custom_css'], ENT_QUOTES ) ); |
|
| 842 | + $scss .= stripslashes( html_entity_decode( $theme['custom_css'], ENT_QUOTES ) ); |
|
| 843 | 843 | |
| 844 | - return apply_filters( 'megamenu_scss', $scss, $location, $theme, $menu_id ); |
|
| 844 | + return apply_filters( 'megamenu_scss', $scss, $location, $theme, $menu_id ); |
|
| 845 | 845 | |
| 846 | - } |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | 848 | |
| 849 | - /** |
|
| 850 | - * Returns the menu ID for a specified menu location, defaults to 0 |
|
| 851 | - * |
|
| 852 | - * @since 1.3 |
|
| 853 | - */ |
|
| 854 | - private function get_menu_id_for_location( $location ) { |
|
| 855 | - $locations = get_nav_menu_locations(); |
|
| 856 | - $menu_id = isset( $locations[ $location ] ) ? $locations[ $location ] : 0; |
|
| 849 | + /** |
|
| 850 | + * Returns the menu ID for a specified menu location, defaults to 0 |
|
| 851 | + * |
|
| 852 | + * @since 1.3 |
|
| 853 | + */ |
|
| 854 | + private function get_menu_id_for_location( $location ) { |
|
| 855 | + $locations = get_nav_menu_locations(); |
|
| 856 | + $menu_id = isset( $locations[ $location ] ) ? $locations[ $location ] : 0; |
|
| 857 | 857 | |
| 858 | - return $menu_id; |
|
| 859 | - } |
|
| 858 | + return $menu_id; |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | 861 | |
| 862 | - /** |
|
| 863 | - * Returns the theme ID for a specified menu location, defaults to 'default' |
|
| 864 | - * |
|
| 865 | - * @since 2.1 |
|
| 866 | - */ |
|
| 867 | - private function get_theme_id_for_location( $location ) { |
|
| 868 | - $settings = $this->settings; |
|
| 869 | - $theme_id = isset( $settings[ $location ]['theme'] ) ? $settings[ $location ]['theme'] : 'default'; |
|
| 862 | + /** |
|
| 863 | + * Returns the theme ID for a specified menu location, defaults to 'default' |
|
| 864 | + * |
|
| 865 | + * @since 2.1 |
|
| 866 | + */ |
|
| 867 | + private function get_theme_id_for_location( $location ) { |
|
| 868 | + $settings = $this->settings; |
|
| 869 | + $theme_id = isset( $settings[ $location ]['theme'] ) ? $settings[ $location ]['theme'] : 'default'; |
|
| 870 | 870 | |
| 871 | - return $theme_id; |
|
| 872 | - } |
|
| 871 | + return $theme_id; |
|
| 872 | + } |
|
| 873 | 873 | |
| 874 | 874 | |
| 875 | - /** |
|
| 876 | - * Returns the theme settings for a specified location. Defaults to the default theme. |
|
| 877 | - * |
|
| 878 | - * @since 1.3 |
|
| 879 | - */ |
|
| 880 | - private function get_theme_settings_for_location( $location ) { |
|
| 881 | - $theme_id = $this->get_theme_id_for_location( $location ); |
|
| 882 | - $all_themes = $this->get_themes(); |
|
| 883 | - $theme_settings = isset( $all_themes[ $theme_id ] ) ? $all_themes[ $theme_id ] : $all_themes['default']; |
|
| 875 | + /** |
|
| 876 | + * Returns the theme settings for a specified location. Defaults to the default theme. |
|
| 877 | + * |
|
| 878 | + * @since 1.3 |
|
| 879 | + */ |
|
| 880 | + private function get_theme_settings_for_location( $location ) { |
|
| 881 | + $theme_id = $this->get_theme_id_for_location( $location ); |
|
| 882 | + $all_themes = $this->get_themes(); |
|
| 883 | + $theme_settings = isset( $all_themes[ $theme_id ] ) ? $all_themes[ $theme_id ] : $all_themes['default']; |
|
| 884 | 884 | |
| 885 | - return $theme_settings; |
|
| 886 | - } |
|
| 885 | + return $theme_settings; |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | 888 | |
| 889 | - /** |
|
| 890 | - * Returns the menu settings for a specified location. |
|
| 891 | - * |
|
| 892 | - * @since 2.2 |
|
| 893 | - */ |
|
| 894 | - private function get_menu_settings_for_location( $location ) { |
|
| 895 | - $settings = $this->settings; |
|
| 896 | - $location_settings = isset( $settings[ $location ] ) ? $settings[ $location ] : array(); |
|
| 897 | - return $location_settings; |
|
| 898 | - } |
|
| 889 | + /** |
|
| 890 | + * Returns the menu settings for a specified location. |
|
| 891 | + * |
|
| 892 | + * @since 2.2 |
|
| 893 | + */ |
|
| 894 | + private function get_menu_settings_for_location( $location ) { |
|
| 895 | + $settings = $this->settings; |
|
| 896 | + $location_settings = isset( $settings[ $location ] ) ? $settings[ $location ] : array(); |
|
| 897 | + return $location_settings; |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | - /** |
|
| 901 | - * Enqueue public CSS and JS files required by Mega Menu |
|
| 902 | - * |
|
| 903 | - * @since 1.0 |
|
| 904 | - */ |
|
| 905 | - public function enqueue_styles() { |
|
| 906 | - if ( 'fs' === $this->get_css_output_method() ) { |
|
| 907 | - $this->enqueue_fs_style(); |
|
| 908 | - } |
|
| 900 | + /** |
|
| 901 | + * Enqueue public CSS and JS files required by Mega Menu |
|
| 902 | + * |
|
| 903 | + * @since 1.0 |
|
| 904 | + */ |
|
| 905 | + public function enqueue_styles() { |
|
| 906 | + if ( 'fs' === $this->get_css_output_method() ) { |
|
| 907 | + $this->enqueue_fs_style(); |
|
| 908 | + } |
|
| 909 | 909 | |
| 910 | - wp_enqueue_style( 'dashicons' ); |
|
| 910 | + wp_enqueue_style( 'dashicons' ); |
|
| 911 | 911 | |
| 912 | - do_action( 'megamenu_enqueue_public_scripts' ); |
|
| 912 | + do_action( 'megamenu_enqueue_public_scripts' ); |
|
| 913 | 913 | |
| 914 | - } |
|
| 914 | + } |
|
| 915 | 915 | |
| 916 | - /** |
|
| 917 | - * Enqueue public CSS and JS files required by Mega Menu |
|
| 918 | - * |
|
| 919 | - * @since 1.0 |
|
| 920 | - */ |
|
| 921 | - public function enqueue_scripts() { |
|
| 916 | + /** |
|
| 917 | + * Enqueue public CSS and JS files required by Mega Menu |
|
| 918 | + * |
|
| 919 | + * @since 1.0 |
|
| 920 | + */ |
|
| 921 | + public function enqueue_scripts() { |
|
| 922 | 922 | |
| 923 | - wp_enqueue_script( 'hoverIntent' ); |
|
| 923 | + wp_enqueue_script( 'hoverIntent' ); |
|
| 924 | 924 | |
| 925 | - $js_path = MEGAMENU_BASE_URL . 'js/maxmegamenu.js'; |
|
| 925 | + $js_path = MEGAMENU_BASE_URL . 'js/maxmegamenu.js'; |
|
| 926 | 926 | |
| 927 | - $dependencies = apply_filters( 'megamenu_javascript_dependencies', array( 'jquery', 'hoverIntent' ) ); |
|
| 927 | + $dependencies = apply_filters( 'megamenu_javascript_dependencies', array( 'jquery', 'hoverIntent' ) ); |
|
| 928 | 928 | |
| 929 | - $scripts_in_footer = apply_filters( 'megamenu_scripts_in_footer', true ); |
|
| 929 | + $scripts_in_footer = apply_filters( 'megamenu_scripts_in_footer', true ); |
|
| 930 | 930 | |
| 931 | - if ( defined( 'MEGAMENU_SCRIPTS_IN_FOOTER' ) ) { |
|
| 932 | - $scripts_in_footer = MEGAMENU_SCRIPTS_IN_FOOTER; |
|
| 933 | - } |
|
| 931 | + if ( defined( 'MEGAMENU_SCRIPTS_IN_FOOTER' ) ) { |
|
| 932 | + $scripts_in_footer = MEGAMENU_SCRIPTS_IN_FOOTER; |
|
| 933 | + } |
|
| 934 | 934 | |
| 935 | - ///** change the script handle to prevent conflict with theme files */ |
|
| 936 | - //function megamenu_script_handle() { |
|
| 937 | - // return "maxmegamenu"; |
|
| 938 | - //} |
|
| 939 | - //add_filter("megamenu_javascript_handle", "megamenu_script_handle");*/ |
|
| 940 | - $handle = apply_filters( 'megamenu_javascript_handle', 'megamenu' ); |
|
| 935 | + ///** change the script handle to prevent conflict with theme files */ |
|
| 936 | + //function megamenu_script_handle() { |
|
| 937 | + // return "maxmegamenu"; |
|
| 938 | + //} |
|
| 939 | + //add_filter("megamenu_javascript_handle", "megamenu_script_handle");*/ |
|
| 940 | + $handle = apply_filters( 'megamenu_javascript_handle', 'megamenu' ); |
|
| 941 | 941 | |
| 942 | - wp_enqueue_script( $handle, $js_path, $dependencies, MEGAMENU_VERSION, $scripts_in_footer ); |
|
| 942 | + wp_enqueue_script( $handle, $js_path, $dependencies, MEGAMENU_VERSION, $scripts_in_footer ); |
|
| 943 | 943 | |
| 944 | - // @todo: remove the following code in future update. Only here to prevent JS errors for users with |
|
| 945 | - // cached versions of maxmegamenu.js |
|
| 946 | - $params = apply_filters( |
|
| 947 | - 'megamenu_javascript_localisation', |
|
| 948 | - array( |
|
| 949 | - 'timeout' => 300, |
|
| 950 | - 'interval' => 100, |
|
| 951 | - ) |
|
| 952 | - ); |
|
| 944 | + // @todo: remove the following code in future update. Only here to prevent JS errors for users with |
|
| 945 | + // cached versions of maxmegamenu.js |
|
| 946 | + $params = apply_filters( |
|
| 947 | + 'megamenu_javascript_localisation', |
|
| 948 | + array( |
|
| 949 | + 'timeout' => 300, |
|
| 950 | + 'interval' => 100, |
|
| 951 | + ) |
|
| 952 | + ); |
|
| 953 | 953 | |
| 954 | - wp_localize_script( $handle, 'megamenu', $params ); |
|
| 955 | - } |
|
| 954 | + wp_localize_script( $handle, 'megamenu', $params ); |
|
| 955 | + } |
|
| 956 | 956 | |
| 957 | 957 | |
| 958 | 958 | |
| 959 | - /** |
|
| 960 | - * Enqueue the stylesheet held on the filesystem. |
|
| 961 | - * |
|
| 962 | - * @since 1.6.1 |
|
| 963 | - */ |
|
| 964 | - public function enqueue_fs_style() { |
|
| 959 | + /** |
|
| 960 | + * Enqueue the stylesheet held on the filesystem. |
|
| 961 | + * |
|
| 962 | + * @since 1.6.1 |
|
| 963 | + */ |
|
| 964 | + public function enqueue_fs_style() { |
|
| 965 | 965 | |
| 966 | - $upload_dir = wp_upload_dir(); |
|
| 966 | + $upload_dir = wp_upload_dir(); |
|
| 967 | 967 | |
| 968 | - $filename = $this->get_css_filename(); |
|
| 968 | + $filename = $this->get_css_filename(); |
|
| 969 | 969 | |
| 970 | - $filepath = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/' . $filename; |
|
| 970 | + $filepath = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/' . $filename; |
|
| 971 | 971 | |
| 972 | - if ( ! is_file( $filepath ) || $this->is_debug_mode() ) { |
|
| 973 | - // regenerate the CSS and save to filesystem. |
|
| 974 | - $this->generate_css(); |
|
| 972 | + if ( ! is_file( $filepath ) || $this->is_debug_mode() ) { |
|
| 973 | + // regenerate the CSS and save to filesystem. |
|
| 974 | + $this->generate_css(); |
|
| 975 | 975 | |
| 976 | - } |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | - // file should now exist. |
|
| 979 | - if ( is_file( $filepath ) ) { |
|
| 978 | + // file should now exist. |
|
| 979 | + if ( is_file( $filepath ) ) { |
|
| 980 | 980 | |
| 981 | - $css_url = trailingslashit( $upload_dir['baseurl'] ) . 'maxmegamenu/' . $filename; |
|
| 981 | + $css_url = trailingslashit( $upload_dir['baseurl'] ) . 'maxmegamenu/' . $filename; |
|
| 982 | 982 | |
| 983 | - $protocol = is_ssl() ? 'https://' : 'http://'; |
|
| 983 | + $protocol = is_ssl() ? 'https://' : 'http://'; |
|
| 984 | 984 | |
| 985 | - // ensure we're using the correct protocol. |
|
| 986 | - $css_url = str_replace( array( 'http://', 'https://' ), $protocol, $css_url ); |
|
| 985 | + // ensure we're using the correct protocol. |
|
| 986 | + $css_url = str_replace( array( 'http://', 'https://' ), $protocol, $css_url ); |
|
| 987 | 987 | |
| 988 | - wp_enqueue_style( 'megamenu', $css_url, false, substr( md5( filemtime( $filepath ) ), 0, 6 ) ); |
|
| 988 | + wp_enqueue_style( 'megamenu', $css_url, false, substr( md5( filemtime( $filepath ) ), 0, 6 ) ); |
|
| 989 | 989 | |
| 990 | - } |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | - } |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | 994 | |
| 995 | - /** |
|
| 996 | - * |
|
| 997 | - * @since 1.6.1 |
|
| 998 | - */ |
|
| 999 | - private function set_cached_css( $css ) { |
|
| 1000 | - // set a far expiration date to prevent transient from being autoloaded. |
|
| 1001 | - $hundred_years_in_seconds = 3153600000; |
|
| 995 | + /** |
|
| 996 | + * |
|
| 997 | + * @since 1.6.1 |
|
| 998 | + */ |
|
| 999 | + private function set_cached_css( $css ) { |
|
| 1000 | + // set a far expiration date to prevent transient from being autoloaded. |
|
| 1001 | + $hundred_years_in_seconds = 3153600000; |
|
| 1002 | 1002 | |
| 1003 | - set_transient( $this->get_transient_key(), $css, $hundred_years_in_seconds ); |
|
| 1004 | - set_transient( 'megamenu_css_version', MEGAMENU_VERSION, $hundred_years_in_seconds ); |
|
| 1005 | - set_transient( 'megamenu_css_last_updated', time(), $hundred_years_in_seconds ); |
|
| 1006 | - } |
|
| 1003 | + set_transient( $this->get_transient_key(), $css, $hundred_years_in_seconds ); |
|
| 1004 | + set_transient( 'megamenu_css_version', MEGAMENU_VERSION, $hundred_years_in_seconds ); |
|
| 1005 | + set_transient( 'megamenu_css_last_updated', time(), $hundred_years_in_seconds ); |
|
| 1006 | + } |
|
| 1007 | 1007 | |
| 1008 | 1008 | |
| 1009 | - /** |
|
| 1010 | - * Return the cached css if it exists |
|
| 1011 | - * |
|
| 1012 | - * @since 1.9 |
|
| 1013 | - * @return mixed |
|
| 1014 | - */ |
|
| 1015 | - private function get_cached_css() { |
|
| 1016 | - return get_transient( $this->get_transient_key() ); |
|
| 1017 | - } |
|
| 1009 | + /** |
|
| 1010 | + * Return the cached css if it exists |
|
| 1011 | + * |
|
| 1012 | + * @since 1.9 |
|
| 1013 | + * @return mixed |
|
| 1014 | + */ |
|
| 1015 | + private function get_cached_css() { |
|
| 1016 | + return get_transient( $this->get_transient_key() ); |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | 1019 | |
| 1020 | - /** |
|
| 1021 | - * Delete the cached CSS |
|
| 1022 | - * |
|
| 1023 | - * @since 1.9 |
|
| 1024 | - * @return mixed |
|
| 1025 | - */ |
|
| 1026 | - public function delete_cache() { |
|
| 1027 | - global $wp_filesystem; |
|
| 1020 | + /** |
|
| 1021 | + * Delete the cached CSS |
|
| 1022 | + * |
|
| 1023 | + * @since 1.9 |
|
| 1024 | + * @return mixed |
|
| 1025 | + */ |
|
| 1026 | + public function delete_cache() { |
|
| 1027 | + global $wp_filesystem; |
|
| 1028 | 1028 | |
| 1029 | - if ( ! $wp_filesystem ) { |
|
| 1030 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 1031 | - } |
|
| 1029 | + if ( ! $wp_filesystem ) { |
|
| 1030 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 1031 | + } |
|
| 1032 | 1032 | |
| 1033 | - $upload_dir = wp_upload_dir(); |
|
| 1034 | - $filename = $this->get_css_filename(); |
|
| 1035 | - $dir = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/'; |
|
| 1033 | + $upload_dir = wp_upload_dir(); |
|
| 1034 | + $filename = $this->get_css_filename(); |
|
| 1035 | + $dir = trailingslashit( $upload_dir['basedir'] ) . 'maxmegamenu/'; |
|
| 1036 | 1036 | |
| 1037 | - WP_Filesystem( false, $upload_dir['basedir'], true ); |
|
| 1038 | - $wp_filesystem->rmdir( $dir, true ); |
|
| 1037 | + WP_Filesystem( false, $upload_dir['basedir'], true ); |
|
| 1038 | + $wp_filesystem->rmdir( $dir, true ); |
|
| 1039 | 1039 | |
| 1040 | - delete_transient( $this->get_transient_key() ); |
|
| 1040 | + delete_transient( $this->get_transient_key() ); |
|
| 1041 | 1041 | |
| 1042 | - $this->generate_css(); |
|
| 1042 | + $this->generate_css(); |
|
| 1043 | 1043 | |
| 1044 | - do_action( 'megamenu_after_delete_cache' ); |
|
| 1044 | + do_action( 'megamenu_after_delete_cache' ); |
|
| 1045 | 1045 | |
| 1046 | - return true; |
|
| 1046 | + return true; |
|
| 1047 | 1047 | |
| 1048 | - } |
|
| 1048 | + } |
|
| 1049 | 1049 | |
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Return the key to use for the CSS transient |
|
| 1053 | - * |
|
| 1054 | - * @since 1.9 |
|
| 1055 | - * @return string |
|
| 1056 | - */ |
|
| 1057 | - private function get_transient_key() { |
|
| 1058 | - return apply_filters( 'megamenu_css_transient_key', 'megamenu_css' ); |
|
| 1059 | - } |
|
| 1051 | + /** |
|
| 1052 | + * Return the key to use for the CSS transient |
|
| 1053 | + * |
|
| 1054 | + * @since 1.9 |
|
| 1055 | + * @return string |
|
| 1056 | + */ |
|
| 1057 | + private function get_transient_key() { |
|
| 1058 | + return apply_filters( 'megamenu_css_transient_key', 'megamenu_css' ); |
|
| 1059 | + } |
|
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /** |
|
| 1063 | - * Return the filename to use for the stylesheet, ensuring the filename is unique |
|
| 1064 | - * for multi site setups |
|
| 1065 | - * |
|
| 1066 | - * @since 1.6.1 |
|
| 1067 | - */ |
|
| 1068 | - private function get_css_filename() { |
|
| 1069 | - return apply_filters( 'megamenu_css_filename', 'style' ) . '.css'; |
|
| 1070 | - } |
|
| 1062 | + /** |
|
| 1063 | + * Return the filename to use for the stylesheet, ensuring the filename is unique |
|
| 1064 | + * for multi site setups |
|
| 1065 | + * |
|
| 1066 | + * @since 1.6.1 |
|
| 1067 | + */ |
|
| 1068 | + private function get_css_filename() { |
|
| 1069 | + return apply_filters( 'megamenu_css_filename', 'style' ) . '.css'; |
|
| 1070 | + } |
|
| 1071 | 1071 | |
| 1072 | 1072 | |
| 1073 | - /** |
|
| 1074 | - * Return the CSS output method, default to filesystem |
|
| 1075 | - * |
|
| 1076 | - * @return string |
|
| 1077 | - */ |
|
| 1078 | - private function get_css_output_method() { |
|
| 1079 | - return isset( $this->settings['css'] ) ? $this->settings['css'] : 'fs'; |
|
| 1080 | - } |
|
| 1073 | + /** |
|
| 1074 | + * Return the CSS output method, default to filesystem |
|
| 1075 | + * |
|
| 1076 | + * @return string |
|
| 1077 | + */ |
|
| 1078 | + private function get_css_output_method() { |
|
| 1079 | + return isset( $this->settings['css'] ) ? $this->settings['css'] : 'fs'; |
|
| 1080 | + } |
|
| 1081 | 1081 | |
| 1082 | 1082 | |
| 1083 | - /** |
|
| 1084 | - * Print CSS to <head> |
|
| 1085 | - * |
|
| 1086 | - * @since 1.3.1 |
|
| 1087 | - */ |
|
| 1088 | - public function head_css() { |
|
| 1083 | + /** |
|
| 1084 | + * Print CSS to <head> |
|
| 1085 | + * |
|
| 1086 | + * @since 1.3.1 |
|
| 1087 | + */ |
|
| 1088 | + public function head_css() { |
|
| 1089 | 1089 | |
| 1090 | - $method = $this->get_css_output_method(); |
|
| 1090 | + $method = $this->get_css_output_method(); |
|
| 1091 | 1091 | |
| 1092 | - if ( in_array( $method, array( 'disabled', 'fs' ) ) ) { |
|
| 1093 | - echo "<style type=\"text/css\">/** Mega Menu CSS: {$method} **/</style>\n"; |
|
| 1094 | - return; |
|
| 1095 | - } |
|
| 1092 | + if ( in_array( $method, array( 'disabled', 'fs' ) ) ) { |
|
| 1093 | + echo "<style type=\"text/css\">/** Mega Menu CSS: {$method} **/</style>\n"; |
|
| 1094 | + return; |
|
| 1095 | + } |
|
| 1096 | 1096 | |
| 1097 | - $css = $this->get_css(); |
|
| 1097 | + $css = $this->get_css(); |
|
| 1098 | 1098 | |
| 1099 | - echo '<style type="text/css">' . str_replace( array( ' ', "\n" ), '', $css ) . "</style>\n"; |
|
| 1099 | + echo '<style type="text/css">' . str_replace( array( ' ', "\n" ), '', $css ) . "</style>\n"; |
|
| 1100 | 1100 | |
| 1101 | - } |
|
| 1101 | + } |
|
| 1102 | 1102 | |
| 1103 | 1103 | |
| 1104 | - /** |
|
| 1105 | - * Delete language specific transients created when PolyLang is installed |
|
| 1106 | - * |
|
| 1107 | - * @since 1.9 |
|
| 1108 | - */ |
|
| 1109 | - public function polylang_delete_cache() { |
|
| 1110 | - global $polylang; |
|
| 1104 | + /** |
|
| 1105 | + * Delete language specific transients created when PolyLang is installed |
|
| 1106 | + * |
|
| 1107 | + * @since 1.9 |
|
| 1108 | + */ |
|
| 1109 | + public function polylang_delete_cache() { |
|
| 1110 | + global $polylang; |
|
| 1111 | 1111 | |
| 1112 | - foreach ( $polylang->model->get_languages_list() as $term ) { |
|
| 1113 | - delete_transient( 'megamenu_css_' . $term->locale ); |
|
| 1114 | - } |
|
| 1115 | - } |
|
| 1112 | + foreach ( $polylang->model->get_languages_list() as $term ) { |
|
| 1113 | + delete_transient( 'megamenu_css_' . $term->locale ); |
|
| 1114 | + } |
|
| 1115 | + } |
|
| 1116 | 1116 | |
| 1117 | 1117 | |
| 1118 | - /** |
|
| 1119 | - * Modify the CSS transient key to make it unique to the current language |
|
| 1120 | - * |
|
| 1121 | - * @since 1.9 |
|
| 1122 | - * @return string |
|
| 1123 | - */ |
|
| 1124 | - public function polylang_transient_key( $key ) { |
|
| 1118 | + /** |
|
| 1119 | + * Modify the CSS transient key to make it unique to the current language |
|
| 1120 | + * |
|
| 1121 | + * @since 1.9 |
|
| 1122 | + * @return string |
|
| 1123 | + */ |
|
| 1124 | + public function polylang_transient_key( $key ) { |
|
| 1125 | 1125 | |
| 1126 | - $locale = strtolower( pll_current_language( 'locale' ) ); |
|
| 1126 | + $locale = strtolower( pll_current_language( 'locale' ) ); |
|
| 1127 | 1127 | |
| 1128 | - if ( strlen( $locale ) ) { |
|
| 1129 | - $key = $key . '_' . $locale; |
|
| 1130 | - } |
|
| 1128 | + if ( strlen( $locale ) ) { |
|
| 1129 | + $key = $key . '_' . $locale; |
|
| 1130 | + } |
|
| 1131 | 1131 | |
| 1132 | - return $key; |
|
| 1133 | - } |
|
| 1132 | + return $key; |
|
| 1133 | + } |
|
| 1134 | 1134 | |
| 1135 | 1135 | |
| 1136 | - /** |
|
| 1137 | - * Modify the CSS filename to make it unique to the current language |
|
| 1138 | - * |
|
| 1139 | - * @since 1.9 |
|
| 1140 | - * @return string |
|
| 1141 | - */ |
|
| 1142 | - public function polylang_css_filename( $filename ) { |
|
| 1136 | + /** |
|
| 1137 | + * Modify the CSS filename to make it unique to the current language |
|
| 1138 | + * |
|
| 1139 | + * @since 1.9 |
|
| 1140 | + * @return string |
|
| 1141 | + */ |
|
| 1142 | + public function polylang_css_filename( $filename ) { |
|
| 1143 | 1143 | |
| 1144 | - $locale = strtolower( pll_current_language( 'locale' ) ); |
|
| 1144 | + $locale = strtolower( pll_current_language( 'locale' ) ); |
|
| 1145 | 1145 | |
| 1146 | - if ( strlen( $locale ) ) { |
|
| 1147 | - $filename .= '_' . $locale; |
|
| 1148 | - } |
|
| 1146 | + if ( strlen( $locale ) ) { |
|
| 1147 | + $filename .= '_' . $locale; |
|
| 1148 | + } |
|
| 1149 | 1149 | |
| 1150 | - return $filename; |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * Delete language specific transients created when WPML is installed |
|
| 1156 | - * |
|
| 1157 | - * @since 1.9 |
|
| 1158 | - */ |
|
| 1159 | - public function wpml_delete_cache() { |
|
| 1150 | + return $filename; |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * Delete language specific transients created when WPML is installed |
|
| 1156 | + * |
|
| 1157 | + * @since 1.9 |
|
| 1158 | + */ |
|
| 1159 | + public function wpml_delete_cache() { |
|
| 1160 | 1160 | |
| 1161 | - $languages = icl_get_languages( 'skip_missing=N' ); |
|
| 1162 | - |
|
| 1163 | - foreach ( $languages as $language ) { |
|
| 1164 | - delete_transient( 'megamenu_css_' . $language['language_code'] ); |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1161 | + $languages = icl_get_languages( 'skip_missing=N' ); |
|
| 1162 | + |
|
| 1163 | + foreach ( $languages as $language ) { |
|
| 1164 | + delete_transient( 'megamenu_css_' . $language['language_code'] ); |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | 1167 | |
| 1168 | 1168 | |
| 1169 | - /** |
|
| 1170 | - * Modify the CSS transient key to make it unique to the current language |
|
| 1171 | - * |
|
| 1172 | - * @since 1.9 |
|
| 1173 | - * @return string |
|
| 1174 | - */ |
|
| 1175 | - public function wpml_transient_key( $key ) { |
|
| 1176 | - $key .= '_' . ICL_LANGUAGE_CODE; |
|
| 1169 | + /** |
|
| 1170 | + * Modify the CSS transient key to make it unique to the current language |
|
| 1171 | + * |
|
| 1172 | + * @since 1.9 |
|
| 1173 | + * @return string |
|
| 1174 | + */ |
|
| 1175 | + public function wpml_transient_key( $key ) { |
|
| 1176 | + $key .= '_' . ICL_LANGUAGE_CODE; |
|
| 1177 | 1177 | |
| 1178 | - return $key; |
|
| 1179 | - } |
|
| 1178 | + return $key; |
|
| 1179 | + } |
|
| 1180 | 1180 | |
| 1181 | 1181 | |
| 1182 | - /** |
|
| 1183 | - * Modify the CSS filename to make it unique to the current language |
|
| 1184 | - * |
|
| 1185 | - * @since 1.9 |
|
| 1186 | - * @return string |
|
| 1187 | - */ |
|
| 1188 | - public function wpml_css_filename( $filename ) { |
|
| 1189 | - $filename .= '_' . ICL_LANGUAGE_CODE; |
|
| 1182 | + /** |
|
| 1183 | + * Modify the CSS filename to make it unique to the current language |
|
| 1184 | + * |
|
| 1185 | + * @since 1.9 |
|
| 1186 | + * @return string |
|
| 1187 | + */ |
|
| 1188 | + public function wpml_css_filename( $filename ) { |
|
| 1189 | + $filename .= '_' . ICL_LANGUAGE_CODE; |
|
| 1190 | 1190 | |
| 1191 | - return $filename; |
|
| 1192 | - } |
|
| 1193 | - } |
|
| 1191 | + return $filename; |
|
| 1192 | + } |
|
| 1193 | + } |
|
| 1194 | 1194 | |
| 1195 | 1195 | endif; |
@@ -1,381 +1,381 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Nav_Menus' ) ) : |
| 8 | - /** |
|
| 9 | - * Handles all admin related functionality. |
|
| 10 | - */ |
|
| 11 | - class Mega_Menu_Nav_Menus { |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * Return the default settings for each menu item |
|
| 15 | - * |
|
| 16 | - * @since 1.5 |
|
| 17 | - */ |
|
| 18 | - public static function get_menu_item_defaults() { |
|
| 19 | - |
|
| 20 | - $defaults = array( |
|
| 21 | - 'type' => 'flyout', |
|
| 22 | - 'align' => 'bottom-left', |
|
| 23 | - 'icon' => 'disabled', |
|
| 24 | - 'hide_text' => 'false', |
|
| 25 | - 'disable_link' => 'false', |
|
| 26 | - 'hide_on_mobile' => 'false', |
|
| 27 | - 'hide_on_desktop' => 'false', |
|
| 28 | - 'close_after_click' => 'false', |
|
| 29 | - 'hide_sub_menu_on_mobile' => 'false', |
|
| 30 | - 'hide_arrow' => 'false', |
|
| 31 | - 'item_align' => 'left', |
|
| 32 | - 'icon_position' => 'left', |
|
| 33 | - 'panel_columns' => 6, // total number of columns displayed in the panel. |
|
| 34 | - 'mega_menu_columns' => 1, // for sub menu items, how many columns to span in the panel. |
|
| 35 | - 'mega_menu_order' => 0, |
|
| 36 | - 'collapse_children' => 'false', |
|
| 37 | - 'submenu_columns' => 1, |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - return apply_filters( 'megamenu_menu_item_defaults', $defaults ); |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Constructor |
|
| 47 | - * |
|
| 48 | - * @since 1.0 |
|
| 49 | - */ |
|
| 50 | - public function __construct() { |
|
| 51 | - add_action( 'admin_init', array( $this, 'register_nav_meta_box' ), 9 ); |
|
| 52 | - add_action( 'megamenu_nav_menus_scripts', array( $this, 'enqueue_menu_page_scripts' ), 10 ); |
|
| 53 | - add_action( 'wp_ajax_mm_save_settings', array( $this, 'save' ) ); |
|
| 54 | - add_filter( 'hidden_meta_boxes', array( $this, 'show_mega_menu_metabox' ) ); |
|
| 55 | - |
|
| 56 | - add_filter( 'siteorigin_panels_is_admin_page', array( $this, 'enable_site_origin_page_builder' ) ); |
|
| 57 | - |
|
| 58 | - if ( function_exists( 'siteorigin_panels_admin_enqueue_scripts' ) ) { |
|
| 59 | - add_action( 'admin_print_scripts-nav-menus.php', array( $this, 'siteorigin_panels_admin_enqueue_scripts' ) ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if ( function_exists( 'siteorigin_panels_admin_enqueue_styles' ) ) { |
|
| 63 | - add_action( 'admin_print_styles-nav-menus.php', array( $this, 'siteorigin_panels_admin_enqueue_styles' ) ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Enqueue Site Origin Page Builder scripts on nav-menus page. |
|
| 71 | - * |
|
| 72 | - * @since 2.3.7 |
|
| 73 | - * @param bool $enabled - Whether or not to load the Page Builder scripts |
|
| 74 | - */ |
|
| 75 | - public function enable_site_origin_page_builder( $enabled ) { |
|
| 76 | - $screen = get_current_screen(); |
|
| 77 | - |
|
| 78 | - if ( 'nav-menus' === $screen->base ) { |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return $enabled; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Enqueue Page Builder scripts (https://wordpress.org/plugins/siteorigin-panels/) |
|
| 87 | - * |
|
| 88 | - * @since 1.9 |
|
| 89 | - */ |
|
| 90 | - public function siteorigin_panels_admin_enqueue_scripts() { |
|
| 91 | - siteorigin_panels_admin_enqueue_scripts( '', true ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Enqueue Page Builder styles (https://wordpress.org/plugins/siteorigin-panels/) |
|
| 97 | - * |
|
| 98 | - * @since 1.9 |
|
| 99 | - */ |
|
| 100 | - public function siteorigin_panels_admin_enqueue_styles() { |
|
| 101 | - siteorigin_panels_admin_enqueue_styles( '', true ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * By default the mega menu meta box is hidden - show it. |
|
| 107 | - * |
|
| 108 | - * @since 1.0 |
|
| 109 | - * @param array $hidden Meta boxes that are hidden from the nav-menus.php page |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function show_mega_menu_metabox( $hidden ) { |
|
| 113 | - |
|
| 114 | - if ( is_array( $hidden ) && count( $hidden ) > 0 ) { |
|
| 115 | - foreach ( $hidden as $key => $value ) { |
|
| 116 | - if ( 'mega_menu_meta_box' === $value ) { |
|
| 117 | - unset( $hidden[ $key ] ); |
|
| 118 | - } |
|
| 119 | - if ( 'add-product_cat' === $value ) { |
|
| 120 | - unset( $hidden[ $key ] ); |
|
| 121 | - } |
|
| 122 | - if ( 'add-product_tag' === $value ) { |
|
| 123 | - unset( $hidden[ $key ] ); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return $hidden; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Adds the meta box container |
|
| 134 | - * |
|
| 135 | - * @since 1.0 |
|
| 136 | - */ |
|
| 137 | - public function register_nav_meta_box() { |
|
| 138 | - global $pagenow; |
|
| 139 | - |
|
| 140 | - $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 141 | - |
|
| 142 | - if ( ! current_user_can( $capability ) ) { |
|
| 143 | - return; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ( 'nav-menus.php' === $pagenow ) { |
|
| 147 | - add_meta_box( |
|
| 148 | - 'mega_menu_meta_box', |
|
| 149 | - __( 'Max Mega Menu Settings', 'megamenu' ), |
|
| 150 | - array( $this, 'metabox_contents' ), |
|
| 151 | - 'nav-menus', |
|
| 152 | - 'side', |
|
| 153 | - 'high' |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Enqueue required CSS and JS for the mega menu lightbox and meta options |
|
| 161 | - * |
|
| 162 | - * @since 1.0 |
|
| 163 | - */ |
|
| 164 | - public function enqueue_menu_page_scripts( $hook ) { |
|
| 165 | - if ( ! in_array( $hook, array( 'nav-menus.php' ) ) ) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 170 | - |
|
| 171 | - if ( ! current_user_can( $capability ) ) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // Compatibility fix for SlideDeck Pro |
|
| 176 | - wp_deregister_script( 'codemirror' ); |
|
| 177 | - wp_deregister_style( 'codemirror' ); |
|
| 178 | - |
|
| 179 | - // Compatibility fix for Pinboard Theme |
|
| 180 | - wp_deregister_script( 'colorbox' ); |
|
| 181 | - wp_deregister_style( 'colorbox' ); |
|
| 182 | - |
|
| 183 | - // Compatibility fix for AGP Font Awesome Collection |
|
| 184 | - wp_deregister_script( 'colorbox-js' ); |
|
| 185 | - wp_deregister_style( 'colorbox-css' ); |
|
| 186 | - |
|
| 187 | - // Compatibility fix for purple-xmls-google-product-feed-for-woocommerce |
|
| 188 | - wp_deregister_script( 'cart-product-colorbox' ); |
|
| 189 | - wp_deregister_style( 'cart-product-colorstyle' ); |
|
| 190 | - |
|
| 191 | - // Compatibility fix for WordFence |
|
| 192 | - wp_deregister_script( 'jquery.wfcolorbox' ); |
|
| 193 | - wp_deregister_style( 'wordfence-colorbox-style' ); |
|
| 194 | - |
|
| 195 | - // Compatibility fix for Profit Builder |
|
| 196 | - wp_deregister_script( 'color-box-min' ); |
|
| 197 | - wp_deregister_script( 'color-box' ); |
|
| 198 | - wp_deregister_style( 'color-box-css' ); |
|
| 199 | - |
|
| 200 | - // Compatibility fix for Reamaze |
|
| 201 | - wp_deregister_script( 'jquery-colorbox' ); |
|
| 202 | - wp_deregister_style( 'colorbox-css' ); |
|
| 203 | - |
|
| 204 | - // Compatibility fix for WP Disquz media uploader |
|
| 205 | - wp_deregister_script( 'wmu-colorbox-js' ); |
|
| 206 | - wp_deregister_style( 'wmu-colorbox-css' ); |
|
| 207 | - |
|
| 208 | - // Compatibility fix for TemplatesNext ToolKit |
|
| 209 | - wp_deregister_script( 'tx-main' ); |
|
| 210 | - wp_deregister_style( 'tx-toolkit-admin-style' ); |
|
| 211 | - |
|
| 212 | - wp_enqueue_style( 'colorbox', MEGAMENU_BASE_URL . 'js/colorbox/colorbox.css', false, MEGAMENU_VERSION ); |
|
| 213 | - wp_enqueue_style( 'maxmegamenu', MEGAMENU_BASE_URL . 'css/admin/admin.css', false, MEGAMENU_VERSION ); |
|
| 214 | - |
|
| 215 | - wp_enqueue_script( |
|
| 216 | - 'maxmegamenu', |
|
| 217 | - MEGAMENU_BASE_URL . 'js/admin.js', |
|
| 218 | - array( |
|
| 219 | - 'jquery', |
|
| 220 | - 'jquery-ui-core', |
|
| 221 | - 'jquery-ui-sortable', |
|
| 222 | - ), |
|
| 223 | - MEGAMENU_VERSION |
|
| 224 | - ); |
|
| 225 | - |
|
| 226 | - wp_enqueue_script( 'colorbox', MEGAMENU_BASE_URL . 'js/colorbox/jquery.colorbox-min.js', array( 'jquery' ), MEGAMENU_VERSION ); |
|
| 227 | - |
|
| 228 | - $settings = get_option( 'megamenu_settings' ); |
|
| 229 | - |
|
| 230 | - $prefix = isset( $settings['prefix'] ) ? $settings['prefix'] : 'true'; |
|
| 231 | - |
|
| 232 | - wp_localize_script( |
|
| 233 | - 'maxmegamenu', |
|
| 234 | - 'megamenu', |
|
| 235 | - array( |
|
| 236 | - 'debug_launched' => __( 'Launched for Menu ID', 'megamenu' ), |
|
| 237 | - 'launch_lightbox' => __( 'Mega Menu', 'megamenu' ), |
|
| 238 | - 'is_disabled_error' => __( 'Please enable Max Mega Menu using the settings on the left of this page.', 'megamenu' ), |
|
| 239 | - 'save_menu' => __( 'Please save the menu structure to enable this option.', 'megamenu' ), |
|
| 240 | - 'unsaved_changes' => __( 'The changes you made will be lost if you navigate away from this page.', 'megamenu'), |
|
| 241 | - 'saving' => __( 'Saving', 'megamenu' ), |
|
| 242 | - 'nonce' => wp_create_nonce( 'megamenu_edit' ), |
|
| 243 | - 'nonce_check_failed' => __( 'Oops. Something went wrong. Please reload the page.', 'megamenu' ), |
|
| 244 | - 'css_prefix' => $prefix, |
|
| 245 | - 'css_prefix_message' => __( "Custom CSS Classes will be prefixed with 'mega-'", 'megamenu' ), |
|
| 246 | - 'row_is_full' => __( 'There is not enough space in this row to add a new column. Make space by reducing the width of the columns within the row or create a new row.', 'megamenu' ), |
|
| 247 | - ) |
|
| 248 | - ); |
|
| 249 | - |
|
| 250 | - do_action( 'megamenu_enqueue_admin_scripts' ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Show the Meta Menu settings |
|
| 255 | - * |
|
| 256 | - * @since 1.0 |
|
| 257 | - */ |
|
| 258 | - public function metabox_contents() { |
|
| 259 | - $menu_id = $this->get_selected_menu_id(); |
|
| 260 | - $this->print_enable_megamenu_options( $menu_id ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Save the mega menu settings (submitted from Menus Page Meta Box) |
|
| 266 | - * |
|
| 267 | - * @since 1.0 |
|
| 268 | - */ |
|
| 269 | - public function save() { |
|
| 270 | - check_ajax_referer( 'megamenu_edit', 'nonce' ); |
|
| 271 | - |
|
| 272 | - $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 273 | - |
|
| 274 | - if ( ! current_user_can( $capability ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if ( isset( $_POST['menu'] ) && $_POST['menu'] > 0 && is_nav_menu( $_POST['menu'] ) && isset( $_POST['megamenu_meta'] ) ) { |
|
| 279 | - $raw_submitted_settings = $_POST['megamenu_meta']; |
|
| 280 | - $parsed_submitted_settings = json_decode( stripslashes( $raw_submitted_settings ), true ); |
|
| 281 | - $submitted_settings = array(); |
|
| 282 | - |
|
| 283 | - foreach ( $parsed_submitted_settings as $index => $value ) { |
|
| 284 | - $name = $value['name']; |
|
| 285 | - |
|
| 286 | - preg_match_all( '/\[(.*?)\]/', $name, $matches ); // find values between square brackets. |
|
| 287 | - |
|
| 288 | - if ( isset( $matches[1][0] ) && isset( $matches[1][1] ) ) { |
|
| 289 | - $location = $matches[1][0]; |
|
| 290 | - $setting = $matches[1][1]; |
|
| 291 | - $submitted_settings[ $location ][ $setting ] = $value['value']; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $submitted_settings = apply_filters( 'megamenu_submitted_settings_meta', $submitted_settings ); |
|
| 296 | - |
|
| 297 | - if ( ! get_option( 'megamenu_settings' ) ) { |
|
| 298 | - update_option( 'megamenu_settings', $submitted_settings ); |
|
| 299 | - } else { |
|
| 300 | - $existing_settings = get_option( 'megamenu_settings' ); |
|
| 301 | - |
|
| 302 | - foreach ( $submitted_settings as $location => $settings ) { |
|
| 303 | - if ( isset( $existing_settings[ $location ] ) ) { |
|
| 304 | - $existing_settings[ $location ] = array_merge( $existing_settings[ $location ], $settings ); |
|
| 305 | - |
|
| 306 | - if ( ! isset( $settings['enabled'] ) ) { |
|
| 307 | - unset( $existing_settings[ $location ]['enabled'] ); |
|
| 308 | - } |
|
| 309 | - } else { |
|
| 310 | - $existing_settings[ $location ] = $settings; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - update_option( 'megamenu_settings', $existing_settings ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - do_action( 'megamenu_after_save_settings' ); |
|
| 318 | - do_action( 'megamenu_delete_cache' ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - wp_die(); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Print the custom Meta Box settings |
|
| 327 | - * |
|
| 328 | - * @param int $menu_id |
|
| 329 | - * @since 1.0 |
|
| 330 | - */ |
|
| 331 | - public function print_enable_megamenu_options( $menu_id ) { |
|
| 332 | - $tagged_menu_locations = $this->get_tagged_theme_locations_for_menu_id( $menu_id ); |
|
| 333 | - $theme_locations = get_registered_nav_menus(); |
|
| 334 | - $saved_settings = get_option( 'megamenu_settings' ); |
|
| 335 | - |
|
| 336 | - if ( ! count( $theme_locations ) ) { |
|
| 337 | - echo "<div style='padding: 15px;'>"; |
|
| 338 | - $link = '<a href="https://www.megamenu.com/documentation/widget/?utm_source=free&utm_medium=link&utm_campaign=pro" target="_blank">' . __( 'here', 'megamenu' ) . '</a>'; |
|
| 339 | - echo '<p>' . esc_html__( 'This theme does not register any menu locations.', 'megamenu' ) . '</p>'; |
|
| 340 | - echo '<p>' . esc_html__( 'You will need to create a new menu location and use the Max Mega Menu widget or shortcode to display the menu on your site.', 'megamenu' ) . '</p>'; |
|
| 341 | - echo '<p>' . str_replace( '{link}', $link, esc_html__( 'Click {link} for instructions.', 'megamenu' ) ) . '</p>'; |
|
| 342 | - echo "</div>"; |
|
| 343 | - } elseif ( ! count( $tagged_menu_locations ) ) { |
|
| 344 | - echo "<div style='padding: 15px;'>"; |
|
| 345 | - echo '<p>' . esc_html__( 'Please assign this menu to a theme location to enable the Mega Menu settings.', 'megamenu' ) . '</p>'; |
|
| 346 | - echo '<p>' . esc_html__( "To assign this menu to a theme location, scroll to the bottom of this page and tag the menu to a 'Display location'.", 'megamenu' ) . '</p>'; |
|
| 347 | - echo "</div>"; |
|
| 348 | - |
|
| 349 | - } else { ?> |
|
| 8 | + /** |
|
| 9 | + * Handles all admin related functionality. |
|
| 10 | + */ |
|
| 11 | + class Mega_Menu_Nav_Menus { |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * Return the default settings for each menu item |
|
| 15 | + * |
|
| 16 | + * @since 1.5 |
|
| 17 | + */ |
|
| 18 | + public static function get_menu_item_defaults() { |
|
| 19 | + |
|
| 20 | + $defaults = array( |
|
| 21 | + 'type' => 'flyout', |
|
| 22 | + 'align' => 'bottom-left', |
|
| 23 | + 'icon' => 'disabled', |
|
| 24 | + 'hide_text' => 'false', |
|
| 25 | + 'disable_link' => 'false', |
|
| 26 | + 'hide_on_mobile' => 'false', |
|
| 27 | + 'hide_on_desktop' => 'false', |
|
| 28 | + 'close_after_click' => 'false', |
|
| 29 | + 'hide_sub_menu_on_mobile' => 'false', |
|
| 30 | + 'hide_arrow' => 'false', |
|
| 31 | + 'item_align' => 'left', |
|
| 32 | + 'icon_position' => 'left', |
|
| 33 | + 'panel_columns' => 6, // total number of columns displayed in the panel. |
|
| 34 | + 'mega_menu_columns' => 1, // for sub menu items, how many columns to span in the panel. |
|
| 35 | + 'mega_menu_order' => 0, |
|
| 36 | + 'collapse_children' => 'false', |
|
| 37 | + 'submenu_columns' => 1, |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + return apply_filters( 'megamenu_menu_item_defaults', $defaults ); |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Constructor |
|
| 47 | + * |
|
| 48 | + * @since 1.0 |
|
| 49 | + */ |
|
| 50 | + public function __construct() { |
|
| 51 | + add_action( 'admin_init', array( $this, 'register_nav_meta_box' ), 9 ); |
|
| 52 | + add_action( 'megamenu_nav_menus_scripts', array( $this, 'enqueue_menu_page_scripts' ), 10 ); |
|
| 53 | + add_action( 'wp_ajax_mm_save_settings', array( $this, 'save' ) ); |
|
| 54 | + add_filter( 'hidden_meta_boxes', array( $this, 'show_mega_menu_metabox' ) ); |
|
| 55 | + |
|
| 56 | + add_filter( 'siteorigin_panels_is_admin_page', array( $this, 'enable_site_origin_page_builder' ) ); |
|
| 57 | + |
|
| 58 | + if ( function_exists( 'siteorigin_panels_admin_enqueue_scripts' ) ) { |
|
| 59 | + add_action( 'admin_print_scripts-nav-menus.php', array( $this, 'siteorigin_panels_admin_enqueue_scripts' ) ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if ( function_exists( 'siteorigin_panels_admin_enqueue_styles' ) ) { |
|
| 63 | + add_action( 'admin_print_styles-nav-menus.php', array( $this, 'siteorigin_panels_admin_enqueue_styles' ) ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Enqueue Site Origin Page Builder scripts on nav-menus page. |
|
| 71 | + * |
|
| 72 | + * @since 2.3.7 |
|
| 73 | + * @param bool $enabled - Whether or not to load the Page Builder scripts |
|
| 74 | + */ |
|
| 75 | + public function enable_site_origin_page_builder( $enabled ) { |
|
| 76 | + $screen = get_current_screen(); |
|
| 77 | + |
|
| 78 | + if ( 'nav-menus' === $screen->base ) { |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return $enabled; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Enqueue Page Builder scripts (https://wordpress.org/plugins/siteorigin-panels/) |
|
| 87 | + * |
|
| 88 | + * @since 1.9 |
|
| 89 | + */ |
|
| 90 | + public function siteorigin_panels_admin_enqueue_scripts() { |
|
| 91 | + siteorigin_panels_admin_enqueue_scripts( '', true ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Enqueue Page Builder styles (https://wordpress.org/plugins/siteorigin-panels/) |
|
| 97 | + * |
|
| 98 | + * @since 1.9 |
|
| 99 | + */ |
|
| 100 | + public function siteorigin_panels_admin_enqueue_styles() { |
|
| 101 | + siteorigin_panels_admin_enqueue_styles( '', true ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * By default the mega menu meta box is hidden - show it. |
|
| 107 | + * |
|
| 108 | + * @since 1.0 |
|
| 109 | + * @param array $hidden Meta boxes that are hidden from the nav-menus.php page |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function show_mega_menu_metabox( $hidden ) { |
|
| 113 | + |
|
| 114 | + if ( is_array( $hidden ) && count( $hidden ) > 0 ) { |
|
| 115 | + foreach ( $hidden as $key => $value ) { |
|
| 116 | + if ( 'mega_menu_meta_box' === $value ) { |
|
| 117 | + unset( $hidden[ $key ] ); |
|
| 118 | + } |
|
| 119 | + if ( 'add-product_cat' === $value ) { |
|
| 120 | + unset( $hidden[ $key ] ); |
|
| 121 | + } |
|
| 122 | + if ( 'add-product_tag' === $value ) { |
|
| 123 | + unset( $hidden[ $key ] ); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return $hidden; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Adds the meta box container |
|
| 134 | + * |
|
| 135 | + * @since 1.0 |
|
| 136 | + */ |
|
| 137 | + public function register_nav_meta_box() { |
|
| 138 | + global $pagenow; |
|
| 139 | + |
|
| 140 | + $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 141 | + |
|
| 142 | + if ( ! current_user_can( $capability ) ) { |
|
| 143 | + return; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ( 'nav-menus.php' === $pagenow ) { |
|
| 147 | + add_meta_box( |
|
| 148 | + 'mega_menu_meta_box', |
|
| 149 | + __( 'Max Mega Menu Settings', 'megamenu' ), |
|
| 150 | + array( $this, 'metabox_contents' ), |
|
| 151 | + 'nav-menus', |
|
| 152 | + 'side', |
|
| 153 | + 'high' |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Enqueue required CSS and JS for the mega menu lightbox and meta options |
|
| 161 | + * |
|
| 162 | + * @since 1.0 |
|
| 163 | + */ |
|
| 164 | + public function enqueue_menu_page_scripts( $hook ) { |
|
| 165 | + if ( ! in_array( $hook, array( 'nav-menus.php' ) ) ) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 170 | + |
|
| 171 | + if ( ! current_user_can( $capability ) ) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // Compatibility fix for SlideDeck Pro |
|
| 176 | + wp_deregister_script( 'codemirror' ); |
|
| 177 | + wp_deregister_style( 'codemirror' ); |
|
| 178 | + |
|
| 179 | + // Compatibility fix for Pinboard Theme |
|
| 180 | + wp_deregister_script( 'colorbox' ); |
|
| 181 | + wp_deregister_style( 'colorbox' ); |
|
| 182 | + |
|
| 183 | + // Compatibility fix for AGP Font Awesome Collection |
|
| 184 | + wp_deregister_script( 'colorbox-js' ); |
|
| 185 | + wp_deregister_style( 'colorbox-css' ); |
|
| 186 | + |
|
| 187 | + // Compatibility fix for purple-xmls-google-product-feed-for-woocommerce |
|
| 188 | + wp_deregister_script( 'cart-product-colorbox' ); |
|
| 189 | + wp_deregister_style( 'cart-product-colorstyle' ); |
|
| 190 | + |
|
| 191 | + // Compatibility fix for WordFence |
|
| 192 | + wp_deregister_script( 'jquery.wfcolorbox' ); |
|
| 193 | + wp_deregister_style( 'wordfence-colorbox-style' ); |
|
| 194 | + |
|
| 195 | + // Compatibility fix for Profit Builder |
|
| 196 | + wp_deregister_script( 'color-box-min' ); |
|
| 197 | + wp_deregister_script( 'color-box' ); |
|
| 198 | + wp_deregister_style( 'color-box-css' ); |
|
| 199 | + |
|
| 200 | + // Compatibility fix for Reamaze |
|
| 201 | + wp_deregister_script( 'jquery-colorbox' ); |
|
| 202 | + wp_deregister_style( 'colorbox-css' ); |
|
| 203 | + |
|
| 204 | + // Compatibility fix for WP Disquz media uploader |
|
| 205 | + wp_deregister_script( 'wmu-colorbox-js' ); |
|
| 206 | + wp_deregister_style( 'wmu-colorbox-css' ); |
|
| 207 | + |
|
| 208 | + // Compatibility fix for TemplatesNext ToolKit |
|
| 209 | + wp_deregister_script( 'tx-main' ); |
|
| 210 | + wp_deregister_style( 'tx-toolkit-admin-style' ); |
|
| 211 | + |
|
| 212 | + wp_enqueue_style( 'colorbox', MEGAMENU_BASE_URL . 'js/colorbox/colorbox.css', false, MEGAMENU_VERSION ); |
|
| 213 | + wp_enqueue_style( 'maxmegamenu', MEGAMENU_BASE_URL . 'css/admin/admin.css', false, MEGAMENU_VERSION ); |
|
| 214 | + |
|
| 215 | + wp_enqueue_script( |
|
| 216 | + 'maxmegamenu', |
|
| 217 | + MEGAMENU_BASE_URL . 'js/admin.js', |
|
| 218 | + array( |
|
| 219 | + 'jquery', |
|
| 220 | + 'jquery-ui-core', |
|
| 221 | + 'jquery-ui-sortable', |
|
| 222 | + ), |
|
| 223 | + MEGAMENU_VERSION |
|
| 224 | + ); |
|
| 225 | + |
|
| 226 | + wp_enqueue_script( 'colorbox', MEGAMENU_BASE_URL . 'js/colorbox/jquery.colorbox-min.js', array( 'jquery' ), MEGAMENU_VERSION ); |
|
| 227 | + |
|
| 228 | + $settings = get_option( 'megamenu_settings' ); |
|
| 229 | + |
|
| 230 | + $prefix = isset( $settings['prefix'] ) ? $settings['prefix'] : 'true'; |
|
| 231 | + |
|
| 232 | + wp_localize_script( |
|
| 233 | + 'maxmegamenu', |
|
| 234 | + 'megamenu', |
|
| 235 | + array( |
|
| 236 | + 'debug_launched' => __( 'Launched for Menu ID', 'megamenu' ), |
|
| 237 | + 'launch_lightbox' => __( 'Mega Menu', 'megamenu' ), |
|
| 238 | + 'is_disabled_error' => __( 'Please enable Max Mega Menu using the settings on the left of this page.', 'megamenu' ), |
|
| 239 | + 'save_menu' => __( 'Please save the menu structure to enable this option.', 'megamenu' ), |
|
| 240 | + 'unsaved_changes' => __( 'The changes you made will be lost if you navigate away from this page.', 'megamenu'), |
|
| 241 | + 'saving' => __( 'Saving', 'megamenu' ), |
|
| 242 | + 'nonce' => wp_create_nonce( 'megamenu_edit' ), |
|
| 243 | + 'nonce_check_failed' => __( 'Oops. Something went wrong. Please reload the page.', 'megamenu' ), |
|
| 244 | + 'css_prefix' => $prefix, |
|
| 245 | + 'css_prefix_message' => __( "Custom CSS Classes will be prefixed with 'mega-'", 'megamenu' ), |
|
| 246 | + 'row_is_full' => __( 'There is not enough space in this row to add a new column. Make space by reducing the width of the columns within the row or create a new row.', 'megamenu' ), |
|
| 247 | + ) |
|
| 248 | + ); |
|
| 249 | + |
|
| 250 | + do_action( 'megamenu_enqueue_admin_scripts' ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Show the Meta Menu settings |
|
| 255 | + * |
|
| 256 | + * @since 1.0 |
|
| 257 | + */ |
|
| 258 | + public function metabox_contents() { |
|
| 259 | + $menu_id = $this->get_selected_menu_id(); |
|
| 260 | + $this->print_enable_megamenu_options( $menu_id ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Save the mega menu settings (submitted from Menus Page Meta Box) |
|
| 266 | + * |
|
| 267 | + * @since 1.0 |
|
| 268 | + */ |
|
| 269 | + public function save() { |
|
| 270 | + check_ajax_referer( 'megamenu_edit', 'nonce' ); |
|
| 271 | + |
|
| 272 | + $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 273 | + |
|
| 274 | + if ( ! current_user_can( $capability ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if ( isset( $_POST['menu'] ) && $_POST['menu'] > 0 && is_nav_menu( $_POST['menu'] ) && isset( $_POST['megamenu_meta'] ) ) { |
|
| 279 | + $raw_submitted_settings = $_POST['megamenu_meta']; |
|
| 280 | + $parsed_submitted_settings = json_decode( stripslashes( $raw_submitted_settings ), true ); |
|
| 281 | + $submitted_settings = array(); |
|
| 282 | + |
|
| 283 | + foreach ( $parsed_submitted_settings as $index => $value ) { |
|
| 284 | + $name = $value['name']; |
|
| 285 | + |
|
| 286 | + preg_match_all( '/\[(.*?)\]/', $name, $matches ); // find values between square brackets. |
|
| 287 | + |
|
| 288 | + if ( isset( $matches[1][0] ) && isset( $matches[1][1] ) ) { |
|
| 289 | + $location = $matches[1][0]; |
|
| 290 | + $setting = $matches[1][1]; |
|
| 291 | + $submitted_settings[ $location ][ $setting ] = $value['value']; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $submitted_settings = apply_filters( 'megamenu_submitted_settings_meta', $submitted_settings ); |
|
| 296 | + |
|
| 297 | + if ( ! get_option( 'megamenu_settings' ) ) { |
|
| 298 | + update_option( 'megamenu_settings', $submitted_settings ); |
|
| 299 | + } else { |
|
| 300 | + $existing_settings = get_option( 'megamenu_settings' ); |
|
| 301 | + |
|
| 302 | + foreach ( $submitted_settings as $location => $settings ) { |
|
| 303 | + if ( isset( $existing_settings[ $location ] ) ) { |
|
| 304 | + $existing_settings[ $location ] = array_merge( $existing_settings[ $location ], $settings ); |
|
| 305 | + |
|
| 306 | + if ( ! isset( $settings['enabled'] ) ) { |
|
| 307 | + unset( $existing_settings[ $location ]['enabled'] ); |
|
| 308 | + } |
|
| 309 | + } else { |
|
| 310 | + $existing_settings[ $location ] = $settings; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + update_option( 'megamenu_settings', $existing_settings ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + do_action( 'megamenu_after_save_settings' ); |
|
| 318 | + do_action( 'megamenu_delete_cache' ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + wp_die(); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Print the custom Meta Box settings |
|
| 327 | + * |
|
| 328 | + * @param int $menu_id |
|
| 329 | + * @since 1.0 |
|
| 330 | + */ |
|
| 331 | + public function print_enable_megamenu_options( $menu_id ) { |
|
| 332 | + $tagged_menu_locations = $this->get_tagged_theme_locations_for_menu_id( $menu_id ); |
|
| 333 | + $theme_locations = get_registered_nav_menus(); |
|
| 334 | + $saved_settings = get_option( 'megamenu_settings' ); |
|
| 335 | + |
|
| 336 | + if ( ! count( $theme_locations ) ) { |
|
| 337 | + echo "<div style='padding: 15px;'>"; |
|
| 338 | + $link = '<a href="https://www.megamenu.com/documentation/widget/?utm_source=free&utm_medium=link&utm_campaign=pro" target="_blank">' . __( 'here', 'megamenu' ) . '</a>'; |
|
| 339 | + echo '<p>' . esc_html__( 'This theme does not register any menu locations.', 'megamenu' ) . '</p>'; |
|
| 340 | + echo '<p>' . esc_html__( 'You will need to create a new menu location and use the Max Mega Menu widget or shortcode to display the menu on your site.', 'megamenu' ) . '</p>'; |
|
| 341 | + echo '<p>' . str_replace( '{link}', $link, esc_html__( 'Click {link} for instructions.', 'megamenu' ) ) . '</p>'; |
|
| 342 | + echo "</div>"; |
|
| 343 | + } elseif ( ! count( $tagged_menu_locations ) ) { |
|
| 344 | + echo "<div style='padding: 15px;'>"; |
|
| 345 | + echo '<p>' . esc_html__( 'Please assign this menu to a theme location to enable the Mega Menu settings.', 'megamenu' ) . '</p>'; |
|
| 346 | + echo '<p>' . esc_html__( "To assign this menu to a theme location, scroll to the bottom of this page and tag the menu to a 'Display location'.", 'megamenu' ) . '</p>'; |
|
| 347 | + echo "</div>"; |
|
| 348 | + |
|
| 349 | + } else { ?> |
|
| 350 | 350 | <div class='mega-accordion'> |
| 351 | 351 | <?php |
| 352 | - $i = 0; |
|
| 353 | - foreach ( $theme_locations as $location => $name ) { |
|
| 354 | - if ( isset( $tagged_menu_locations[ $location ] ) ) { |
|
| 355 | - $open_class = count( $tagged_menu_locations ) === 1 ? ' mega-accordion-open' : ''; |
|
| 356 | - $last_class = $i + 1 == count( $tagged_menu_locations ) ? ' mega-last' : ''; |
|
| 357 | - $edit_url = admin_url( "admin.php?page=maxmegamenu&location={$location}" ); |
|
| 358 | - $i++; |
|
| 359 | - |
|
| 360 | - $is_enabled_class = ''; |
|
| 361 | - if ( max_mega_menu_is_enabled( $location ) ) { |
|
| 362 | - $is_enabled_class = ' mega-location-enabled'; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - $has_active_location_class = ''; |
|
| 366 | - $active_instance = 0; |
|
| 367 | - |
|
| 368 | - if ( isset( $saved_settings[ $location ]['active_instance'] ) ) { |
|
| 369 | - $active_instance = $saved_settings[ $location ]['active_instance']; |
|
| 370 | - } elseif ( isset( $saved_settings['instances'][ $location ] ) ) { |
|
| 371 | - $active_instance = $saved_settings['instances'][ $location ]; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( $active_instance > 0 ) { |
|
| 375 | - $has_active_location_class = ' mega-has-active-location'; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - ?> |
|
| 352 | + $i = 0; |
|
| 353 | + foreach ( $theme_locations as $location => $name ) { |
|
| 354 | + if ( isset( $tagged_menu_locations[ $location ] ) ) { |
|
| 355 | + $open_class = count( $tagged_menu_locations ) === 1 ? ' mega-accordion-open' : ''; |
|
| 356 | + $last_class = $i + 1 == count( $tagged_menu_locations ) ? ' mega-last' : ''; |
|
| 357 | + $edit_url = admin_url( "admin.php?page=maxmegamenu&location={$location}" ); |
|
| 358 | + $i++; |
|
| 359 | + |
|
| 360 | + $is_enabled_class = ''; |
|
| 361 | + if ( max_mega_menu_is_enabled( $location ) ) { |
|
| 362 | + $is_enabled_class = ' mega-location-enabled'; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + $has_active_location_class = ''; |
|
| 366 | + $active_instance = 0; |
|
| 367 | + |
|
| 368 | + if ( isset( $saved_settings[ $location ]['active_instance'] ) ) { |
|
| 369 | + $active_instance = $saved_settings[ $location ]['active_instance']; |
|
| 370 | + } elseif ( isset( $saved_settings['instances'][ $location ] ) ) { |
|
| 371 | + $active_instance = $saved_settings['instances'][ $location ]; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( $active_instance > 0 ) { |
|
| 375 | + $has_active_location_class = ' mega-has-active-location'; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + ?> |
|
| 379 | 379 | <div class='mega-accordion-title<?php echo esc_attr( $open_class ); ?><?php echo esc_attr( $last_class ); ?><?php echo esc_attr( $is_enabled_class ); ?><?php echo esc_attr( $has_active_location_class ); ?>'> |
| 380 | 380 | <h4><span class='dashicons dashicons-location'></span><?php esc_html_e( $name ); ?></h4> |
| 381 | 381 | <span class='mega-tooltip'> |
@@ -397,22 +397,22 @@ discard block |
||
| 397 | 397 | </div> |
| 398 | 398 | |
| 399 | 399 | <?php |
| 400 | - } |
|
| 401 | - } |
|
| 402 | - ?> |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + ?> |
|
| 403 | 403 | </div> |
| 404 | 404 | |
| 405 | 405 | <?php |
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Print the list of Mega Menu settings |
|
| 411 | - * |
|
| 412 | - * @since 1.0 |
|
| 413 | - */ |
|
| 414 | - public function settings_table( $location, $settings ) { |
|
| 415 | - ?> |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Print the list of Mega Menu settings |
|
| 411 | + * |
|
| 412 | + * @since 1.0 |
|
| 413 | + */ |
|
| 414 | + public function settings_table( $location, $settings ) { |
|
| 415 | + ?> |
|
| 416 | 416 | <table> |
| 417 | 417 | <tr> |
| 418 | 418 | <td><?php esc_html_e( 'Enable', 'megamenu' ); ?></td> |
@@ -436,68 +436,68 @@ discard block |
||
| 436 | 436 | <select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][effect]'> |
| 437 | 437 | <?php |
| 438 | 438 | |
| 439 | - $selected = isset( $settings[ $location ]['effect'] ) ? $settings[ $location ]['effect'] : 'fade_up'; |
|
| 440 | - |
|
| 441 | - $options = apply_filters( |
|
| 442 | - 'megamenu_transition_effects', |
|
| 443 | - array( |
|
| 444 | - 'disabled' => array( |
|
| 445 | - 'label' => __( 'None', 'megamenu' ), |
|
| 446 | - 'selected' => $selected === 'disabled', |
|
| 447 | - ), |
|
| 448 | - 'fade' => array( |
|
| 449 | - 'label' => __( 'Fade', 'megamenu' ), |
|
| 450 | - 'selected' => $selected === 'fade', |
|
| 451 | - ), |
|
| 452 | - 'fade_up' => array( |
|
| 453 | - 'label' => __( 'Fade Up', 'megamenu' ), |
|
| 454 | - 'selected' => $selected === 'fade_up' || $selected === 'fadeUp', |
|
| 455 | - ), |
|
| 456 | - 'slide' => array( |
|
| 457 | - 'label' => __( 'Slide', 'megamenu' ), |
|
| 458 | - 'selected' => $selected === 'slide', |
|
| 459 | - ), |
|
| 460 | - 'slide_up' => array( |
|
| 461 | - 'label' => __( 'Slide Up', 'megamenu' ), |
|
| 462 | - 'selected' => $selected === 'slide_up', |
|
| 463 | - ), |
|
| 464 | - ), |
|
| 465 | - $selected |
|
| 466 | - ); |
|
| 467 | - |
|
| 468 | - foreach ( $options as $key => $value ) { |
|
| 469 | - ?> |
|
| 439 | + $selected = isset( $settings[ $location ]['effect'] ) ? $settings[ $location ]['effect'] : 'fade_up'; |
|
| 440 | + |
|
| 441 | + $options = apply_filters( |
|
| 442 | + 'megamenu_transition_effects', |
|
| 443 | + array( |
|
| 444 | + 'disabled' => array( |
|
| 445 | + 'label' => __( 'None', 'megamenu' ), |
|
| 446 | + 'selected' => $selected === 'disabled', |
|
| 447 | + ), |
|
| 448 | + 'fade' => array( |
|
| 449 | + 'label' => __( 'Fade', 'megamenu' ), |
|
| 450 | + 'selected' => $selected === 'fade', |
|
| 451 | + ), |
|
| 452 | + 'fade_up' => array( |
|
| 453 | + 'label' => __( 'Fade Up', 'megamenu' ), |
|
| 454 | + 'selected' => $selected === 'fade_up' || $selected === 'fadeUp', |
|
| 455 | + ), |
|
| 456 | + 'slide' => array( |
|
| 457 | + 'label' => __( 'Slide', 'megamenu' ), |
|
| 458 | + 'selected' => $selected === 'slide', |
|
| 459 | + ), |
|
| 460 | + 'slide_up' => array( |
|
| 461 | + 'label' => __( 'Slide Up', 'megamenu' ), |
|
| 462 | + 'selected' => $selected === 'slide_up', |
|
| 463 | + ), |
|
| 464 | + ), |
|
| 465 | + $selected |
|
| 466 | + ); |
|
| 467 | + |
|
| 468 | + foreach ( $options as $key => $value ) { |
|
| 469 | + ?> |
|
| 470 | 470 | <option value='<?php echo esc_attr( $key ); ?>' <?php selected( $value['selected'] ); ?>><?php echo esc_html( $value['label'] ); ?></option> |
| 471 | 471 | <?php |
| 472 | - } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | - ?> |
|
| 474 | + ?> |
|
| 475 | 475 | </select> |
| 476 | 476 | |
| 477 | 477 | <select name='megamenu_meta[<?php echo esc_attr( $location ); ?>][effect_speed]'> |
| 478 | 478 | <?php |
| 479 | 479 | |
| 480 | - $selected = isset( $settings[ $location ]['effect_speed'] ) ? $settings[ $location ]['effect_speed'] : '200'; |
|
| 480 | + $selected = isset( $settings[ $location ]['effect_speed'] ) ? $settings[ $location ]['effect_speed'] : '200'; |
|
| 481 | 481 | |
| 482 | - $options = apply_filters( |
|
| 483 | - 'megamenu_effect_speed', |
|
| 484 | - array( |
|
| 485 | - '600' => __( 'Slow', 'megamenu' ), |
|
| 486 | - '400' => __( 'Med', 'megamenu' ), |
|
| 487 | - '200' => __( 'Fast', 'megamenu' ), |
|
| 488 | - ), |
|
| 489 | - $selected |
|
| 490 | - ); |
|
| 482 | + $options = apply_filters( |
|
| 483 | + 'megamenu_effect_speed', |
|
| 484 | + array( |
|
| 485 | + '600' => __( 'Slow', 'megamenu' ), |
|
| 486 | + '400' => __( 'Med', 'megamenu' ), |
|
| 487 | + '200' => __( 'Fast', 'megamenu' ), |
|
| 488 | + ), |
|
| 489 | + $selected |
|
| 490 | + ); |
|
| 491 | 491 | |
| 492 | - ksort( $options ); |
|
| 492 | + ksort( $options ); |
|
| 493 | 493 | |
| 494 | - foreach ( $options as $key => $value ) { |
|
| 495 | - ?> |
|
| 494 | + foreach ( $options as $key => $value ) { |
|
| 495 | + ?> |
|
| 496 | 496 | <option value='<?php echo esc_attr( $key ); ?>' <?php selected( $key === $selected ); ?>><?php echo esc_html( $value ); ?></option> |
| 497 | 497 | <?php |
| 498 | - } |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | - ?> |
|
| 500 | + ?> |
|
| 501 | 501 | </select> |
| 502 | 502 | </td> |
| 503 | 503 | </tr> |
@@ -507,64 +507,64 @@ discard block |
||
| 507 | 507 | <select class='megamenu_effect_mobile' name='megamenu_meta[<?php echo $location; ?>][effect_mobile]'> |
| 508 | 508 | <?php |
| 509 | 509 | |
| 510 | - $selected = isset( $settings[ $location ]['effect_mobile'] ) ? $settings[ $location ]['effect_mobile'] : 'disabled'; |
|
| 511 | - |
|
| 512 | - $options = apply_filters( |
|
| 513 | - 'megamenu_transition_effects_mobile', |
|
| 514 | - array( |
|
| 515 | - 'disabled' => array( |
|
| 516 | - 'label' => __( 'None', 'megamenu' ), |
|
| 517 | - 'selected' => $selected == 'disabled', |
|
| 518 | - ), |
|
| 519 | - 'slide' => array( |
|
| 520 | - 'label' => __( 'Slide Down', 'megamenu' ), |
|
| 521 | - 'selected' => $selected == 'slide', |
|
| 522 | - ), |
|
| 523 | - 'slide_left' => array( |
|
| 524 | - 'label' => __( 'Slide Left (Off Canvas)', 'megamenu' ), |
|
| 525 | - 'selected' => $selected == 'slide_left', |
|
| 526 | - ), |
|
| 527 | - 'slide_right' => array( |
|
| 528 | - 'label' => __( 'Slide Right (Off Canvas)', 'megamenu' ), |
|
| 529 | - 'selected' => $selected == 'slide_right', |
|
| 530 | - ), |
|
| 531 | - ), |
|
| 532 | - $selected |
|
| 533 | - ); |
|
| 534 | - |
|
| 535 | - foreach ( $options as $key => $value ) { |
|
| 536 | - ?> |
|
| 510 | + $selected = isset( $settings[ $location ]['effect_mobile'] ) ? $settings[ $location ]['effect_mobile'] : 'disabled'; |
|
| 511 | + |
|
| 512 | + $options = apply_filters( |
|
| 513 | + 'megamenu_transition_effects_mobile', |
|
| 514 | + array( |
|
| 515 | + 'disabled' => array( |
|
| 516 | + 'label' => __( 'None', 'megamenu' ), |
|
| 517 | + 'selected' => $selected == 'disabled', |
|
| 518 | + ), |
|
| 519 | + 'slide' => array( |
|
| 520 | + 'label' => __( 'Slide Down', 'megamenu' ), |
|
| 521 | + 'selected' => $selected == 'slide', |
|
| 522 | + ), |
|
| 523 | + 'slide_left' => array( |
|
| 524 | + 'label' => __( 'Slide Left (Off Canvas)', 'megamenu' ), |
|
| 525 | + 'selected' => $selected == 'slide_left', |
|
| 526 | + ), |
|
| 527 | + 'slide_right' => array( |
|
| 528 | + 'label' => __( 'Slide Right (Off Canvas)', 'megamenu' ), |
|
| 529 | + 'selected' => $selected == 'slide_right', |
|
| 530 | + ), |
|
| 531 | + ), |
|
| 532 | + $selected |
|
| 533 | + ); |
|
| 534 | + |
|
| 535 | + foreach ( $options as $key => $value ) { |
|
| 536 | + ?> |
|
| 537 | 537 | <option value='<?php echo $key; ?>' <?php selected( $value['selected'] ); ?>><?php echo $value['label']; ?></option> |
| 538 | 538 | <?php |
| 539 | - } |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - ?> |
|
| 541 | + ?> |
|
| 542 | 542 | </select> |
| 543 | 543 | |
| 544 | 544 | <select name='megamenu_meta[<?php echo $location; ?>][effect_speed_mobile]'> |
| 545 | 545 | <?php |
| 546 | 546 | |
| 547 | - $selected = isset( $settings[ $location ]['effect_speed_mobile'] ) ? $settings[ $location ]['effect_speed_mobile'] : '200'; |
|
| 547 | + $selected = isset( $settings[ $location ]['effect_speed_mobile'] ) ? $settings[ $location ]['effect_speed_mobile'] : '200'; |
|
| 548 | 548 | |
| 549 | - $options = apply_filters( |
|
| 550 | - 'megamenu_effect_speed_mobile', |
|
| 551 | - array( |
|
| 552 | - '600' => __( 'Slow', 'megamenu' ), |
|
| 553 | - '400' => __( 'Med', 'megamenu' ), |
|
| 554 | - '200' => __( 'Fast', 'megamenu' ), |
|
| 555 | - ), |
|
| 556 | - $selected |
|
| 557 | - ); |
|
| 549 | + $options = apply_filters( |
|
| 550 | + 'megamenu_effect_speed_mobile', |
|
| 551 | + array( |
|
| 552 | + '600' => __( 'Slow', 'megamenu' ), |
|
| 553 | + '400' => __( 'Med', 'megamenu' ), |
|
| 554 | + '200' => __( 'Fast', 'megamenu' ), |
|
| 555 | + ), |
|
| 556 | + $selected |
|
| 557 | + ); |
|
| 558 | 558 | |
| 559 | - ksort( $options ); |
|
| 559 | + ksort( $options ); |
|
| 560 | 560 | |
| 561 | - foreach ( $options as $key => $value ) { |
|
| 562 | - ?> |
|
| 561 | + foreach ( $options as $key => $value ) { |
|
| 562 | + ?> |
|
| 563 | 563 | <option value='<?php echo $key; ?>' <?php selected( $key == $selected ); ?>><?php echo $value; ?></option> |
| 564 | 564 | <?php |
| 565 | - } |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - ?> |
|
| 567 | + ?> |
|
| 568 | 568 | </select> |
| 569 | 569 | </td> |
| 570 | 570 | </tr> |
@@ -574,14 +574,14 @@ discard block |
||
| 574 | 574 | |
| 575 | 575 | <select name='megamenu_meta[<?php echo $location; ?>][theme]'> |
| 576 | 576 | <?php |
| 577 | - $style_manager = new Mega_Menu_Style_Manager(); |
|
| 578 | - $themes = $style_manager->get_themes(); |
|
| 579 | - $selected_theme = isset( $settings[ $location ]['theme'] ) ? $settings[ $location ]['theme'] : 'default'; |
|
| 580 | - |
|
| 581 | - foreach ( $themes as $key => $theme ) { |
|
| 582 | - echo "<option value='" . esc_attr( $key ) . "' " . selected( $selected_theme, $key ) . '>' . esc_html( $theme['title'] ) . '</option>'; |
|
| 583 | - } |
|
| 584 | - ?> |
|
| 577 | + $style_manager = new Mega_Menu_Style_Manager(); |
|
| 578 | + $themes = $style_manager->get_themes(); |
|
| 579 | + $selected_theme = isset( $settings[ $location ]['theme'] ) ? $settings[ $location ]['theme'] : 'default'; |
|
| 580 | + |
|
| 581 | + foreach ( $themes as $key => $theme ) { |
|
| 582 | + echo "<option value='" . esc_attr( $key ) . "' " . selected( $selected_theme, $key ) . '>' . esc_html( $theme['title'] ) . '</option>'; |
|
| 583 | + } |
|
| 584 | + ?> |
|
| 585 | 585 | </select> |
| 586 | 586 | </td> |
| 587 | 587 | </tr> |
@@ -589,80 +589,80 @@ discard block |
||
| 589 | 589 | <?php do_action( 'megamenu_settings_table', $location, $settings ); ?> |
| 590 | 590 | </table> |
| 591 | 591 | <?php |
| 592 | - } |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | 594 | |
| 595 | - /** |
|
| 596 | - * Return the locations that a specific menu ID has been tagged to. |
|
| 597 | - * |
|
| 598 | - * @param $menu_id int |
|
| 599 | - * @return array |
|
| 600 | - */ |
|
| 601 | - public function get_tagged_theme_locations_for_menu_id( $menu_id ) { |
|
| 595 | + /** |
|
| 596 | + * Return the locations that a specific menu ID has been tagged to. |
|
| 597 | + * |
|
| 598 | + * @param $menu_id int |
|
| 599 | + * @return array |
|
| 600 | + */ |
|
| 601 | + public function get_tagged_theme_locations_for_menu_id( $menu_id ) { |
|
| 602 | 602 | |
| 603 | - $locations = array(); |
|
| 603 | + $locations = array(); |
|
| 604 | 604 | |
| 605 | - $nav_menu_locations = get_nav_menu_locations(); |
|
| 605 | + $nav_menu_locations = get_nav_menu_locations(); |
|
| 606 | 606 | |
| 607 | - foreach ( get_registered_nav_menus() as $id => $name ) { |
|
| 607 | + foreach ( get_registered_nav_menus() as $id => $name ) { |
|
| 608 | 608 | |
| 609 | - if ( isset( $nav_menu_locations[ $id ] ) && $nav_menu_locations[ $id ] == $menu_id ) { |
|
| 610 | - $locations[ $id ] = $name; |
|
| 611 | - } |
|
| 612 | - } |
|
| 609 | + if ( isset( $nav_menu_locations[ $id ] ) && $nav_menu_locations[ $id ] == $menu_id ) { |
|
| 610 | + $locations[ $id ] = $name; |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - return $locations; |
|
| 615 | - } |
|
| 614 | + return $locations; |
|
| 615 | + } |
|
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * Get the current menu ID. |
|
| 619 | - * |
|
| 620 | - * Most of this taken from wp-admin/nav-menus.php (no built in functions to do this) |
|
| 621 | - * |
|
| 622 | - * @since 1.0 |
|
| 623 | - * @return int |
|
| 624 | - */ |
|
| 625 | - public function get_selected_menu_id() { |
|
| 617 | + /** |
|
| 618 | + * Get the current menu ID. |
|
| 619 | + * |
|
| 620 | + * Most of this taken from wp-admin/nav-menus.php (no built in functions to do this) |
|
| 621 | + * |
|
| 622 | + * @since 1.0 |
|
| 623 | + * @return int |
|
| 624 | + */ |
|
| 625 | + public function get_selected_menu_id() { |
|
| 626 | 626 | |
| 627 | - $nav_menus = wp_get_nav_menus( array( 'orderby' => 'name' ) ); |
|
| 627 | + $nav_menus = wp_get_nav_menus( array( 'orderby' => 'name' ) ); |
|
| 628 | 628 | |
| 629 | - $menu_count = count( $nav_menus ); |
|
| 629 | + $menu_count = count( $nav_menus ); |
|
| 630 | 630 | |
| 631 | - $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0; |
|
| 631 | + $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0; |
|
| 632 | 632 | |
| 633 | - $add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false; |
|
| 633 | + $add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false; |
|
| 634 | 634 | |
| 635 | - // If we have one theme location, and zero menus, we take them right into editing their first menu. |
|
| 636 | - $page_count = wp_count_posts( 'page' ); |
|
| 637 | - $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false; |
|
| 635 | + // If we have one theme location, and zero menus, we take them right into editing their first menu. |
|
| 636 | + $page_count = wp_count_posts( 'page' ); |
|
| 637 | + $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false; |
|
| 638 | 638 | |
| 639 | - // Get recently edited nav menu. |
|
| 640 | - $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) ); |
|
| 641 | - if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) { |
|
| 642 | - $recently_edited = $nav_menu_selected_id; |
|
| 643 | - } |
|
| 639 | + // Get recently edited nav menu. |
|
| 640 | + $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) ); |
|
| 641 | + if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) { |
|
| 642 | + $recently_edited = $nav_menu_selected_id; |
|
| 643 | + } |
|
| 644 | 644 | |
| 645 | - // Use $recently_edited if none are selected. |
|
| 646 | - if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) { |
|
| 647 | - $nav_menu_selected_id = $recently_edited; |
|
| 648 | - } |
|
| 645 | + // Use $recently_edited if none are selected. |
|
| 646 | + if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) { |
|
| 647 | + $nav_menu_selected_id = $recently_edited; |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - // On deletion of menu, if another menu exists, show it. |
|
| 651 | - if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) { |
|
| 652 | - $nav_menu_selected_id = $nav_menus[0]->term_id; |
|
| 653 | - } |
|
| 650 | + // On deletion of menu, if another menu exists, show it. |
|
| 651 | + if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) { |
|
| 652 | + $nav_menu_selected_id = $nav_menus[0]->term_id; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - // Set $nav_menu_selected_id to 0 if no menus. |
|
| 656 | - if ( $one_theme_location_no_menus ) { |
|
| 657 | - $nav_menu_selected_id = 0; |
|
| 658 | - } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) { |
|
| 659 | - // if we have no selection yet, and we have menus, set to the first one in the list. |
|
| 660 | - $nav_menu_selected_id = $nav_menus[0]->term_id; |
|
| 661 | - } |
|
| 655 | + // Set $nav_menu_selected_id to 0 if no menus. |
|
| 656 | + if ( $one_theme_location_no_menus ) { |
|
| 657 | + $nav_menu_selected_id = 0; |
|
| 658 | + } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) { |
|
| 659 | + // if we have no selection yet, and we have menus, set to the first one in the list. |
|
| 660 | + $nav_menu_selected_id = $nav_menus[0]->term_id; |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - return $nav_menu_selected_id; |
|
| 663 | + return $nav_menu_selected_id; |
|
| 664 | 664 | |
| 665 | - } |
|
| 666 | - } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | 668 | endif; |
@@ -1,681 +1,681 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Toggle_Blocks' ) ) : |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Mobile Toggle Blocks |
|
| 11 | - */ |
|
| 12 | - class Mega_Menu_Toggle_Blocks { |
|
| 9 | + /** |
|
| 10 | + * Mobile Toggle Blocks |
|
| 11 | + */ |
|
| 12 | + class Mega_Menu_Toggle_Blocks { |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Constructor |
|
| 16 | - * |
|
| 17 | - * @since 2.1 |
|
| 18 | - */ |
|
| 19 | - public function __construct() { |
|
| 14 | + /** |
|
| 15 | + * Constructor |
|
| 16 | + * |
|
| 17 | + * @since 2.1 |
|
| 18 | + */ |
|
| 19 | + public function __construct() { |
|
| 20 | 20 | |
| 21 | - add_filter( 'megamenu_scss_variables', array( $this, 'add_menu_toggle_block_vars_to_scss' ), 10, 5 ); |
|
| 22 | - add_filter( 'megamenu_scss_variables', array( $this, 'add_spacer_block_vars_to_scss' ), 10, 5 ); |
|
| 23 | - add_filter( 'megamenu_scss_variables', array( $this, 'add_menu_toggle_animated_block_vars_to_scss' ), 10, 5 ); |
|
| 21 | + add_filter( 'megamenu_scss_variables', array( $this, 'add_menu_toggle_block_vars_to_scss' ), 10, 5 ); |
|
| 22 | + add_filter( 'megamenu_scss_variables', array( $this, 'add_spacer_block_vars_to_scss' ), 10, 5 ); |
|
| 23 | + add_filter( 'megamenu_scss_variables', array( $this, 'add_menu_toggle_animated_block_vars_to_scss' ), 10, 5 ); |
|
| 24 | 24 | |
| 25 | - add_filter( 'megamenu_load_scss_file_contents', array( $this, 'append_scss' ), 10 ); |
|
| 26 | - add_filter( 'megamenu_toggle_bar_content', array( $this, 'output_public_toggle_blocks' ), 10, 4 ); |
|
| 25 | + add_filter( 'megamenu_load_scss_file_contents', array( $this, 'append_scss' ), 10 ); |
|
| 26 | + add_filter( 'megamenu_toggle_bar_content', array( $this, 'output_public_toggle_blocks' ), 10, 4 ); |
|
| 27 | 27 | |
| 28 | - add_action( 'wp_ajax_mm_get_toggle_block_menu_toggle', array( $this, 'output_menu_toggle_block_html' ) ); |
|
| 29 | - add_action( 'megamenu_output_admin_toggle_block_menu_toggle', array( $this, 'output_menu_toggle_block_html' ), 10, 2 ); |
|
| 30 | - add_action( 'megamenu_output_public_toggle_block_menu_toggle', array( $this, 'output_menu_public_toggle_block_html' ), 10, 2 ); |
|
| 28 | + add_action( 'wp_ajax_mm_get_toggle_block_menu_toggle', array( $this, 'output_menu_toggle_block_html' ) ); |
|
| 29 | + add_action( 'megamenu_output_admin_toggle_block_menu_toggle', array( $this, 'output_menu_toggle_block_html' ), 10, 2 ); |
|
| 30 | + add_action( 'megamenu_output_public_toggle_block_menu_toggle', array( $this, 'output_menu_public_toggle_block_html' ), 10, 2 ); |
|
| 31 | 31 | |
| 32 | - add_action( 'wp_ajax_mm_get_toggle_block_menu_toggle_animated', array( $this, 'output_menu_toggle_block_animated_html' ) ); |
|
| 33 | - add_action( 'megamenu_output_admin_toggle_block_menu_toggle_animated', array( $this, 'output_menu_toggle_block_animated_html' ), 10, 2 ); |
|
| 34 | - add_action( 'megamenu_output_public_toggle_block_menu_toggle_animated', array( $this, 'output_menu_public_toggle_block_animated_html' ), 10, 2 ); |
|
| 32 | + add_action( 'wp_ajax_mm_get_toggle_block_menu_toggle_animated', array( $this, 'output_menu_toggle_block_animated_html' ) ); |
|
| 33 | + add_action( 'megamenu_output_admin_toggle_block_menu_toggle_animated', array( $this, 'output_menu_toggle_block_animated_html' ), 10, 2 ); |
|
| 34 | + add_action( 'megamenu_output_public_toggle_block_menu_toggle_animated', array( $this, 'output_menu_public_toggle_block_animated_html' ), 10, 2 ); |
|
| 35 | 35 | |
| 36 | - add_action( 'wp_ajax_mm_get_toggle_block_spacer', array( $this, 'output_spacer_block_html' ) ); |
|
| 37 | - add_action( 'megamenu_output_admin_toggle_block_spacer', array( $this, 'output_spacer_block_html' ), 10, 2 ); |
|
| 36 | + add_action( 'wp_ajax_mm_get_toggle_block_spacer', array( $this, 'output_spacer_block_html' ) ); |
|
| 37 | + add_action( 'megamenu_output_admin_toggle_block_spacer', array( $this, 'output_spacer_block_html' ), 10, 2 ); |
|
| 38 | 38 | |
| 39 | - add_action( 'megamenu_after_theme_revert', array( $this, 'revert_toggle_blocks' ) ); |
|
| 40 | - add_action( 'megamenu_after_theme_save', array( $this, 'save_toggle_blocks' ) ); |
|
| 41 | - |
|
| 42 | - add_action( 'megamenu_admin_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 43 | - add_action( 'megamenu_print_theme_option_toggle_blocks', array( $this, 'print_theme_toggle_bar_designer_option' ), 10, 2 ); |
|
| 44 | - |
|
| 45 | - add_filter( 'megamenu_theme_editor_settings', array( $this, 'add_toggle_designer_to_theme_editor' ), 10 ); |
|
| 46 | - |
|
| 47 | - } |
|
| 39 | + add_action( 'megamenu_after_theme_revert', array( $this, 'revert_toggle_blocks' ) ); |
|
| 40 | + add_action( 'megamenu_after_theme_save', array( $this, 'save_toggle_blocks' ) ); |
|
| 41 | + |
|
| 42 | + add_action( 'megamenu_admin_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 43 | + add_action( 'megamenu_print_theme_option_toggle_blocks', array( $this, 'print_theme_toggle_bar_designer_option' ), 10, 2 ); |
|
| 44 | + |
|
| 45 | + add_filter( 'megamenu_theme_editor_settings', array( $this, 'add_toggle_designer_to_theme_editor' ), 10 ); |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Output the menu toggle block (front end) |
|
| 52 | - * |
|
| 53 | - * @since 2.4.1 |
|
| 54 | - * @param string $html |
|
| 55 | - * @param array $settings |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function output_menu_public_toggle_block_html( $html, $settings ) { |
|
| 50 | + /** |
|
| 51 | + * Output the menu toggle block (front end) |
|
| 52 | + * |
|
| 53 | + * @since 2.4.1 |
|
| 54 | + * @param string $html |
|
| 55 | + * @param array $settings |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function output_menu_public_toggle_block_html( $html, $settings ) { |
|
| 59 | 59 | |
| 60 | - $css_version = get_transient( 'megamenu_css_version' ); |
|
| 60 | + $css_version = get_transient( 'megamenu_css_version' ); |
|
| 61 | 61 | |
| 62 | - // only use HTML version of toggle block if CSS version is above 2.4.0.2 |
|
| 63 | - // if transient is missing, assume the latest version of the CSS is present and use Flex layout |
|
| 64 | - if ( ! $css_version || version_compare( $css_version, '2.4.0.2' ) >= 0 ) { |
|
| 65 | - $closed_text = isset( $settings['closed_text'] ) ? do_shortcode( stripslashes( $settings['closed_text'] ) ) : 'MENU'; |
|
| 66 | - $open_text = isset( $settings['open_text'] ) ? do_shortcode( stripslashes( $settings['open_text'] ) ) : 'MENU'; |
|
| 62 | + // only use HTML version of toggle block if CSS version is above 2.4.0.2 |
|
| 63 | + // if transient is missing, assume the latest version of the CSS is present and use Flex layout |
|
| 64 | + if ( ! $css_version || version_compare( $css_version, '2.4.0.2' ) >= 0 ) { |
|
| 65 | + $closed_text = isset( $settings['closed_text'] ) ? do_shortcode( stripslashes( $settings['closed_text'] ) ) : 'MENU'; |
|
| 66 | + $open_text = isset( $settings['open_text'] ) ? do_shortcode( stripslashes( $settings['open_text'] ) ) : 'MENU'; |
|
| 67 | 67 | |
| 68 | - $html = "<span class='mega-toggle-label' role='button' aria-expanded='false'><span class='mega-toggle-label-closed'>{$closed_text}</span><span class='mega-toggle-label-open'>{$open_text}</span></span>"; |
|
| 69 | - } else { |
|
| 70 | - $html = ''; |
|
| 71 | - } |
|
| 68 | + $html = "<span class='mega-toggle-label' role='button' aria-expanded='false'><span class='mega-toggle-label-closed'>{$closed_text}</span><span class='mega-toggle-label-open'>{$open_text}</span></span>"; |
|
| 69 | + } else { |
|
| 70 | + $html = ''; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return apply_filters( 'megamenu_toggle_menu_toggle_html', $html ); |
|
| 73 | + return apply_filters( 'megamenu_toggle_menu_toggle_html', $html ); |
|
| 74 | 74 | |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Return the saved toggle blocks for a specified theme |
|
| 79 | - * |
|
| 80 | - * @param string $theme_id |
|
| 81 | - * @since 2.1 |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - private function get_toggle_blocks_for_theme( $theme_id ) { |
|
| 77 | + /** |
|
| 78 | + * Return the saved toggle blocks for a specified theme |
|
| 79 | + * |
|
| 80 | + * @param string $theme_id |
|
| 81 | + * @since 2.1 |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + private function get_toggle_blocks_for_theme( $theme_id ) { |
|
| 85 | 85 | |
| 86 | - $blocks = max_mega_menu_get_toggle_blocks(); |
|
| 87 | - |
|
| 88 | - if ( isset( $blocks[ $theme_id ] ) ) { |
|
| 89 | - return $blocks[ $theme_id ]; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $defaults[] = array( |
|
| 93 | - 'type' => 'menu_toggle_animated', |
|
| 94 | - 'align' => 'right', |
|
| 95 | - 'icon_scale' => isset( $settings['icon_scale'] ) && strlen( $settings['icon_scale'] ) ? $settings['icon_scale'] : '0.8', |
|
| 96 | - 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : 'rgb(221, 221, 221)', |
|
| 97 | - ); |
|
| 86 | + $blocks = max_mega_menu_get_toggle_blocks(); |
|
| 87 | + |
|
| 88 | + if ( isset( $blocks[ $theme_id ] ) ) { |
|
| 89 | + return $blocks[ $theme_id ]; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $defaults[] = array( |
|
| 93 | + 'type' => 'menu_toggle_animated', |
|
| 94 | + 'align' => 'right', |
|
| 95 | + 'icon_scale' => isset( $settings['icon_scale'] ) && strlen( $settings['icon_scale'] ) ? $settings['icon_scale'] : '0.8', |
|
| 96 | + 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : 'rgb(221, 221, 221)', |
|
| 97 | + ); |
|
| 98 | 98 | |
| 99 | - return $defaults; |
|
| 99 | + return $defaults; |
|
| 100 | 100 | |
| 101 | - } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Return default menu toggle block settings |
|
| 106 | - * |
|
| 107 | - * @since 2.1 |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - private function get_default_menu_toggle_block( $theme_id = 'default' ) { |
|
| 104 | + /** |
|
| 105 | + * Return default menu toggle block settings |
|
| 106 | + * |
|
| 107 | + * @since 2.1 |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + private function get_default_menu_toggle_block( $theme_id = 'default' ) { |
|
| 111 | 111 | |
| 112 | - $style_manager = new Mega_Menu_Style_Manager(); |
|
| 112 | + $style_manager = new Mega_Menu_Style_Manager(); |
|
| 113 | 113 | |
| 114 | - $themes = $style_manager->get_themes(); |
|
| 114 | + $themes = $style_manager->get_themes(); |
|
| 115 | 115 | |
| 116 | - $menu_theme = isset( $themes[ $theme_id ] ) ? $themes[ $theme_id ] : $themes['default']; |
|
| 116 | + $menu_theme = isset( $themes[ $theme_id ] ) ? $themes[ $theme_id ] : $themes['default']; |
|
| 117 | 117 | |
| 118 | - $defaults = array( |
|
| 119 | - 'type' => 'menu_toggle', |
|
| 120 | - 'align' => 'right', |
|
| 121 | - 'closed_text' => isset( $menu_theme['responsive_text'] ) ? $menu_theme['responsive_text'] : 'MENU', |
|
| 122 | - 'open_text' => isset( $menu_theme['responsive_text'] ) ? $menu_theme['responsive_text'] : 'MENU', |
|
| 123 | - 'closed_icon' => 'dash-f333', |
|
| 124 | - 'open_icon' => 'dash-f153', |
|
| 125 | - 'icon_position' => 'after', |
|
| 126 | - 'text_color' => isset( $menu_theme['toggle_font_color'] ) ? $menu_theme['toggle_font_color'] : 'rgb(221, 221, 221)', |
|
| 127 | - 'icon_color' => isset( $menu_theme['toggle_font_color'] ) ? $menu_theme['toggle_font_color'] : 'rgb(221, 221, 221)', |
|
| 128 | - 'text_size' => '14px', |
|
| 129 | - 'icon_size' => '24px', |
|
| 130 | - ); |
|
| 118 | + $defaults = array( |
|
| 119 | + 'type' => 'menu_toggle', |
|
| 120 | + 'align' => 'right', |
|
| 121 | + 'closed_text' => isset( $menu_theme['responsive_text'] ) ? $menu_theme['responsive_text'] : 'MENU', |
|
| 122 | + 'open_text' => isset( $menu_theme['responsive_text'] ) ? $menu_theme['responsive_text'] : 'MENU', |
|
| 123 | + 'closed_icon' => 'dash-f333', |
|
| 124 | + 'open_icon' => 'dash-f153', |
|
| 125 | + 'icon_position' => 'after', |
|
| 126 | + 'text_color' => isset( $menu_theme['toggle_font_color'] ) ? $menu_theme['toggle_font_color'] : 'rgb(221, 221, 221)', |
|
| 127 | + 'icon_color' => isset( $menu_theme['toggle_font_color'] ) ? $menu_theme['toggle_font_color'] : 'rgb(221, 221, 221)', |
|
| 128 | + 'text_size' => '14px', |
|
| 129 | + 'icon_size' => '24px', |
|
| 130 | + ); |
|
| 131 | 131 | |
| 132 | - return $defaults; |
|
| 133 | - } |
|
| 132 | + return $defaults; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Get the HTML output for the toggle blocks |
|
| 138 | - * |
|
| 139 | - * @since 2.1 |
|
| 140 | - * @param string $content |
|
| 141 | - * @param string $nav_menu |
|
| 142 | - * @param array $args |
|
| 143 | - * @param string $theme_id |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function output_public_toggle_blocks( $content, $nav_menu, $args, $theme_id ) { |
|
| 147 | - |
|
| 148 | - $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 149 | - |
|
| 150 | - $blocks_html = ''; |
|
| 151 | - |
|
| 152 | - if ( is_array( $toggle_blocks ) ) { |
|
| 153 | - |
|
| 154 | - $css_version = get_transient( 'megamenu_css_version' ); |
|
| 155 | - |
|
| 156 | - // only use Flex layout version of toggle blocks if CSS version is above 2.4.0.2 |
|
| 157 | - // if transient is missing, assume the latest version of the CSS is present and use Flex layout |
|
| 158 | - if ( ! $css_version || version_compare( $css_version, '2.4.0.2' ) >= 0 ) { |
|
| 159 | - $blocks_html = $this->get_flex_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ); |
|
| 160 | - } else { |
|
| 161 | - $blocks_html = $this->get_backwards_compatibility_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $content .= $blocks_html; |
|
| 136 | + /** |
|
| 137 | + * Get the HTML output for the toggle blocks |
|
| 138 | + * |
|
| 139 | + * @since 2.1 |
|
| 140 | + * @param string $content |
|
| 141 | + * @param string $nav_menu |
|
| 142 | + * @param array $args |
|
| 143 | + * @param string $theme_id |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function output_public_toggle_blocks( $content, $nav_menu, $args, $theme_id ) { |
|
| 147 | + |
|
| 148 | + $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 149 | + |
|
| 150 | + $blocks_html = ''; |
|
| 151 | + |
|
| 152 | + if ( is_array( $toggle_blocks ) ) { |
|
| 153 | + |
|
| 154 | + $css_version = get_transient( 'megamenu_css_version' ); |
|
| 155 | + |
|
| 156 | + // only use Flex layout version of toggle blocks if CSS version is above 2.4.0.2 |
|
| 157 | + // if transient is missing, assume the latest version of the CSS is present and use Flex layout |
|
| 158 | + if ( ! $css_version || version_compare( $css_version, '2.4.0.2' ) >= 0 ) { |
|
| 159 | + $blocks_html = $this->get_flex_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ); |
|
| 160 | + } else { |
|
| 161 | + $blocks_html = $this->get_backwards_compatibility_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $content .= $blocks_html; |
|
| 166 | 166 | |
| 167 | - return $content; |
|
| 167 | + return $content; |
|
| 168 | 168 | |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Sort the toggle blocks into 3 divs (left, center, right) to be aligned using flex CSS. |
|
| 173 | - * |
|
| 174 | - * @param array $toggle_blocks |
|
| 175 | - * @since 2.4.1 |
|
| 176 | - * @return string html |
|
| 177 | - */ |
|
| 178 | - private function get_flex_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ) { |
|
| 179 | - |
|
| 180 | - $sorted_blocks = array(); |
|
| 171 | + /** |
|
| 172 | + * Sort the toggle blocks into 3 divs (left, center, right) to be aligned using flex CSS. |
|
| 173 | + * |
|
| 174 | + * @param array $toggle_blocks |
|
| 175 | + * @since 2.4.1 |
|
| 176 | + * @return string html |
|
| 177 | + */ |
|
| 178 | + private function get_flex_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ) { |
|
| 179 | + |
|
| 180 | + $sorted_blocks = array(); |
|
| 181 | 181 | |
| 182 | - /** Sort blocks into left, center, right array **/ |
|
| 183 | - foreach ( $toggle_blocks as $block_id => $block ) { |
|
| 184 | - if ( isset( $block['align'] ) ) { |
|
| 185 | - $sorted_blocks[ $block['align'] ][ $block_id ] = $block; |
|
| 186 | - } else { |
|
| 187 | - $sorted_blocks['left'][ $block_id ] = $block; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $blocks_html = '<div class="mega-toggle-blocks-left">'; |
|
| 192 | - |
|
| 193 | - if ( isset( $sorted_blocks['left'] ) ) { |
|
| 194 | - foreach ( $sorted_blocks['left'] as $block_id => $block ) { |
|
| 195 | - $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 196 | - } |
|
| 197 | - } |
|
| 182 | + /** Sort blocks into left, center, right array **/ |
|
| 183 | + foreach ( $toggle_blocks as $block_id => $block ) { |
|
| 184 | + if ( isset( $block['align'] ) ) { |
|
| 185 | + $sorted_blocks[ $block['align'] ][ $block_id ] = $block; |
|
| 186 | + } else { |
|
| 187 | + $sorted_blocks['left'][ $block_id ] = $block; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $blocks_html = '<div class="mega-toggle-blocks-left">'; |
|
| 192 | + |
|
| 193 | + if ( isset( $sorted_blocks['left'] ) ) { |
|
| 194 | + foreach ( $sorted_blocks['left'] as $block_id => $block ) { |
|
| 195 | + $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - $blocks_html .= '</div>'; |
|
| 200 | - |
|
| 201 | - $blocks_html .= '<div class="mega-toggle-blocks-center">'; |
|
| 202 | - |
|
| 203 | - if ( isset( $sorted_blocks['center'] ) ) { |
|
| 204 | - foreach ( $sorted_blocks['center'] as $block_id => $block ) { |
|
| 205 | - $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $blocks_html .= '</div>'; |
|
| 210 | - |
|
| 211 | - $blocks_html .= '<div class="mega-toggle-blocks-right">'; |
|
| 212 | - |
|
| 213 | - if ( isset( $sorted_blocks['right'] ) ) { |
|
| 214 | - foreach ( $sorted_blocks['right'] as $block_id => $block ) { |
|
| 215 | - $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $blocks_html .= '</div>'; |
|
| 220 | - |
|
| 221 | - return $blocks_html; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Generate the HTML for a single toggle block |
|
| 226 | - * |
|
| 227 | - * @since 2.4.1 |
|
| 228 | - * @param string block_id |
|
| 229 | - * @param array $block |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - private function get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ) { |
|
| 233 | - $block_html = ''; |
|
| 234 | - |
|
| 235 | - if ( isset( $block['type'] ) ) { |
|
| 236 | - $class = 'mega-' . str_replace( '_', '-', $block['type'] ) . '-block'; |
|
| 237 | - } else { |
|
| 238 | - $class = ''; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $id = apply_filters( 'megamenu_toggle_block_id', 'mega-toggle-block-' . $block_id ); |
|
| 242 | - |
|
| 243 | - $atts = array( |
|
| 244 | - 'class' => "mega-toggle-block {$class} mega-toggle-block-{$block_id}", |
|
| 245 | - 'id' => "mega-toggle-block-{$block_id}", |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - if ( isset( $block['type'] ) && $block['type'] == 'menu_toggle' ) { |
|
| 249 | - $atts['tabindex'] = '0'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $attributes = apply_filters( 'megamenu_toggle_block_attributes', $atts, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 253 | - |
|
| 254 | - $block_html .= '<div'; |
|
| 255 | - |
|
| 256 | - foreach ( $attributes as $attribute => $val ) { |
|
| 257 | - $block_html .= ' ' . $attribute . "='" . esc_attr( $val ) . "'"; |
|
| 258 | - } |
|
| 199 | + $blocks_html .= '</div>'; |
|
| 200 | + |
|
| 201 | + $blocks_html .= '<div class="mega-toggle-blocks-center">'; |
|
| 202 | + |
|
| 203 | + if ( isset( $sorted_blocks['center'] ) ) { |
|
| 204 | + foreach ( $sorted_blocks['center'] as $block_id => $block ) { |
|
| 205 | + $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $blocks_html .= '</div>'; |
|
| 210 | + |
|
| 211 | + $blocks_html .= '<div class="mega-toggle-blocks-right">'; |
|
| 212 | + |
|
| 213 | + if ( isset( $sorted_blocks['right'] ) ) { |
|
| 214 | + foreach ( $sorted_blocks['right'] as $block_id => $block ) { |
|
| 215 | + $blocks_html .= $this->get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $blocks_html .= '</div>'; |
|
| 220 | + |
|
| 221 | + return $blocks_html; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Generate the HTML for a single toggle block |
|
| 226 | + * |
|
| 227 | + * @since 2.4.1 |
|
| 228 | + * @param string block_id |
|
| 229 | + * @param array $block |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + private function get_toggle_block_html( $block_id, $block, $content, $nav_menu, $args, $theme_id ) { |
|
| 233 | + $block_html = ''; |
|
| 234 | + |
|
| 235 | + if ( isset( $block['type'] ) ) { |
|
| 236 | + $class = 'mega-' . str_replace( '_', '-', $block['type'] ) . '-block'; |
|
| 237 | + } else { |
|
| 238 | + $class = ''; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $id = apply_filters( 'megamenu_toggle_block_id', 'mega-toggle-block-' . $block_id ); |
|
| 242 | + |
|
| 243 | + $atts = array( |
|
| 244 | + 'class' => "mega-toggle-block {$class} mega-toggle-block-{$block_id}", |
|
| 245 | + 'id' => "mega-toggle-block-{$block_id}", |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + if ( isset( $block['type'] ) && $block['type'] == 'menu_toggle' ) { |
|
| 249 | + $atts['tabindex'] = '0'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $attributes = apply_filters( 'megamenu_toggle_block_attributes', $atts, $block, $content, $nav_menu, $args, $theme_id ); |
|
| 253 | + |
|
| 254 | + $block_html .= '<div'; |
|
| 255 | + |
|
| 256 | + foreach ( $attributes as $attribute => $val ) { |
|
| 257 | + $block_html .= ' ' . $attribute . "='" . esc_attr( $val ) . "'"; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - $block_html .= '>'; |
|
| 261 | - $block_html .= apply_filters( "megamenu_output_public_toggle_block_{$block['type']}", '', $block ); |
|
| 262 | - $block_html .= '</div>'; |
|
| 260 | + $block_html .= '>'; |
|
| 261 | + $block_html .= apply_filters( "megamenu_output_public_toggle_block_{$block['type']}", '', $block ); |
|
| 262 | + $block_html .= '</div>'; |
|
| 263 | 263 | |
| 264 | - return $block_html; |
|
| 265 | - } |
|
| 264 | + return $block_html; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Return a flat HTML list of menu toggle blocks. Only used when CSS version has not been updated to 2.4.1+ |
|
| 270 | - * |
|
| 271 | - * @param array $toggle_blocks |
|
| 272 | - * @since 2.4.1 |
|
| 273 | - * @return string html |
|
| 274 | - */ |
|
| 275 | - private function get_backwards_compatibility_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ) { |
|
| 276 | - |
|
| 277 | - $blocks_html = ''; |
|
| 268 | + /** |
|
| 269 | + * Return a flat HTML list of menu toggle blocks. Only used when CSS version has not been updated to 2.4.1+ |
|
| 270 | + * |
|
| 271 | + * @param array $toggle_blocks |
|
| 272 | + * @since 2.4.1 |
|
| 273 | + * @return string html |
|
| 274 | + */ |
|
| 275 | + private function get_backwards_compatibility_blocks_html( $toggle_blocks, $content, $nav_menu, $args, $theme_id ) { |
|
| 276 | + |
|
| 277 | + $blocks_html = ''; |
|
| 278 | 278 | |
| 279 | - foreach ( $toggle_blocks as $block_id => $block ) { |
|
| 279 | + foreach ( $toggle_blocks as $block_id => $block ) { |
|
| 280 | 280 | |
| 281 | - if ( isset( $block['type'] ) ) { |
|
| 282 | - $class = 'mega-' . str_replace( '_', '-', $block['type'] ) . '-block'; |
|
| 283 | - } else { |
|
| 284 | - $class = ''; |
|
| 285 | - } |
|
| 281 | + if ( isset( $block['type'] ) ) { |
|
| 282 | + $class = 'mega-' . str_replace( '_', '-', $block['type'] ) . '-block'; |
|
| 283 | + } else { |
|
| 284 | + $class = ''; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - if ( isset( $block['align'] ) ) { |
|
| 288 | - $align = 'mega-toggle-block-' . $block['align']; |
|
| 289 | - } else { |
|
| 290 | - $align = 'mega-toggle-block-left'; |
|
| 291 | - } |
|
| 287 | + if ( isset( $block['align'] ) ) { |
|
| 288 | + $align = 'mega-toggle-block-' . $block['align']; |
|
| 289 | + } else { |
|
| 290 | + $align = 'mega-toggle-block-left'; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - // @todo remove ID once MMM Pro has been updated to use classes |
|
| 294 | - $id = apply_filters( 'megamenu_toggle_block_id', 'mega-toggle-block-' . $block_id ); |
|
| 295 | - |
|
| 296 | - $attributes = apply_filters( |
|
| 297 | - 'megamenu_toggle_block_attributes', |
|
| 298 | - array( |
|
| 299 | - 'class' => "mega-toggle-block {$class} {$align} mega-toggle-block-{$block_id}", |
|
| 300 | - 'id' => "mega-toggle-block-{$block_id}", |
|
| 301 | - ), |
|
| 302 | - $block, |
|
| 303 | - $content, |
|
| 304 | - $nav_menu, |
|
| 305 | - $args, |
|
| 306 | - $theme_id |
|
| 307 | - ); |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * |
|
| 311 | - * function remove_ids_from_toggle_blocks($attributes, $block, $content, $nav_menu, $args, $theme_id) { |
|
| 312 | - * if (isset($attributes['id'])) { |
|
| 313 | - * unset($attributes['id']); |
|
| 314 | - * } |
|
| 315 | - * return $attributes; |
|
| 316 | - * } |
|
| 317 | - * add_filter('megamenu_toggle_block_attributes', 'remove_ids_from_toggle_blocks', 10, 6); |
|
| 318 | - * |
|
| 319 | - */ |
|
| 320 | - |
|
| 321 | - $blocks_html .= '<div'; |
|
| 322 | - |
|
| 323 | - foreach ( $attributes as $attribute => $val ) { |
|
| 324 | - $blocks_html .= ' ' . $attribute . "='" . esc_attr( $val ) . "'"; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $blocks_html .= '>'; |
|
| 328 | - $blocks_html .= apply_filters( "megamenu_output_public_toggle_block_{$block['type']}", '', $block ); |
|
| 329 | - $blocks_html .= '</div>'; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - return $blocks_html; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Save the toggle blocks when the theme is saved |
|
| 338 | - * |
|
| 339 | - * @since 2.1 |
|
| 340 | - */ |
|
| 341 | - public function save_toggle_blocks() { |
|
| 342 | - |
|
| 343 | - $theme = esc_attr( $_POST['theme_id'] ); |
|
| 344 | - |
|
| 345 | - $saved_blocks = max_mega_menu_get_toggle_blocks(); |
|
| 293 | + // @todo remove ID once MMM Pro has been updated to use classes |
|
| 294 | + $id = apply_filters( 'megamenu_toggle_block_id', 'mega-toggle-block-' . $block_id ); |
|
| 295 | + |
|
| 296 | + $attributes = apply_filters( |
|
| 297 | + 'megamenu_toggle_block_attributes', |
|
| 298 | + array( |
|
| 299 | + 'class' => "mega-toggle-block {$class} {$align} mega-toggle-block-{$block_id}", |
|
| 300 | + 'id' => "mega-toggle-block-{$block_id}", |
|
| 301 | + ), |
|
| 302 | + $block, |
|
| 303 | + $content, |
|
| 304 | + $nav_menu, |
|
| 305 | + $args, |
|
| 306 | + $theme_id |
|
| 307 | + ); |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * |
|
| 311 | + * function remove_ids_from_toggle_blocks($attributes, $block, $content, $nav_menu, $args, $theme_id) { |
|
| 312 | + * if (isset($attributes['id'])) { |
|
| 313 | + * unset($attributes['id']); |
|
| 314 | + * } |
|
| 315 | + * return $attributes; |
|
| 316 | + * } |
|
| 317 | + * add_filter('megamenu_toggle_block_attributes', 'remove_ids_from_toggle_blocks', 10, 6); |
|
| 318 | + * |
|
| 319 | + */ |
|
| 320 | + |
|
| 321 | + $blocks_html .= '<div'; |
|
| 322 | + |
|
| 323 | + foreach ( $attributes as $attribute => $val ) { |
|
| 324 | + $blocks_html .= ' ' . $attribute . "='" . esc_attr( $val ) . "'"; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $blocks_html .= '>'; |
|
| 328 | + $blocks_html .= apply_filters( "megamenu_output_public_toggle_block_{$block['type']}", '', $block ); |
|
| 329 | + $blocks_html .= '</div>'; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + return $blocks_html; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Save the toggle blocks when the theme is saved |
|
| 338 | + * |
|
| 339 | + * @since 2.1 |
|
| 340 | + */ |
|
| 341 | + public function save_toggle_blocks() { |
|
| 342 | + |
|
| 343 | + $theme = esc_attr( $_POST['theme_id'] ); |
|
| 344 | + |
|
| 345 | + $saved_blocks = max_mega_menu_get_toggle_blocks(); |
|
| 346 | 346 | |
| 347 | - if ( isset( $saved_blocks[ $theme ] ) ) { |
|
| 348 | - unset( $saved_blocks[ $theme ] ); |
|
| 349 | - } |
|
| 347 | + if ( isset( $saved_blocks[ $theme ] ) ) { |
|
| 348 | + unset( $saved_blocks[ $theme ] ); |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - $submitted_settings = $_POST['toggle_blocks']; |
|
| 351 | + $submitted_settings = $_POST['toggle_blocks']; |
|
| 352 | 352 | |
| 353 | - $saved_blocks[ $theme ] = $submitted_settings; |
|
| 354 | - |
|
| 355 | - max_mega_menu_save_toggle_blocks( $saved_blocks ); |
|
| 356 | - |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Revert the toggle blocks when a theme is reverted |
|
| 362 | - * |
|
| 363 | - * @since 2.1 |
|
| 364 | - */ |
|
| 365 | - public function revert_toggle_blocks() { |
|
| 366 | - |
|
| 367 | - $theme = esc_attr( $_GET['theme_id'] ); |
|
| 368 | - |
|
| 369 | - $saved_toggle_blocks = max_mega_menu_get_toggle_blocks(); |
|
| 370 | - |
|
| 371 | - if ( isset( $saved_toggle_blocks[ $theme ] ) ) { |
|
| 372 | - unset( $saved_toggle_blocks[ $theme ] ); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - max_mega_menu_save_toggle_blocks( $saved_toggle_blocks ); |
|
| 376 | - } |
|
| 353 | + $saved_blocks[ $theme ] = $submitted_settings; |
|
| 354 | + |
|
| 355 | + max_mega_menu_save_toggle_blocks( $saved_blocks ); |
|
| 356 | + |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Revert the toggle blocks when a theme is reverted |
|
| 362 | + * |
|
| 363 | + * @since 2.1 |
|
| 364 | + */ |
|
| 365 | + public function revert_toggle_blocks() { |
|
| 366 | + |
|
| 367 | + $theme = esc_attr( $_GET['theme_id'] ); |
|
| 368 | + |
|
| 369 | + $saved_toggle_blocks = max_mega_menu_get_toggle_blocks(); |
|
| 370 | + |
|
| 371 | + if ( isset( $saved_toggle_blocks[ $theme ] ) ) { |
|
| 372 | + unset( $saved_toggle_blocks[ $theme ] ); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + max_mega_menu_save_toggle_blocks( $saved_toggle_blocks ); |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Add the toggle bar designer to the theme editor |
|
| 381 | - * |
|
| 382 | - * @since 2.1 |
|
| 383 | - * @return array |
|
| 384 | - */ |
|
| 385 | - public function add_toggle_designer_to_theme_editor( $settings ) { |
|
| 386 | - |
|
| 387 | - $settings['mobile_menu']['settings']['toggle_blocks'] = array( |
|
| 388 | - 'priority' => 6, |
|
| 389 | - 'title' => __( 'Toggle Bar Designer', 'megamenu' ), |
|
| 390 | - 'description' => __( 'Configure the contents of the mobile toggle bar', 'megamenu' ), |
|
| 391 | - 'settings' => array( |
|
| 392 | - array( |
|
| 393 | - 'title' => '', |
|
| 394 | - 'type' => 'toggle_blocks', |
|
| 395 | - 'key' => 'toggle_blocks', |
|
| 396 | - ), |
|
| 397 | - ), |
|
| 398 | - ); |
|
| 399 | - |
|
| 400 | - return $settings; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Enqueue nav-menus.php scripts |
|
| 406 | - * |
|
| 407 | - * @since 2.1 |
|
| 408 | - */ |
|
| 409 | - public function enqueue_scripts() { |
|
| 410 | - |
|
| 411 | - $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 412 | - |
|
| 413 | - if ( ! current_user_can( $capability ) ) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 379 | + /** |
|
| 380 | + * Add the toggle bar designer to the theme editor |
|
| 381 | + * |
|
| 382 | + * @since 2.1 |
|
| 383 | + * @return array |
|
| 384 | + */ |
|
| 385 | + public function add_toggle_designer_to_theme_editor( $settings ) { |
|
| 386 | + |
|
| 387 | + $settings['mobile_menu']['settings']['toggle_blocks'] = array( |
|
| 388 | + 'priority' => 6, |
|
| 389 | + 'title' => __( 'Toggle Bar Designer', 'megamenu' ), |
|
| 390 | + 'description' => __( 'Configure the contents of the mobile toggle bar', 'megamenu' ), |
|
| 391 | + 'settings' => array( |
|
| 392 | + array( |
|
| 393 | + 'title' => '', |
|
| 394 | + 'type' => 'toggle_blocks', |
|
| 395 | + 'key' => 'toggle_blocks', |
|
| 396 | + ), |
|
| 397 | + ), |
|
| 398 | + ); |
|
| 399 | + |
|
| 400 | + return $settings; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Enqueue nav-menus.php scripts |
|
| 406 | + * |
|
| 407 | + * @since 2.1 |
|
| 408 | + */ |
|
| 409 | + public function enqueue_scripts() { |
|
| 410 | + |
|
| 411 | + $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); |
|
| 412 | + |
|
| 413 | + if ( ! current_user_can( $capability ) ) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - if ( isset( $_GET['page'] ) && 'maxmegamenu_theme_editor' === $_GET['page'] ) { // @codingStandardsIgnoreLine |
|
| 418 | - wp_enqueue_script( 'mega-menu-toggle-bar-designer', MEGAMENU_BASE_URL . 'js/toggledesigner.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), MEGAMENU_VERSION ); |
|
| 417 | + if ( isset( $_GET['page'] ) && 'maxmegamenu_theme_editor' === $_GET['page'] ) { // @codingStandardsIgnoreLine |
|
| 418 | + wp_enqueue_script( 'mega-menu-toggle-bar-designer', MEGAMENU_BASE_URL . 'js/toggledesigner.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), MEGAMENU_VERSION ); |
|
| 419 | 419 | |
| 420 | - wp_localize_script( |
|
| 421 | - 'mega-menu-toggle-bar-designer', |
|
| 422 | - 'megamenu', |
|
| 423 | - array( |
|
| 424 | - 'nonce' => wp_create_nonce( 'megamenu_edit' ), |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - } |
|
| 420 | + wp_localize_script( |
|
| 421 | + 'mega-menu-toggle-bar-designer', |
|
| 422 | + 'megamenu', |
|
| 423 | + array( |
|
| 424 | + 'nonce' => wp_create_nonce( 'megamenu_edit' ), |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Append the logo SCSS to the main SCSS file |
|
| 433 | - * |
|
| 434 | - * @since 2.1 |
|
| 435 | - * @param string $scss |
|
| 436 | - * @param string |
|
| 437 | - */ |
|
| 438 | - public function append_scss( $scss ) { |
|
| 431 | + /** |
|
| 432 | + * Append the logo SCSS to the main SCSS file |
|
| 433 | + * |
|
| 434 | + * @since 2.1 |
|
| 435 | + * @param string $scss |
|
| 436 | + * @param string |
|
| 437 | + */ |
|
| 438 | + public function append_scss( $scss ) { |
|
| 439 | 439 | |
| 440 | - $path = MEGAMENU_PATH . 'css/toggle-blocks.scss'; |
|
| 441 | - |
|
| 442 | - $contents = file_get_contents( $path ); |
|
| 443 | - |
|
| 444 | - return $scss . $contents; |
|
| 445 | - |
|
| 446 | - } |
|
| 440 | + $path = MEGAMENU_PATH . 'css/toggle-blocks.scss'; |
|
| 441 | + |
|
| 442 | + $contents = file_get_contents( $path ); |
|
| 443 | + |
|
| 444 | + return $scss . $contents; |
|
| 445 | + |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Create a new variable containing the toggle blocks to be used by the SCSS file |
|
| 451 | - * |
|
| 452 | - * @param array $vars |
|
| 453 | - * @param string $location |
|
| 454 | - * @param string $theme |
|
| 455 | - * @param int $menu_id |
|
| 456 | - * @param string $theme_id |
|
| 457 | - * @return array - all custom SCSS vars |
|
| 458 | - * @since 2.1 |
|
| 459 | - */ |
|
| 460 | - public function add_menu_toggle_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 461 | - |
|
| 462 | - $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 463 | - |
|
| 464 | - $menu_toggle_blocks = array(); |
|
| 465 | - |
|
| 466 | - if ( is_array( $toggle_blocks ) ) { |
|
| 467 | - |
|
| 468 | - foreach ( $toggle_blocks as $index => $settings ) { |
|
| 469 | - |
|
| 470 | - if ( isset( $settings['type'] ) && $settings['type'] == 'menu_toggle' ) { |
|
| 471 | - |
|
| 472 | - if ( isset( $settings['closed_icon'] ) ) { |
|
| 473 | - $closed_icon_parts = explode( '-', $settings['closed_icon'] ); |
|
| 474 | - $closed_icon = end( $closed_icon_parts ); |
|
| 475 | - } else { |
|
| 476 | - $closed_icon = 'disabled'; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ( isset( $settings['open_icon'] ) ) { |
|
| 480 | - $open_icon_parts = explode( '-', $settings['open_icon'] ); |
|
| 481 | - $open_icon = end( $open_icon_parts ); |
|
| 482 | - } else { |
|
| 483 | - $open_icon = 'disabled'; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $styles = array( |
|
| 487 | - 'id' => $index, |
|
| 488 | - 'align' => isset( $settings['align'] ) ? "'" . $settings['align'] . "'" : "'right'", |
|
| 489 | - 'closed_text' => "''", // deprecated |
|
| 490 | - 'open_text' => "''", // deprecated |
|
| 491 | - 'closed_icon' => $closed_icon != 'disabled' ? "'\\" . $closed_icon . "'" : "''", |
|
| 492 | - 'open_icon' => $open_icon != 'disabled' ? "'\\" . $open_icon . "'" : "''", |
|
| 493 | - 'text_color' => isset( $settings['text_color'] ) ? $settings['text_color'] : '#fff', |
|
| 494 | - 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : '#fff', |
|
| 495 | - 'icon_position' => isset( $settings['icon_position'] ) ? "'" . $settings['icon_position'] . "'" : 'after', |
|
| 496 | - 'text_size' => isset( $settings['text_size'] ) && strlen( $settings['text_size'] ) ? $settings['text_size'] : '14px', |
|
| 497 | - 'icon_size' => isset( $settings['icon_size'] ) && strlen( $settings['icon_size'] ) ? $settings['icon_size'] : '24px', |
|
| 498 | - ); |
|
| 449 | + /** |
|
| 450 | + * Create a new variable containing the toggle blocks to be used by the SCSS file |
|
| 451 | + * |
|
| 452 | + * @param array $vars |
|
| 453 | + * @param string $location |
|
| 454 | + * @param string $theme |
|
| 455 | + * @param int $menu_id |
|
| 456 | + * @param string $theme_id |
|
| 457 | + * @return array - all custom SCSS vars |
|
| 458 | + * @since 2.1 |
|
| 459 | + */ |
|
| 460 | + public function add_menu_toggle_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 461 | + |
|
| 462 | + $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 463 | + |
|
| 464 | + $menu_toggle_blocks = array(); |
|
| 465 | + |
|
| 466 | + if ( is_array( $toggle_blocks ) ) { |
|
| 467 | + |
|
| 468 | + foreach ( $toggle_blocks as $index => $settings ) { |
|
| 469 | + |
|
| 470 | + if ( isset( $settings['type'] ) && $settings['type'] == 'menu_toggle' ) { |
|
| 471 | + |
|
| 472 | + if ( isset( $settings['closed_icon'] ) ) { |
|
| 473 | + $closed_icon_parts = explode( '-', $settings['closed_icon'] ); |
|
| 474 | + $closed_icon = end( $closed_icon_parts ); |
|
| 475 | + } else { |
|
| 476 | + $closed_icon = 'disabled'; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ( isset( $settings['open_icon'] ) ) { |
|
| 480 | + $open_icon_parts = explode( '-', $settings['open_icon'] ); |
|
| 481 | + $open_icon = end( $open_icon_parts ); |
|
| 482 | + } else { |
|
| 483 | + $open_icon = 'disabled'; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $styles = array( |
|
| 487 | + 'id' => $index, |
|
| 488 | + 'align' => isset( $settings['align'] ) ? "'" . $settings['align'] . "'" : "'right'", |
|
| 489 | + 'closed_text' => "''", // deprecated |
|
| 490 | + 'open_text' => "''", // deprecated |
|
| 491 | + 'closed_icon' => $closed_icon != 'disabled' ? "'\\" . $closed_icon . "'" : "''", |
|
| 492 | + 'open_icon' => $open_icon != 'disabled' ? "'\\" . $open_icon . "'" : "''", |
|
| 493 | + 'text_color' => isset( $settings['text_color'] ) ? $settings['text_color'] : '#fff', |
|
| 494 | + 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : '#fff', |
|
| 495 | + 'icon_position' => isset( $settings['icon_position'] ) ? "'" . $settings['icon_position'] . "'" : 'after', |
|
| 496 | + 'text_size' => isset( $settings['text_size'] ) && strlen( $settings['text_size'] ) ? $settings['text_size'] : '14px', |
|
| 497 | + 'icon_size' => isset( $settings['icon_size'] ) && strlen( $settings['icon_size'] ) ? $settings['icon_size'] : '24px', |
|
| 498 | + ); |
|
| 499 | 499 | |
| 500 | - $menu_toggle_blocks[ $index ] = $styles; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - //$menu_toggle_blocks( |
|
| 506 | - // (123, red, 150px), |
|
| 507 | - // (456, green, null), |
|
| 508 | - // (789, blue, 90%),()); |
|
| 509 | - if ( count( $menu_toggle_blocks ) ) { |
|
| 500 | + $menu_toggle_blocks[ $index ] = $styles; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + //$menu_toggle_blocks( |
|
| 506 | + // (123, red, 150px), |
|
| 507 | + // (456, green, null), |
|
| 508 | + // (789, blue, 90%),()); |
|
| 509 | + if ( count( $menu_toggle_blocks ) ) { |
|
| 510 | 510 | |
| 511 | - $list = '('; |
|
| 511 | + $list = '('; |
|
| 512 | 512 | |
| 513 | - foreach ( $menu_toggle_blocks as $id => $vals ) { |
|
| 514 | - $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 515 | - } |
|
| 513 | + foreach ( $menu_toggle_blocks as $id => $vals ) { |
|
| 514 | + $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 518 | - // Lists with a single item are not treated the same way by SASS |
|
| 519 | - $list .= '());'; |
|
| 517 | + // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 518 | + // Lists with a single item are not treated the same way by SASS |
|
| 519 | + $list .= '());'; |
|
| 520 | 520 | |
| 521 | - $vars['menu_toggle_blocks'] = $list; |
|
| 521 | + $vars['menu_toggle_blocks'] = $list; |
|
| 522 | 522 | |
| 523 | - } else { |
|
| 523 | + } else { |
|
| 524 | 524 | |
| 525 | - $vars['menu_toggle_blocks'] = '()'; |
|
| 525 | + $vars['menu_toggle_blocks'] = '()'; |
|
| 526 | 526 | |
| 527 | - } |
|
| 527 | + } |
|
| 528 | 528 | |
| 529 | - return $vars; |
|
| 530 | - } |
|
| 529 | + return $vars; |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - /** |
|
| 533 | - * Create a new variable containing the spacer blocks to be used by the SCSS file |
|
| 534 | - * |
|
| 535 | - * @param array $vars |
|
| 536 | - * @param string $location |
|
| 537 | - * @param string $theme |
|
| 538 | - * @param int $menu_id |
|
| 539 | - * @param string $theme_id |
|
| 540 | - * @return array - all custom SCSS vars |
|
| 541 | - * @since 2.1 |
|
| 542 | - */ |
|
| 543 | - public function add_spacer_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 532 | + /** |
|
| 533 | + * Create a new variable containing the spacer blocks to be used by the SCSS file |
|
| 534 | + * |
|
| 535 | + * @param array $vars |
|
| 536 | + * @param string $location |
|
| 537 | + * @param string $theme |
|
| 538 | + * @param int $menu_id |
|
| 539 | + * @param string $theme_id |
|
| 540 | + * @return array - all custom SCSS vars |
|
| 541 | + * @since 2.1 |
|
| 542 | + */ |
|
| 543 | + public function add_spacer_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 544 | 544 | |
| 545 | - $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 545 | + $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 546 | 546 | |
| 547 | - $spacer_blocks = array(); |
|
| 547 | + $spacer_blocks = array(); |
|
| 548 | 548 | |
| 549 | - if ( is_array( $toggle_blocks ) ) { |
|
| 549 | + if ( is_array( $toggle_blocks ) ) { |
|
| 550 | 550 | |
| 551 | - foreach ( $toggle_blocks as $index => $settings ) { |
|
| 551 | + foreach ( $toggle_blocks as $index => $settings ) { |
|
| 552 | 552 | |
| 553 | - if ( isset( $settings['type'] ) && $settings['type'] == 'spacer' ) { |
|
| 553 | + if ( isset( $settings['type'] ) && $settings['type'] == 'spacer' ) { |
|
| 554 | 554 | |
| 555 | - $styles = array( |
|
| 556 | - 'id' => $index, |
|
| 557 | - 'align' => isset( $settings['align'] ) ? "'" . $settings['align'] . "'" : "'right'", |
|
| 558 | - 'width' => isset( $settings['width'] ) ? $settings['width'] : '0px', |
|
| 559 | - ); |
|
| 555 | + $styles = array( |
|
| 556 | + 'id' => $index, |
|
| 557 | + 'align' => isset( $settings['align'] ) ? "'" . $settings['align'] . "'" : "'right'", |
|
| 558 | + 'width' => isset( $settings['width'] ) ? $settings['width'] : '0px', |
|
| 559 | + ); |
|
| 560 | 560 | |
| 561 | - $spacer_blocks[ $index ] = $styles; |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - } |
|
| 561 | + $spacer_blocks[ $index ] = $styles; |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | 565 | |
| 566 | - //$menu_toggle_blocks( |
|
| 567 | - // (123, red, 150px), |
|
| 568 | - // (456, green, null), |
|
| 569 | - // (789, blue, 90%),()); |
|
| 570 | - if ( count( $spacer_blocks ) ) { |
|
| 566 | + //$menu_toggle_blocks( |
|
| 567 | + // (123, red, 150px), |
|
| 568 | + // (456, green, null), |
|
| 569 | + // (789, blue, 90%),()); |
|
| 570 | + if ( count( $spacer_blocks ) ) { |
|
| 571 | 571 | |
| 572 | - $list = '('; |
|
| 572 | + $list = '('; |
|
| 573 | 573 | |
| 574 | - foreach ( $spacer_blocks as $id => $vals ) { |
|
| 575 | - $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 576 | - } |
|
| 574 | + foreach ( $spacer_blocks as $id => $vals ) { |
|
| 575 | + $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | - // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 579 | - // Lists with a single item are not treated the same way by SASS |
|
| 580 | - $list .= '());'; |
|
| 578 | + // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 579 | + // Lists with a single item are not treated the same way by SASS |
|
| 580 | + $list .= '());'; |
|
| 581 | 581 | |
| 582 | - $vars['spacer_toggle_blocks'] = $list; |
|
| 582 | + $vars['spacer_toggle_blocks'] = $list; |
|
| 583 | 583 | |
| 584 | - } else { |
|
| 584 | + } else { |
|
| 585 | 585 | |
| 586 | - $vars['spacer_toggle_blocks'] = '()'; |
|
| 586 | + $vars['spacer_toggle_blocks'] = '()'; |
|
| 587 | 587 | |
| 588 | - } |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - return $vars; |
|
| 590 | + return $vars; |
|
| 591 | 591 | |
| 592 | - } |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | - /** |
|
| 595 | - * Create a new variable containing the animated menu toggle blocks to be used by the SCSS file |
|
| 596 | - * |
|
| 597 | - * @param array $vars |
|
| 598 | - * @param string $location |
|
| 599 | - * @param string $theme |
|
| 600 | - * @param int $menu_id |
|
| 601 | - * @param string $theme_id |
|
| 602 | - * @return array - all custom SCSS vars |
|
| 603 | - * @since 2.5.3 |
|
| 604 | - */ |
|
| 605 | - public function add_menu_toggle_animated_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 594 | + /** |
|
| 595 | + * Create a new variable containing the animated menu toggle blocks to be used by the SCSS file |
|
| 596 | + * |
|
| 597 | + * @param array $vars |
|
| 598 | + * @param string $location |
|
| 599 | + * @param string $theme |
|
| 600 | + * @param int $menu_id |
|
| 601 | + * @param string $theme_id |
|
| 602 | + * @return array - all custom SCSS vars |
|
| 603 | + * @since 2.5.3 |
|
| 604 | + */ |
|
| 605 | + public function add_menu_toggle_animated_block_vars_to_scss( $vars, $location, $theme, $menu_id, $theme_id ) { |
|
| 606 | 606 | |
| 607 | - $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 607 | + $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 608 | 608 | |
| 609 | - $menu_toggle_animated_blocks = array(); |
|
| 609 | + $menu_toggle_animated_blocks = array(); |
|
| 610 | 610 | |
| 611 | - if ( is_array( $toggle_blocks ) ) { |
|
| 611 | + if ( is_array( $toggle_blocks ) ) { |
|
| 612 | 612 | |
| 613 | - foreach ( $toggle_blocks as $index => $settings ) { |
|
| 613 | + foreach ( $toggle_blocks as $index => $settings ) { |
|
| 614 | 614 | |
| 615 | - if ( isset( $settings['type'] ) && $settings['type'] == 'menu_toggle_animated' ) { |
|
| 615 | + if ( isset( $settings['type'] ) && $settings['type'] == 'menu_toggle_animated' ) { |
|
| 616 | 616 | |
| 617 | - $styles = array( |
|
| 618 | - 'id' => $index, |
|
| 619 | - 'icon_scale' => isset( $settings['icon_scale'] ) && strlen( $settings['icon_scale'] ) ? $settings['icon_scale'] : '0.8', |
|
| 620 | - 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : 'rgb(221, 221, 221)', |
|
| 621 | - ); |
|
| 617 | + $styles = array( |
|
| 618 | + 'id' => $index, |
|
| 619 | + 'icon_scale' => isset( $settings['icon_scale'] ) && strlen( $settings['icon_scale'] ) ? $settings['icon_scale'] : '0.8', |
|
| 620 | + 'icon_color' => isset( $settings['icon_color'] ) ? $settings['icon_color'] : 'rgb(221, 221, 221)', |
|
| 621 | + ); |
|
| 622 | 622 | |
| 623 | - $menu_toggle_animated_blocks[ $index ] = $styles; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 623 | + $menu_toggle_animated_blocks[ $index ] = $styles; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | - //$menu_toggle_blocks( |
|
| 629 | - // (123, red, 150px), |
|
| 630 | - // (456, green, null), |
|
| 631 | - // (789, blue, 90%),()); |
|
| 632 | - if ( count( $menu_toggle_animated_blocks ) ) { |
|
| 628 | + //$menu_toggle_blocks( |
|
| 629 | + // (123, red, 150px), |
|
| 630 | + // (456, green, null), |
|
| 631 | + // (789, blue, 90%),()); |
|
| 632 | + if ( count( $menu_toggle_animated_blocks ) ) { |
|
| 633 | 633 | |
| 634 | - $list = '('; |
|
| 634 | + $list = '('; |
|
| 635 | 635 | |
| 636 | - foreach ( $menu_toggle_animated_blocks as $id => $vals ) { |
|
| 637 | - $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 638 | - } |
|
| 636 | + foreach ( $menu_toggle_animated_blocks as $id => $vals ) { |
|
| 637 | + $list .= '(' . implode( ',', $vals ) . '),'; |
|
| 638 | + } |
|
| 639 | 639 | |
| 640 | - // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 641 | - // Lists with a single item are not treated the same way by SASS |
|
| 642 | - $list .= '());'; |
|
| 640 | + // Always add an empty list item to meke sure there are always at least 2 items in the list |
|
| 641 | + // Lists with a single item are not treated the same way by SASS |
|
| 642 | + $list .= '());'; |
|
| 643 | 643 | |
| 644 | - $vars['menu_toggle_animated_blocks'] = $list; |
|
| 644 | + $vars['menu_toggle_animated_blocks'] = $list; |
|
| 645 | 645 | |
| 646 | - } else { |
|
| 646 | + } else { |
|
| 647 | 647 | |
| 648 | - $vars['menu_toggle_animated_blocks'] = '()'; |
|
| 648 | + $vars['menu_toggle_animated_blocks'] = '()'; |
|
| 649 | 649 | |
| 650 | - } |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | - return $vars; |
|
| 652 | + return $vars; |
|
| 653 | 653 | |
| 654 | - } |
|
| 654 | + } |
|
| 655 | 655 | |
| 656 | 656 | |
| 657 | - /** |
|
| 658 | - * Print the toggle bar designer option |
|
| 659 | - * |
|
| 660 | - * @since 2.1 |
|
| 661 | - * @param string $key |
|
| 662 | - * @param string $theme_id |
|
| 663 | - */ |
|
| 664 | - public function print_theme_toggle_bar_designer_option( $key, $theme_id ) { |
|
| 657 | + /** |
|
| 658 | + * Print the toggle bar designer option |
|
| 659 | + * |
|
| 660 | + * @since 2.1 |
|
| 661 | + * @param string $key |
|
| 662 | + * @param string $theme_id |
|
| 663 | + */ |
|
| 664 | + public function print_theme_toggle_bar_designer_option( $key, $theme_id ) { |
|
| 665 | 665 | |
| 666 | - $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 666 | + $toggle_blocks = $this->get_toggle_blocks_for_theme( $theme_id ); |
|
| 667 | 667 | |
| 668 | - $block_types = apply_filters( |
|
| 669 | - 'megamenu_registered_toggle_blocks', |
|
| 670 | - array( |
|
| 671 | - 'menu_toggle_animated' => __( 'Menu Toggle (Animated)', 'megamenu' ), |
|
| 672 | - 'menu_toggle' => __( 'Menu Toggle (Standard)', 'megamenu' ), |
|
| 673 | - 'spacer' => __( 'Spacer', 'megamenu' ), |
|
| 674 | - ) |
|
| 675 | - ); |
|
| 668 | + $block_types = apply_filters( |
|
| 669 | + 'megamenu_registered_toggle_blocks', |
|
| 670 | + array( |
|
| 671 | + 'menu_toggle_animated' => __( 'Menu Toggle (Animated)', 'megamenu' ), |
|
| 672 | + 'menu_toggle' => __( 'Menu Toggle (Standard)', 'megamenu' ), |
|
| 673 | + 'spacer' => __( 'Spacer', 'megamenu' ), |
|
| 674 | + ) |
|
| 675 | + ); |
|
| 676 | 676 | |
| 677 | - ksort( $block_types ); |
|
| 678 | - ?> |
|
| 677 | + ksort( $block_types ); |
|
| 678 | + ?> |
|
| 679 | 679 | |
| 680 | 680 | <select id='toggle-block-selector'> |
| 681 | 681 | <option value='title'><?php echo __( 'Add block to toggle bar', 'megamenu' ); ?></option> |
@@ -698,47 +698,47 @@ discard block |
||
| 698 | 698 | <div class='mega-left'> |
| 699 | 699 | <?php |
| 700 | 700 | |
| 701 | - if ( is_array( $toggle_blocks ) ) { |
|
| 702 | - foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 703 | - if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'left' || ! isset( $settings['align'] ) ) { |
|
| 704 | - if ( isset( $settings['type'] ) ) { |
|
| 705 | - do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - ?> |
|
| 701 | + if ( is_array( $toggle_blocks ) ) { |
|
| 702 | + foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 703 | + if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'left' || ! isset( $settings['align'] ) ) { |
|
| 704 | + if ( isset( $settings['type'] ) ) { |
|
| 705 | + do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + ?> |
|
| 712 | 712 | </div> |
| 713 | 713 | <div class='mega-center'> |
| 714 | 714 | <?php |
| 715 | 715 | |
| 716 | - if ( is_array( $toggle_blocks ) ) { |
|
| 717 | - foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 718 | - if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'center' ) { |
|
| 719 | - if ( isset( $settings['type'] ) ) { |
|
| 720 | - do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 721 | - } |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - ?> |
|
| 716 | + if ( is_array( $toggle_blocks ) ) { |
|
| 717 | + foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 718 | + if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'center' ) { |
|
| 719 | + if ( isset( $settings['type'] ) ) { |
|
| 720 | + do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 721 | + } |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + ?> |
|
| 727 | 727 | </div> |
| 728 | 728 | <div class='mega-right'> |
| 729 | 729 | <?php |
| 730 | 730 | |
| 731 | - if ( is_array( $toggle_blocks ) ) { |
|
| 732 | - foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 733 | - if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'right' ) { |
|
| 734 | - if ( isset( $settings['type'] ) ) { |
|
| 735 | - do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - ?> |
|
| 731 | + if ( is_array( $toggle_blocks ) ) { |
|
| 732 | + foreach ( $toggle_blocks as $block_id => $settings ) { |
|
| 733 | + if ( is_int( $block_id ) && is_array( $settings ) && isset( $settings['align'] ) && $settings['align'] == 'right' ) { |
|
| 734 | + if ( isset( $settings['type'] ) ) { |
|
| 735 | + do_action( "megamenu_output_admin_toggle_block_{$settings['type']}", $block_id, $settings ); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + ?> |
|
| 742 | 742 | </div> |
| 743 | 743 | |
| 744 | 744 | </div> |
@@ -750,30 +750,30 @@ discard block |
||
| 750 | 750 | |
| 751 | 751 | |
| 752 | 752 | <?php |
| 753 | - } |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | 755 | |
| 756 | - /** |
|
| 757 | - * Output the HTML for the "Spacer" toggle block settings |
|
| 758 | - * |
|
| 759 | - * @since 2.1 |
|
| 760 | - * @param int $block_id |
|
| 761 | - * @param array $settings |
|
| 762 | - */ |
|
| 763 | - public function output_spacer_block_html( $block_id, $settings = array() ) { |
|
| 756 | + /** |
|
| 757 | + * Output the HTML for the "Spacer" toggle block settings |
|
| 758 | + * |
|
| 759 | + * @since 2.1 |
|
| 760 | + * @param int $block_id |
|
| 761 | + * @param array $settings |
|
| 762 | + */ |
|
| 763 | + public function output_spacer_block_html( $block_id, $settings = array() ) { |
|
| 764 | 764 | |
| 765 | - if ( empty( $settings ) ) { |
|
| 766 | - $block_id = '0'; |
|
| 767 | - } |
|
| 765 | + if ( empty( $settings ) ) { |
|
| 766 | + $block_id = '0'; |
|
| 767 | + } |
|
| 768 | 768 | |
| 769 | - $defaults = array( |
|
| 770 | - 'align' => 'right', |
|
| 771 | - 'width' => '0px', |
|
| 772 | - ); |
|
| 769 | + $defaults = array( |
|
| 770 | + 'align' => 'right', |
|
| 771 | + 'width' => '0px', |
|
| 772 | + ); |
|
| 773 | 773 | |
| 774 | - $settings = array_merge( $defaults, $settings ); |
|
| 774 | + $settings = array_merge( $defaults, $settings ); |
|
| 775 | 775 | |
| 776 | - ?> |
|
| 776 | + ?> |
|
| 777 | 777 | |
| 778 | 778 | <div class='block'> |
| 779 | 779 | <div class='block-title'><span title='<?php _e( 'Spacer', 'megamenu' ); ?>' class="dashicons dashicons-leftright"></span></div> |
@@ -789,34 +789,34 @@ discard block |
||
| 789 | 789 | </div> |
| 790 | 790 | |
| 791 | 791 | <?php |
| 792 | - } |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | 794 | |
| 795 | - /** |
|
| 796 | - * Output the HTML for the "Menu Toggle" block settings |
|
| 797 | - * |
|
| 798 | - * @since 2.1 |
|
| 799 | - * @param int $block_id |
|
| 800 | - * @param array $settings |
|
| 801 | - */ |
|
| 802 | - public function output_menu_toggle_block_html( $block_id, $settings = array() ) { |
|
| 795 | + /** |
|
| 796 | + * Output the HTML for the "Menu Toggle" block settings |
|
| 797 | + * |
|
| 798 | + * @since 2.1 |
|
| 799 | + * @param int $block_id |
|
| 800 | + * @param array $settings |
|
| 801 | + */ |
|
| 802 | + public function output_menu_toggle_block_html( $block_id, $settings = array() ) { |
|
| 803 | 803 | |
| 804 | - if ( empty( $settings ) ) { |
|
| 805 | - $block_id = '0'; |
|
| 806 | - } |
|
| 804 | + if ( empty( $settings ) ) { |
|
| 805 | + $block_id = '0'; |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | - $theme_id = 'default'; |
|
| 808 | + $theme_id = 'default'; |
|
| 809 | 809 | |
| 810 | - if ( isset( $_GET['theme'] ) ) { |
|
| 811 | - $theme_id = esc_attr( $_GET['theme'] ); |
|
| 810 | + if ( isset( $_GET['theme'] ) ) { |
|
| 811 | + $theme_id = esc_attr( $_GET['theme'] ); |
|
| 812 | 812 | |
| 813 | - } |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | - $defaults = $this->get_default_menu_toggle_block( $theme_id ); |
|
| 815 | + $defaults = $this->get_default_menu_toggle_block( $theme_id ); |
|
| 816 | 816 | |
| 817 | - $settings = array_merge( $defaults, $settings ); |
|
| 817 | + $settings = array_merge( $defaults, $settings ); |
|
| 818 | 818 | |
| 819 | - ?> |
|
| 819 | + ?> |
|
| 820 | 820 | |
| 821 | 821 | <div class='block'> |
| 822 | 822 | <div class='block-title'><?php _e( 'TOGGLE', 'megamenu' ); ?> <span title='<?php _e( 'Menu Toggle', 'megamenu' ); ?>' class="dashicons dashicons-menu"></span></div> |
@@ -863,53 +863,53 @@ discard block |
||
| 863 | 863 | </div> |
| 864 | 864 | |
| 865 | 865 | <?php |
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * Output the menu toggle block (front end) |
|
| 871 | - * |
|
| 872 | - * @since 2.5.3 |
|
| 873 | - * @param string $html |
|
| 874 | - * @param array $settings |
|
| 875 | - * @return string |
|
| 876 | - */ |
|
| 877 | - public function output_menu_public_toggle_block_animated_html( $html, $settings ) { |
|
| 878 | - $style = isset( $settings['style'] ) ? $settings['style'] : 'slider'; |
|
| 879 | - $label = isset( $settings['aria_label'] ) ? do_shortcode( stripslashes( $settings['aria_label'] ) ) : 'Toggle Menu'; |
|
| 880 | - |
|
| 881 | - $html = '<button aria-label="' . esc_attr( $label ) . '" class="mega-toggle-animated mega-toggle-animated-' . esc_attr( $style ) . '" type="button" aria-expanded="false"> |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * Output the menu toggle block (front end) |
|
| 871 | + * |
|
| 872 | + * @since 2.5.3 |
|
| 873 | + * @param string $html |
|
| 874 | + * @param array $settings |
|
| 875 | + * @return string |
|
| 876 | + */ |
|
| 877 | + public function output_menu_public_toggle_block_animated_html( $html, $settings ) { |
|
| 878 | + $style = isset( $settings['style'] ) ? $settings['style'] : 'slider'; |
|
| 879 | + $label = isset( $settings['aria_label'] ) ? do_shortcode( stripslashes( $settings['aria_label'] ) ) : 'Toggle Menu'; |
|
| 880 | + |
|
| 881 | + $html = '<button aria-label="' . esc_attr( $label ) . '" class="mega-toggle-animated mega-toggle-animated-' . esc_attr( $style ) . '" type="button" aria-expanded="false"> |
|
| 882 | 882 | <span class="mega-toggle-animated-box"> |
| 883 | 883 | <span class="mega-toggle-animated-inner"></span> |
| 884 | 884 | </span> |
| 885 | 885 | </button>'; |
| 886 | 886 | |
| 887 | - return apply_filters( 'megamenu_toggle_menu_toggle_animated_html', $html ); |
|
| 887 | + return apply_filters( 'megamenu_toggle_menu_toggle_animated_html', $html ); |
|
| 888 | 888 | |
| 889 | - } |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - /** |
|
| 892 | - * Output the HTML for the "Menu Toggle (Animated)" block settings |
|
| 893 | - * |
|
| 894 | - * @since 2.5.3 |
|
| 895 | - * @param int $block_id |
|
| 896 | - * @param array $settings |
|
| 897 | - */ |
|
| 898 | - public function output_menu_toggle_block_animated_html( $block_id, $settings = array() ) { |
|
| 891 | + /** |
|
| 892 | + * Output the HTML for the "Menu Toggle (Animated)" block settings |
|
| 893 | + * |
|
| 894 | + * @since 2.5.3 |
|
| 895 | + * @param int $block_id |
|
| 896 | + * @param array $settings |
|
| 897 | + */ |
|
| 898 | + public function output_menu_toggle_block_animated_html( $block_id, $settings = array() ) { |
|
| 899 | 899 | |
| 900 | - if ( empty( $settings ) ) { |
|
| 901 | - $block_id = '0'; |
|
| 902 | - } |
|
| 900 | + if ( empty( $settings ) ) { |
|
| 901 | + $block_id = '0'; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - $defaults = array( |
|
| 905 | - 'icon_scale' => '0.8', |
|
| 906 | - 'icon_color' => 'rgb(221, 221, 221)', |
|
| 907 | - 'aria_label' => 'Toggle Menu', |
|
| 908 | - ); |
|
| 904 | + $defaults = array( |
|
| 905 | + 'icon_scale' => '0.8', |
|
| 906 | + 'icon_color' => 'rgb(221, 221, 221)', |
|
| 907 | + 'aria_label' => 'Toggle Menu', |
|
| 908 | + ); |
|
| 909 | 909 | |
| 910 | - $settings = array_merge( $defaults, $settings ); |
|
| 910 | + $settings = array_merge( $defaults, $settings ); |
|
| 911 | 911 | |
| 912 | - ?> |
|
| 912 | + ?> |
|
| 913 | 913 | |
| 914 | 914 | <div class='block'> |
| 915 | 915 | <div class='block-title'><?php _e( 'TOGGLE', 'megamenu' ); ?> <span title='<?php _e( 'Menu Toggle', 'megamenu' ); ?>' class="dashicons dashicons-menu"></span></div> |
@@ -939,100 +939,100 @@ discard block |
||
| 939 | 939 | </div> |
| 940 | 940 | |
| 941 | 941 | <?php |
| 942 | - } |
|
| 942 | + } |
|
| 943 | 943 | |
| 944 | 944 | |
| 945 | - /** |
|
| 946 | - * Print an icon selection box |
|
| 947 | - * |
|
| 948 | - * @since 2.1 |
|
| 949 | - * @param string $key |
|
| 950 | - * @param int $block_id |
|
| 951 | - * @param string $value |
|
| 952 | - */ |
|
| 953 | - public function print_icon_option( $key, $block_id, $value, $icons ) { |
|
| 945 | + /** |
|
| 946 | + * Print an icon selection box |
|
| 947 | + * |
|
| 948 | + * @since 2.1 |
|
| 949 | + * @param string $key |
|
| 950 | + * @param int $block_id |
|
| 951 | + * @param string $value |
|
| 952 | + */ |
|
| 953 | + public function print_icon_option( $key, $block_id, $value, $icons ) { |
|
| 954 | 954 | |
| 955 | - ?> |
|
| 955 | + ?> |
|
| 956 | 956 | <select class='icon_dropdown' name='toggle_blocks[<?php echo $block_id; ?>][<?php echo $key; ?>]'> |
| 957 | 957 | <?php |
| 958 | 958 | |
| 959 | - echo "<option value='disabled'>" . __( 'Disabled', 'megamenu' ) . '</option>'; |
|
| 959 | + echo "<option value='disabled'>" . __( 'Disabled', 'megamenu' ) . '</option>'; |
|
| 960 | 960 | |
| 961 | - foreach ( $icons as $code => $class ) { |
|
| 962 | - $name = str_replace( 'dashicons-', '', $class ); |
|
| 963 | - $name = ucwords( str_replace( array( '-', 'arrow' ), ' ', $name ) ); |
|
| 964 | - echo "<option data-class='{$class}' value='{$code}'" . selected( $value, $code, false ) . '>' . $name . '</option>'; |
|
| 965 | - } |
|
| 961 | + foreach ( $icons as $code => $class ) { |
|
| 962 | + $name = str_replace( 'dashicons-', '', $class ); |
|
| 963 | + $name = ucwords( str_replace( array( '-', 'arrow' ), ' ', $name ) ); |
|
| 964 | + echo "<option data-class='{$class}' value='{$code}'" . selected( $value, $code, false ) . '>' . $name . '</option>'; |
|
| 965 | + } |
|
| 966 | 966 | |
| 967 | - ?> |
|
| 967 | + ?> |
|
| 968 | 968 | </select> |
| 969 | 969 | |
| 970 | 970 | <?php |
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * Print a color picker |
|
| 976 | - * |
|
| 977 | - * @since 2.1 |
|
| 978 | - * @param string $key |
|
| 979 | - * @param int $block_id |
|
| 980 | - * @param string $value |
|
| 981 | - */ |
|
| 982 | - public function print_toggle_color_option( $key, $block_id, $value ) { |
|
| 983 | - |
|
| 984 | - if ( $value == 'transparent' ) { |
|
| 985 | - $value = 'rgba(0,0,0,0)'; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - if ( $value == 'rgba(0,0,0,0)' ) { |
|
| 989 | - $value_text = 'transparent'; |
|
| 990 | - } else { |
|
| 991 | - $value_text = $value; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - echo "<div class='mm-picker-container'>"; |
|
| 995 | - echo " <input type='text' class='mm_colorpicker' name='toggle_blocks[{$block_id}][{$key}]' value='{$value}' />"; |
|
| 996 | - echo " <div class='chosen-color'>{$value_text}</div>"; |
|
| 997 | - echo '</div>'; |
|
| 998 | - |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * List of all available toggle DashIcon classes. |
|
| 1004 | - * |
|
| 1005 | - * @since 2.1 |
|
| 1006 | - * @return array - Sorted list of toggle classes |
|
| 1007 | - */ |
|
| 1008 | - public function toggle_icons() { |
|
| 1009 | - |
|
| 1010 | - $icons = array( |
|
| 1011 | - 'dash-f333' => 'dashicons-menu', |
|
| 1012 | - 'dash-f228' => 'dashicons-menu-alt', |
|
| 1013 | - 'dash-f329' => 'dashicons-menu-alt2', |
|
| 1014 | - 'dash-f349' => 'dashicons-menu-alt3', |
|
| 1015 | - 'dash-f214' => 'dashicons-editor-justify', |
|
| 1016 | - 'dash-f158' => 'dashicons-no', |
|
| 1017 | - 'dash-f335' => 'dashicons-no-alt', |
|
| 1018 | - 'dash-f132' => 'dashicons-plus', |
|
| 1019 | - 'dash-f502' => 'dashicons-plus-alt', |
|
| 1020 | - 'dash-f460' => 'dashicons-minus', |
|
| 1021 | - 'dash-f153' => 'dashicons-dismiss', |
|
| 1022 | - 'dash-f142' => 'dashicons-arrow-up', |
|
| 1023 | - 'dash-f140' => 'dashicons-arrow-down', |
|
| 1024 | - 'dash-f342' => 'dashicons-arrow-up-alt', |
|
| 1025 | - 'dash-f346' => 'dashicons-arrow-down-alt', |
|
| 1026 | - 'dash-f343' => 'dashicons-arrow-up-alt2', |
|
| 1027 | - 'dash-f347' => 'dashicons-arrow-down-alt2', |
|
| 1028 | - ); |
|
| 1029 | - |
|
| 1030 | - $icons = apply_filters( 'megamenu_toggle_icons', $icons ); |
|
| 1031 | - |
|
| 1032 | - return $icons; |
|
| 1033 | - |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - } |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * Print a color picker |
|
| 976 | + * |
|
| 977 | + * @since 2.1 |
|
| 978 | + * @param string $key |
|
| 979 | + * @param int $block_id |
|
| 980 | + * @param string $value |
|
| 981 | + */ |
|
| 982 | + public function print_toggle_color_option( $key, $block_id, $value ) { |
|
| 983 | + |
|
| 984 | + if ( $value == 'transparent' ) { |
|
| 985 | + $value = 'rgba(0,0,0,0)'; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + if ( $value == 'rgba(0,0,0,0)' ) { |
|
| 989 | + $value_text = 'transparent'; |
|
| 990 | + } else { |
|
| 991 | + $value_text = $value; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + echo "<div class='mm-picker-container'>"; |
|
| 995 | + echo " <input type='text' class='mm_colorpicker' name='toggle_blocks[{$block_id}][{$key}]' value='{$value}' />"; |
|
| 996 | + echo " <div class='chosen-color'>{$value_text}</div>"; |
|
| 997 | + echo '</div>'; |
|
| 998 | + |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * List of all available toggle DashIcon classes. |
|
| 1004 | + * |
|
| 1005 | + * @since 2.1 |
|
| 1006 | + * @return array - Sorted list of toggle classes |
|
| 1007 | + */ |
|
| 1008 | + public function toggle_icons() { |
|
| 1009 | + |
|
| 1010 | + $icons = array( |
|
| 1011 | + 'dash-f333' => 'dashicons-menu', |
|
| 1012 | + 'dash-f228' => 'dashicons-menu-alt', |
|
| 1013 | + 'dash-f329' => 'dashicons-menu-alt2', |
|
| 1014 | + 'dash-f349' => 'dashicons-menu-alt3', |
|
| 1015 | + 'dash-f214' => 'dashicons-editor-justify', |
|
| 1016 | + 'dash-f158' => 'dashicons-no', |
|
| 1017 | + 'dash-f335' => 'dashicons-no-alt', |
|
| 1018 | + 'dash-f132' => 'dashicons-plus', |
|
| 1019 | + 'dash-f502' => 'dashicons-plus-alt', |
|
| 1020 | + 'dash-f460' => 'dashicons-minus', |
|
| 1021 | + 'dash-f153' => 'dashicons-dismiss', |
|
| 1022 | + 'dash-f142' => 'dashicons-arrow-up', |
|
| 1023 | + 'dash-f140' => 'dashicons-arrow-down', |
|
| 1024 | + 'dash-f342' => 'dashicons-arrow-up-alt', |
|
| 1025 | + 'dash-f346' => 'dashicons-arrow-down-alt', |
|
| 1026 | + 'dash-f343' => 'dashicons-arrow-up-alt2', |
|
| 1027 | + 'dash-f347' => 'dashicons-arrow-down-alt2', |
|
| 1028 | + ); |
|
| 1029 | + |
|
| 1030 | + $icons = apply_filters( 'megamenu_toggle_icons', $icons ); |
|
| 1031 | + |
|
| 1032 | + return $icons; |
|
| 1033 | + |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + } |
|
| 1037 | 1037 | |
| 1038 | 1038 | endif; |
@@ -1,103 +1,103 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Widget' ) ) : |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Outputs a registered menu location using wp_nav_menu |
|
| 11 | - */ |
|
| 12 | - class Mega_Menu_Widget extends WP_Widget { |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Register widget with WordPress. |
|
| 16 | - */ |
|
| 17 | - public function __construct() { |
|
| 18 | - parent::__construct( |
|
| 19 | - 'maxmegamenu', // Base ID |
|
| 20 | - __( 'Max Mega Menu', 'megamenu' ), // Name |
|
| 21 | - array( 'description' => __( 'Outputs a menu for a selected theme location.', 'megamenu' ) ) // Args |
|
| 22 | - ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Front-end display of widget. |
|
| 27 | - * |
|
| 28 | - * @since 1.7.4 |
|
| 29 | - * @see WP_Widget::widget() |
|
| 30 | - * @param array $args Widget arguments. |
|
| 31 | - * @param array $instance Saved values from database. |
|
| 32 | - */ |
|
| 33 | - public function widget( $args, $instance ) { |
|
| 34 | - if ( ! is_array( $args ) ) { |
|
| 35 | - $args = array( |
|
| 36 | - 'before_widget' => '', |
|
| 37 | - 'after_widget' => '', |
|
| 38 | - ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - extract( $args ); |
|
| 42 | - |
|
| 43 | - if ( isset( $instance['location'] ) ) { |
|
| 44 | - $location = $instance['location']; |
|
| 45 | - |
|
| 46 | - $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ""; |
|
| 47 | - |
|
| 48 | - echo $before_widget; |
|
| 49 | - |
|
| 50 | - if ( ! empty( $title ) ) { |
|
| 51 | - echo $before_title . $title . $after_title; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ( has_nav_menu( $location ) ) { |
|
| 55 | - wp_nav_menu( array( 'theme_location' => $location ) ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - echo $after_widget; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Sanitize widget form values as they are saved. |
|
| 64 | - * |
|
| 65 | - * @since 1.7.4 |
|
| 66 | - * @see WP_Widget::update() |
|
| 67 | - * @param array $new_instance Values just sent to be saved. |
|
| 68 | - * @param array $old_instance Previously saved values from database. |
|
| 69 | - * @return array Updated safe values to be saved. |
|
| 70 | - */ |
|
| 71 | - public function update( $new_instance, $old_instance ) { |
|
| 72 | - $instance = array(); |
|
| 73 | - $instance['location'] = strip_tags( $new_instance['location'] ); |
|
| 74 | - $instance['title'] = strip_tags( $new_instance['title'] ); |
|
| 75 | - |
|
| 76 | - return $instance; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Back-end widget form. |
|
| 81 | - * |
|
| 82 | - * @since 1.7.4 |
|
| 83 | - * @see WP_Widget::form() |
|
| 84 | - * @param array $instance Previously saved values from database. |
|
| 85 | - */ |
|
| 86 | - public function form( $instance ) { |
|
| 87 | - |
|
| 88 | - $selected_location = 0; |
|
| 89 | - $title = ''; |
|
| 90 | - $locations = get_registered_nav_menus(); |
|
| 91 | - |
|
| 92 | - if ( isset( $instance['location'] ) ) { |
|
| 93 | - $selected_location = $instance['location']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ( isset( $instance['title'] ) ) { |
|
| 97 | - $title = $instance['title']; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - ?> |
|
| 9 | + /** |
|
| 10 | + * Outputs a registered menu location using wp_nav_menu |
|
| 11 | + */ |
|
| 12 | + class Mega_Menu_Widget extends WP_Widget { |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Register widget with WordPress. |
|
| 16 | + */ |
|
| 17 | + public function __construct() { |
|
| 18 | + parent::__construct( |
|
| 19 | + 'maxmegamenu', // Base ID |
|
| 20 | + __( 'Max Mega Menu', 'megamenu' ), // Name |
|
| 21 | + array( 'description' => __( 'Outputs a menu for a selected theme location.', 'megamenu' ) ) // Args |
|
| 22 | + ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Front-end display of widget. |
|
| 27 | + * |
|
| 28 | + * @since 1.7.4 |
|
| 29 | + * @see WP_Widget::widget() |
|
| 30 | + * @param array $args Widget arguments. |
|
| 31 | + * @param array $instance Saved values from database. |
|
| 32 | + */ |
|
| 33 | + public function widget( $args, $instance ) { |
|
| 34 | + if ( ! is_array( $args ) ) { |
|
| 35 | + $args = array( |
|
| 36 | + 'before_widget' => '', |
|
| 37 | + 'after_widget' => '', |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + extract( $args ); |
|
| 42 | + |
|
| 43 | + if ( isset( $instance['location'] ) ) { |
|
| 44 | + $location = $instance['location']; |
|
| 45 | + |
|
| 46 | + $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ""; |
|
| 47 | + |
|
| 48 | + echo $before_widget; |
|
| 49 | + |
|
| 50 | + if ( ! empty( $title ) ) { |
|
| 51 | + echo $before_title . $title . $after_title; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ( has_nav_menu( $location ) ) { |
|
| 55 | + wp_nav_menu( array( 'theme_location' => $location ) ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + echo $after_widget; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Sanitize widget form values as they are saved. |
|
| 64 | + * |
|
| 65 | + * @since 1.7.4 |
|
| 66 | + * @see WP_Widget::update() |
|
| 67 | + * @param array $new_instance Values just sent to be saved. |
|
| 68 | + * @param array $old_instance Previously saved values from database. |
|
| 69 | + * @return array Updated safe values to be saved. |
|
| 70 | + */ |
|
| 71 | + public function update( $new_instance, $old_instance ) { |
|
| 72 | + $instance = array(); |
|
| 73 | + $instance['location'] = strip_tags( $new_instance['location'] ); |
|
| 74 | + $instance['title'] = strip_tags( $new_instance['title'] ); |
|
| 75 | + |
|
| 76 | + return $instance; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Back-end widget form. |
|
| 81 | + * |
|
| 82 | + * @since 1.7.4 |
|
| 83 | + * @see WP_Widget::form() |
|
| 84 | + * @param array $instance Previously saved values from database. |
|
| 85 | + */ |
|
| 86 | + public function form( $instance ) { |
|
| 87 | + |
|
| 88 | + $selected_location = 0; |
|
| 89 | + $title = ''; |
|
| 90 | + $locations = get_registered_nav_menus(); |
|
| 91 | + |
|
| 92 | + if ( isset( $instance['location'] ) ) { |
|
| 93 | + $selected_location = $instance['location']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ( isset( $instance['title'] ) ) { |
|
| 97 | + $title = $instance['title']; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + ?> |
|
| 101 | 101 | <p> |
| 102 | 102 | <?php if ( $locations ) { ?> |
| 103 | 103 | <p> |
@@ -108,53 +108,53 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | <select id="<?php echo $this->get_field_id( 'location' ); ?>" name="<?php echo $this->get_field_name( 'location' ); ?>"> |
| 110 | 110 | <?php |
| 111 | - if ( $selected_location === 0 ) { |
|
| 112 | - echo "<option selected='true' disabled='disabled'>" . __( 'Select location', 'megamenu' ) . '</option>'; |
|
| 113 | - } |
|
| 114 | - ?> |
|
| 111 | + if ( $selected_location === 0 ) { |
|
| 112 | + echo "<option selected='true' disabled='disabled'>" . __( 'Select location', 'megamenu' ) . '</option>'; |
|
| 113 | + } |
|
| 114 | + ?> |
|
| 115 | 115 | |
| 116 | 116 | <?php |
| 117 | 117 | |
| 118 | - $enabled_locations = array(); |
|
| 119 | - $disabled_locations = array(); |
|
| 118 | + $enabled_locations = array(); |
|
| 119 | + $disabled_locations = array(); |
|
| 120 | 120 | |
| 121 | - foreach ( $locations as $location => $description ) { |
|
| 122 | - if ( max_mega_menu_is_enabled( $location ) ) { |
|
| 123 | - $enabled_locations[ $location ] = $description; |
|
| 124 | - } else { |
|
| 125 | - $disabled_locations[ $location ] = $description; |
|
| 126 | - } |
|
| 127 | - } |
|
| 121 | + foreach ( $locations as $location => $description ) { |
|
| 122 | + if ( max_mega_menu_is_enabled( $location ) ) { |
|
| 123 | + $enabled_locations[ $location ] = $description; |
|
| 124 | + } else { |
|
| 125 | + $disabled_locations[ $location ] = $description; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - if ( count( $enabled_locations ) ) { |
|
| 130 | - echo "<optgroup label='✓ " . __( 'Active locations', 'megamenu' ) . "'>"; |
|
| 129 | + if ( count( $enabled_locations ) ) { |
|
| 130 | + echo "<optgroup label='✓ " . __( 'Active locations', 'megamenu' ) . "'>"; |
|
| 131 | 131 | |
| 132 | - foreach ( $enabled_locations as $location => $description ) { |
|
| 133 | - echo "<option value='{$location}'" . selected( $location, $selected_location ) . ">{$description}</option>"; |
|
| 134 | - } |
|
| 132 | + foreach ( $enabled_locations as $location => $description ) { |
|
| 133 | + echo "<option value='{$location}'" . selected( $location, $selected_location ) . ">{$description}</option>"; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - echo '</optgroup>'; |
|
| 137 | - } |
|
| 136 | + echo '</optgroup>'; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ( count( $disabled_locations ) ) { |
|
| 140 | - echo "<optgroup label='✘ " . __( 'Inactive locations', 'megamenu' ) . "'>"; |
|
| 139 | + if ( count( $disabled_locations ) ) { |
|
| 140 | + echo "<optgroup label='✘ " . __( 'Inactive locations', 'megamenu' ) . "'>"; |
|
| 141 | 141 | |
| 142 | - foreach ( $disabled_locations as $location => $description ) { |
|
| 143 | - echo "<option value='{$location}'" . selected( $location, $selected_location ) . ">{$description}</option>"; |
|
| 144 | - } |
|
| 142 | + foreach ( $disabled_locations as $location => $description ) { |
|
| 143 | + echo "<option value='{$location}'" . selected( $location, $selected_location ) . ">{$description}</option>"; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - echo '</optgroup>'; |
|
| 147 | - } |
|
| 148 | - ?> |
|
| 146 | + echo '</optgroup>'; |
|
| 147 | + } |
|
| 148 | + ?> |
|
| 149 | 149 | </select> |
| 150 | 150 | <?php |
| 151 | - } else { |
|
| 152 | - _e( 'No menu locations found', 'megamenu' ); |
|
| 153 | - } |
|
| 154 | - ?> |
|
| 151 | + } else { |
|
| 152 | + _e( 'No menu locations found', 'megamenu' ); |
|
| 153 | + } |
|
| 154 | + ?> |
|
| 155 | 155 | </p> |
| 156 | 156 | <?php |
| 157 | - } |
|
| 158 | - } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | endif; |
@@ -1,99 +1,99 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Widget_Reusable_Block' ) ) : |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Outputs a reusable block |
|
| 11 | - * |
|
| 12 | - * Credit: Based on https://wordpress.org/plugins/block-widget/ by Maarten Menten |
|
| 13 | - */ |
|
| 14 | - class Mega_Menu_Widget_Reusable_Block extends WP_Widget { |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Register widget with WordPress. |
|
| 18 | - */ |
|
| 19 | - public function __construct() { |
|
| 20 | - parent::__construct( |
|
| 21 | - 'maxmegamenu_reusable_block', // Base ID |
|
| 22 | - 'Reusable Block', // Name |
|
| 23 | - array( 'description' => __( 'Outputs a reusable block.', 'megamenu' ) ) // Args |
|
| 24 | - ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Front-end display of widget. |
|
| 30 | - * |
|
| 31 | - * @since 2.7.4 |
|
| 32 | - * @see WP_Widget::widget() |
|
| 33 | - * @param array $args Widget arguments. |
|
| 34 | - * @param array $instance Saved values from database. |
|
| 35 | - */ |
|
| 36 | - public function widget( $args, $instance ) { |
|
| 37 | - if ( empty( $instance['block'] ) || ! get_post_type( $instance['block'] ) ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - extract( $args ); |
|
| 42 | - |
|
| 43 | - echo $before_widget; |
|
| 44 | - |
|
| 45 | - echo do_blocks( get_post_field( 'post_content', $instance['block'] ) ); |
|
| 46 | - |
|
| 47 | - echo $after_widget; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Sanitize widget form values as they are saved. |
|
| 53 | - * |
|
| 54 | - * @since 2.7.4 |
|
| 55 | - * @see WP_Widget::update() |
|
| 56 | - * @param array $new_instance Values just sent to be saved. |
|
| 57 | - * @param array $old_instance Previously saved values from database. |
|
| 58 | - * @return array Updated safe values to be saved. |
|
| 59 | - */ |
|
| 60 | - public function update( $new_instance, $old_instance ) { |
|
| 61 | - $instance = array(); |
|
| 62 | - $instance['block'] = ! empty( $new_instance['block'] ) ? $new_instance['block'] : 0; |
|
| 63 | - |
|
| 64 | - return $instance; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Back-end widget form. |
|
| 70 | - * |
|
| 71 | - * @since 2.7.4 |
|
| 72 | - * @see WP_Widget::form() |
|
| 73 | - * @param array $instance Previously saved values from database. |
|
| 74 | - */ |
|
| 75 | - public function form( $instance ) { |
|
| 76 | - $block_id = ! empty( $instance['block'] ) ? absint( $instance['block'] ) : 0; |
|
| 77 | - |
|
| 78 | - $widget_title = $block_id ? get_post_field( 'post_title', $block_id ) : ''; |
|
| 79 | - |
|
| 80 | - $posts = get_posts( |
|
| 81 | - array( |
|
| 82 | - 'post_type' => 'wp_block', |
|
| 83 | - 'post_status' => 'publish', |
|
| 84 | - 'numberposts' => -1, |
|
| 85 | - ) |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - // No blocks found. |
|
| 89 | - if ( empty( $posts ) ) { |
|
| 90 | - printf( '<p>%s</p>', __( 'No reusable blocks available.', 'megamenu' ) ); |
|
| 91 | - |
|
| 92 | - return; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Input field with id is required for WordPress to display the title in the widget header. |
|
| 96 | - ?> |
|
| 9 | + /** |
|
| 10 | + * Outputs a reusable block |
|
| 11 | + * |
|
| 12 | + * Credit: Based on https://wordpress.org/plugins/block-widget/ by Maarten Menten |
|
| 13 | + */ |
|
| 14 | + class Mega_Menu_Widget_Reusable_Block extends WP_Widget { |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Register widget with WordPress. |
|
| 18 | + */ |
|
| 19 | + public function __construct() { |
|
| 20 | + parent::__construct( |
|
| 21 | + 'maxmegamenu_reusable_block', // Base ID |
|
| 22 | + 'Reusable Block', // Name |
|
| 23 | + array( 'description' => __( 'Outputs a reusable block.', 'megamenu' ) ) // Args |
|
| 24 | + ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Front-end display of widget. |
|
| 30 | + * |
|
| 31 | + * @since 2.7.4 |
|
| 32 | + * @see WP_Widget::widget() |
|
| 33 | + * @param array $args Widget arguments. |
|
| 34 | + * @param array $instance Saved values from database. |
|
| 35 | + */ |
|
| 36 | + public function widget( $args, $instance ) { |
|
| 37 | + if ( empty( $instance['block'] ) || ! get_post_type( $instance['block'] ) ) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + extract( $args ); |
|
| 42 | + |
|
| 43 | + echo $before_widget; |
|
| 44 | + |
|
| 45 | + echo do_blocks( get_post_field( 'post_content', $instance['block'] ) ); |
|
| 46 | + |
|
| 47 | + echo $after_widget; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Sanitize widget form values as they are saved. |
|
| 53 | + * |
|
| 54 | + * @since 2.7.4 |
|
| 55 | + * @see WP_Widget::update() |
|
| 56 | + * @param array $new_instance Values just sent to be saved. |
|
| 57 | + * @param array $old_instance Previously saved values from database. |
|
| 58 | + * @return array Updated safe values to be saved. |
|
| 59 | + */ |
|
| 60 | + public function update( $new_instance, $old_instance ) { |
|
| 61 | + $instance = array(); |
|
| 62 | + $instance['block'] = ! empty( $new_instance['block'] ) ? $new_instance['block'] : 0; |
|
| 63 | + |
|
| 64 | + return $instance; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Back-end widget form. |
|
| 70 | + * |
|
| 71 | + * @since 2.7.4 |
|
| 72 | + * @see WP_Widget::form() |
|
| 73 | + * @param array $instance Previously saved values from database. |
|
| 74 | + */ |
|
| 75 | + public function form( $instance ) { |
|
| 76 | + $block_id = ! empty( $instance['block'] ) ? absint( $instance['block'] ) : 0; |
|
| 77 | + |
|
| 78 | + $widget_title = $block_id ? get_post_field( 'post_title', $block_id ) : ''; |
|
| 79 | + |
|
| 80 | + $posts = get_posts( |
|
| 81 | + array( |
|
| 82 | + 'post_type' => 'wp_block', |
|
| 83 | + 'post_status' => 'publish', |
|
| 84 | + 'numberposts' => -1, |
|
| 85 | + ) |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + // No blocks found. |
|
| 89 | + if ( empty( $posts ) ) { |
|
| 90 | + printf( '<p>%s</p>', __( 'No reusable blocks available.', 'megamenu' ) ); |
|
| 91 | + |
|
| 92 | + return; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Input field with id is required for WordPress to display the title in the widget header. |
|
| 96 | + ?> |
|
| 97 | 97 | <input type="hidden" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" value="<?php echo esc_attr( $widget_title ); ?>"> |
| 98 | 98 | |
| 99 | 99 | <p> |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | </p> |
| 108 | 108 | |
| 109 | 109 | <?php |
| 110 | - } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | endif; |
@@ -1,104 +1,104 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // disable direct access |
|
| 4 | + exit; // disable direct access |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'Mega_Menu_Widget_Elementor_Template' ) ) : |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Outputs an Elementor template |
|
| 11 | - */ |
|
| 12 | - class Mega_Menu_Widget_Elementor_Template extends WP_Widget { |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Register widget with WordPress. |
|
| 16 | - */ |
|
| 17 | - public function __construct() { |
|
| 18 | - parent::__construct( |
|
| 19 | - 'maxmegamenu_elementor_template', // Base ID |
|
| 20 | - 'Elementor Template', // Name |
|
| 21 | - array( 'description' => __( 'Outputs a saved Elementor template.', 'megamenu' ) ) // Args |
|
| 22 | - ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Front-end display of widget. |
|
| 28 | - * |
|
| 29 | - * @since 2.7.4 |
|
| 30 | - * @see WP_Widget::widget() |
|
| 31 | - * @param array $args Widget arguments. |
|
| 32 | - * @param array $instance Saved values from database. |
|
| 33 | - */ |
|
| 34 | - public function widget( $args, $instance ) { |
|
| 35 | - if ( empty( $instance['template_id'] ) || ! get_post_type( $instance['template_id'] ) ) { |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - extract( $args ); |
|
| 40 | - |
|
| 41 | - echo $before_widget; |
|
| 42 | - |
|
| 43 | - $contentElementor = ''; |
|
| 44 | - |
|
| 45 | - if ( class_exists( '\\Elementor\\Plugin' ) ) { |
|
| 46 | - $pluginElementor = \Elementor\Plugin::instance(); |
|
| 47 | - $contentElementor = $pluginElementor->frontend->get_builder_content( $instance['template_id'] ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - echo $contentElementor; |
|
| 51 | - |
|
| 52 | - echo $after_widget; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Sanitize widget form values as they are saved. |
|
| 58 | - * |
|
| 59 | - * @since 2.7.4 |
|
| 60 | - * @see WP_Widget::update() |
|
| 61 | - * @param array $new_instance Values just sent to be saved. |
|
| 62 | - * @param array $old_instance Previously saved values from database. |
|
| 63 | - * @return array Updated safe values to be saved. |
|
| 64 | - */ |
|
| 65 | - public function update( $new_instance, $old_instance ) { |
|
| 66 | - $instance = array(); |
|
| 67 | - $instance['template_id'] = ! empty( $new_instance['template_id'] ) ? $new_instance['template_id'] : 0; |
|
| 68 | - |
|
| 69 | - return $instance; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Back-end widget form. |
|
| 75 | - * |
|
| 76 | - * @since 2.7.4 |
|
| 77 | - * @see WP_Widget::form() |
|
| 78 | - * @param array $instance Previously saved values from database. |
|
| 79 | - */ |
|
| 80 | - public function form( $instance ) { |
|
| 81 | - $template_id = ! empty( $instance['template_id'] ) ? absint( $instance['template_id'] ) : 0; |
|
| 82 | - |
|
| 83 | - $widget_title = $template_id ? get_post_field( 'post_title', $template_id ) : ''; |
|
| 84 | - |
|
| 85 | - $posts = get_posts( |
|
| 86 | - array( |
|
| 87 | - 'post_type' => 'elementor_library', |
|
| 88 | - 'post_status' => 'publish', |
|
| 89 | - 'numberposts' => -1, |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // No blocks found. |
|
| 94 | - if ( empty( $posts ) ) { |
|
| 95 | - printf( '<p>%s</p>', __( 'No Elementor Templates found.', 'megamenu' ) ); |
|
| 96 | - |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Input field with id is required for WordPress to display the title in the widget header. |
|
| 101 | - ?> |
|
| 9 | + /** |
|
| 10 | + * Outputs an Elementor template |
|
| 11 | + */ |
|
| 12 | + class Mega_Menu_Widget_Elementor_Template extends WP_Widget { |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Register widget with WordPress. |
|
| 16 | + */ |
|
| 17 | + public function __construct() { |
|
| 18 | + parent::__construct( |
|
| 19 | + 'maxmegamenu_elementor_template', // Base ID |
|
| 20 | + 'Elementor Template', // Name |
|
| 21 | + array( 'description' => __( 'Outputs a saved Elementor template.', 'megamenu' ) ) // Args |
|
| 22 | + ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Front-end display of widget. |
|
| 28 | + * |
|
| 29 | + * @since 2.7.4 |
|
| 30 | + * @see WP_Widget::widget() |
|
| 31 | + * @param array $args Widget arguments. |
|
| 32 | + * @param array $instance Saved values from database. |
|
| 33 | + */ |
|
| 34 | + public function widget( $args, $instance ) { |
|
| 35 | + if ( empty( $instance['template_id'] ) || ! get_post_type( $instance['template_id'] ) ) { |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + extract( $args ); |
|
| 40 | + |
|
| 41 | + echo $before_widget; |
|
| 42 | + |
|
| 43 | + $contentElementor = ''; |
|
| 44 | + |
|
| 45 | + if ( class_exists( '\\Elementor\\Plugin' ) ) { |
|
| 46 | + $pluginElementor = \Elementor\Plugin::instance(); |
|
| 47 | + $contentElementor = $pluginElementor->frontend->get_builder_content( $instance['template_id'] ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + echo $contentElementor; |
|
| 51 | + |
|
| 52 | + echo $after_widget; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Sanitize widget form values as they are saved. |
|
| 58 | + * |
|
| 59 | + * @since 2.7.4 |
|
| 60 | + * @see WP_Widget::update() |
|
| 61 | + * @param array $new_instance Values just sent to be saved. |
|
| 62 | + * @param array $old_instance Previously saved values from database. |
|
| 63 | + * @return array Updated safe values to be saved. |
|
| 64 | + */ |
|
| 65 | + public function update( $new_instance, $old_instance ) { |
|
| 66 | + $instance = array(); |
|
| 67 | + $instance['template_id'] = ! empty( $new_instance['template_id'] ) ? $new_instance['template_id'] : 0; |
|
| 68 | + |
|
| 69 | + return $instance; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Back-end widget form. |
|
| 75 | + * |
|
| 76 | + * @since 2.7.4 |
|
| 77 | + * @see WP_Widget::form() |
|
| 78 | + * @param array $instance Previously saved values from database. |
|
| 79 | + */ |
|
| 80 | + public function form( $instance ) { |
|
| 81 | + $template_id = ! empty( $instance['template_id'] ) ? absint( $instance['template_id'] ) : 0; |
|
| 82 | + |
|
| 83 | + $widget_title = $template_id ? get_post_field( 'post_title', $template_id ) : ''; |
|
| 84 | + |
|
| 85 | + $posts = get_posts( |
|
| 86 | + array( |
|
| 87 | + 'post_type' => 'elementor_library', |
|
| 88 | + 'post_status' => 'publish', |
|
| 89 | + 'numberposts' => -1, |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // No blocks found. |
|
| 94 | + if ( empty( $posts ) ) { |
|
| 95 | + printf( '<p>%s</p>', __( 'No Elementor Templates found.', 'megamenu' ) ); |
|
| 96 | + |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Input field with id is required for WordPress to display the title in the widget header. |
|
| 101 | + ?> |
|
| 102 | 102 | <input type="hidden" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" value="<?php echo esc_attr( $widget_title ); ?>"> |
| 103 | 103 | |
| 104 | 104 | <p> |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | <?php |
| 112 | - $elementor_data = get_post_meta( $instance['template_id'], '_elementor_data' ); |
|
| 112 | + $elementor_data = get_post_meta( $instance['template_id'], '_elementor_data' ); |
|
| 113 | 113 | |
| 114 | - $type = $elementor_data['elType']; |
|
| 114 | + $type = $elementor_data['elType']; |
|
| 115 | 115 | |
| 116 | - ?> |
|
| 116 | + ?> |
|
| 117 | 117 | <option value="<?php echo esc_attr( $post->ID ); ?>"<?php selected( $post->ID, $template_id ); ?>> |
| 118 | 118 | <?php echo esc_html( $post->post_title . ' (' . $post->ID . ' - ' . get_post_meta( $post->ID, '_elementor_template_type', true ) . ')' ); ?></option> |
| 119 | 119 | <?php endforeach; ?> |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | </p> |
| 122 | 122 | |
| 123 | 123 | <?php |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | endif; |
@@ -21,1649 +21,1649 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | if ( ! defined( 'ABSPATH' ) ) { |
| 24 | - exit; // disable direct access. |
|
| 24 | + exit; // disable direct access. |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | if ( ! class_exists( 'Mega_Menu' ) ) : |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Main plugin class |
|
| 31 | - */ |
|
| 32 | - final class Mega_Menu { |
|
| 33 | - /** |
|
| 34 | - * Current plugin version |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $version = '2.9.8'; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Identify the last version where a change was made to the CSS that requires the menu CSS to be rebuilt |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - public $scss_last_updated = '2.4.1.3'; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Init |
|
| 51 | - * |
|
| 52 | - * @since 1.0 |
|
| 53 | - */ |
|
| 54 | - public static function init() { |
|
| 55 | - $plugin = new self(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Constructor |
|
| 61 | - * |
|
| 62 | - * @since 1.0 |
|
| 63 | - */ |
|
| 64 | - public function __construct() { |
|
| 65 | - $this->define_constants(); |
|
| 66 | - $this->includes(); |
|
| 67 | - |
|
| 68 | - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
| 69 | - add_action( 'init', array( $this, 'register_sidebar' ) ); |
|
| 70 | - add_action( 'admin_init', array( $this, 'install_upgrade_check' ) ); |
|
| 71 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 72 | - add_action( 'widgets_init', array( $this, 'register_widget' ) ); |
|
| 73 | - add_filter( 'in_widget_form', array( $this, 'add_notice_to_nav_menu_widget' ), 10, 3 ); |
|
| 74 | - |
|
| 75 | - add_action( 'after_setup_theme', array( $this, 'register_nav_menus' ) ); |
|
| 76 | - |
|
| 77 | - add_filter( 'wp_nav_menu_args', array( $this, 'modify_nav_menu_args' ), 99999 ); |
|
| 78 | - add_filter( 'wp_nav_menu', array( $this, 'add_responsive_toggle' ), 10, 2 ); |
|
| 79 | - |
|
| 80 | - add_filter( 'wp_nav_menu_objects', array( $this, 'add_widgets_to_menu' ), apply_filters( 'megamenu_wp_nav_menu_objects_priority', 10 ), 2 ); |
|
| 81 | - add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'apply_depth_to_menu_items' ), 5, 2 ); |
|
| 82 | - add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'setup_menu_items' ), 5, 2 ); |
|
| 83 | - add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'reorder_menu_items_within_megamenus' ), 6, 2 ); |
|
| 84 | - add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'apply_classes_to_menu_items' ), 7, 2 ); |
|
| 85 | - add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'set_descriptions_if_enabled' ), 8, 2 ); |
|
| 86 | - add_filter( 'body_class', array( $this, 'add_megamenu_body_classes' ), 10, 1 ); |
|
| 87 | - |
|
| 88 | - add_filter( 'megamenu_nav_menu_css_class', array( $this, 'prefix_menu_classes' ), 10, 3 ); |
|
| 89 | - add_filter( 'megamenu_nav_menu_css_class', array( $this, 'css_classes_never_highlight' ), 10, 3 ); |
|
| 90 | - |
|
| 91 | - // plugin compatibility. |
|
| 92 | - add_filter( 'conditional_menus_theme_location', array( $this, 'conditional_menus_restore_theme_location' ), 10, 3 ); |
|
| 93 | - add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'megamenu_blackstudio_tinymce' ) ); |
|
| 94 | - |
|
| 95 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 11 ); |
|
| 96 | - |
|
| 97 | - add_action( 'admin_print_footer_scripts-nav-menus.php', array( $this, 'admin_print_footer_scripts' ) ); |
|
| 98 | - add_action( 'admin_print_scripts-nav-menus.php', array( $this, 'admin_print_scripts' ) ); |
|
| 99 | - add_action( 'admin_print_styles-nav-menus.php', array( $this, 'admin_print_styles' ) ); |
|
| 100 | - |
|
| 101 | - add_shortcode( 'maxmenu', array( $this, 'register_shortcode' ) ); |
|
| 102 | - add_shortcode( 'maxmegamenu', array( $this, 'register_shortcode' ) ); |
|
| 103 | - |
|
| 104 | - if ( is_admin() ) { |
|
| 105 | - $admin_classes = array( |
|
| 106 | - 'Mega_Menu_Nav_Menus', |
|
| 107 | - 'Mega_Menu_Widget_Manager', |
|
| 108 | - 'Mega_Menu_Menu_Item_Manager', |
|
| 109 | - 'Mega_Menu_Page', |
|
| 110 | - 'Mega_Menu_General', |
|
| 111 | - 'Mega_Menu_Locations', |
|
| 112 | - 'Mega_Menu_Themes', |
|
| 113 | - 'Mega_Menu_Tools', |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - foreach ( $admin_classes as $class ) { |
|
| 117 | - if ( class_exists( $class ) ) { |
|
| 118 | - new $class(); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if ( class_exists( 'Mega_Menu_Toggle_Blocks' ) ) { |
|
| 124 | - new Mega_Menu_Toggle_Blocks(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if ( class_exists( 'Mega_Menu_Style_Manager' ) ) { |
|
| 128 | - $mega_menu_style_manager = new Mega_Menu_Style_Manager(); |
|
| 129 | - $mega_menu_style_manager->setup_actions(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Add a body class for each active mega menu location. |
|
| 137 | - * |
|
| 138 | - * @since 2.3 |
|
| 139 | - * @param array $classes current body classes. |
|
| 140 | - * @return array |
|
| 141 | - */ |
|
| 142 | - public function add_megamenu_body_classes( $classes ) { |
|
| 143 | - $locations = get_nav_menu_locations(); |
|
| 144 | - |
|
| 145 | - if ( count( $locations ) ) { |
|
| 146 | - foreach ( $locations as $location => $id ) { |
|
| 147 | - if ( has_nav_menu( $location ) && max_mega_menu_is_enabled( $location ) ) { |
|
| 148 | - $classes[] = 'mega-menu-' . str_replace( '_', '-', $location ); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $classes; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Add custom actions to allow enqueuing scripts on specific pages |
|
| 159 | - * |
|
| 160 | - * @since 1.8.3 |
|
| 161 | - * @param string $hook page ID. |
|
| 162 | - */ |
|
| 163 | - public function admin_enqueue_scripts( $hook ) { |
|
| 164 | - if ( ! wp_script_is( 'maxmegamenu' ) ) { |
|
| 165 | - |
|
| 166 | - if ( in_array( $hook, array( 'nav-menus.php', 'gutenberg_page_gutenberg-navigation' ), true ) ) { |
|
| 167 | - // load widget scripts and styles first to allow us to dequeue conflicting colorbox scripts from other plugins. |
|
| 168 | - do_action( 'sidebar_admin_setup' ); |
|
| 169 | - do_action( 'admin_enqueue_scripts', 'widgets.php' ); |
|
| 170 | - do_action( 'megamenu_nav_menus_scripts', $hook ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if ( strpos( $hook, 'maxmegamenu' ) !== false ) { |
|
| 174 | - do_action( 'megamenu_admin_scripts', $hook ); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 182 | - * |
|
| 183 | - * @since 2.3.7 |
|
| 184 | - * @param string $hook page ID. |
|
| 185 | - */ |
|
| 186 | - public function admin_print_footer_scripts( $hook ) { |
|
| 187 | - do_action( 'admin_footer-widgets.php' ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 193 | - * |
|
| 194 | - * @since 2.3.7 |
|
| 195 | - * @param string $hook page ID. |
|
| 196 | - */ |
|
| 197 | - public function admin_print_scripts( $hook ) { |
|
| 198 | - do_action( 'admin_print_scripts-widgets.php' ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 204 | - * |
|
| 205 | - * @since 2.3.7 |
|
| 206 | - * @param string $hook page ID. |
|
| 207 | - */ |
|
| 208 | - public function admin_print_styles( $hook ) { |
|
| 209 | - do_action( 'admin_print_styles-widgets.php' ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Register menu locations created within Max Mega Menu. |
|
| 215 | - * |
|
| 216 | - * @since 1.8 |
|
| 217 | - */ |
|
| 218 | - public function register_nav_menus() { |
|
| 219 | - |
|
| 220 | - $locations = get_option( 'megamenu_locations' ); |
|
| 221 | - |
|
| 222 | - if ( is_array( $locations ) && count( $locations ) ) { |
|
| 223 | - foreach ( $locations as $key => $val ) { |
|
| 224 | - register_nav_menu( $key, $val ); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Black Studio TinyMCE Compatibility. |
|
| 232 | - * Load TinyMCE assets on nav-menus.php page. |
|
| 233 | - * |
|
| 234 | - * @since 1.8 |
|
| 29 | + /** |
|
| 30 | + * Main plugin class |
|
| 31 | + */ |
|
| 32 | + final class Mega_Menu { |
|
| 33 | + /** |
|
| 34 | + * Current plugin version |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $version = '2.9.8'; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Identify the last version where a change was made to the CSS that requires the menu CSS to be rebuilt |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + public $scss_last_updated = '2.4.1.3'; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Init |
|
| 51 | + * |
|
| 52 | + * @since 1.0 |
|
| 53 | + */ |
|
| 54 | + public static function init() { |
|
| 55 | + $plugin = new self(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Constructor |
|
| 61 | + * |
|
| 62 | + * @since 1.0 |
|
| 63 | + */ |
|
| 64 | + public function __construct() { |
|
| 65 | + $this->define_constants(); |
|
| 66 | + $this->includes(); |
|
| 67 | + |
|
| 68 | + add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
| 69 | + add_action( 'init', array( $this, 'register_sidebar' ) ); |
|
| 70 | + add_action( 'admin_init', array( $this, 'install_upgrade_check' ) ); |
|
| 71 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 72 | + add_action( 'widgets_init', array( $this, 'register_widget' ) ); |
|
| 73 | + add_filter( 'in_widget_form', array( $this, 'add_notice_to_nav_menu_widget' ), 10, 3 ); |
|
| 74 | + |
|
| 75 | + add_action( 'after_setup_theme', array( $this, 'register_nav_menus' ) ); |
|
| 76 | + |
|
| 77 | + add_filter( 'wp_nav_menu_args', array( $this, 'modify_nav_menu_args' ), 99999 ); |
|
| 78 | + add_filter( 'wp_nav_menu', array( $this, 'add_responsive_toggle' ), 10, 2 ); |
|
| 79 | + |
|
| 80 | + add_filter( 'wp_nav_menu_objects', array( $this, 'add_widgets_to_menu' ), apply_filters( 'megamenu_wp_nav_menu_objects_priority', 10 ), 2 ); |
|
| 81 | + add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'apply_depth_to_menu_items' ), 5, 2 ); |
|
| 82 | + add_filter( 'megamenu_nav_menu_objects_before', array( $this, 'setup_menu_items' ), 5, 2 ); |
|
| 83 | + add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'reorder_menu_items_within_megamenus' ), 6, 2 ); |
|
| 84 | + add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'apply_classes_to_menu_items' ), 7, 2 ); |
|
| 85 | + add_filter( 'megamenu_nav_menu_objects_after', array( $this, 'set_descriptions_if_enabled' ), 8, 2 ); |
|
| 86 | + add_filter( 'body_class', array( $this, 'add_megamenu_body_classes' ), 10, 1 ); |
|
| 87 | + |
|
| 88 | + add_filter( 'megamenu_nav_menu_css_class', array( $this, 'prefix_menu_classes' ), 10, 3 ); |
|
| 89 | + add_filter( 'megamenu_nav_menu_css_class', array( $this, 'css_classes_never_highlight' ), 10, 3 ); |
|
| 90 | + |
|
| 91 | + // plugin compatibility. |
|
| 92 | + add_filter( 'conditional_menus_theme_location', array( $this, 'conditional_menus_restore_theme_location' ), 10, 3 ); |
|
| 93 | + add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'megamenu_blackstudio_tinymce' ) ); |
|
| 94 | + |
|
| 95 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 11 ); |
|
| 96 | + |
|
| 97 | + add_action( 'admin_print_footer_scripts-nav-menus.php', array( $this, 'admin_print_footer_scripts' ) ); |
|
| 98 | + add_action( 'admin_print_scripts-nav-menus.php', array( $this, 'admin_print_scripts' ) ); |
|
| 99 | + add_action( 'admin_print_styles-nav-menus.php', array( $this, 'admin_print_styles' ) ); |
|
| 100 | + |
|
| 101 | + add_shortcode( 'maxmenu', array( $this, 'register_shortcode' ) ); |
|
| 102 | + add_shortcode( 'maxmegamenu', array( $this, 'register_shortcode' ) ); |
|
| 103 | + |
|
| 104 | + if ( is_admin() ) { |
|
| 105 | + $admin_classes = array( |
|
| 106 | + 'Mega_Menu_Nav_Menus', |
|
| 107 | + 'Mega_Menu_Widget_Manager', |
|
| 108 | + 'Mega_Menu_Menu_Item_Manager', |
|
| 109 | + 'Mega_Menu_Page', |
|
| 110 | + 'Mega_Menu_General', |
|
| 111 | + 'Mega_Menu_Locations', |
|
| 112 | + 'Mega_Menu_Themes', |
|
| 113 | + 'Mega_Menu_Tools', |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + foreach ( $admin_classes as $class ) { |
|
| 117 | + if ( class_exists( $class ) ) { |
|
| 118 | + new $class(); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if ( class_exists( 'Mega_Menu_Toggle_Blocks' ) ) { |
|
| 124 | + new Mega_Menu_Toggle_Blocks(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if ( class_exists( 'Mega_Menu_Style_Manager' ) ) { |
|
| 128 | + $mega_menu_style_manager = new Mega_Menu_Style_Manager(); |
|
| 129 | + $mega_menu_style_manager->setup_actions(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Add a body class for each active mega menu location. |
|
| 137 | + * |
|
| 138 | + * @since 2.3 |
|
| 139 | + * @param array $classes current body classes. |
|
| 140 | + * @return array |
|
| 141 | + */ |
|
| 142 | + public function add_megamenu_body_classes( $classes ) { |
|
| 143 | + $locations = get_nav_menu_locations(); |
|
| 144 | + |
|
| 145 | + if ( count( $locations ) ) { |
|
| 146 | + foreach ( $locations as $location => $id ) { |
|
| 147 | + if ( has_nav_menu( $location ) && max_mega_menu_is_enabled( $location ) ) { |
|
| 148 | + $classes[] = 'mega-menu-' . str_replace( '_', '-', $location ); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $classes; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Add custom actions to allow enqueuing scripts on specific pages |
|
| 159 | + * |
|
| 160 | + * @since 1.8.3 |
|
| 161 | + * @param string $hook page ID. |
|
| 162 | + */ |
|
| 163 | + public function admin_enqueue_scripts( $hook ) { |
|
| 164 | + if ( ! wp_script_is( 'maxmegamenu' ) ) { |
|
| 165 | + |
|
| 166 | + if ( in_array( $hook, array( 'nav-menus.php', 'gutenberg_page_gutenberg-navigation' ), true ) ) { |
|
| 167 | + // load widget scripts and styles first to allow us to dequeue conflicting colorbox scripts from other plugins. |
|
| 168 | + do_action( 'sidebar_admin_setup' ); |
|
| 169 | + do_action( 'admin_enqueue_scripts', 'widgets.php' ); |
|
| 170 | + do_action( 'megamenu_nav_menus_scripts', $hook ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if ( strpos( $hook, 'maxmegamenu' ) !== false ) { |
|
| 174 | + do_action( 'megamenu_admin_scripts', $hook ); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 182 | + * |
|
| 183 | + * @since 2.3.7 |
|
| 184 | + * @param string $hook page ID. |
|
| 185 | + */ |
|
| 186 | + public function admin_print_footer_scripts( $hook ) { |
|
| 187 | + do_action( 'admin_footer-widgets.php' ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 193 | + * |
|
| 194 | + * @since 2.3.7 |
|
| 195 | + * @param string $hook page ID. |
|
| 196 | + */ |
|
| 197 | + public function admin_print_scripts( $hook ) { |
|
| 198 | + do_action( 'admin_print_scripts-widgets.php' ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Print the widgets.php scripts on the nav-menus.php page. Required for 4.8 Core Media Widgets. |
|
| 204 | + * |
|
| 205 | + * @since 2.3.7 |
|
| 206 | + * @param string $hook page ID. |
|
| 207 | + */ |
|
| 208 | + public function admin_print_styles( $hook ) { |
|
| 209 | + do_action( 'admin_print_styles-widgets.php' ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Register menu locations created within Max Mega Menu. |
|
| 215 | + * |
|
| 216 | + * @since 1.8 |
|
| 217 | + */ |
|
| 218 | + public function register_nav_menus() { |
|
| 219 | + |
|
| 220 | + $locations = get_option( 'megamenu_locations' ); |
|
| 221 | + |
|
| 222 | + if ( is_array( $locations ) && count( $locations ) ) { |
|
| 223 | + foreach ( $locations as $key => $val ) { |
|
| 224 | + register_nav_menu( $key, $val ); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Black Studio TinyMCE Compatibility. |
|
| 232 | + * Load TinyMCE assets on nav-menus.php page. |
|
| 233 | + * |
|
| 234 | + * @since 1.8 |
|
| 235 | 235 | . * @param array $pages Pages to load tinymce scripts on |
| 236 | - * @return array $pages |
|
| 237 | - */ |
|
| 238 | - public function megamenu_blackstudio_tinymce( $pages ) { |
|
| 239 | - $pages[] = 'nav-menus.php'; |
|
| 240 | - return $pages; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Detect new or updated installations and run actions accordingly. |
|
| 246 | - * |
|
| 247 | - * @since 1.3 |
|
| 248 | - */ |
|
| 249 | - public function install_upgrade_check() { |
|
| 250 | - $version = get_option( 'megamenu_version' ); |
|
| 251 | - |
|
| 252 | - if ( $version ) { |
|
| 253 | - |
|
| 254 | - if ( version_compare( $this->version, $version, '!=' ) ) { |
|
| 255 | - |
|
| 256 | - update_option( 'megamenu_version', $this->version ); |
|
| 257 | - |
|
| 258 | - do_action( 'megamenu_after_update' ); |
|
| 259 | - |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - |
|
| 263 | - add_option( 'megamenu_version', $this->version ); |
|
| 264 | - add_option( 'megamenu_initial_version', $this->version ); |
|
| 265 | - add_option( 'megamenu_multisite_share_themes', 'false' ); |
|
| 266 | - |
|
| 267 | - do_action( 'megamenu_after_install' ); |
|
| 268 | - |
|
| 269 | - $settings = get_option( 'megamenu_settings' ); |
|
| 270 | - |
|
| 271 | - // set defaults. |
|
| 272 | - if ( ! $settings ) { |
|
| 273 | - $settings['prefix'] = 'disabled'; |
|
| 274 | - $settings['descriptions'] = 'enabled'; |
|
| 275 | - $settings['second_click'] = 'go'; |
|
| 276 | - |
|
| 277 | - add_option( 'megamenu_settings', $settings ); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Register widget |
|
| 285 | - * |
|
| 286 | - * @since 1.7.4 |
|
| 287 | - */ |
|
| 288 | - public function register_widget() { |
|
| 289 | - if ( class_exists( 'Mega_Menu_Widget' ) ) { |
|
| 290 | - register_widget( 'Mega_Menu_Widget' ); |
|
| 291 | - } |
|
| 292 | - //register_widget( 'Mega_Menu_Widget_Reusable_Block' ); |
|
| 293 | - |
|
| 294 | - // Check if Elementor installed and activated |
|
| 295 | - //if ( did_action( 'elementor/loaded' ) ) { |
|
| 296 | - // register_widget( 'Mega_Menu_Widget_Elementor_Template' ); |
|
| 297 | - //} |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Create our own widget area to store all mega menu widgets. |
|
| 303 | - * All widgets from all menus are stored here, they are filtered later |
|
| 304 | - * to ensure the correct widgets show under the correct menu item. |
|
| 305 | - * |
|
| 306 | - * @since 1.0 |
|
| 307 | - */ |
|
| 308 | - public function register_sidebar() { |
|
| 309 | - |
|
| 310 | - register_sidebar( |
|
| 311 | - array( |
|
| 312 | - 'id' => 'mega-menu', |
|
| 313 | - 'name' => __( 'Max Mega Menu Widgets', 'megamenu' ), |
|
| 314 | - 'description' => __( 'This is where Max Mega Menu stores widgets that you have added to sub menus using the mega menu builder. You can edit existing widgets here, but new widgets must be added through the Mega Menu interface (under Appearance > Menus).', 'megamenu' ), |
|
| 315 | - ) |
|
| 316 | - ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Shortcode used to display a menu. |
|
| 322 | - * |
|
| 323 | - * @since 1.3 |
|
| 324 | - * @param array $atts shortcode attributes. |
|
| 325 | - * @return string |
|
| 326 | - */ |
|
| 327 | - public function register_shortcode( $atts ) { |
|
| 328 | - if ( ! isset( $atts['location'] ) ) { |
|
| 329 | - return false; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - if ( has_nav_menu( $atts['location'] ) ) { |
|
| 333 | - return wp_nav_menu( |
|
| 334 | - array( |
|
| 335 | - 'theme_location' => $atts['location'], |
|
| 336 | - 'echo' => false, |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return '<!-- menu not found [maxmegamenu] -->'; |
|
| 342 | - |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Initialise translations |
|
| 348 | - * |
|
| 349 | - * @since 1.0 |
|
| 350 | - */ |
|
| 351 | - public function load_plugin_textdomain() { |
|
| 352 | - load_plugin_textdomain( 'megamenu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Define Mega Menu constants |
|
| 358 | - * |
|
| 359 | - * @since 1.0 |
|
| 360 | - */ |
|
| 361 | - private function define_constants() { |
|
| 362 | - define( 'MEGAMENU_VERSION', $this->version ); |
|
| 363 | - define( 'MEGAMENU_BASE_URL', trailingslashit( plugins_url( 'megamenu' ) ) ); |
|
| 364 | - define( 'MEGAMENU_PATH', plugin_dir_path( __FILE__ ) ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * All Mega Menu classes |
|
| 370 | - * |
|
| 371 | - * @since 1.0 |
|
| 372 | - */ |
|
| 373 | - private function plugin_classes() { |
|
| 374 | - $classes = array( |
|
| 375 | - 'Mega_Menu_Walker' => MEGAMENU_PATH . 'classes/walker.class.php', |
|
| 376 | - 'Mega_Menu_Widget_Manager' => MEGAMENU_PATH . 'classes/widget-manager.class.php', |
|
| 377 | - 'Mega_Menu_Menu_item_Manager' => MEGAMENU_PATH . 'classes/menu-item-manager.class.php', |
|
| 378 | - 'Mega_Menu_Nav_Menus' => MEGAMENU_PATH . 'classes/nav-menus.class.php', |
|
| 379 | - 'Mega_Menu_Style_Manager' => MEGAMENU_PATH . 'classes/style-manager.class.php', |
|
| 380 | - 'Mega_Menu_Page' => MEGAMENU_PATH . 'classes/pages/page.php', |
|
| 381 | - 'Mega_Menu_General' => MEGAMENU_PATH . 'classes/pages/general.php', |
|
| 382 | - 'Mega_Menu_Locations' => MEGAMENU_PATH . 'classes/pages/locations.php', |
|
| 383 | - 'Mega_Menu_Themes' => MEGAMENU_PATH . 'classes/pages/themes.php', |
|
| 384 | - 'Mega_Menu_Tools' => MEGAMENU_PATH . 'classes/pages/tools.php', |
|
| 385 | - 'Mega_Menu_Widget' => MEGAMENU_PATH . 'classes/widgets/widget.class.php', |
|
| 386 | - 'Mega_Menu_Widget_Reusable_Block' => MEGAMENU_PATH . 'classes/widgets/widget-reusable-block.class.php', |
|
| 387 | - 'Mega_Menu_Widget_Elementor_Template' => MEGAMENU_PATH . 'classes/widgets/widget-elementor-template.class.php', |
|
| 388 | - 'Mega_Menu_toggle_Blocks' => MEGAMENU_PATH . 'classes/toggle-blocks.class.php', |
|
| 389 | - ); |
|
| 390 | - |
|
| 391 | - return $classes; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Load required classes |
|
| 397 | - * |
|
| 398 | - * @since 1.0 |
|
| 399 | - */ |
|
| 400 | - private function includes() { |
|
| 401 | - foreach ( $this->plugin_classes() as $id => $path ) { |
|
| 402 | - if ( is_readable( $path ) && ! class_exists( $id ) ) { |
|
| 403 | - include_once $path; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $template = get_template(); |
|
| 408 | - |
|
| 409 | - if ( 'zerif-pro' === $template ) { |
|
| 410 | - $template = 'zerif'; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - switch ( $template ) { |
|
| 414 | - case 'twentyseventeen': |
|
| 415 | - case 'zerif': |
|
| 416 | - if ( is_readable( MEGAMENU_PATH . "integration/{$template}/functions.php" ) ) { |
|
| 417 | - include_once MEGAMENU_PATH . "integration/{$template}/functions.php"; |
|
| 418 | - } |
|
| 419 | - default: |
|
| 420 | - break; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - // gutenberg block |
|
| 424 | - //include_once MEGAMENU_PATH . "integration/location/location.php"; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Appends "mega-" to all menu classes. |
|
| 430 | - * This is to help avoid theme CSS conflicts. |
|
| 431 | - * |
|
| 432 | - * @since 1.0 |
|
| 433 | - * @param array $classes classes for this menu item. |
|
| 434 | - * @param object $item The menu item object. |
|
| 435 | - * @param object $args Menu arguments. |
|
| 436 | - * @return array |
|
| 437 | - */ |
|
| 438 | - public function prefix_menu_classes( $classes, $item, $args ) { |
|
| 439 | - $return = array(); |
|
| 440 | - |
|
| 441 | - foreach ( $classes as $class ) { |
|
| 442 | - $return[] = 'mega-' . $class; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - $location = $args->theme_location; |
|
| 446 | - $settings = get_option( 'megamenu_settings' ); |
|
| 447 | - |
|
| 448 | - $prefix = isset( $settings['prefix'] ) ? $settings['prefix'] : 'enabled'; |
|
| 449 | - |
|
| 450 | - if ( isset( $settings[ $location ]['prefix'] ) ) { |
|
| 451 | - $prefix = $settings[ $location ]['prefix']; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - if ( 'disabled' === $prefix ) { |
|
| 455 | - // add in custom classes, sans 'mega-' prefix. |
|
| 456 | - foreach ( $classes as $class ) { |
|
| 457 | - |
|
| 458 | - // custom classes are added before the 'menu-item' class. |
|
| 459 | - if ( 'menu-item' === $class ) { |
|
| 460 | - break; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - if ( in_array( $class, array( 'menu-column', 'menu-row', 'hide-on-mobile', 'hide-on-desktop' ), true ) ) { // these are always prefixed. |
|
| 464 | - continue; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ( strpos( $class, 'menu-columns-' ) !== false ) { // mega-menu-columns-X-of-Y are always prefixed. |
|
| 468 | - continue; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $return[] = $class; |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - return $return; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Remove the current menu item classes when a custom class of 'never-highlight' has been added to the menu item |
|
| 480 | - * |
|
| 481 | - * @param array $classes |
|
| 482 | - * @param ovject $item |
|
| 483 | - * @param array $args |
|
| 484 | - * @return array |
|
| 485 | - */ |
|
| 486 | - public function css_classes_never_highlight( $classes, $item, $args ) { |
|
| 487 | - if ( in_array( 'mega-never-highlight', $classes ) ) { |
|
| 488 | - if ( in_array( 'mega-current-menu-ancestor', $classes ) ) { |
|
| 489 | - $classes = array_diff( $classes, array( 'mega-current-menu-ancestor' ) ); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ( in_array( 'mega-current-menu-item', $classes ) ) { |
|
| 493 | - $classes = array_diff( $classes, array( 'mega-current-menu-item' ) ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if ( in_array( 'mega-current-page-ancestor', $classes ) ) { |
|
| 497 | - $classes = array_diff( $classes, array( 'mega-current-page-ancestor' ) ); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - return $classes; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Add the html for the responsive toggle box to the menu |
|
| 507 | - * |
|
| 508 | - * @param string $nav_menu HTML markup of menu. |
|
| 509 | - * @param object $args wp_nav_menu arguments. |
|
| 510 | - * @return string |
|
| 511 | - * @since 1.3 |
|
| 512 | - */ |
|
| 513 | - public function add_responsive_toggle( $nav_menu, $args ) { |
|
| 514 | - $args = (object) $args; |
|
| 515 | - |
|
| 516 | - // make sure we're working with a Mega Menu. |
|
| 517 | - if ( ! $args->walker || ! is_a( $args->walker, 'Mega_Menu_Walker' ) ) { |
|
| 518 | - return $nav_menu; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $find = 'class="' . $args->container_class . '">'; |
|
| 522 | - |
|
| 523 | - $theme_id = mmm_get_theme_id_for_location( $args->theme_location ); |
|
| 524 | - |
|
| 525 | - $content = ''; |
|
| 526 | - |
|
| 527 | - $content = apply_filters( 'megamenu_toggle_bar_content', $content, $nav_menu, $args, $theme_id ); |
|
| 528 | - |
|
| 529 | - $replace = $find . '<div class="mega-menu-toggle">' . $content . '</div>'; |
|
| 530 | - |
|
| 531 | - return str_replace( $find, $replace, $nav_menu ); |
|
| 532 | - } |
|
| 236 | + * @return array $pages |
|
| 237 | + */ |
|
| 238 | + public function megamenu_blackstudio_tinymce( $pages ) { |
|
| 239 | + $pages[] = 'nav-menus.php'; |
|
| 240 | + return $pages; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Detect new or updated installations and run actions accordingly. |
|
| 246 | + * |
|
| 247 | + * @since 1.3 |
|
| 248 | + */ |
|
| 249 | + public function install_upgrade_check() { |
|
| 250 | + $version = get_option( 'megamenu_version' ); |
|
| 251 | + |
|
| 252 | + if ( $version ) { |
|
| 253 | + |
|
| 254 | + if ( version_compare( $this->version, $version, '!=' ) ) { |
|
| 255 | + |
|
| 256 | + update_option( 'megamenu_version', $this->version ); |
|
| 257 | + |
|
| 258 | + do_action( 'megamenu_after_update' ); |
|
| 259 | + |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + |
|
| 263 | + add_option( 'megamenu_version', $this->version ); |
|
| 264 | + add_option( 'megamenu_initial_version', $this->version ); |
|
| 265 | + add_option( 'megamenu_multisite_share_themes', 'false' ); |
|
| 266 | + |
|
| 267 | + do_action( 'megamenu_after_install' ); |
|
| 268 | + |
|
| 269 | + $settings = get_option( 'megamenu_settings' ); |
|
| 270 | + |
|
| 271 | + // set defaults. |
|
| 272 | + if ( ! $settings ) { |
|
| 273 | + $settings['prefix'] = 'disabled'; |
|
| 274 | + $settings['descriptions'] = 'enabled'; |
|
| 275 | + $settings['second_click'] = 'go'; |
|
| 276 | + |
|
| 277 | + add_option( 'megamenu_settings', $settings ); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Register widget |
|
| 285 | + * |
|
| 286 | + * @since 1.7.4 |
|
| 287 | + */ |
|
| 288 | + public function register_widget() { |
|
| 289 | + if ( class_exists( 'Mega_Menu_Widget' ) ) { |
|
| 290 | + register_widget( 'Mega_Menu_Widget' ); |
|
| 291 | + } |
|
| 292 | + //register_widget( 'Mega_Menu_Widget_Reusable_Block' ); |
|
| 293 | + |
|
| 294 | + // Check if Elementor installed and activated |
|
| 295 | + //if ( did_action( 'elementor/loaded' ) ) { |
|
| 296 | + // register_widget( 'Mega_Menu_Widget_Elementor_Template' ); |
|
| 297 | + //} |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Create our own widget area to store all mega menu widgets. |
|
| 303 | + * All widgets from all menus are stored here, they are filtered later |
|
| 304 | + * to ensure the correct widgets show under the correct menu item. |
|
| 305 | + * |
|
| 306 | + * @since 1.0 |
|
| 307 | + */ |
|
| 308 | + public function register_sidebar() { |
|
| 309 | + |
|
| 310 | + register_sidebar( |
|
| 311 | + array( |
|
| 312 | + 'id' => 'mega-menu', |
|
| 313 | + 'name' => __( 'Max Mega Menu Widgets', 'megamenu' ), |
|
| 314 | + 'description' => __( 'This is where Max Mega Menu stores widgets that you have added to sub menus using the mega menu builder. You can edit existing widgets here, but new widgets must be added through the Mega Menu interface (under Appearance > Menus).', 'megamenu' ), |
|
| 315 | + ) |
|
| 316 | + ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Shortcode used to display a menu. |
|
| 322 | + * |
|
| 323 | + * @since 1.3 |
|
| 324 | + * @param array $atts shortcode attributes. |
|
| 325 | + * @return string |
|
| 326 | + */ |
|
| 327 | + public function register_shortcode( $atts ) { |
|
| 328 | + if ( ! isset( $atts['location'] ) ) { |
|
| 329 | + return false; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + if ( has_nav_menu( $atts['location'] ) ) { |
|
| 333 | + return wp_nav_menu( |
|
| 334 | + array( |
|
| 335 | + 'theme_location' => $atts['location'], |
|
| 336 | + 'echo' => false, |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return '<!-- menu not found [maxmegamenu] -->'; |
|
| 342 | + |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Initialise translations |
|
| 348 | + * |
|
| 349 | + * @since 1.0 |
|
| 350 | + */ |
|
| 351 | + public function load_plugin_textdomain() { |
|
| 352 | + load_plugin_textdomain( 'megamenu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Define Mega Menu constants |
|
| 358 | + * |
|
| 359 | + * @since 1.0 |
|
| 360 | + */ |
|
| 361 | + private function define_constants() { |
|
| 362 | + define( 'MEGAMENU_VERSION', $this->version ); |
|
| 363 | + define( 'MEGAMENU_BASE_URL', trailingslashit( plugins_url( 'megamenu' ) ) ); |
|
| 364 | + define( 'MEGAMENU_PATH', plugin_dir_path( __FILE__ ) ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * All Mega Menu classes |
|
| 370 | + * |
|
| 371 | + * @since 1.0 |
|
| 372 | + */ |
|
| 373 | + private function plugin_classes() { |
|
| 374 | + $classes = array( |
|
| 375 | + 'Mega_Menu_Walker' => MEGAMENU_PATH . 'classes/walker.class.php', |
|
| 376 | + 'Mega_Menu_Widget_Manager' => MEGAMENU_PATH . 'classes/widget-manager.class.php', |
|
| 377 | + 'Mega_Menu_Menu_item_Manager' => MEGAMENU_PATH . 'classes/menu-item-manager.class.php', |
|
| 378 | + 'Mega_Menu_Nav_Menus' => MEGAMENU_PATH . 'classes/nav-menus.class.php', |
|
| 379 | + 'Mega_Menu_Style_Manager' => MEGAMENU_PATH . 'classes/style-manager.class.php', |
|
| 380 | + 'Mega_Menu_Page' => MEGAMENU_PATH . 'classes/pages/page.php', |
|
| 381 | + 'Mega_Menu_General' => MEGAMENU_PATH . 'classes/pages/general.php', |
|
| 382 | + 'Mega_Menu_Locations' => MEGAMENU_PATH . 'classes/pages/locations.php', |
|
| 383 | + 'Mega_Menu_Themes' => MEGAMENU_PATH . 'classes/pages/themes.php', |
|
| 384 | + 'Mega_Menu_Tools' => MEGAMENU_PATH . 'classes/pages/tools.php', |
|
| 385 | + 'Mega_Menu_Widget' => MEGAMENU_PATH . 'classes/widgets/widget.class.php', |
|
| 386 | + 'Mega_Menu_Widget_Reusable_Block' => MEGAMENU_PATH . 'classes/widgets/widget-reusable-block.class.php', |
|
| 387 | + 'Mega_Menu_Widget_Elementor_Template' => MEGAMENU_PATH . 'classes/widgets/widget-elementor-template.class.php', |
|
| 388 | + 'Mega_Menu_toggle_Blocks' => MEGAMENU_PATH . 'classes/toggle-blocks.class.php', |
|
| 389 | + ); |
|
| 390 | + |
|
| 391 | + return $classes; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Load required classes |
|
| 397 | + * |
|
| 398 | + * @since 1.0 |
|
| 399 | + */ |
|
| 400 | + private function includes() { |
|
| 401 | + foreach ( $this->plugin_classes() as $id => $path ) { |
|
| 402 | + if ( is_readable( $path ) && ! class_exists( $id ) ) { |
|
| 403 | + include_once $path; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $template = get_template(); |
|
| 408 | + |
|
| 409 | + if ( 'zerif-pro' === $template ) { |
|
| 410 | + $template = 'zerif'; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + switch ( $template ) { |
|
| 414 | + case 'twentyseventeen': |
|
| 415 | + case 'zerif': |
|
| 416 | + if ( is_readable( MEGAMENU_PATH . "integration/{$template}/functions.php" ) ) { |
|
| 417 | + include_once MEGAMENU_PATH . "integration/{$template}/functions.php"; |
|
| 418 | + } |
|
| 419 | + default: |
|
| 420 | + break; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + // gutenberg block |
|
| 424 | + //include_once MEGAMENU_PATH . "integration/location/location.php"; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Appends "mega-" to all menu classes. |
|
| 430 | + * This is to help avoid theme CSS conflicts. |
|
| 431 | + * |
|
| 432 | + * @since 1.0 |
|
| 433 | + * @param array $classes classes for this menu item. |
|
| 434 | + * @param object $item The menu item object. |
|
| 435 | + * @param object $args Menu arguments. |
|
| 436 | + * @return array |
|
| 437 | + */ |
|
| 438 | + public function prefix_menu_classes( $classes, $item, $args ) { |
|
| 439 | + $return = array(); |
|
| 440 | + |
|
| 441 | + foreach ( $classes as $class ) { |
|
| 442 | + $return[] = 'mega-' . $class; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + $location = $args->theme_location; |
|
| 446 | + $settings = get_option( 'megamenu_settings' ); |
|
| 447 | + |
|
| 448 | + $prefix = isset( $settings['prefix'] ) ? $settings['prefix'] : 'enabled'; |
|
| 449 | + |
|
| 450 | + if ( isset( $settings[ $location ]['prefix'] ) ) { |
|
| 451 | + $prefix = $settings[ $location ]['prefix']; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + if ( 'disabled' === $prefix ) { |
|
| 455 | + // add in custom classes, sans 'mega-' prefix. |
|
| 456 | + foreach ( $classes as $class ) { |
|
| 457 | + |
|
| 458 | + // custom classes are added before the 'menu-item' class. |
|
| 459 | + if ( 'menu-item' === $class ) { |
|
| 460 | + break; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + if ( in_array( $class, array( 'menu-column', 'menu-row', 'hide-on-mobile', 'hide-on-desktop' ), true ) ) { // these are always prefixed. |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ( strpos( $class, 'menu-columns-' ) !== false ) { // mega-menu-columns-X-of-Y are always prefixed. |
|
| 468 | + continue; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $return[] = $class; |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + return $return; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Remove the current menu item classes when a custom class of 'never-highlight' has been added to the menu item |
|
| 480 | + * |
|
| 481 | + * @param array $classes |
|
| 482 | + * @param ovject $item |
|
| 483 | + * @param array $args |
|
| 484 | + * @return array |
|
| 485 | + */ |
|
| 486 | + public function css_classes_never_highlight( $classes, $item, $args ) { |
|
| 487 | + if ( in_array( 'mega-never-highlight', $classes ) ) { |
|
| 488 | + if ( in_array( 'mega-current-menu-ancestor', $classes ) ) { |
|
| 489 | + $classes = array_diff( $classes, array( 'mega-current-menu-ancestor' ) ); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ( in_array( 'mega-current-menu-item', $classes ) ) { |
|
| 493 | + $classes = array_diff( $classes, array( 'mega-current-menu-item' ) ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if ( in_array( 'mega-current-page-ancestor', $classes ) ) { |
|
| 497 | + $classes = array_diff( $classes, array( 'mega-current-page-ancestor' ) ); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + return $classes; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Add the html for the responsive toggle box to the menu |
|
| 507 | + * |
|
| 508 | + * @param string $nav_menu HTML markup of menu. |
|
| 509 | + * @param object $args wp_nav_menu arguments. |
|
| 510 | + * @return string |
|
| 511 | + * @since 1.3 |
|
| 512 | + */ |
|
| 513 | + public function add_responsive_toggle( $nav_menu, $args ) { |
|
| 514 | + $args = (object) $args; |
|
| 515 | + |
|
| 516 | + // make sure we're working with a Mega Menu. |
|
| 517 | + if ( ! $args->walker || ! is_a( $args->walker, 'Mega_Menu_Walker' ) ) { |
|
| 518 | + return $nav_menu; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $find = 'class="' . $args->container_class . '">'; |
|
| 522 | + |
|
| 523 | + $theme_id = mmm_get_theme_id_for_location( $args->theme_location ); |
|
| 524 | + |
|
| 525 | + $content = ''; |
|
| 526 | + |
|
| 527 | + $content = apply_filters( 'megamenu_toggle_bar_content', $content, $nav_menu, $args, $theme_id ); |
|
| 528 | + |
|
| 529 | + $replace = $find . '<div class="mega-menu-toggle">' . $content . '</div>'; |
|
| 530 | + |
|
| 531 | + return str_replace( $find, $replace, $nav_menu ); |
|
| 532 | + } |
|
| 533 | 533 | |
| 534 | 534 | |
| 535 | - /** |
|
| 536 | - * Append the widget objects to the menu array before the |
|
| 537 | - * menu is processed by the walker. |
|
| 538 | - * |
|
| 539 | - * @since 1.0 |
|
| 540 | - * @param array $items - All menu item objects. |
|
| 541 | - * @param object $args wp_nav_menu arguments. |
|
| 542 | - * @return array - Menu objects including widgets |
|
| 543 | - */ |
|
| 544 | - public function add_widgets_to_menu( $items, $args ) { |
|
| 535 | + /** |
|
| 536 | + * Append the widget objects to the menu array before the |
|
| 537 | + * menu is processed by the walker. |
|
| 538 | + * |
|
| 539 | + * @since 1.0 |
|
| 540 | + * @param array $items - All menu item objects. |
|
| 541 | + * @param object $args wp_nav_menu arguments. |
|
| 542 | + * @return array - Menu objects including widgets |
|
| 543 | + */ |
|
| 544 | + public function add_widgets_to_menu( $items, $args ) { |
|
| 545 | 545 | |
| 546 | - $args = (object) $args; |
|
| 546 | + $args = (object) $args; |
|
| 547 | 547 | |
| 548 | - // make sure we're working with a Mega Menu. |
|
| 549 | - if ( ! $args->walker || ! is_a( $args->walker, 'Mega_Menu_Walker' ) ) { |
|
| 550 | - return $items; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $items = apply_filters( 'megamenu_nav_menu_objects_before', $items, $args ); |
|
| 554 | - |
|
| 555 | - $widget_manager = new Mega_Menu_Widget_Manager(); |
|
| 556 | - |
|
| 557 | - $rolling_dummy_id = 999999999; |
|
| 558 | - |
|
| 559 | - $items_to_move = array(); |
|
| 548 | + // make sure we're working with a Mega Menu. |
|
| 549 | + if ( ! $args->walker || ! is_a( $args->walker, 'Mega_Menu_Walker' ) ) { |
|
| 550 | + return $items; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $items = apply_filters( 'megamenu_nav_menu_objects_before', $items, $args ); |
|
| 554 | + |
|
| 555 | + $widget_manager = new Mega_Menu_Widget_Manager(); |
|
| 556 | + |
|
| 557 | + $rolling_dummy_id = 999999999; |
|
| 558 | + |
|
| 559 | + $items_to_move = array(); |
|
| 560 | 560 | |
| 561 | - foreach ( $items as $item ) { |
|
| 561 | + foreach ( $items as $item ) { |
|
| 562 | 562 | |
| 563 | - // populate standard (non-grid) sub menus. |
|
| 564 | - if ( property_exists( $item, 'depth' ) && 0 === $item->depth && 'megamenu' === $item->megamenu_settings['type'] || ( property_exists( $item, 'depth' ) && 1 === $item->depth && 'tabbed' === $item->parent_submenu_type && 'grid' !== $item->megamenu_settings['type'] ) ) { |
|
| 563 | + // populate standard (non-grid) sub menus. |
|
| 564 | + if ( property_exists( $item, 'depth' ) && 0 === $item->depth && 'megamenu' === $item->megamenu_settings['type'] || ( property_exists( $item, 'depth' ) && 1 === $item->depth && 'tabbed' === $item->parent_submenu_type && 'grid' !== $item->megamenu_settings['type'] ) ) { |
|
| 565 | 565 | |
| 566 | - $panel_widgets = $widget_manager->get_widgets_for_menu_id( $item->ID, $args->menu ); |
|
| 566 | + $panel_widgets = $widget_manager->get_widgets_for_menu_id( $item->ID, $args->menu ); |
|
| 567 | 567 | |
| 568 | - if ( ! in_array( 'menu-megamenu', $item->classes, true ) ) { |
|
| 569 | - $item->classes[] = 'menu-megamenu'; |
|
| 570 | - } |
|
| 568 | + if ( ! in_array( 'menu-megamenu', $item->classes, true ) ) { |
|
| 569 | + $item->classes[] = 'menu-megamenu'; |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - if ( count( $panel_widgets ) ) { |
|
| 572 | + if ( count( $panel_widgets ) ) { |
|
| 573 | 573 | |
| 574 | - $widget_position = 0; |
|
| 575 | - $total_widgets_in_menu = count( $panel_widgets ); |
|
| 576 | - $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items ); |
|
| 574 | + $widget_position = 0; |
|
| 575 | + $total_widgets_in_menu = count( $panel_widgets ); |
|
| 576 | + $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items ); |
|
| 577 | 577 | |
| 578 | - if ( ! in_array( 'menu-item-has-children', $item->classes, true ) ) { |
|
| 579 | - $item->classes[] = 'menu-item-has-children'; |
|
| 580 | - } |
|
| 578 | + if ( ! in_array( 'menu-item-has-children', $item->classes, true ) ) { |
|
| 579 | + $item->classes[] = 'menu-item-has-children'; |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - foreach ( $panel_widgets as $widget ) { |
|
| 583 | - $widget_settings = array_merge( |
|
| 584 | - Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 585 | - array( |
|
| 586 | - 'mega_menu_columns' => absint( $widget['columns'] ), |
|
| 587 | - ) |
|
| 588 | - ); |
|
| 582 | + foreach ( $panel_widgets as $widget ) { |
|
| 583 | + $widget_settings = array_merge( |
|
| 584 | + Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 585 | + array( |
|
| 586 | + 'mega_menu_columns' => absint( $widget['columns'] ), |
|
| 587 | + ) |
|
| 588 | + ); |
|
| 589 | 589 | |
| 590 | - $menu_item = array( |
|
| 591 | - 'type' => 'widget', |
|
| 592 | - 'parent_submenu_type' => 'megamenu', |
|
| 593 | - 'title' => $widget['id'], |
|
| 594 | - 'content' => $widget_manager->show_widget( $widget['id'] ), |
|
| 595 | - 'menu_item_parent' => $item->ID, |
|
| 596 | - 'db_id' => 0, |
|
| 597 | - 'ID' => $widget['id'], |
|
| 598 | - 'menu_order' => $next_order - $total_widgets_in_menu + $widget_position, |
|
| 599 | - 'megamenu_order' => $widget['order'], |
|
| 600 | - 'megamenu_settings' => $widget_settings, |
|
| 601 | - 'depth' => 1, |
|
| 602 | - 'classes' => array( |
|
| 603 | - 'menu-item', |
|
| 604 | - 'menu-item-type-widget', |
|
| 605 | - 'menu-widget-class-' . $widget_manager->get_widget_class( $widget['id'] ), |
|
| 606 | - ), |
|
| 607 | - ); |
|
| 590 | + $menu_item = array( |
|
| 591 | + 'type' => 'widget', |
|
| 592 | + 'parent_submenu_type' => 'megamenu', |
|
| 593 | + 'title' => $widget['id'], |
|
| 594 | + 'content' => $widget_manager->show_widget( $widget['id'] ), |
|
| 595 | + 'menu_item_parent' => $item->ID, |
|
| 596 | + 'db_id' => 0, |
|
| 597 | + 'ID' => $widget['id'], |
|
| 598 | + 'menu_order' => $next_order - $total_widgets_in_menu + $widget_position, |
|
| 599 | + 'megamenu_order' => $widget['order'], |
|
| 600 | + 'megamenu_settings' => $widget_settings, |
|
| 601 | + 'depth' => 1, |
|
| 602 | + 'classes' => array( |
|
| 603 | + 'menu-item', |
|
| 604 | + 'menu-item-type-widget', |
|
| 605 | + 'menu-widget-class-' . $widget_manager->get_widget_class( $widget['id'] ), |
|
| 606 | + ), |
|
| 607 | + ); |
|
| 608 | 608 | |
| 609 | - $items[] = (object) $menu_item; |
|
| 609 | + $items[] = (object) $menu_item; |
|
| 610 | 610 | |
| 611 | - $widget_position++; |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - } |
|
| 611 | + $widget_position++; |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - // populate grid sub menus. |
|
| 617 | - if ( property_exists( $item, 'depth' ) && 0 === $item->depth && 'grid' === $item->megamenu_settings['type'] || ( property_exists( $item, 'depth' ) && 1 === $item->depth && 'tabbed' === $item->parent_submenu_type && 'grid' === $item->megamenu_settings['type'] ) ) { |
|
| 616 | + // populate grid sub menus. |
|
| 617 | + if ( property_exists( $item, 'depth' ) && 0 === $item->depth && 'grid' === $item->megamenu_settings['type'] || ( property_exists( $item, 'depth' ) && 1 === $item->depth && 'tabbed' === $item->parent_submenu_type && 'grid' === $item->megamenu_settings['type'] ) ) { |
|
| 618 | 618 | |
| 619 | - $saved_grid = $widget_manager->get_grid_widgets_and_menu_items_for_menu_id( $item->ID, $args->menu->term_id, $items ); |
|
| 619 | + $saved_grid = $widget_manager->get_grid_widgets_and_menu_items_for_menu_id( $item->ID, $args->menu->term_id, $items ); |
|
| 620 | 620 | |
| 621 | - $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items ) - 999; |
|
| 621 | + $next_order = $this->menu_order_of_next_sibling( $item->ID, $item->menu_item_parent, $items ) - 999; |
|
| 622 | 622 | |
| 623 | - foreach ( $saved_grid as $row => $row_data ) { |
|
| 623 | + foreach ( $saved_grid as $row => $row_data ) { |
|
| 624 | 624 | |
| 625 | - $rolling_dummy_id++; |
|
| 626 | - $next_order++; |
|
| 625 | + $rolling_dummy_id++; |
|
| 626 | + $next_order++; |
|
| 627 | 627 | |
| 628 | - if ( isset( $row_data['columns'] ) ) { |
|
| 629 | - |
|
| 630 | - if ( ! in_array( 'menu-item-has-children', $item->classes, true ) ) { |
|
| 631 | - $item->classes[] = 'menu-item-has-children'; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( ! in_array( 'menu-megamenu', $item->classes, true ) ) { |
|
| 635 | - $item->classes[] = 'menu-megamenu'; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $classes = array( 'menu-row' ); |
|
| 639 | - |
|
| 640 | - if ( isset( $row_data['meta']['class'] ) ) { |
|
| 641 | - $classes = array_merge( $classes, array_unique( explode( ' ', $row_data['meta']['class'] ) ) ); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - $row_item = array( |
|
| 645 | - 'menu_item_parent' => $item->ID, |
|
| 646 | - 'type' => 'mega_row', |
|
| 647 | - 'title' => 'Custom Row', |
|
| 648 | - 'parent_submenu_type' => '', |
|
| 649 | - 'menu_order' => $next_order, |
|
| 650 | - 'depth' => 0, |
|
| 651 | - 'ID' => "{$item->ID}-{$row}", |
|
| 652 | - 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 653 | - 'db_id' => $rolling_dummy_id, |
|
| 654 | - 'classes' => $classes, |
|
| 655 | - ); |
|
| 656 | - |
|
| 657 | - $items[] = (object) $row_item; |
|
| 658 | - |
|
| 659 | - $row_dummy_id = $rolling_dummy_id; |
|
| 660 | - |
|
| 661 | - foreach ( $row_data['columns'] as $col => $col_data ) { |
|
| 662 | - |
|
| 663 | - $rolling_dummy_id++; |
|
| 664 | - $next_order++; |
|
| 665 | - |
|
| 666 | - $classes = array( 'menu-column' ); |
|
| 667 | - |
|
| 668 | - if ( isset( $col_data['meta']['class'] ) ) { |
|
| 669 | - $classes = array_merge( $classes, array_unique( explode( ' ', $col_data['meta']['class'] ) ) ); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - if ( isset( $row_data['meta']['columns'] ) ) { |
|
| 673 | - $row_columns = $row_data['meta']['columns']; |
|
| 674 | - } else { |
|
| 675 | - $row_columns = 12; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - if ( isset( $col_data['meta']['span'] ) ) { |
|
| 679 | - $classes[] = "menu-columns-{$col_data['meta']['span']}-of-{$row_columns}"; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if ( isset( $col_data['meta']['hide-on-mobile'] ) && 'true' === $col_data['meta']['hide-on-mobile'] ) { |
|
| 683 | - $classes[] = 'hide-on-mobile'; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - if ( isset( $col_data['meta']['hide-on-mobile'] ) && 'true' === $col_data['meta']['hide-on-desktop'] ) { |
|
| 687 | - $classes[] = 'hide-on-desktop'; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - $col_item = array( |
|
| 691 | - 'menu_item_parent' => $row_dummy_id, |
|
| 692 | - 'type' => 'mega_column', |
|
| 693 | - 'title' => 'Custom Column', |
|
| 694 | - 'parent_submenu_type' => '', |
|
| 695 | - 'menu_order' => $next_order, |
|
| 696 | - 'depth' => 0, |
|
| 697 | - 'ID' => "{$item->ID}-{$row}-{$col}", |
|
| 698 | - 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 699 | - 'db_id' => $rolling_dummy_id, |
|
| 700 | - 'classes' => $classes, |
|
| 701 | - ); |
|
| 702 | - |
|
| 703 | - $items[] = (object) $col_item; |
|
| 704 | - |
|
| 705 | - if ( isset( $col_data['items'] ) ) { |
|
| 706 | - |
|
| 707 | - foreach ( $col_data['items'] as $key => $block ) { |
|
| 708 | - |
|
| 709 | - $next_order++; |
|
| 710 | - |
|
| 711 | - if ( 'widget' === $block['type'] ) { |
|
| 712 | - |
|
| 713 | - $widget_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults() ); |
|
| 714 | - |
|
| 715 | - $menu_item = array( |
|
| 716 | - 'type' => 'widget', |
|
| 717 | - 'parent_submenu_type' => '', |
|
| 718 | - 'title' => $block['id'], |
|
| 719 | - 'content' => $widget_manager->show_widget( $block['id'] ), |
|
| 720 | - 'menu_item_parent' => $rolling_dummy_id, |
|
| 721 | - 'db_id' => 0, |
|
| 722 | - 'ID' => $block['id'], |
|
| 723 | - 'menu_order' => $next_order, |
|
| 724 | - 'megamenu_order' => 0, |
|
| 725 | - 'megamenu_settings' => $widget_settings, |
|
| 726 | - 'depth' => 1, |
|
| 727 | - 'classes' => array( |
|
| 728 | - 'menu-item', |
|
| 729 | - 'menu-item-type-widget', |
|
| 730 | - 'menu-widget-class-' . $widget_manager->get_widget_class( $block['id'] ), |
|
| 731 | - ), |
|
| 732 | - ); |
|
| 733 | - |
|
| 734 | - $items[] = (object) $menu_item; |
|
| 735 | - |
|
| 736 | - } else { |
|
| 737 | - // mark this menu item to be moved into a new position. |
|
| 738 | - $items_to_move[ $block['id'] ] = array( |
|
| 739 | - 'new_parent' => $rolling_dummy_id, |
|
| 740 | - 'new_order' => $next_order, |
|
| 741 | - ); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - if ( count( $items_to_move ) ) { |
|
| 752 | - foreach ( $items_to_move as $id => $new_parent ) { |
|
| 753 | - $items_to_find[] = $id; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - foreach ( $items as $item ) { |
|
| 757 | - if ( in_array( $item->ID, $items_to_find, true ) ) { |
|
| 758 | - $item->menu_item_parent = $items_to_move[ $item->ID ]['new_parent']; |
|
| 759 | - $item->menu_order = $items_to_move[ $item->ID ]['new_order']; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - $items = apply_filters( 'megamenu_nav_menu_objects_after', $items, $args ); |
|
| 765 | - |
|
| 766 | - return $items; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Return the menu order of the next sibling menu item. |
|
| 772 | - * Eg, given A as the $item_id, the menu order of D will be returned |
|
| 773 | - * Eg, given B as the $item_id, the menu order of C will be returned |
|
| 774 | - * Eg, given D as the $item_id, the menu order of D + 1000 will be returned |
|
| 775 | - * |
|
| 776 | - * - A |
|
| 777 | - * --- B |
|
| 778 | - * --- C |
|
| 779 | - * - D |
|
| 780 | - * |
|
| 781 | - * @since 2.0 |
|
| 782 | - * @param int $item_id ID of the menu item. |
|
| 783 | - * @param array $menu_item_parent ID of the parent menu item. |
|
| 784 | - * @param array $items array of all items. |
|
| 785 | - * @return int |
|
| 786 | - */ |
|
| 787 | - private function menu_order_of_next_sibling( $item_id, $menu_item_parent, $items ) { |
|
| 788 | - |
|
| 789 | - $get_order_of_next_item = false; |
|
| 790 | - |
|
| 791 | - foreach ( $items as $key => $item ) { |
|
| 792 | - |
|
| 793 | - if ( $menu_item_parent !== $item->menu_item_parent ) { |
|
| 794 | - continue; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if ( 'widget' === $item->type ) { |
|
| 798 | - continue; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - if ( $get_order_of_next_item ) { |
|
| 802 | - return $item->menu_order; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if ( $item->ID === $item_id ) { |
|
| 806 | - $get_order_of_next_item = true; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if ( isset( $item->menu_order ) ) { |
|
| 810 | - $rolling_last_menu_order = $item->menu_order; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - // there isn't a next sibling. |
|
| 815 | - return $rolling_last_menu_order + 1000; |
|
| 816 | - |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Determine if menu item is a top level item or a second level item |
|
| 822 | - * |
|
| 823 | - * @since 2.7.7 |
|
| 824 | - * @param array $items - All menu item objects. |
|
| 825 | - * @param object $args wp_nav_menu arguments. |
|
| 826 | - * @return array |
|
| 827 | - */ |
|
| 828 | - public function apply_depth_to_menu_items( $items, $args ) { |
|
| 829 | - $parents = array(); |
|
| 830 | - |
|
| 831 | - foreach ( $items as $key => $item ) { |
|
| 832 | - if ( $item->menu_item_parent == 0 ) { |
|
| 833 | - $parents[] = $item->ID; |
|
| 834 | - $item->depth = 0; |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - if ( count( $parents ) ) { |
|
| 839 | - foreach ( $items as $key => $item ) { |
|
| 840 | - if ( in_array( $item->menu_item_parent, $parents ) ) { |
|
| 841 | - $item->depth = 1; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - return $items; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Setup the mega menu settings for each menu item |
|
| 852 | - * |
|
| 853 | - * @since 2.0 |
|
| 854 | - * @param array $items - All menu item objects. |
|
| 855 | - * @param object $args wp_nav_menu arguments. |
|
| 856 | - * @return array |
|
| 857 | - */ |
|
| 858 | - public function setup_menu_items( $items, $args ) { |
|
| 859 | - |
|
| 860 | - // apply saved metadata to each menu item. |
|
| 861 | - foreach ( $items as $item ) { |
|
| 862 | - $saved_settings = array_filter( (array) get_post_meta( $item->ID, '_megamenu', true ) ); |
|
| 863 | - |
|
| 864 | - $item->megamenu_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $saved_settings ); |
|
| 865 | - $item->megamenu_order = isset( $item->megamenu_settings['mega_menu_order'][ $item->menu_item_parent ] ) ? $item->megamenu_settings['mega_menu_order'][ $item->menu_item_parent ] : 0; |
|
| 866 | - $item->parent_submenu_type = 'flyout'; |
|
| 867 | - |
|
| 868 | - if ( isset( $item->menu_order ) ) { |
|
| 869 | - $item->menu_order = $item->menu_order * 1000; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // add parent mega menu type. |
|
| 873 | - if ( property_exists( $item, 'depth' ) && absint( $item->depth ) === 1 ) { |
|
| 874 | - $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) ); |
|
| 875 | - |
|
| 876 | - if ( isset( $parent_settings['type'] ) ) { |
|
| 877 | - $item->parent_submenu_type = $parent_settings['type']; |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - return $items; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Reorder items within the mega menu. |
|
| 888 | - * |
|
| 889 | - * @since 2.0 |
|
| 890 | - * @param array $items - All menu item objects. |
|
| 891 | - * @param object $args wp_nav_menu arguments. |
|
| 892 | - * @return array |
|
| 893 | - */ |
|
| 894 | - public function reorder_menu_items_within_megamenus( $items, $args ) { |
|
| 895 | - $new_items = array(); |
|
| 896 | - |
|
| 897 | - // reorder menu items within mega menus based on internal ordering. |
|
| 898 | - foreach ( $items as $item ) { |
|
| 899 | - // items ordered with 'forced' ordering. |
|
| 900 | - if ( property_exists( $item, 'parent_submenu_type' ) && 'megamenu' === $item->parent_submenu_type && property_exists( $item, 'megamenu_order' ) && 0 !== $item->megamenu_order ) { |
|
| 901 | - if ( $parent_menu_item = get_post( $item->menu_item_parent ) ) { |
|
| 902 | - $item->menu_order = $parent_menu_item->menu_order * 1000 + $item->megamenu_order; |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - foreach ( $items as $item ) { |
|
| 908 | - if ( in_array( 'wpml-ls-item', $item->classes, true ) ) { |
|
| 909 | - $item->classes[] = 'menu-flyout'; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - $new_items[ $item->menu_order ] = $item; |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - ksort( $new_items ); |
|
| 916 | - |
|
| 917 | - return $new_items; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * If descriptions are enabled, create a new 'mega_description' property. |
|
| 923 | - * This is for backwards compatibility for users who have used filters |
|
| 924 | - * to display descriptions |
|
| 925 | - * |
|
| 926 | - * @since 2.3 |
|
| 927 | - * @param array $items All menu item objects. |
|
| 928 | - * @param object $args wp_nav_menu arguments. |
|
| 929 | - * @return array |
|
| 930 | - */ |
|
| 931 | - public function set_descriptions_if_enabled( $items, $args ) { |
|
| 932 | - |
|
| 933 | - $location = $args->theme_location; |
|
| 934 | - $settings = get_option( 'megamenu_settings' ); |
|
| 935 | - |
|
| 936 | - $descriptions = isset( $settings['descriptions'] ) ? $settings['descriptions'] : 'disabled'; |
|
| 937 | - |
|
| 938 | - if ( isset( $settings[ $location ]['descriptions'] ) ) { |
|
| 939 | - $descriptions = $settings[ $location ]['descriptions']; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - if ( 'enabled' === $descriptions ) { |
|
| 943 | - foreach ( $items as $item ) { |
|
| 944 | - if ( property_exists( $item, 'description' ) && strlen( $item->description ) ) { |
|
| 945 | - $item->mega_description = $item->description; |
|
| 946 | - $item->classes[] = 'has-description'; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return $items; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * Apply column and clear classes to menu items (inc. widgets) |
|
| 957 | - * |
|
| 958 | - * @since 2.0 |
|
| 959 | - * @param array $items All menu item objects. |
|
| 960 | - * @param object $args wp_nav_menu arguments. |
|
| 961 | - * @return array |
|
| 962 | - */ |
|
| 963 | - public function apply_classes_to_menu_items( $items, $args ) { |
|
| 964 | - $parents = array(); |
|
| 965 | - |
|
| 966 | - foreach ( $items as $item ) { |
|
| 967 | - |
|
| 968 | - if ( ! in_array( 'menu-row', $item->classes, true ) && ! in_array( 'menu-column', $item->classes, true ) ) { |
|
| 969 | - if ( property_exists( $item, 'depth' ) && 0 === $item->depth ) { |
|
| 970 | - $item->classes[] = 'align-' . $item->megamenu_settings['align']; |
|
| 971 | - $item->classes[] = 'menu-' . $item->megamenu_settings['type']; |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - if ( 'true' === $item->megamenu_settings['hide_arrow'] ) { |
|
| 975 | - $item->classes[] = 'hide-arrow'; |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - if ( 'disabled' !== $item->megamenu_settings['icon'] ) { |
|
| 979 | - $item->classes[] = 'has-icon'; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - if ( 'disabled' !== $item->megamenu_settings['icon'] && isset( $item->megamenu_settings['icon_position'] ) ) { |
|
| 983 | - $item->classes[] = 'icon-' . $item->megamenu_settings['icon_position']; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - if ( 'true' === $item->megamenu_settings['hide_text'] && 0 === $item->depth ) { |
|
| 987 | - $item->classes[] = 'hide-text'; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - if ( 'left' !== $item->megamenu_settings['item_align'] && 0 === $item->depth ) { |
|
| 991 | - $item->classes[] = 'item-align-' . $item->megamenu_settings['item_align']; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - if ( 'true' === $item->megamenu_settings['hide_on_desktop'] ) { |
|
| 995 | - $item->classes[] = 'hide-on-desktop'; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - if ( 'true' === $item->megamenu_settings['hide_on_mobile'] ) { |
|
| 999 | - $item->classes[] = 'hide-on-mobile'; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - if ( 'true' === $item->megamenu_settings['close_after_click'] ) { |
|
| 1003 | - $item->classes[] = 'close-after-click'; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - if ( 'true' === $item->megamenu_settings['hide_sub_menu_on_mobile'] ) { |
|
| 1007 | - $item->classes[] = 'hide-sub-menu-on-mobile'; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - if ( 'true' === $item->megamenu_settings['disable_link'] ) { |
|
| 1011 | - $item->classes[] = 'disable-link'; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - if ( 'true' === $item->megamenu_settings['collapse_children'] ) { |
|
| 1015 | - $item->classes[] = 'collapse-children'; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - if ( absint( $item->megamenu_settings['submenu_columns'] ) > 1 ) { |
|
| 1019 | - $item->classes[] = absint( $item->megamenu_settings['submenu_columns'] ) . '-columns'; |
|
| 1020 | - } |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - // add column classes for second level menu items displayed in mega menus. |
|
| 1024 | - if ( 'megamenu' === $item->parent_submenu_type ) { |
|
| 1025 | - |
|
| 1026 | - $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) ); |
|
| 1027 | - $parent_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $parent_settings ); |
|
| 1028 | - |
|
| 1029 | - $span = $item->megamenu_settings['mega_menu_columns']; |
|
| 628 | + if ( isset( $row_data['columns'] ) ) { |
|
| 629 | + |
|
| 630 | + if ( ! in_array( 'menu-item-has-children', $item->classes, true ) ) { |
|
| 631 | + $item->classes[] = 'menu-item-has-children'; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( ! in_array( 'menu-megamenu', $item->classes, true ) ) { |
|
| 635 | + $item->classes[] = 'menu-megamenu'; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $classes = array( 'menu-row' ); |
|
| 639 | + |
|
| 640 | + if ( isset( $row_data['meta']['class'] ) ) { |
|
| 641 | + $classes = array_merge( $classes, array_unique( explode( ' ', $row_data['meta']['class'] ) ) ); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + $row_item = array( |
|
| 645 | + 'menu_item_parent' => $item->ID, |
|
| 646 | + 'type' => 'mega_row', |
|
| 647 | + 'title' => 'Custom Row', |
|
| 648 | + 'parent_submenu_type' => '', |
|
| 649 | + 'menu_order' => $next_order, |
|
| 650 | + 'depth' => 0, |
|
| 651 | + 'ID' => "{$item->ID}-{$row}", |
|
| 652 | + 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 653 | + 'db_id' => $rolling_dummy_id, |
|
| 654 | + 'classes' => $classes, |
|
| 655 | + ); |
|
| 656 | + |
|
| 657 | + $items[] = (object) $row_item; |
|
| 658 | + |
|
| 659 | + $row_dummy_id = $rolling_dummy_id; |
|
| 660 | + |
|
| 661 | + foreach ( $row_data['columns'] as $col => $col_data ) { |
|
| 662 | + |
|
| 663 | + $rolling_dummy_id++; |
|
| 664 | + $next_order++; |
|
| 665 | + |
|
| 666 | + $classes = array( 'menu-column' ); |
|
| 667 | + |
|
| 668 | + if ( isset( $col_data['meta']['class'] ) ) { |
|
| 669 | + $classes = array_merge( $classes, array_unique( explode( ' ', $col_data['meta']['class'] ) ) ); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + if ( isset( $row_data['meta']['columns'] ) ) { |
|
| 673 | + $row_columns = $row_data['meta']['columns']; |
|
| 674 | + } else { |
|
| 675 | + $row_columns = 12; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + if ( isset( $col_data['meta']['span'] ) ) { |
|
| 679 | + $classes[] = "menu-columns-{$col_data['meta']['span']}-of-{$row_columns}"; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if ( isset( $col_data['meta']['hide-on-mobile'] ) && 'true' === $col_data['meta']['hide-on-mobile'] ) { |
|
| 683 | + $classes[] = 'hide-on-mobile'; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + if ( isset( $col_data['meta']['hide-on-mobile'] ) && 'true' === $col_data['meta']['hide-on-desktop'] ) { |
|
| 687 | + $classes[] = 'hide-on-desktop'; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + $col_item = array( |
|
| 691 | + 'menu_item_parent' => $row_dummy_id, |
|
| 692 | + 'type' => 'mega_column', |
|
| 693 | + 'title' => 'Custom Column', |
|
| 694 | + 'parent_submenu_type' => '', |
|
| 695 | + 'menu_order' => $next_order, |
|
| 696 | + 'depth' => 0, |
|
| 697 | + 'ID' => "{$item->ID}-{$row}-{$col}", |
|
| 698 | + 'megamenu_settings' => Mega_Menu_Nav_Menus::get_menu_item_defaults(), |
|
| 699 | + 'db_id' => $rolling_dummy_id, |
|
| 700 | + 'classes' => $classes, |
|
| 701 | + ); |
|
| 702 | + |
|
| 703 | + $items[] = (object) $col_item; |
|
| 704 | + |
|
| 705 | + if ( isset( $col_data['items'] ) ) { |
|
| 706 | + |
|
| 707 | + foreach ( $col_data['items'] as $key => $block ) { |
|
| 708 | + |
|
| 709 | + $next_order++; |
|
| 710 | + |
|
| 711 | + if ( 'widget' === $block['type'] ) { |
|
| 712 | + |
|
| 713 | + $widget_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults() ); |
|
| 714 | + |
|
| 715 | + $menu_item = array( |
|
| 716 | + 'type' => 'widget', |
|
| 717 | + 'parent_submenu_type' => '', |
|
| 718 | + 'title' => $block['id'], |
|
| 719 | + 'content' => $widget_manager->show_widget( $block['id'] ), |
|
| 720 | + 'menu_item_parent' => $rolling_dummy_id, |
|
| 721 | + 'db_id' => 0, |
|
| 722 | + 'ID' => $block['id'], |
|
| 723 | + 'menu_order' => $next_order, |
|
| 724 | + 'megamenu_order' => 0, |
|
| 725 | + 'megamenu_settings' => $widget_settings, |
|
| 726 | + 'depth' => 1, |
|
| 727 | + 'classes' => array( |
|
| 728 | + 'menu-item', |
|
| 729 | + 'menu-item-type-widget', |
|
| 730 | + 'menu-widget-class-' . $widget_manager->get_widget_class( $block['id'] ), |
|
| 731 | + ), |
|
| 732 | + ); |
|
| 733 | + |
|
| 734 | + $items[] = (object) $menu_item; |
|
| 735 | + |
|
| 736 | + } else { |
|
| 737 | + // mark this menu item to be moved into a new position. |
|
| 738 | + $items_to_move[ $block['id'] ] = array( |
|
| 739 | + 'new_parent' => $rolling_dummy_id, |
|
| 740 | + 'new_order' => $next_order, |
|
| 741 | + ); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + if ( count( $items_to_move ) ) { |
|
| 752 | + foreach ( $items_to_move as $id => $new_parent ) { |
|
| 753 | + $items_to_find[] = $id; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + foreach ( $items as $item ) { |
|
| 757 | + if ( in_array( $item->ID, $items_to_find, true ) ) { |
|
| 758 | + $item->menu_item_parent = $items_to_move[ $item->ID ]['new_parent']; |
|
| 759 | + $item->menu_order = $items_to_move[ $item->ID ]['new_order']; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + $items = apply_filters( 'megamenu_nav_menu_objects_after', $items, $args ); |
|
| 765 | + |
|
| 766 | + return $items; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Return the menu order of the next sibling menu item. |
|
| 772 | + * Eg, given A as the $item_id, the menu order of D will be returned |
|
| 773 | + * Eg, given B as the $item_id, the menu order of C will be returned |
|
| 774 | + * Eg, given D as the $item_id, the menu order of D + 1000 will be returned |
|
| 775 | + * |
|
| 776 | + * - A |
|
| 777 | + * --- B |
|
| 778 | + * --- C |
|
| 779 | + * - D |
|
| 780 | + * |
|
| 781 | + * @since 2.0 |
|
| 782 | + * @param int $item_id ID of the menu item. |
|
| 783 | + * @param array $menu_item_parent ID of the parent menu item. |
|
| 784 | + * @param array $items array of all items. |
|
| 785 | + * @return int |
|
| 786 | + */ |
|
| 787 | + private function menu_order_of_next_sibling( $item_id, $menu_item_parent, $items ) { |
|
| 788 | + |
|
| 789 | + $get_order_of_next_item = false; |
|
| 790 | + |
|
| 791 | + foreach ( $items as $key => $item ) { |
|
| 792 | + |
|
| 793 | + if ( $menu_item_parent !== $item->menu_item_parent ) { |
|
| 794 | + continue; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if ( 'widget' === $item->type ) { |
|
| 798 | + continue; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + if ( $get_order_of_next_item ) { |
|
| 802 | + return $item->menu_order; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if ( $item->ID === $item_id ) { |
|
| 806 | + $get_order_of_next_item = true; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if ( isset( $item->menu_order ) ) { |
|
| 810 | + $rolling_last_menu_order = $item->menu_order; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + // there isn't a next sibling. |
|
| 815 | + return $rolling_last_menu_order + 1000; |
|
| 816 | + |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Determine if menu item is a top level item or a second level item |
|
| 822 | + * |
|
| 823 | + * @since 2.7.7 |
|
| 824 | + * @param array $items - All menu item objects. |
|
| 825 | + * @param object $args wp_nav_menu arguments. |
|
| 826 | + * @return array |
|
| 827 | + */ |
|
| 828 | + public function apply_depth_to_menu_items( $items, $args ) { |
|
| 829 | + $parents = array(); |
|
| 830 | + |
|
| 831 | + foreach ( $items as $key => $item ) { |
|
| 832 | + if ( $item->menu_item_parent == 0 ) { |
|
| 833 | + $parents[] = $item->ID; |
|
| 834 | + $item->depth = 0; |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + if ( count( $parents ) ) { |
|
| 839 | + foreach ( $items as $key => $item ) { |
|
| 840 | + if ( in_array( $item->menu_item_parent, $parents ) ) { |
|
| 841 | + $item->depth = 1; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + return $items; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Setup the mega menu settings for each menu item |
|
| 852 | + * |
|
| 853 | + * @since 2.0 |
|
| 854 | + * @param array $items - All menu item objects. |
|
| 855 | + * @param object $args wp_nav_menu arguments. |
|
| 856 | + * @return array |
|
| 857 | + */ |
|
| 858 | + public function setup_menu_items( $items, $args ) { |
|
| 859 | + |
|
| 860 | + // apply saved metadata to each menu item. |
|
| 861 | + foreach ( $items as $item ) { |
|
| 862 | + $saved_settings = array_filter( (array) get_post_meta( $item->ID, '_megamenu', true ) ); |
|
| 863 | + |
|
| 864 | + $item->megamenu_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $saved_settings ); |
|
| 865 | + $item->megamenu_order = isset( $item->megamenu_settings['mega_menu_order'][ $item->menu_item_parent ] ) ? $item->megamenu_settings['mega_menu_order'][ $item->menu_item_parent ] : 0; |
|
| 866 | + $item->parent_submenu_type = 'flyout'; |
|
| 867 | + |
|
| 868 | + if ( isset( $item->menu_order ) ) { |
|
| 869 | + $item->menu_order = $item->menu_order * 1000; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // add parent mega menu type. |
|
| 873 | + if ( property_exists( $item, 'depth' ) && absint( $item->depth ) === 1 ) { |
|
| 874 | + $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) ); |
|
| 875 | + |
|
| 876 | + if ( isset( $parent_settings['type'] ) ) { |
|
| 877 | + $item->parent_submenu_type = $parent_settings['type']; |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + return $items; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Reorder items within the mega menu. |
|
| 888 | + * |
|
| 889 | + * @since 2.0 |
|
| 890 | + * @param array $items - All menu item objects. |
|
| 891 | + * @param object $args wp_nav_menu arguments. |
|
| 892 | + * @return array |
|
| 893 | + */ |
|
| 894 | + public function reorder_menu_items_within_megamenus( $items, $args ) { |
|
| 895 | + $new_items = array(); |
|
| 896 | + |
|
| 897 | + // reorder menu items within mega menus based on internal ordering. |
|
| 898 | + foreach ( $items as $item ) { |
|
| 899 | + // items ordered with 'forced' ordering. |
|
| 900 | + if ( property_exists( $item, 'parent_submenu_type' ) && 'megamenu' === $item->parent_submenu_type && property_exists( $item, 'megamenu_order' ) && 0 !== $item->megamenu_order ) { |
|
| 901 | + if ( $parent_menu_item = get_post( $item->menu_item_parent ) ) { |
|
| 902 | + $item->menu_order = $parent_menu_item->menu_order * 1000 + $item->megamenu_order; |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + foreach ( $items as $item ) { |
|
| 908 | + if ( in_array( 'wpml-ls-item', $item->classes, true ) ) { |
|
| 909 | + $item->classes[] = 'menu-flyout'; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + $new_items[ $item->menu_order ] = $item; |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + ksort( $new_items ); |
|
| 916 | + |
|
| 917 | + return $new_items; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * If descriptions are enabled, create a new 'mega_description' property. |
|
| 923 | + * This is for backwards compatibility for users who have used filters |
|
| 924 | + * to display descriptions |
|
| 925 | + * |
|
| 926 | + * @since 2.3 |
|
| 927 | + * @param array $items All menu item objects. |
|
| 928 | + * @param object $args wp_nav_menu arguments. |
|
| 929 | + * @return array |
|
| 930 | + */ |
|
| 931 | + public function set_descriptions_if_enabled( $items, $args ) { |
|
| 932 | + |
|
| 933 | + $location = $args->theme_location; |
|
| 934 | + $settings = get_option( 'megamenu_settings' ); |
|
| 935 | + |
|
| 936 | + $descriptions = isset( $settings['descriptions'] ) ? $settings['descriptions'] : 'disabled'; |
|
| 937 | + |
|
| 938 | + if ( isset( $settings[ $location ]['descriptions'] ) ) { |
|
| 939 | + $descriptions = $settings[ $location ]['descriptions']; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + if ( 'enabled' === $descriptions ) { |
|
| 943 | + foreach ( $items as $item ) { |
|
| 944 | + if ( property_exists( $item, 'description' ) && strlen( $item->description ) ) { |
|
| 945 | + $item->mega_description = $item->description; |
|
| 946 | + $item->classes[] = 'has-description'; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return $items; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * Apply column and clear classes to menu items (inc. widgets) |
|
| 957 | + * |
|
| 958 | + * @since 2.0 |
|
| 959 | + * @param array $items All menu item objects. |
|
| 960 | + * @param object $args wp_nav_menu arguments. |
|
| 961 | + * @return array |
|
| 962 | + */ |
|
| 963 | + public function apply_classes_to_menu_items( $items, $args ) { |
|
| 964 | + $parents = array(); |
|
| 965 | + |
|
| 966 | + foreach ( $items as $item ) { |
|
| 967 | + |
|
| 968 | + if ( ! in_array( 'menu-row', $item->classes, true ) && ! in_array( 'menu-column', $item->classes, true ) ) { |
|
| 969 | + if ( property_exists( $item, 'depth' ) && 0 === $item->depth ) { |
|
| 970 | + $item->classes[] = 'align-' . $item->megamenu_settings['align']; |
|
| 971 | + $item->classes[] = 'menu-' . $item->megamenu_settings['type']; |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + if ( 'true' === $item->megamenu_settings['hide_arrow'] ) { |
|
| 975 | + $item->classes[] = 'hide-arrow'; |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + if ( 'disabled' !== $item->megamenu_settings['icon'] ) { |
|
| 979 | + $item->classes[] = 'has-icon'; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + if ( 'disabled' !== $item->megamenu_settings['icon'] && isset( $item->megamenu_settings['icon_position'] ) ) { |
|
| 983 | + $item->classes[] = 'icon-' . $item->megamenu_settings['icon_position']; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + if ( 'true' === $item->megamenu_settings['hide_text'] && 0 === $item->depth ) { |
|
| 987 | + $item->classes[] = 'hide-text'; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + if ( 'left' !== $item->megamenu_settings['item_align'] && 0 === $item->depth ) { |
|
| 991 | + $item->classes[] = 'item-align-' . $item->megamenu_settings['item_align']; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + if ( 'true' === $item->megamenu_settings['hide_on_desktop'] ) { |
|
| 995 | + $item->classes[] = 'hide-on-desktop'; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + if ( 'true' === $item->megamenu_settings['hide_on_mobile'] ) { |
|
| 999 | + $item->classes[] = 'hide-on-mobile'; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + if ( 'true' === $item->megamenu_settings['close_after_click'] ) { |
|
| 1003 | + $item->classes[] = 'close-after-click'; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + if ( 'true' === $item->megamenu_settings['hide_sub_menu_on_mobile'] ) { |
|
| 1007 | + $item->classes[] = 'hide-sub-menu-on-mobile'; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + if ( 'true' === $item->megamenu_settings['disable_link'] ) { |
|
| 1011 | + $item->classes[] = 'disable-link'; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + if ( 'true' === $item->megamenu_settings['collapse_children'] ) { |
|
| 1015 | + $item->classes[] = 'collapse-children'; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + if ( absint( $item->megamenu_settings['submenu_columns'] ) > 1 ) { |
|
| 1019 | + $item->classes[] = absint( $item->megamenu_settings['submenu_columns'] ) . '-columns'; |
|
| 1020 | + } |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + // add column classes for second level menu items displayed in mega menus. |
|
| 1024 | + if ( 'megamenu' === $item->parent_submenu_type ) { |
|
| 1025 | + |
|
| 1026 | + $parent_settings = array_filter( (array) get_post_meta( $item->menu_item_parent, '_megamenu', true ) ); |
|
| 1027 | + $parent_settings = array_merge( Mega_Menu_Nav_Menus::get_menu_item_defaults(), $parent_settings ); |
|
| 1028 | + |
|
| 1029 | + $span = $item->megamenu_settings['mega_menu_columns']; |
|
| 1030 | 1030 | |
| 1031 | - $total_columns = $parent_settings['panel_columns']; |
|
| 1031 | + $total_columns = $parent_settings['panel_columns']; |
|
| 1032 | 1032 | |
| 1033 | - if ( $total_columns >= $span ) { |
|
| 1034 | - $item->classes[] = "menu-columns-{$span}-of-{$total_columns}"; |
|
| 1035 | - $column_count = $span; |
|
| 1036 | - } else { |
|
| 1037 | - $item->classes[] = "menu-columns-{$total_columns}-of-{$total_columns}"; |
|
| 1038 | - $column_count = $total_columns; |
|
| 1039 | - } |
|
| 1033 | + if ( $total_columns >= $span ) { |
|
| 1034 | + $item->classes[] = "menu-columns-{$span}-of-{$total_columns}"; |
|
| 1035 | + $column_count = $span; |
|
| 1036 | + } else { |
|
| 1037 | + $item->classes[] = "menu-columns-{$total_columns}-of-{$total_columns}"; |
|
| 1038 | + $column_count = $total_columns; |
|
| 1039 | + } |
|
| 1040 | 1040 | |
| 1041 | - if ( ! isset( $parents[ $item->menu_item_parent ] ) ) { |
|
| 1042 | - $parents[ $item->menu_item_parent ] = $column_count; |
|
| 1043 | - } else { |
|
| 1044 | - $parents[ $item->menu_item_parent ] = $parents[ $item->menu_item_parent ] + $column_count; |
|
| 1041 | + if ( ! isset( $parents[ $item->menu_item_parent ] ) ) { |
|
| 1042 | + $parents[ $item->menu_item_parent ] = $column_count; |
|
| 1043 | + } else { |
|
| 1044 | + $parents[ $item->menu_item_parent ] = $parents[ $item->menu_item_parent ] + $column_count; |
|
| 1045 | 1045 | |
| 1046 | - if ( $parents[ $item->menu_item_parent ] > $total_columns ) { |
|
| 1047 | - $parents[ $item->menu_item_parent ] = $column_count; |
|
| 1048 | - $item->classes[] = 'menu-clear'; |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1046 | + if ( $parents[ $item->menu_item_parent ] > $total_columns ) { |
|
| 1047 | + $parents[ $item->menu_item_parent ] = $column_count; |
|
| 1048 | + $item->classes[] = 'menu-clear'; |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | 1053 | |
| 1054 | - return $items; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * Use the Mega Menu walker to output the menu |
|
| 1060 | - * Resets all parameters used in the wp_nav_menu call |
|
| 1061 | - * Wraps the menu in mega-menu IDs and classes |
|
| 1062 | - * |
|
| 1063 | - * @since 1.0 |
|
| 1064 | - * @param object $args wp_nav_menu arguments. |
|
| 1065 | - * @return array |
|
| 1066 | - */ |
|
| 1067 | - public function modify_nav_menu_args( $args ) { |
|
| 1054 | + return $items; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * Use the Mega Menu walker to output the menu |
|
| 1060 | + * Resets all parameters used in the wp_nav_menu call |
|
| 1061 | + * Wraps the menu in mega-menu IDs and classes |
|
| 1062 | + * |
|
| 1063 | + * @since 1.0 |
|
| 1064 | + * @param object $args wp_nav_menu arguments. |
|
| 1065 | + * @return array |
|
| 1066 | + */ |
|
| 1067 | + public function modify_nav_menu_args( $args ) { |
|
| 1068 | 1068 | |
| 1069 | - if ( ! isset( $args['theme_location'] ) ) { |
|
| 1070 | - return $args; |
|
| 1071 | - } |
|
| 1069 | + if ( ! isset( $args['theme_location'] ) ) { |
|
| 1070 | + return $args; |
|
| 1071 | + } |
|
| 1072 | 1072 | |
| 1073 | - // internal action to use as a counter. |
|
| 1074 | - do_action( 'megamenu_instance_counter_' . $args['theme_location'] ); |
|
| 1073 | + // internal action to use as a counter. |
|
| 1074 | + do_action( 'megamenu_instance_counter_' . $args['theme_location'] ); |
|
| 1075 | 1075 | |
| 1076 | - $num_times_called = did_action( 'megamenu_instance_counter_' . $args['theme_location'] ); |
|
| 1076 | + $num_times_called = did_action( 'megamenu_instance_counter_' . $args['theme_location'] ); |
|
| 1077 | 1077 | |
| 1078 | - $settings = get_option( 'megamenu_settings' ); |
|
| 1079 | - $current_theme_location = $args['theme_location']; |
|
| 1078 | + $settings = get_option( 'megamenu_settings' ); |
|
| 1079 | + $current_theme_location = $args['theme_location']; |
|
| 1080 | 1080 | |
| 1081 | - $active_instance = 0; |
|
| 1081 | + $active_instance = 0; |
|
| 1082 | 1082 | |
| 1083 | - if ( isset( $settings[ $current_theme_location ]['active_instance'] ) ) { |
|
| 1084 | - $active_instance = $settings[ $current_theme_location ]['active_instance']; |
|
| 1085 | - } elseif ( isset( $settings['instances'][ $current_theme_location ] ) ) { |
|
| 1086 | - $active_instance = $settings['instances'][ $current_theme_location ]; |
|
| 1087 | - } |
|
| 1083 | + if ( isset( $settings[ $current_theme_location ]['active_instance'] ) ) { |
|
| 1084 | + $active_instance = $settings[ $current_theme_location ]['active_instance']; |
|
| 1085 | + } elseif ( isset( $settings['instances'][ $current_theme_location ] ) ) { |
|
| 1086 | + $active_instance = $settings['instances'][ $current_theme_location ]; |
|
| 1087 | + } |
|
| 1088 | 1088 | |
| 1089 | - if ( $active_instance != '0' && strlen( $active_instance ) ) { |
|
| 1090 | - if ( strpos( $active_instance, ',' ) || is_numeric( $active_instance ) ) { |
|
| 1091 | - $active_instances = explode( ',', $active_instance ); |
|
| 1089 | + if ( $active_instance != '0' && strlen( $active_instance ) ) { |
|
| 1090 | + if ( strpos( $active_instance, ',' ) || is_numeric( $active_instance ) ) { |
|
| 1091 | + $active_instances = explode( ',', $active_instance ); |
|
| 1092 | 1092 | |
| 1093 | - if ( ! in_array( $num_times_called, $active_instances ) ) { |
|
| 1094 | - return $args; |
|
| 1095 | - } |
|
| 1096 | - } else if ( isset( $args['container_id'] ) && $active_instance != $args['container_id'] ) { |
|
| 1097 | - return $args; |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1093 | + if ( ! in_array( $num_times_called, $active_instances ) ) { |
|
| 1094 | + return $args; |
|
| 1095 | + } |
|
| 1096 | + } else if ( isset( $args['container_id'] ) && $active_instance != $args['container_id'] ) { |
|
| 1097 | + return $args; |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | 1100 | |
| 1101 | - $locations = get_nav_menu_locations(); |
|
| 1101 | + $locations = get_nav_menu_locations(); |
|
| 1102 | 1102 | |
| 1103 | - if ( isset( $settings[ $current_theme_location ]['enabled'] ) && true === boolval( $settings[ $current_theme_location ]['enabled'] ) ) { |
|
| 1103 | + if ( isset( $settings[ $current_theme_location ]['enabled'] ) && true === boolval( $settings[ $current_theme_location ]['enabled'] ) ) { |
|
| 1104 | 1104 | |
| 1105 | - if ( ! isset( $locations[ $current_theme_location ] ) ) { |
|
| 1106 | - return $args; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - $menu_id = $locations[ $current_theme_location ]; |
|
| 1110 | - |
|
| 1111 | - if ( ! $menu_id ) { |
|
| 1112 | - return $args; |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - $menu_theme = mmm_get_theme_for_location( $current_theme_location ); |
|
| 1116 | - $menu_settings = $settings[ $current_theme_location ]; |
|
| 1117 | - |
|
| 1118 | - $effect = isset( $menu_settings['effect'] ) ? $menu_settings['effect'] : 'disabled'; |
|
| 1119 | - |
|
| 1120 | - // as set on the main settings page. |
|
| 1121 | - $vertical_behaviour = isset( $settings['mobile_behaviour'] ) ? $settings['mobile_behaviour'] : 'standard'; |
|
| 1122 | - |
|
| 1123 | - if ( isset( $menu_settings['mobile_behaviour'] ) ) { |
|
| 1124 | - $vertical_behaviour = $menu_settings['mobile_behaviour']; |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - // as set on the main settings page. |
|
| 1128 | - $second_click = isset( $settings['second_click'] ) ? $settings['second_click'] : 'go'; |
|
| 1129 | - |
|
| 1130 | - if ( isset( $menu_settings['second_click'] ) ) { |
|
| 1131 | - $second_click = $menu_settings['second_click']; |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - $unbind = isset( $settings['unbind'] ) ? $settings['unbind'] : 'enabled'; |
|
| 1135 | - |
|
| 1136 | - if ( isset( $menu_settings['unbind'] ) ) { |
|
| 1137 | - $unbind = $menu_settings['unbind']; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - $event = 'hover_intent'; |
|
| 1141 | - |
|
| 1142 | - if ( isset( $menu_settings['event'] ) ) { |
|
| 1143 | - if ( 'hover' === $menu_settings['event'] ) { |
|
| 1144 | - $event = 'hover_intent'; |
|
| 1145 | - } elseif ( 'hover_' === $menu_settings['event'] ) { |
|
| 1146 | - $event = 'hover'; |
|
| 1147 | - } else { |
|
| 1148 | - $event = $menu_settings['event']; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - $mobile_force_width = 'false'; |
|
| 1153 | - |
|
| 1154 | - if ( isset( $menu_theme['mobile_menu_force_width'] ) && 'on' === $menu_theme['mobile_menu_force_width'] ) { |
|
| 1155 | - if ( isset( $menu_theme['mobile_menu_force_width_selector'] ) ) { |
|
| 1156 | - $mobile_force_width = $menu_theme['mobile_menu_force_width_selector']; |
|
| 1157 | - } else { |
|
| 1158 | - $mobile_force_width = 'body'; |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - $effect_mobile = 'disabled'; |
|
| 1163 | - |
|
| 1164 | - if ( isset( $menu_settings['effect_mobile'] ) ) { |
|
| 1165 | - $effect_mobile = $menu_settings['effect_mobile']; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $effect_speed_mobile = 200; |
|
| 1169 | - |
|
| 1170 | - if ( isset( $menu_settings['effect_speed_mobile'] ) ) { |
|
| 1171 | - $effect_speed_mobile = $menu_settings['effect_speed_mobile']; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - $container = 'div'; |
|
| 1175 | - |
|
| 1176 | - if ( isset( $menu_settings['container'] ) ) { |
|
| 1177 | - $container = $menu_settings['container']; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - if ( 'disabled' === $effect_mobile ) { |
|
| 1181 | - $effect_speed_mobile = 0; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - $mobile_state = 'collapse_all'; |
|
| 1185 | - |
|
| 1186 | - if ( isset( $menu_settings['mobile_state'] ) ) { |
|
| 1187 | - $mobile_state = $menu_settings['mobile_state']; |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - $hover_intent_params = apply_filters( |
|
| 1191 | - 'megamenu_javascript_localisation', // backwards compatiblity. |
|
| 1192 | - array( |
|
| 1193 | - 'timeout' => 300, |
|
| 1194 | - 'interval' => 100, |
|
| 1195 | - ) |
|
| 1196 | - ); |
|
| 1197 | - |
|
| 1198 | - $wrap_attributes = apply_filters( |
|
| 1199 | - 'megamenu_wrap_attributes', |
|
| 1200 | - array( |
|
| 1201 | - 'id' => '%1$s', |
|
| 1202 | - 'class' => '%2$s mega-no-js', |
|
| 1203 | - 'data-event' => $event, |
|
| 1204 | - 'data-effect' => $effect, |
|
| 1205 | - 'data-effect-speed' => isset( $menu_settings['effect_speed'] ) ? $menu_settings['effect_speed'] : '200', |
|
| 1206 | - 'data-effect-mobile' => $effect_mobile, |
|
| 1207 | - 'data-effect-speed-mobile' => $effect_speed_mobile, |
|
| 1208 | - 'data-panel-width' => preg_match( '/^\d/', $menu_theme['panel_width'] ) !== 1 ? $menu_theme['panel_width'] : '', |
|
| 1209 | - 'data-panel-inner-width' => substr( trim( $menu_theme['panel_inner_width'] ), -1 ) !== '%' ? $menu_theme['panel_inner_width'] : '', |
|
| 1210 | - 'data-mobile-force-width' => $mobile_force_width, |
|
| 1211 | - 'data-second-click' => $second_click, |
|
| 1212 | - 'data-document-click' => 'collapse', |
|
| 1213 | - 'data-vertical-behaviour' => $vertical_behaviour, |
|
| 1214 | - 'data-breakpoint' => absint( $menu_theme['responsive_breakpoint'] ), |
|
| 1215 | - 'data-unbind' => 'disabled' === $unbind ? 'false' : 'true', |
|
| 1216 | - 'data-mobile-state' => $mobile_state, |
|
| 1217 | - 'data-hover-intent-timeout' => absint( $hover_intent_params['timeout'] ), |
|
| 1218 | - 'data-hover-intent-interval' => absint( $hover_intent_params['interval'] ), |
|
| 1219 | - ), |
|
| 1220 | - $menu_id, |
|
| 1221 | - $menu_settings, |
|
| 1222 | - $settings, |
|
| 1223 | - $current_theme_location |
|
| 1224 | - ); |
|
| 1225 | - |
|
| 1226 | - $attributes = ''; |
|
| 1227 | - |
|
| 1228 | - foreach ( $wrap_attributes as $attribute => $value ) { |
|
| 1229 | - if ( strlen( $value ) ) { |
|
| 1230 | - $attributes .= ' ' . $attribute . '="' . esc_attr( $value ) . '"'; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - $sanitized_location = str_replace( apply_filters( 'megamenu_location_replacements', array( '-', ' ' ) ), '-', $current_theme_location ); |
|
| 1235 | - |
|
| 1236 | - $defaults = array( |
|
| 1237 | - 'menu' => wp_get_nav_menu_object( $menu_id ), |
|
| 1238 | - 'container' => $container, |
|
| 1239 | - 'container_class' => 'mega-menu-wrap', |
|
| 1240 | - 'container_id' => 'mega-menu-wrap-' . $sanitized_location, |
|
| 1241 | - 'menu_class' => 'mega-menu max-mega-menu mega-menu-horizontal', |
|
| 1242 | - 'menu_id' => 'mega-menu-' . $sanitized_location, |
|
| 1243 | - 'fallback_cb' => 'wp_page_menu', |
|
| 1244 | - 'before' => '', |
|
| 1245 | - 'after' => '', |
|
| 1246 | - 'link_before' => '', |
|
| 1247 | - 'link_after' => '', |
|
| 1248 | - 'items_wrap' => '<ul' . $attributes . '>%3$s</ul>', |
|
| 1249 | - 'depth' => 0, |
|
| 1250 | - 'walker' => new Mega_Menu_Walker(), |
|
| 1251 | - ); |
|
| 1252 | - |
|
| 1253 | - $args = array_merge( $args, apply_filters( 'megamenu_nav_menu_args', $defaults, $menu_id, $current_theme_location ) ); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - return $args; |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * Display admin notices. |
|
| 1262 | - */ |
|
| 1263 | - public function admin_notices() { |
|
| 1264 | - |
|
| 1265 | - if ( ! $this->is_compatible_wordpress_version() ) : |
|
| 1266 | - |
|
| 1267 | - ?> |
|
| 1105 | + if ( ! isset( $locations[ $current_theme_location ] ) ) { |
|
| 1106 | + return $args; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + $menu_id = $locations[ $current_theme_location ]; |
|
| 1110 | + |
|
| 1111 | + if ( ! $menu_id ) { |
|
| 1112 | + return $args; |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + $menu_theme = mmm_get_theme_for_location( $current_theme_location ); |
|
| 1116 | + $menu_settings = $settings[ $current_theme_location ]; |
|
| 1117 | + |
|
| 1118 | + $effect = isset( $menu_settings['effect'] ) ? $menu_settings['effect'] : 'disabled'; |
|
| 1119 | + |
|
| 1120 | + // as set on the main settings page. |
|
| 1121 | + $vertical_behaviour = isset( $settings['mobile_behaviour'] ) ? $settings['mobile_behaviour'] : 'standard'; |
|
| 1122 | + |
|
| 1123 | + if ( isset( $menu_settings['mobile_behaviour'] ) ) { |
|
| 1124 | + $vertical_behaviour = $menu_settings['mobile_behaviour']; |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + // as set on the main settings page. |
|
| 1128 | + $second_click = isset( $settings['second_click'] ) ? $settings['second_click'] : 'go'; |
|
| 1129 | + |
|
| 1130 | + if ( isset( $menu_settings['second_click'] ) ) { |
|
| 1131 | + $second_click = $menu_settings['second_click']; |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + $unbind = isset( $settings['unbind'] ) ? $settings['unbind'] : 'enabled'; |
|
| 1135 | + |
|
| 1136 | + if ( isset( $menu_settings['unbind'] ) ) { |
|
| 1137 | + $unbind = $menu_settings['unbind']; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + $event = 'hover_intent'; |
|
| 1141 | + |
|
| 1142 | + if ( isset( $menu_settings['event'] ) ) { |
|
| 1143 | + if ( 'hover' === $menu_settings['event'] ) { |
|
| 1144 | + $event = 'hover_intent'; |
|
| 1145 | + } elseif ( 'hover_' === $menu_settings['event'] ) { |
|
| 1146 | + $event = 'hover'; |
|
| 1147 | + } else { |
|
| 1148 | + $event = $menu_settings['event']; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + $mobile_force_width = 'false'; |
|
| 1153 | + |
|
| 1154 | + if ( isset( $menu_theme['mobile_menu_force_width'] ) && 'on' === $menu_theme['mobile_menu_force_width'] ) { |
|
| 1155 | + if ( isset( $menu_theme['mobile_menu_force_width_selector'] ) ) { |
|
| 1156 | + $mobile_force_width = $menu_theme['mobile_menu_force_width_selector']; |
|
| 1157 | + } else { |
|
| 1158 | + $mobile_force_width = 'body'; |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + $effect_mobile = 'disabled'; |
|
| 1163 | + |
|
| 1164 | + if ( isset( $menu_settings['effect_mobile'] ) ) { |
|
| 1165 | + $effect_mobile = $menu_settings['effect_mobile']; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $effect_speed_mobile = 200; |
|
| 1169 | + |
|
| 1170 | + if ( isset( $menu_settings['effect_speed_mobile'] ) ) { |
|
| 1171 | + $effect_speed_mobile = $menu_settings['effect_speed_mobile']; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + $container = 'div'; |
|
| 1175 | + |
|
| 1176 | + if ( isset( $menu_settings['container'] ) ) { |
|
| 1177 | + $container = $menu_settings['container']; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + if ( 'disabled' === $effect_mobile ) { |
|
| 1181 | + $effect_speed_mobile = 0; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + $mobile_state = 'collapse_all'; |
|
| 1185 | + |
|
| 1186 | + if ( isset( $menu_settings['mobile_state'] ) ) { |
|
| 1187 | + $mobile_state = $menu_settings['mobile_state']; |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + $hover_intent_params = apply_filters( |
|
| 1191 | + 'megamenu_javascript_localisation', // backwards compatiblity. |
|
| 1192 | + array( |
|
| 1193 | + 'timeout' => 300, |
|
| 1194 | + 'interval' => 100, |
|
| 1195 | + ) |
|
| 1196 | + ); |
|
| 1197 | + |
|
| 1198 | + $wrap_attributes = apply_filters( |
|
| 1199 | + 'megamenu_wrap_attributes', |
|
| 1200 | + array( |
|
| 1201 | + 'id' => '%1$s', |
|
| 1202 | + 'class' => '%2$s mega-no-js', |
|
| 1203 | + 'data-event' => $event, |
|
| 1204 | + 'data-effect' => $effect, |
|
| 1205 | + 'data-effect-speed' => isset( $menu_settings['effect_speed'] ) ? $menu_settings['effect_speed'] : '200', |
|
| 1206 | + 'data-effect-mobile' => $effect_mobile, |
|
| 1207 | + 'data-effect-speed-mobile' => $effect_speed_mobile, |
|
| 1208 | + 'data-panel-width' => preg_match( '/^\d/', $menu_theme['panel_width'] ) !== 1 ? $menu_theme['panel_width'] : '', |
|
| 1209 | + 'data-panel-inner-width' => substr( trim( $menu_theme['panel_inner_width'] ), -1 ) !== '%' ? $menu_theme['panel_inner_width'] : '', |
|
| 1210 | + 'data-mobile-force-width' => $mobile_force_width, |
|
| 1211 | + 'data-second-click' => $second_click, |
|
| 1212 | + 'data-document-click' => 'collapse', |
|
| 1213 | + 'data-vertical-behaviour' => $vertical_behaviour, |
|
| 1214 | + 'data-breakpoint' => absint( $menu_theme['responsive_breakpoint'] ), |
|
| 1215 | + 'data-unbind' => 'disabled' === $unbind ? 'false' : 'true', |
|
| 1216 | + 'data-mobile-state' => $mobile_state, |
|
| 1217 | + 'data-hover-intent-timeout' => absint( $hover_intent_params['timeout'] ), |
|
| 1218 | + 'data-hover-intent-interval' => absint( $hover_intent_params['interval'] ), |
|
| 1219 | + ), |
|
| 1220 | + $menu_id, |
|
| 1221 | + $menu_settings, |
|
| 1222 | + $settings, |
|
| 1223 | + $current_theme_location |
|
| 1224 | + ); |
|
| 1225 | + |
|
| 1226 | + $attributes = ''; |
|
| 1227 | + |
|
| 1228 | + foreach ( $wrap_attributes as $attribute => $value ) { |
|
| 1229 | + if ( strlen( $value ) ) { |
|
| 1230 | + $attributes .= ' ' . $attribute . '="' . esc_attr( $value ) . '"'; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + $sanitized_location = str_replace( apply_filters( 'megamenu_location_replacements', array( '-', ' ' ) ), '-', $current_theme_location ); |
|
| 1235 | + |
|
| 1236 | + $defaults = array( |
|
| 1237 | + 'menu' => wp_get_nav_menu_object( $menu_id ), |
|
| 1238 | + 'container' => $container, |
|
| 1239 | + 'container_class' => 'mega-menu-wrap', |
|
| 1240 | + 'container_id' => 'mega-menu-wrap-' . $sanitized_location, |
|
| 1241 | + 'menu_class' => 'mega-menu max-mega-menu mega-menu-horizontal', |
|
| 1242 | + 'menu_id' => 'mega-menu-' . $sanitized_location, |
|
| 1243 | + 'fallback_cb' => 'wp_page_menu', |
|
| 1244 | + 'before' => '', |
|
| 1245 | + 'after' => '', |
|
| 1246 | + 'link_before' => '', |
|
| 1247 | + 'link_after' => '', |
|
| 1248 | + 'items_wrap' => '<ul' . $attributes . '>%3$s</ul>', |
|
| 1249 | + 'depth' => 0, |
|
| 1250 | + 'walker' => new Mega_Menu_Walker(), |
|
| 1251 | + ); |
|
| 1252 | + |
|
| 1253 | + $args = array_merge( $args, apply_filters( 'megamenu_nav_menu_args', $defaults, $menu_id, $current_theme_location ) ); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + return $args; |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * Display admin notices. |
|
| 1262 | + */ |
|
| 1263 | + public function admin_notices() { |
|
| 1264 | + |
|
| 1265 | + if ( ! $this->is_compatible_wordpress_version() ) : |
|
| 1266 | + |
|
| 1267 | + ?> |
|
| 1268 | 1268 | <div class="error"> |
| 1269 | 1269 | <p><?php esc_html_e( 'Max Mega Menu is not compatible with your version of WordPress. Please upgrade WordPress to the latest version or disable Max Mega Menu.', 'megamenu' ); ?></p> |
| 1270 | 1270 | </div> |
| 1271 | 1271 | <?php |
| 1272 | 1272 | |
| 1273 | - endif; |
|
| 1273 | + endif; |
|
| 1274 | 1274 | |
| 1275 | - if ( did_action( 'megamenu_after_install' ) === 1 ) : |
|
| 1275 | + if ( did_action( 'megamenu_after_install' ) === 1 ) : |
|
| 1276 | 1276 | |
| 1277 | - ?> |
|
| 1277 | + ?> |
|
| 1278 | 1278 | |
| 1279 | 1279 | <?php |
| 1280 | 1280 | |
| 1281 | - endif; |
|
| 1281 | + endif; |
|
| 1282 | 1282 | |
| 1283 | - if ( defined( 'MEGAMENU_HIDE_CSS_NAG' ) && MEGAMENU_HIDE_CSS_NAG === true ) { |
|
| 1284 | - return; |
|
| 1285 | - } |
|
| 1283 | + if ( defined( 'MEGAMENU_HIDE_CSS_NAG' ) && MEGAMENU_HIDE_CSS_NAG === true ) { |
|
| 1284 | + return; |
|
| 1285 | + } |
|
| 1286 | 1286 | |
| 1287 | - $css_version = get_transient( 'megamenu_css_version' ); |
|
| 1288 | - $css = get_transient( 'megamenu_css' ); |
|
| 1287 | + $css_version = get_transient( 'megamenu_css_version' ); |
|
| 1288 | + $css = get_transient( 'megamenu_css' ); |
|
| 1289 | 1289 | |
| 1290 | - if ( $css && version_compare( $this->scss_last_updated, $css_version, '>' ) ) : |
|
| 1290 | + if ( $css && version_compare( $this->scss_last_updated, $css_version, '>' ) ) : |
|
| 1291 | 1291 | |
| 1292 | - ?> |
|
| 1292 | + ?> |
|
| 1293 | 1293 | <div class="updated"> |
| 1294 | 1294 | <?php |
| 1295 | 1295 | |
| 1296 | - $clear_cache_url = esc_url( |
|
| 1297 | - add_query_arg( |
|
| 1298 | - array( |
|
| 1299 | - 'action' => 'megamenu_clear_css_cache', |
|
| 1300 | - ), |
|
| 1301 | - wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_clear_css_cache' ) |
|
| 1302 | - ) |
|
| 1303 | - ); |
|
| 1296 | + $clear_cache_url = esc_url( |
|
| 1297 | + add_query_arg( |
|
| 1298 | + array( |
|
| 1299 | + 'action' => 'megamenu_clear_css_cache', |
|
| 1300 | + ), |
|
| 1301 | + wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_clear_css_cache' ) |
|
| 1302 | + ) |
|
| 1303 | + ); |
|
| 1304 | 1304 | |
| 1305 | - $link = "<a href='{$clear_cache_url}'>" . __( 'clear the CSS cache', 'megamenu' ) . '</a>'; |
|
| 1305 | + $link = "<a href='{$clear_cache_url}'>" . __( 'clear the CSS cache', 'megamenu' ) . '</a>'; |
|
| 1306 | 1306 | |
| 1307 | - $allowed_html = array( |
|
| 1308 | - 'a' => array( |
|
| 1309 | - 'href' => array(), |
|
| 1310 | - 'title' => array(), |
|
| 1311 | - ), |
|
| 1312 | - ); |
|
| 1307 | + $allowed_html = array( |
|
| 1308 | + 'a' => array( |
|
| 1309 | + 'href' => array(), |
|
| 1310 | + 'title' => array(), |
|
| 1311 | + ), |
|
| 1312 | + ); |
|
| 1313 | 1313 | |
| 1314 | - ?> |
|
| 1314 | + ?> |
|
| 1315 | 1315 | |
| 1316 | 1316 | <p> |
| 1317 | 1317 | <?php |
| 1318 | - printf( |
|
| 1319 | - /* translators: %s is the link to clear the menu CSS cache */ |
|
| 1320 | - esc_html__( 'Max Mega Menu has been updated. Please %s to ensure maximum compatibility with the latest version.', 'megamenu' ), |
|
| 1321 | - wp_kses( $link, $allowed_html ) |
|
| 1322 | - ); |
|
| 1323 | - ?> |
|
| 1318 | + printf( |
|
| 1319 | + /* translators: %s is the link to clear the menu CSS cache */ |
|
| 1320 | + esc_html__( 'Max Mega Menu has been updated. Please %s to ensure maximum compatibility with the latest version.', 'megamenu' ), |
|
| 1321 | + wp_kses( $link, $allowed_html ) |
|
| 1322 | + ); |
|
| 1323 | + ?> |
|
| 1324 | 1324 | </p> |
| 1325 | 1325 | </div> |
| 1326 | 1326 | <?php |
| 1327 | 1327 | |
| 1328 | - endif; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Checks this WordPress installation is v3.8 or above. |
|
| 1334 | - * 3.8 is needed for dashicons. |
|
| 1335 | - */ |
|
| 1336 | - public function is_compatible_wordpress_version() { |
|
| 1337 | - global $wp_version; |
|
| 1338 | - |
|
| 1339 | - return $wp_version >= 3.8; |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * Add compatibility for conditional menus plugin |
|
| 1344 | - * |
|
| 1345 | - * @since 2.2 |
|
| 1346 | - */ |
|
| 1347 | - public function conditional_menus_restore_theme_location( $location, $new_args, $old_args ) { |
|
| 1348 | - return $old_args['theme_location']; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Add a note to the Navigation Widget to explain that Max Mega Menu will not work with it. |
|
| 1353 | - * |
|
| 1354 | - * @since 2.5.1 |
|
| 1355 | - */ |
|
| 1356 | - public function add_notice_to_nav_menu_widget( $widget, $return, $instance ) { |
|
| 1357 | - if ( 'nav_menu' === $widget->id_base ) { |
|
| 1358 | - ?> |
|
| 1328 | + endif; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Checks this WordPress installation is v3.8 or above. |
|
| 1334 | + * 3.8 is needed for dashicons. |
|
| 1335 | + */ |
|
| 1336 | + public function is_compatible_wordpress_version() { |
|
| 1337 | + global $wp_version; |
|
| 1338 | + |
|
| 1339 | + return $wp_version >= 3.8; |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * Add compatibility for conditional menus plugin |
|
| 1344 | + * |
|
| 1345 | + * @since 2.2 |
|
| 1346 | + */ |
|
| 1347 | + public function conditional_menus_restore_theme_location( $location, $new_args, $old_args ) { |
|
| 1348 | + return $old_args['theme_location']; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Add a note to the Navigation Widget to explain that Max Mega Menu will not work with it. |
|
| 1353 | + * |
|
| 1354 | + * @since 2.5.1 |
|
| 1355 | + */ |
|
| 1356 | + public function add_notice_to_nav_menu_widget( $widget, $return, $instance ) { |
|
| 1357 | + if ( 'nav_menu' === $widget->id_base ) { |
|
| 1358 | + ?> |
|
| 1359 | 1359 | <p style="font-size: 11px; font-style: italic;"> |
| 1360 | 1360 | <?php esc_html_e( "If you are trying to display Max Mega Menu here, use the 'Max Mega Menu' widget instead.", 'megamenu' ); ?> |
| 1361 | 1361 | <a href="https://www.megamenu.com/documentation/widget/" target="_blank"><?php esc_html_e( 'More information', 'megamenu' ); ?></a> |
| 1362 | 1362 | </p> |
| 1363 | 1363 | <?php |
| 1364 | - } |
|
| 1365 | - } |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | - } |
|
| 1367 | + } |
|
| 1368 | 1368 | |
| 1369 | - add_action( 'plugins_loaded', array( 'Mega_Menu', 'init' ), 10 ); |
|
| 1369 | + add_action( 'plugins_loaded', array( 'Mega_Menu', 'init' ), 10 ); |
|
| 1370 | 1370 | |
| 1371 | 1371 | endif; |
| 1372 | 1372 | |
| 1373 | 1373 | |
| 1374 | 1374 | if ( ! function_exists( 'mmm_get_theme_id_for_location' ) ) { |
| 1375 | - /** |
|
| 1376 | - * Get the menu theme for a specific location |
|
| 1377 | - * |
|
| 1378 | - * @since 2.1 |
|
| 1379 | - * @param string $location - theme location identifier. |
|
| 1380 | - * @return array Menu Theme. |
|
| 1381 | - */ |
|
| 1382 | - function mmm_get_theme_id_for_location( $location = false ) { |
|
| 1383 | - |
|
| 1384 | - if ( ! $location ) { |
|
| 1385 | - return false; |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - if ( ! has_nav_menu( $location ) ) { |
|
| 1389 | - return false; |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1393 | - $settings = get_option( 'megamenu_settings' ); |
|
| 1394 | - |
|
| 1395 | - if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) { |
|
| 1396 | - return $settings[ $location ]['theme']; |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - return false; |
|
| 1400 | - } |
|
| 1375 | + /** |
|
| 1376 | + * Get the menu theme for a specific location |
|
| 1377 | + * |
|
| 1378 | + * @since 2.1 |
|
| 1379 | + * @param string $location - theme location identifier. |
|
| 1380 | + * @return array Menu Theme. |
|
| 1381 | + */ |
|
| 1382 | + function mmm_get_theme_id_for_location( $location = false ) { |
|
| 1383 | + |
|
| 1384 | + if ( ! $location ) { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + if ( ! has_nav_menu( $location ) ) { |
|
| 1389 | + return false; |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1393 | + $settings = get_option( 'megamenu_settings' ); |
|
| 1394 | + |
|
| 1395 | + if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) { |
|
| 1396 | + return $settings[ $location ]['theme']; |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + return false; |
|
| 1400 | + } |
|
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | 1403 | if ( ! function_exists( 'mmm_get_theme_for_location' ) ) { |
| 1404 | - /** |
|
| 1405 | - * Get the theme assigned to a specified location |
|
| 1406 | - * |
|
| 1407 | - * @since 2.0.2 |
|
| 1408 | - * @param string $location - theme location identifier. |
|
| 1409 | - */ |
|
| 1410 | - function mmm_get_theme_for_location( $location = false ) { |
|
| 1404 | + /** |
|
| 1405 | + * Get the theme assigned to a specified location |
|
| 1406 | + * |
|
| 1407 | + * @since 2.0.2 |
|
| 1408 | + * @param string $location - theme location identifier. |
|
| 1409 | + */ |
|
| 1410 | + function mmm_get_theme_for_location( $location = false ) { |
|
| 1411 | 1411 | |
| 1412 | - if ( ! $location ) { |
|
| 1413 | - return false; |
|
| 1414 | - } |
|
| 1412 | + if ( ! $location ) { |
|
| 1413 | + return false; |
|
| 1414 | + } |
|
| 1415 | 1415 | |
| 1416 | - if ( ! has_nav_menu( $location ) ) { |
|
| 1417 | - return false; |
|
| 1418 | - } |
|
| 1416 | + if ( ! has_nav_menu( $location ) ) { |
|
| 1417 | + return false; |
|
| 1418 | + } |
|
| 1419 | 1419 | |
| 1420 | - // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1421 | - $settings = get_option( 'megamenu_settings' ); |
|
| 1420 | + // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1421 | + $settings = get_option( 'megamenu_settings' ); |
|
| 1422 | 1422 | |
| 1423 | - $style_manager = new Mega_Menu_Style_Manager(); |
|
| 1423 | + $style_manager = new Mega_Menu_Style_Manager(); |
|
| 1424 | 1424 | |
| 1425 | - $themes = $style_manager->get_themes(); |
|
| 1425 | + $themes = $style_manager->get_themes(); |
|
| 1426 | 1426 | |
| 1427 | - if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) { |
|
| 1428 | - $theme = $settings[ $location ]['theme']; |
|
| 1427 | + if ( is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && isset( $settings[ $location ]['theme'] ) ) { |
|
| 1428 | + $theme = $settings[ $location ]['theme']; |
|
| 1429 | 1429 | |
| 1430 | - $menu_theme = isset( $themes[ $theme ] ) ? $themes[ $theme ] : $themes['default']; |
|
| 1430 | + $menu_theme = isset( $themes[ $theme ] ) ? $themes[ $theme ] : $themes['default']; |
|
| 1431 | 1431 | |
| 1432 | - return $menu_theme; |
|
| 1433 | - } |
|
| 1432 | + return $menu_theme; |
|
| 1433 | + } |
|
| 1434 | 1434 | |
| 1435 | - return $themes['default']; |
|
| 1436 | - } |
|
| 1435 | + return $themes['default']; |
|
| 1436 | + } |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | |
| 1440 | 1440 | if ( ! function_exists( 'max_mega_menu_is_enabled' ) ) { |
| 1441 | - /** |
|
| 1442 | - * Determines if Max Mega Menu has been enabled for a given menu location. |
|
| 1443 | - * |
|
| 1444 | - * Usage: |
|
| 1445 | - * |
|
| 1446 | - * Max Mega Menu is enabled: |
|
| 1447 | - * function_exists( 'max_mega_menu_is_enabled' ) |
|
| 1448 | - * |
|
| 1449 | - * Max Mega Menu has been enabled for a theme location: |
|
| 1450 | - * function_exists( 'max_mega_menu_is_enabled' ) && max_mega_menu_is_enabled( $location ) |
|
| 1451 | - * |
|
| 1452 | - * @since 1.8 |
|
| 1453 | - * @param string $location - theme location identifier. |
|
| 1454 | - */ |
|
| 1455 | - function max_mega_menu_is_enabled( $location = false ) { |
|
| 1456 | - |
|
| 1457 | - if ( ! $location ) { |
|
| 1458 | - return true; // the plugin is enabled. |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - if ( ! has_nav_menu( $location ) ) { |
|
| 1462 | - return false; |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1466 | - $settings = get_option( 'megamenu_settings' ); |
|
| 1467 | - |
|
| 1468 | - return is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && $settings[ $location ]['enabled'] == true; |
|
| 1469 | - } |
|
| 1441 | + /** |
|
| 1442 | + * Determines if Max Mega Menu has been enabled for a given menu location. |
|
| 1443 | + * |
|
| 1444 | + * Usage: |
|
| 1445 | + * |
|
| 1446 | + * Max Mega Menu is enabled: |
|
| 1447 | + * function_exists( 'max_mega_menu_is_enabled' ) |
|
| 1448 | + * |
|
| 1449 | + * Max Mega Menu has been enabled for a theme location: |
|
| 1450 | + * function_exists( 'max_mega_menu_is_enabled' ) && max_mega_menu_is_enabled( $location ) |
|
| 1451 | + * |
|
| 1452 | + * @since 1.8 |
|
| 1453 | + * @param string $location - theme location identifier. |
|
| 1454 | + */ |
|
| 1455 | + function max_mega_menu_is_enabled( $location = false ) { |
|
| 1456 | + |
|
| 1457 | + if ( ! $location ) { |
|
| 1458 | + return true; // the plugin is enabled. |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + if ( ! has_nav_menu( $location ) ) { |
|
| 1462 | + return false; |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + // if a location has been passed, check to see if MMM has been enabled for the location. |
|
| 1466 | + $settings = get_option( 'megamenu_settings' ); |
|
| 1467 | + |
|
| 1468 | + return is_array( $settings ) && isset( $settings[ $location ]['enabled'] ) && $settings[ $location ]['enabled'] == true; |
|
| 1469 | + } |
|
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | 1472 | if ( ! function_exists( 'max_mega_menu_share_themes_across_multisite' ) ) { |
| 1473 | - /** |
|
| 1474 | - * In the first version of MMM, themes were (incorrectly) shared between all sites in a multi site network. |
|
| 1475 | - * Themes will not be shared across sites for new users installing v2.4.3 onwards, but they will be shared for existing (older) users. |
|
| 1476 | - * |
|
| 1477 | - * @since 2.3.7 |
|
| 1478 | - */ |
|
| 1479 | - function max_mega_menu_share_themes_across_multisite() { |
|
| 1473 | + /** |
|
| 1474 | + * In the first version of MMM, themes were (incorrectly) shared between all sites in a multi site network. |
|
| 1475 | + * Themes will not be shared across sites for new users installing v2.4.3 onwards, but they will be shared for existing (older) users. |
|
| 1476 | + * |
|
| 1477 | + * @since 2.3.7 |
|
| 1478 | + */ |
|
| 1479 | + function max_mega_menu_share_themes_across_multisite() { |
|
| 1480 | 1480 | |
| 1481 | - if ( defined( 'MEGAMENU_SHARE_THEMES_MULTISITE' ) && MEGAMENU_SHARE_THEMES_MULTISITE === false ) { |
|
| 1482 | - return false; |
|
| 1483 | - } |
|
| 1481 | + if ( defined( 'MEGAMENU_SHARE_THEMES_MULTISITE' ) && MEGAMENU_SHARE_THEMES_MULTISITE === false ) { |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1484 | 1484 | |
| 1485 | - if ( defined( 'MEGAMENU_SHARE_THEMES_MULTISITE' ) && MEGAMENU_SHARE_THEMES_MULTISITE === true ) { |
|
| 1486 | - return true; |
|
| 1487 | - } |
|
| 1485 | + if ( defined( 'MEGAMENU_SHARE_THEMES_MULTISITE' ) && MEGAMENU_SHARE_THEMES_MULTISITE === true ) { |
|
| 1486 | + return true; |
|
| 1487 | + } |
|
| 1488 | 1488 | |
| 1489 | - if ( get_option( 'megamenu_multisite_share_themes' ) === 'false' ) { // only exists if initially installed version is 2.4.3+. |
|
| 1490 | - return false; |
|
| 1491 | - } |
|
| 1489 | + if ( get_option( 'megamenu_multisite_share_themes' ) === 'false' ) { // only exists if initially installed version is 2.4.3+. |
|
| 1490 | + return false; |
|
| 1491 | + } |
|
| 1492 | 1492 | |
| 1493 | - return apply_filters( 'megamenu_share_themes_across_multisite', true ); |
|
| 1493 | + return apply_filters( 'megamenu_share_themes_across_multisite', true ); |
|
| 1494 | 1494 | |
| 1495 | - } |
|
| 1495 | + } |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | if ( ! function_exists( 'max_mega_menu_get_themes' ) ) { |
| 1499 | - /** |
|
| 1500 | - * Return saved themes |
|
| 1501 | - * |
|
| 1502 | - * @since 2.3.7 |
|
| 1503 | - */ |
|
| 1504 | - function max_mega_menu_get_themes() { |
|
| 1499 | + /** |
|
| 1500 | + * Return saved themes |
|
| 1501 | + * |
|
| 1502 | + * @since 2.3.7 |
|
| 1503 | + */ |
|
| 1504 | + function max_mega_menu_get_themes() { |
|
| 1505 | 1505 | |
| 1506 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1507 | - return get_option( 'megamenu_themes' ); |
|
| 1508 | - } |
|
| 1506 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1507 | + return get_option( 'megamenu_themes' ); |
|
| 1508 | + } |
|
| 1509 | 1509 | |
| 1510 | - return get_site_option( 'megamenu_themes' ); |
|
| 1510 | + return get_site_option( 'megamenu_themes' ); |
|
| 1511 | 1511 | |
| 1512 | - } |
|
| 1512 | + } |
|
| 1513 | 1513 | } |
| 1514 | 1514 | |
| 1515 | 1515 | if ( ! function_exists( 'max_mega_menu_save_themes' ) ) { |
| 1516 | - /** |
|
| 1517 | - * Save menu theme |
|
| 1518 | - * |
|
| 1519 | - * @since 2.3.7 |
|
| 1520 | - * @param array $themes menu themes. |
|
| 1521 | - */ |
|
| 1522 | - function max_mega_menu_save_themes( $themes ) { |
|
| 1516 | + /** |
|
| 1517 | + * Save menu theme |
|
| 1518 | + * |
|
| 1519 | + * @since 2.3.7 |
|
| 1520 | + * @param array $themes menu themes. |
|
| 1521 | + */ |
|
| 1522 | + function max_mega_menu_save_themes( $themes ) { |
|
| 1523 | 1523 | |
| 1524 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1525 | - return update_option( 'megamenu_themes', $themes ); |
|
| 1526 | - } |
|
| 1524 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1525 | + return update_option( 'megamenu_themes', $themes ); |
|
| 1526 | + } |
|
| 1527 | 1527 | |
| 1528 | - return update_site_option( 'megamenu_themes', $themes ); |
|
| 1528 | + return update_site_option( 'megamenu_themes', $themes ); |
|
| 1529 | 1529 | |
| 1530 | - } |
|
| 1530 | + } |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | if ( ! function_exists( 'max_mega_menu_save_last_updated_theme' ) ) { |
| 1534 | - /** |
|
| 1535 | - * Save last updated theme |
|
| 1536 | - * |
|
| 1537 | - * @since 2.3.7 |
|
| 1538 | - * @param string $theme The ID of the theme. |
|
| 1539 | - */ |
|
| 1540 | - function max_mega_menu_save_last_updated_theme( $theme ) { |
|
| 1534 | + /** |
|
| 1535 | + * Save last updated theme |
|
| 1536 | + * |
|
| 1537 | + * @since 2.3.7 |
|
| 1538 | + * @param string $theme The ID of the theme. |
|
| 1539 | + */ |
|
| 1540 | + function max_mega_menu_save_last_updated_theme( $theme ) { |
|
| 1541 | 1541 | |
| 1542 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1543 | - return update_option( 'megamenu_themes_last_updated', $theme ); |
|
| 1544 | - } |
|
| 1542 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1543 | + return update_option( 'megamenu_themes_last_updated', $theme ); |
|
| 1544 | + } |
|
| 1545 | 1545 | |
| 1546 | - return update_site_option( 'megamenu_themes_last_updated', $theme ); |
|
| 1546 | + return update_site_option( 'megamenu_themes_last_updated', $theme ); |
|
| 1547 | 1547 | |
| 1548 | - } |
|
| 1548 | + } |
|
| 1549 | 1549 | } |
| 1550 | 1550 | |
| 1551 | 1551 | if ( ! function_exists( 'max_mega_menu_get_last_updated_theme' ) ) { |
| 1552 | - /** |
|
| 1553 | - * Return last updated theme |
|
| 1554 | - * |
|
| 1555 | - * @since 2.3.7 |
|
| 1556 | - */ |
|
| 1557 | - function max_mega_menu_get_last_updated_theme() { |
|
| 1552 | + /** |
|
| 1553 | + * Return last updated theme |
|
| 1554 | + * |
|
| 1555 | + * @since 2.3.7 |
|
| 1556 | + */ |
|
| 1557 | + function max_mega_menu_get_last_updated_theme() { |
|
| 1558 | 1558 | |
| 1559 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1560 | - return get_option( 'megamenu_themes_last_updated' ); |
|
| 1561 | - } |
|
| 1559 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1560 | + return get_option( 'megamenu_themes_last_updated' ); |
|
| 1561 | + } |
|
| 1562 | 1562 | |
| 1563 | - return get_site_option( 'megamenu_themes_last_updated' ); |
|
| 1563 | + return get_site_option( 'megamenu_themes_last_updated' ); |
|
| 1564 | 1564 | |
| 1565 | - } |
|
| 1565 | + } |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | if ( ! function_exists( 'max_mega_menu_get_toggle_blocks' ) ) { |
| 1569 | - /** |
|
| 1570 | - * Return saved toggle blocks |
|
| 1571 | - * |
|
| 1572 | - * @since 2.3.7 |
|
| 1573 | - */ |
|
| 1574 | - function max_mega_menu_get_toggle_blocks() { |
|
| 1569 | + /** |
|
| 1570 | + * Return saved toggle blocks |
|
| 1571 | + * |
|
| 1572 | + * @since 2.3.7 |
|
| 1573 | + */ |
|
| 1574 | + function max_mega_menu_get_toggle_blocks() { |
|
| 1575 | 1575 | |
| 1576 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1577 | - return get_option( 'megamenu_toggle_blocks' ); |
|
| 1578 | - } |
|
| 1576 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1577 | + return get_option( 'megamenu_toggle_blocks' ); |
|
| 1578 | + } |
|
| 1579 | 1579 | |
| 1580 | - return get_site_option( 'megamenu_toggle_blocks' ); |
|
| 1580 | + return get_site_option( 'megamenu_toggle_blocks' ); |
|
| 1581 | 1581 | |
| 1582 | - } |
|
| 1582 | + } |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | if ( ! function_exists( 'max_mega_menu_save_toggle_blocks' ) ) { |
| 1586 | - /** |
|
| 1587 | - * Save toggle blocks |
|
| 1588 | - * |
|
| 1589 | - * @since 2.3.7 |
|
| 1590 | - */ |
|
| 1591 | - function max_mega_menu_save_toggle_blocks( $saved_blocks ) { |
|
| 1586 | + /** |
|
| 1587 | + * Save toggle blocks |
|
| 1588 | + * |
|
| 1589 | + * @since 2.3.7 |
|
| 1590 | + */ |
|
| 1591 | + function max_mega_menu_save_toggle_blocks( $saved_blocks ) { |
|
| 1592 | 1592 | |
| 1593 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1594 | - return update_option( 'megamenu_toggle_blocks', $saved_blocks ); |
|
| 1595 | - } |
|
| 1593 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1594 | + return update_option( 'megamenu_toggle_blocks', $saved_blocks ); |
|
| 1595 | + } |
|
| 1596 | 1596 | |
| 1597 | - return update_site_option( 'megamenu_toggle_blocks', $saved_blocks ); |
|
| 1597 | + return update_site_option( 'megamenu_toggle_blocks', $saved_blocks ); |
|
| 1598 | 1598 | |
| 1599 | - } |
|
| 1599 | + } |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | if ( ! function_exists( 'max_mega_menu_delete_themes' ) ) { |
| 1603 | - /** |
|
| 1604 | - * Delete saved themes |
|
| 1605 | - * |
|
| 1606 | - * @since 2.3.7 |
|
| 1607 | - */ |
|
| 1608 | - function max_mega_menu_delete_themes() { |
|
| 1603 | + /** |
|
| 1604 | + * Delete saved themes |
|
| 1605 | + * |
|
| 1606 | + * @since 2.3.7 |
|
| 1607 | + */ |
|
| 1608 | + function max_mega_menu_delete_themes() { |
|
| 1609 | 1609 | |
| 1610 | - if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1611 | - return delete_option( 'megamenu_themes' ); |
|
| 1612 | - } |
|
| 1610 | + if ( ! max_mega_menu_share_themes_across_multisite() ) { |
|
| 1611 | + return delete_option( 'megamenu_themes' ); |
|
| 1612 | + } |
|
| 1613 | 1613 | |
| 1614 | - return delete_site_option( 'megamenu_themes' ); |
|
| 1614 | + return delete_site_option( 'megamenu_themes' ); |
|
| 1615 | 1615 | |
| 1616 | - } |
|
| 1616 | + } |
|
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | if ( ! function_exists( 'max_mega_menu_get_active_caching_plugins' ) ) { |
| 1620 | - /** |
|
| 1621 | - * Return list of active caching/CDN/minification plugins |
|
| 1622 | - * |
|
| 1623 | - * @since 2.4 |
|
| 1624 | - * @return array |
|
| 1625 | - */ |
|
| 1626 | - function max_mega_menu_get_active_caching_plugins() { |
|
| 1627 | - |
|
| 1628 | - $caching_plugins = apply_filters( |
|
| 1629 | - 'megamenu_caching_plugins', |
|
| 1630 | - array( |
|
| 1631 | - 'litespeed-cache/litespeed-cache.php', |
|
| 1632 | - 'js-css-script-optimizer/js-css-script-optimizer.php', |
|
| 1633 | - 'merge-minify-refresh/merge-minify-refresh.php', |
|
| 1634 | - 'minify-html-markup/minify-html.php', |
|
| 1635 | - 'simple-cache/simple-cache.php', |
|
| 1636 | - 'w3-total-cache/w3-total-cache.php', |
|
| 1637 | - 'wp-fastest-cache/wpFastestCache.php', |
|
| 1638 | - 'wp-speed-of-light/wp-speed-of-light.php', |
|
| 1639 | - 'wp-super-cache/wp-cache.php', |
|
| 1640 | - 'wp-super-minify/wp-super-minify.php', |
|
| 1641 | - 'autoptimize/autoptimize.php', |
|
| 1642 | - 'bwp-minify/bwp-minify.php', |
|
| 1643 | - 'cache-enabler/cache-enabler.php', |
|
| 1644 | - 'cloudflare/cloudflare.php', |
|
| 1645 | - 'comet-cache/comet-cache.php', |
|
| 1646 | - 'css-optimizer/bpminifycss.php', |
|
| 1647 | - 'fast-velocity-minify/fvm.php', |
|
| 1648 | - 'hyper-cache/plugin.php', |
|
| 1649 | - 'remove-query-strings-littlebizzy/remove-query-strings.php', |
|
| 1650 | - 'remove-query-strings-from-static-resources/remove-query-strings.php', |
|
| 1651 | - 'query-strings-remover/query-strings-remover.php', |
|
| 1652 | - 'wp-rocket/wp-rocket.php', |
|
| 1653 | - 'hummingbird-performance/wp-hummingbird.php', |
|
| 1654 | - 'breeze/breeze.php', |
|
| 1655 | - ) |
|
| 1656 | - ); |
|
| 1657 | - |
|
| 1658 | - $active_plugins = array(); |
|
| 1659 | - |
|
| 1660 | - foreach ( $caching_plugins as $plugin_path ) { |
|
| 1661 | - if ( is_plugin_active( $plugin_path ) ) { |
|
| 1662 | - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path ); |
|
| 1663 | - $active_plugins[] = $plugin_data['Name']; |
|
| 1664 | - } |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - return $active_plugins; |
|
| 1668 | - } |
|
| 1620 | + /** |
|
| 1621 | + * Return list of active caching/CDN/minification plugins |
|
| 1622 | + * |
|
| 1623 | + * @since 2.4 |
|
| 1624 | + * @return array |
|
| 1625 | + */ |
|
| 1626 | + function max_mega_menu_get_active_caching_plugins() { |
|
| 1627 | + |
|
| 1628 | + $caching_plugins = apply_filters( |
|
| 1629 | + 'megamenu_caching_plugins', |
|
| 1630 | + array( |
|
| 1631 | + 'litespeed-cache/litespeed-cache.php', |
|
| 1632 | + 'js-css-script-optimizer/js-css-script-optimizer.php', |
|
| 1633 | + 'merge-minify-refresh/merge-minify-refresh.php', |
|
| 1634 | + 'minify-html-markup/minify-html.php', |
|
| 1635 | + 'simple-cache/simple-cache.php', |
|
| 1636 | + 'w3-total-cache/w3-total-cache.php', |
|
| 1637 | + 'wp-fastest-cache/wpFastestCache.php', |
|
| 1638 | + 'wp-speed-of-light/wp-speed-of-light.php', |
|
| 1639 | + 'wp-super-cache/wp-cache.php', |
|
| 1640 | + 'wp-super-minify/wp-super-minify.php', |
|
| 1641 | + 'autoptimize/autoptimize.php', |
|
| 1642 | + 'bwp-minify/bwp-minify.php', |
|
| 1643 | + 'cache-enabler/cache-enabler.php', |
|
| 1644 | + 'cloudflare/cloudflare.php', |
|
| 1645 | + 'comet-cache/comet-cache.php', |
|
| 1646 | + 'css-optimizer/bpminifycss.php', |
|
| 1647 | + 'fast-velocity-minify/fvm.php', |
|
| 1648 | + 'hyper-cache/plugin.php', |
|
| 1649 | + 'remove-query-strings-littlebizzy/remove-query-strings.php', |
|
| 1650 | + 'remove-query-strings-from-static-resources/remove-query-strings.php', |
|
| 1651 | + 'query-strings-remover/query-strings-remover.php', |
|
| 1652 | + 'wp-rocket/wp-rocket.php', |
|
| 1653 | + 'hummingbird-performance/wp-hummingbird.php', |
|
| 1654 | + 'breeze/breeze.php', |
|
| 1655 | + ) |
|
| 1656 | + ); |
|
| 1657 | + |
|
| 1658 | + $active_plugins = array(); |
|
| 1659 | + |
|
| 1660 | + foreach ( $caching_plugins as $plugin_path ) { |
|
| 1661 | + if ( is_plugin_active( $plugin_path ) ) { |
|
| 1662 | + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path ); |
|
| 1663 | + $active_plugins[] = $plugin_data['Name']; |
|
| 1664 | + } |
|
| 1665 | + } |
|
| 1666 | + |
|
| 1667 | + return $active_plugins; |
|
| 1668 | + } |
|
| 1669 | 1669 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | if ( defined( 'ABSPATH' ) && ! defined( 'RWMB_VER' ) ) { |
| 17 | - require_once dirname( __FILE__ ) . '/inc/loader.php'; |
|
| 18 | - $rwmb_loader = new RWMB_Loader(); |
|
| 19 | - $rwmb_loader->init(); |
|
| 17 | + require_once dirname( __FILE__ ) . '/inc/loader.php'; |
|
| 18 | + $rwmb_loader = new RWMB_Loader(); |
|
| 19 | + $rwmb_loader->init(); |
|
| 20 | 20 | } |
@@ -10,13 +10,13 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface RWMB_Storage_Interface { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Get value from storage. |
|
| 15 | - * |
|
| 16 | - * @param int $object_id Object id. |
|
| 17 | - * @param string $name Field name. |
|
| 18 | - * @param array $args Custom arguments.. |
|
| 19 | - * @return mixed |
|
| 20 | - */ |
|
| 21 | - public function get( $object_id, $name, $args = array() ); |
|
| 13 | + /** |
|
| 14 | + * Get value from storage. |
|
| 15 | + * |
|
| 16 | + * @param int $object_id Object id. |
|
| 17 | + * @param string $name Field name. |
|
| 18 | + * @param array $args Custom arguments.. |
|
| 19 | + * @return mixed |
|
| 20 | + */ |
|
| 21 | + public function get( $object_id, $name, $args = array() ); |
|
| 22 | 22 | } |