themes = $style_manager->get_themes(); $last_updated = max_mega_menu_get_last_updated_theme(); $preselected_theme = isset( $this->themes[ $last_updated ] ) ? $last_updated : 'default'; $theme_id = isset( $_GET['theme'] ) ? sanitize_text_field( $_GET['theme'] ) : $preselected_theme; // @codingStandardsIgnoreLine if ( isset( $this->themes[ $theme_id ] ) ) { $this->id = $theme_id; } else { $this->id = $preselected_theme; } $this->active_theme = $this->themes[ $this->id ]; } } /** * Returns the next available custom theme ID * * @since 1.0 */ public function get_next_theme_id() { $last_id = 0; if ( $saved_themes = max_mega_menu_get_themes() ) { foreach ( $saved_themes as $key => $value ) { if ( strpos( $key, 'custom_theme' ) !== false ) { $parts = explode( '_', $key ); $theme_id = end( $parts ); if ( $theme_id > $last_id ) { $last_id = $theme_id; } } } } $next_id = $last_id + 1; return $next_id; } /** * * @since 2.4.1 */ public function ajax_save_theme() { check_ajax_referer( 'megamenu_save_theme' ); $capability = apply_filters( 'megamenu_options_capability', 'edit_theme_options' ); if ( ! current_user_can( $capability ) ) { return; } $style_manager = new Mega_Menu_Style_Manager(); $test = $style_manager->test_theme_compilation( $this->get_prepared_theme_for_saving() ); if ( is_wp_error( $test ) ) { wp_send_json_error( $test->get_error_message() ); } else { $this->save_theme( true ); wp_send_json_success( 'Saved' ); } wp_die(); } /** * * @since 2.4.1 */ public function get_prepared_theme_for_saving() { $submitted_settings = $_POST['settings']; if ( isset( $_POST['checkboxes'] ) ) { foreach ( $_POST['checkboxes'] as $checkbox => $value ) { if ( isset( $submitted_settings[ $checkbox ] ) ) { $submitted_settings[ $checkbox ] = 'on'; } else { $submitted_settings[ $checkbox ] = 'off'; } } } if ( is_numeric( $submitted_settings['responsive_breakpoint'] ) ) { $submitted_settings['responsive_breakpoint'] = $submitted_settings['responsive_breakpoint'] . 'px'; } if ( isset( $submitted_settings['toggle_blocks'] ) ) { unset( $submitted_settings['toggle_blocks'] ); } if ( isset( $submitted_settings['panel_width'] ) ) { $submitted_settings['panel_width'] = trim( $submitted_settings['panel_width'] ); } if ( isset( $submitted_settings['panel_inner_width'] ) ) { $submitted_settings['panel_inner_width'] = trim( $submitted_settings['panel_inner_width'] ); } $theme = array_map( 'esc_attr', $submitted_settings ); return $theme; } /** * Save changes to an exiting theme. * * @since 1.0 */ public function save_theme( $is_ajax = false ) { check_admin_referer( 'megamenu_save_theme' ); $theme = esc_attr( $_POST['theme_id'] ); $saved_themes = max_mega_menu_get_themes(); if ( isset( $saved_themes[ $theme ] ) ) { unset( $saved_themes[ $theme ] ); } $prepared_theme = $this->get_prepared_theme_for_saving(); $saved_themes[ $theme ] = $prepared_theme; max_mega_menu_save_themes( $saved_themes ); max_mega_menu_save_last_updated_theme( $theme ); do_action( 'megamenu_after_theme_save' ); do_action( 'megamenu_delete_cache' ); if ( ! $is_ajax ) { $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme={$theme}&saved=true" ) ); return; } return $prepared_theme; } /** * Duplicate an existing theme. * * @since 1.0 */ public function duplicate_theme() { check_admin_referer( 'megamenu_duplicate_theme' ); $this->init(); $theme = esc_attr( $_GET['theme_id'] ); $copy = $this->themes[ $theme ]; $saved_themes = max_mega_menu_get_themes(); $next_id = $this->get_next_theme_id(); $copy['title'] = $copy['title'] . ' ' . __( 'Copy', 'megamenu' ); $copy['plugin_version'] = MEGAMENU_VERSION; $new_theme_id = 'custom_theme_' . $next_id; $saved_themes[ $new_theme_id ] = $copy; max_mega_menu_save_themes( $saved_themes ); do_action( 'megamenu_after_theme_duplicate' ); $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme={$new_theme_id}&duplicated=true" ) ); } /** * Delete a theme * * @since 1.0 */ public function delete_theme() { check_admin_referer( 'megamenu_delete_theme' ); $theme = esc_attr( $_GET['theme_id'] ); if ( $this->theme_is_being_used_by_location( $theme ) ) { $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme={$theme}&deleted=false" ) ); return; } $saved_themes = max_mega_menu_get_themes(); if ( isset( $saved_themes[ $theme ] ) ) { unset( $saved_themes[ $theme ] ); } max_mega_menu_save_themes( $saved_themes ); do_action( 'megamenu_after_theme_delete' ); do_action( 'megamenu_delete_cache' ); $this->redirect( admin_url( 'admin.php?page=maxmegamenu_theme_editor&theme=default&deleted=true' ) ); } /** * Revert a theme (only available for default themes, you can't revert a custom theme) * * @since 1.0 */ public function revert_theme() { check_admin_referer( 'megamenu_revert_theme' ); $theme = esc_attr( $_GET['theme_id'] ); $saved_themes = max_mega_menu_get_themes(); if ( isset( $saved_themes[ $theme ] ) ) { unset( $saved_themes[ $theme ] ); } max_mega_menu_save_themes( $saved_themes ); do_action( 'megamenu_after_theme_revert' ); do_action( 'megamenu_delete_cache' ); $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme={$theme}&reverted=true" ) ); } /** * Create a new custom theme * * @since 1.0 */ public function create_theme() { check_admin_referer( 'megamenu_create_theme' ); $this->init(); $saved_themes = max_mega_menu_get_themes(); $next_id = $this->get_next_theme_id(); $new_theme_id = 'custom_theme_' . $next_id; $style_manager = new Mega_Menu_Style_Manager(); $new_theme = $style_manager->get_default_theme(); $new_theme['title'] = "Custom {$next_id}"; $new_theme['plugin_version'] = MEGAMENU_VERSION; $saved_themes[ $new_theme_id ] = $new_theme; max_mega_menu_save_themes( $saved_themes ); do_action( 'megamenu_after_theme_create' ); $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme={$new_theme_id}&created=true" ) ); } /** * Duplicate an existing theme. * * @since 1.8 */ public function import_theme() { check_admin_referer( 'megamenu_import_theme' ); $import = json_decode( stripslashes( $_POST['data'] ), true ); $sanitized = array(); foreach ( $import as $key => $value ) { if ( $key == 'custom_css' ) { $sanitized[ $key ] = sanitize_textarea_field( $value ); } else { $sanitized[ $key ] = sanitize_text_field( $value ); } } $import = $sanitized; if ( is_array( $import ) ) { $saved_themes = max_mega_menu_get_themes(); $next_id = $this->get_next_theme_id(); $import['title'] = $import['title'] . ' ' . __( ' - Imported', 'megamenu' ); $import['plugin_version'] = MEGAMENU_VERSION; $new_theme_id = 'custom_theme_' . $next_id; $saved_themes[ $new_theme_id ] = $import; max_mega_menu_save_themes( $saved_themes ); do_action( 'megamenu_after_theme_import' ); $url = add_query_arg( array( 'page' => 'maxmegamenu_theme_editor', 'theme' => $new_theme_id, 'imported' => 'true', ), admin_url( 'admin.php' ) ); } else { $url = add_query_arg( array( 'page' => 'maxmegamenu_theme_editor', 'imported' => 'false', ), admin_url( 'admin.php' ) ); } $this->redirect( $url ); } /** * Redirect and exit * * @since 1.8 */ public function redirect( $url ) { wp_redirect( $url ); exit; } /** * Checks to see if a certain theme is in use. * * @since 1.0 * @param string $theme */ public function theme_is_being_used_by_location( $theme ) { $settings = get_option( 'megamenu_settings' ); if ( ! $settings ) { return false; } $locations = get_nav_menu_locations(); $menus = get_registered_nav_menus(); $theme_in_use_locations = array(); if ( count( $locations ) ) { foreach ( $locations as $location => $menu_id ) { if ( has_nav_menu( $location ) && max_mega_menu_is_enabled( $location ) && isset( $settings[ $location ]['theme'] ) && $settings[ $location ]['theme'] == $theme ) { $theme_in_use_locations[] = isset( $menus[ $location ] ) ? $menus[ $location ] : $location; } } if ( count( $theme_in_use_locations ) ) { return $theme_in_use_locations; } } return false; } /** * Display messages to the user * * @since 1.0 */ public function print_messages() { $this->init(); $style_manager = new Mega_Menu_Style_Manager(); $test = $style_manager->test_theme_compilation( $this->active_theme ); if ( is_wp_error( $test ) ) { ?>

