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' ) ?>
SCSS into the custom styling area. If using SCSS there are some variables and mixins you can use:", 'megamenu'); ?>
#{$wrap} #{$menu} @include mobile|desktop { .. } #{$menu}', $string );
?>
/** **/
#{$wrap} #{$menu} > li.mega-menu-item > a.mega-menu-link {
text-shadow: 1px 1px #000000;
}
/** **/
@include desktop {
#{$wrap} #{$menu} > li.mega-menu-item > a.mega-menu-link {
text-shadow: 1px 1px #000000;
}
}