get_error_message(); ?>

Mega Menu > Menu Locations and select this theme from the 'Theme' dropdown.", 'megamenu' ) ?>

"; foreach ( $this->themes as $id => $theme ) { $locations = $this->theme_is_being_used_by_location( $id ); $selected = $id == $this->id ? 'selected=selected' : ''; $list_items .= "'; } return $list_items .= ''; } /** * Checks to see if a given string contains any of the provided search terms * * @param srgin $key * @param array $needles * @since 1.0 */ private function string_contains( $key, $needles ) { foreach ( $needles as $needle ) { if ( strpos( $key, $needle ) !== false ) { return true; } } return false; } /** * * @since 2.9 */ public function export_theme() { $style_manager = new Mega_Menu_Style_Manager(); $default_theme = $style_manager->get_default_theme(); $theme_to_export = $this->active_theme; $diff = array(); foreach ( $default_theme as $key => $value ) { if ( isset( $theme_to_export[ $key ] ) && $theme_to_export[ $key ] != $value || $key == 'title' ) { $diff[ $key ] = $theme_to_export[ $key ]; } } ?> init(); if ( isset( $_GET['export'] ) ) { $this->export_theme(); return; } if ( isset( $_GET['import'] ) ) { $this->import_theme_page(); return; } $create_url = esc_url( add_query_arg( array( 'action' => 'megamenu_add_theme', ), wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_create_theme' ) ) ); $duplicate_url = esc_url( add_query_arg( array( 'action' => 'megamenu_duplicate_theme', 'theme_id' => $this->id, ), wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_duplicate_theme' ) ) ); $delete_url = esc_url( add_query_arg( array( 'action' => 'megamenu_delete_theme', 'theme_id' => $this->id, ), wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_delete_theme' ) ) ); $revert_url = esc_url( add_query_arg( array( 'action' => 'megamenu_revert_theme', 'theme_id' => $this->id, ), wp_nonce_url( admin_url( 'admin-post.php' ), 'megamenu_revert_theme' ) ) ); $export_url = esc_url( add_query_arg( array( 'page' => 'maxmegamenu_theme_editor', 'theme' => $this->id, 'export' => 'true', ), admin_url( 'admin.php' ) ) ); $import_url = esc_url( add_query_arg( array( 'page' => 'maxmegamenu_theme_editor', 'import' => 'true', ), admin_url( 'admin.php' ) ) ); ?> print_messages(); ?> =' ) ) { return true; } if ( defined( 'MEGAMENU_ENABLE_FLEX_CSS_OPTION' ) && MEGAMENU_ENABLE_FLEX_CSS_OPTION ) { return true; } return false; } /** * Check for installed caching/minification/CDN plugins and output a warning if one is found to be * installed and activated */ public function show_cache_warning() { $active_plugins = max_mega_menu_get_active_caching_plugins(); if ( count( $active_plugins ) ) : ?>

$elem2['priority'] ) { return 1; } if ( $elem1['priority'] == $elem2['priority'] ) { return 0; } return -1; } /** * Print a select dropdown with left, center and right options * * @since 1.6.1 * @param string $key * @param string $value */ public function print_theme_align_option( $key ) { $value = $this->active_theme[ $key ]; $use_flex_css = $this->active_theme[ 'use_flex_css' ]; ?> active_theme[ $key ]; ?> active_theme[ $key ]; ?> active_theme[ $key ]; ?> /> active_theme[ $key ]; $arrow_icons = $this->arrow_icons(); ?> active_theme[ $key ]; $arrow_icons = $this->close_icons(); ?> active_theme[ $key ]; if ( $value == 'transparent' ) { $value = 'rgba(0,0,0,0)'; } if ( $value == 'rgba(0,0,0,0)' ) { $value_text = 'transparent'; } else { $value_text = $value; } echo ""; } /** * Print a font weight selector * * @since 1.0 * @param string $key * @param string $value */ public function print_theme_weight_option( $key ) { $value = $this->active_theme[ $key ]; $options = apply_filters( 'megamenu_font_weights', array( 'inherit' => __( 'Theme Default', 'megamenu' ), '300' => __( 'Light (300)', 'megamenu' ), 'normal' => __( 'Normal (400)', 'megamenu' ), 'bold' => __( 'Bold (700)', 'megamenu' ), ) ); /** * '100' => __("Thin (100)", "megamenu"), * '200' => __("Extra Light (200)", "megamenu"), * '300' => __("Light (300)", "megamenu"), * 'normal' => __("Normal (400)", "megamenu"), * '500' => __("Medium (500)", "megamenu"), * '600' => __("Semi Bold (600)", "megamenu"), * 'bold' => __("Bold (700)", "megamenu"), * '800' => __("Extra Bold (800)", "megamenu"), * '900' => __("Black (900)", "megamenu") */ echo "'; } /** * Print a font transform selector * * @since 1.0 * @param string $key * @param string $value */ public function print_theme_transform_option( $key ) { $value = $this->active_theme[ $key ]; echo "'; } /** * Print a textarea * * @since 1.0 * @param string $key * @param string $value */ public function print_theme_textarea_option( $key ) { $value = sanitize_textarea_field( $this->active_theme[ $key ] ); ?>

SCSS into the custom styling area. If using SCSS there are some variables and mixins you can use:", 'megamenu'); ?>

active_theme[ $key ]; echo "'; } /** * Print a text input * * @since 1.0 * @param string $key * @param string $value */ public function print_theme_freetext_option( $key ) { $value = $this->active_theme[ $key ]; echo ""; } /** * Returns a list of available fonts. * * @since 1.0 */ public function fonts() { $fonts = array( 'Georgia, serif', 'Palatino Linotype, Book Antiqua, Palatino, serif', 'Times New Roman, Times, serif', 'Arial, Helvetica, sans-serif', 'Arial Black, Gadget, sans-serif', 'Comic Sans MS, cursive, sans-serif', 'Impact, Charcoal, sans-serif', 'Lucida Sans Unicode, Lucida Grande, sans-serif', 'Tahoma, Geneva, sans-serif', 'Trebuchet MS, Helvetica, sans-serif', 'Verdana, Geneva, sans-serif', 'Courier New, Courier, monospace', 'Lucida Console, Monaco, monospace', ); $fonts = apply_filters( 'megamenu_fonts', $fonts ); return $fonts; } /** * List of all available arrow DashIcon classes. * * @since 1.0 * @return array - Sorted list of icon classes */ private function arrow_icons() { $icons = array( 'dash-f142' => 'dashicons-arrow-up', 'dash-f140' => 'dashicons-arrow-down', 'dash-f141' => 'dashicons-arrow-left', 'dash-f139' => 'dashicons-arrow-right', 'dash-f342' => 'dashicons-arrow-up-alt', 'dash-f346' => 'dashicons-arrow-down-alt', 'dash-f340' => 'dashicons-arrow-left-alt', 'dash-f344' => 'dashicons-arrow-right-alt', 'dash-f343' => 'dashicons-arrow-up-alt2', 'dash-f347' => 'dashicons-arrow-down-alt2', 'dash-f341' => 'dashicons-arrow-left-alt2', 'dash-f345' => 'dashicons-arrow-right-alt2', 'dash-f132' => 'dashicons-plus', 'dash-f460' => 'dashicons-minus', 'dash-f158' => 'dashicons-no', 'dash-f335' => 'dashicons-no-alt', ); $icons = apply_filters( 'megamenu_arrow_icons', $icons ); return $icons; } /** * List of all available arrow DashIcon classes. * * @since 1.0 * @return array - Sorted list of icon classes */ private function close_icons() { $icons = array( 'dash-f171' => 'dashicons-undo', 'dash-f518' => 'dashicons-controls-back', 'dash-f14f' => 'dashicons-remove', 'dash-f340' => 'dashicons-arrow-left-alt', 'dash-f341' => 'dashicons-arrow-left-alt2', 'dash-f460' => 'dashicons-minus', 'dash-f158' => 'dashicons-no', 'dash-f335' => 'dashicons-no-alt', 'dash-f148' => 'dashicons-admin-collapse', 'dash-f158' => 'dashicons-no', 'dash-f335' => 'dashicons-no-alt', ); $icons = apply_filters( 'megamenu_close_icons', $icons ); return $icons; } } endif;