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; if ( isset( $this->themes[ $theme_id ] ) ) { $this->id = $theme_id; } else { $this->id = $preselected_theme; } $this->active_theme = $this->themes[$this->id]; } } /** * * @since 2.4.1 */ public function ajax_save_theme() { check_ajax_referer( 'megamenu_save_theme' ); $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'] ); } $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; } /** * Add a new menu location. * * @since 1.8 */ public function add_menu_location() { check_admin_referer( 'megamenu_add_menu_location' ); $locations = get_option( 'megamenu_locations' ); $next_id = $this->get_next_menu_location_id(); $new_menu_location_id = "max_mega_menu_" . $next_id; $locations[$new_menu_location_id] = "Max Mega Menu Location " . $next_id; update_option( 'megamenu_locations', $locations ); do_action("megamenu_after_add_menu_location"); $this->redirect( admin_url( 'admin.php?page=maxmegamenu_menu_locations&add_location=true' ) ); } /** * Delete a menu location. * * @since 1.8 */ public function delete_menu_location() { check_admin_referer( 'megamenu_delete_menu_location' ); $locations = get_option( 'megamenu_locations' ); $location_to_delete = esc_attr( $_GET['location'] ); if ( isset( $locations[ $location_to_delete ] ) ) { unset( $locations[ $location_to_delete ] ); update_option( 'megamenu_locations', $locations ); } do_action("megamenu_after_delete_menu_location"); do_action("megamenu_delete_cache"); $this->redirect( admin_url( 'admin.php?page=maxmegamenu_menu_locations&delete_location=true' ) ); } /** * Clear the CSS cache. * * @since 1.5 */ public function tools_clear_css_cache() { check_admin_referer( 'megamenu_clear_css_cache' ); do_action( 'megamenu_delete_cache' ); $this->redirect( admin_url( 'admin.php?page=maxmegamenu_tools&clear_css_cache=true' ) ); } /** * Deletes all Max Mega Menu data from the database * * @since 1.5 */ public function delete_data() { check_admin_referer( 'megamenu_delete_data' ); do_action("megamenu_delete_cache"); // delete options delete_option("megamenu_settings"); delete_option("megamenu_locations"); delete_option("megamenu_toggle_blocks"); delete_option("megamenu_version"); delete_option("megamenu_initial_version"); delete_option("megamenu_themes_last_updated"); delete_option("megamenu_multisite_share_themes"); // delete all widgets assigned to menus $widget_manager = new Mega_Menu_Widget_Manager(); if ( $mega_menu_widgets = $widget_manager->get_mega_menu_sidebar_widgets() ) { foreach ( $mega_menu_widgets as $widget_id ) { $widget_manager->delete_widget( $widget_id ); } } // delete all mega menu metadata stored against menu items delete_metadata( 'post', 0, '_megamenu', '', true ); // clear cache delete_transient( "megamenu_css" ); // delete custom themes max_mega_menu_delete_themes(); $this->redirect( admin_url( "admin.php?page=maxmegamenu_tools&delete_data=true" ) ); } /** * Save menu general settings. * * @since 1.0 */ public function save_settings() { check_admin_referer( 'megamenu_save_settings' ); if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) { $submitted_settings = apply_filters( "megamenu_submitted_settings", $_POST['settings'] ); $existing_settings = get_option( 'megamenu_settings' ); $new_settings = array_merge( (array)$existing_settings, $submitted_settings ); update_option( 'megamenu_settings', $new_settings ); } // update location description if ( isset( $_POST['location'] ) && is_array( $_POST['location'] ) ) { $locations = get_option('megamenu_locations'); $new_locations = array_merge( (array)$locations, $_POST['location'] ); update_option( 'megamenu_locations', $new_locations ); } delete_transient('megamenu_failed_to_write_css_to_filesystem'); do_action("megamenu_after_save_general_settings"); do_action("megamenu_delete_cache"); $url = isset( $_POST['_wp_http_referer'] ) ? $_POST['_wp_http_referer'] : admin_url( "admin.php?page=maxmegamenu&saved=true" ); $this->redirect( $url ); } /** * Duplicate an existing theme. * * @since 1.8 */ public function import_theme() { check_admin_referer( 'megamenu_import_theme' ); $this->init(); $import = json_decode( stripslashes( $_POST['data'] ), true ); if ( is_array( $import ) ) { $saved_themes = max_mega_menu_get_themes(); $next_id = $this->get_next_theme_id(); $import['title'] = $import['title'] . " " . __(' - Imported', 'megamenu'); $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"); $this->redirect( admin_url( "admin.php?page=maxmegamenu_theme_editor&theme=" . $new_theme_id . "&created=true" ) ); } else { $this->redirect( admin_url( "admin.php?page=maxmegamenu_tools&theme_imported=false") ); } } /** * 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'); $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}"; $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") ); } /** * Redirect and exit * * @since 1.8 */ public function redirect( $url ) { wp_redirect( $url ); exit; } /** * Returns the next available menu location ID * * @since 1.0 */ public function get_next_menu_location_id() { $last_id = 0; if ( $locations = get_option( "megamenu_locations" ) ) { foreach ( $locations as $key => $value ) { if ( strpos( $key, 'max_mega_menu_' ) !== FALSE ) { $parts = explode( "_", $key ); $menu_id = end( $parts ); if ($menu_id > $last_id) { $last_id = $menu_id; } } } } $next_id = $last_id + 1; return $next_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; } /** * 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; } /** * Adds the "Menu Themes" menu item and page. * * @since 1.0 */ public function megamenu_themes_page() { $page = add_menu_page( __('Max Mega Menu', 'megamenu'), __('Mega Menu', 'megamenu'), 'edit_theme_options', 'maxmegamenu', array($this, 'page') ); $tabs = apply_filters("megamenu_menu_tabs", array( 'general_settings' => __("General Settings", "megamenu"), 'theme_editor' => __("Menu Themes", "megamenu"), 'menu_locations' => __("Menu Locations", "megamenu"), 'tools' => __("Tools", "megamenu") )); foreach ( $tabs as $key => $title ) { if ( $key == 'general_settings') { add_submenu_page( 'maxmegamenu', __('Max Mega Menu', 'megamenu') . ' - ' . $title, $title, 'edit_theme_options', 'maxmegamenu', array($this, 'page') ); } else { add_submenu_page( 'maxmegamenu', __('Max Mega Menu', 'megamenu') . ' - ' . $title, $title, 'edit_theme_options', 'maxmegamenu_' . $key, array($this, 'page') ); } } } /** * Content for 'Settings' tab * * @since 1.4 */ public function general_settings_page( $saved_settings ) { $css = isset( $saved_settings['css'] ) ? $saved_settings['css'] : 'fs'; $mobile_second_click = isset( $saved_settings['second_click'] ) ? $saved_settings['second_click'] : 'close'; $mobile_behaviour = isset( $saved_settings['mobile_behaviour'] ) ? $saved_settings['mobile_behaviour'] : 'standard'; $descriptions = isset( $saved_settings['descriptions'] ) ? $saved_settings['descriptions'] : 'disabled'; $unbind = isset( $saved_settings['unbind'] ) ? $saved_settings['unbind'] : 'enabled'; $prefix = isset( $saved_settings['prefix'] ) ? $saved_settings['prefix'] : 'enabled'; $locations = get_registered_nav_menus(); ?>
$description ) { if ( false !== strpos( $loc, '___' ) ) { // Remove locations created by Polylang unregister_nav_menu( $loc ); } else { // Remove the language name appended to the original locations register_nav_menu( $loc, str_replace( ' ' . $default_lang, '', $description ) ); } } $all_locations = get_registered_nav_menus(); } $locations = array(); $custom_locations = get_option( 'megamenu_locations' ); if ( is_array( $custom_locations ) ) { $all_locations = array_merge( $custom_locations, $all_locations ); } if ( count( $all_locations ) ) { $megamenu_locations = array(); // reorder locations so custom MMM locations are listed at the bottom foreach ( $all_locations as $location => $val ) { if ( strpos( $location, 'max_mega_menu_' ) === FALSE ) { $locations[$location] = $val; } else { $megamenu_locations[$location] = $val; } } $locations = array_merge( $locations, $megamenu_locations ); } ?> get_menu_id_for_location( $location ); $menus = wp_get_nav_menus(); foreach ( $menus as $menu ) { if ( $menu->term_id == $id ) { return $menu->name; } } return false; } /** * Content for 'Tools' tab * * @since 1.4 */ public function tools_page( $saved_settings ) { ?> array( 'url' => 'https://www.megamenu.com/?utm_source=free&utm_medium=settings&utm_campaign=pro', 'target' => '_mmmpro', 'text' => __("Homepage", "megamenu"), 'class' => '' ), 'documentation' => array( 'url' => 'https://www.megamenu.com/documentation/installation/?utm_source=free&utm_medium=settings&utm_campaign=pro', 'text' => __("Documentation", "megamenu"), 'target' => '_mmmpro', 'class' => '' ), 'troubleshooting' => array( 'url' => 'https://www.megamenu.com/articles/troubleshooting/?utm_source=free&utm_medium=settings&utm_campaign=pro', 'text' => __("Troubleshooting", "megamenu"), 'target' => '_mmmpro', 'class' => '' ) ) ); if ( ! is_plugin_active('megamenu-pro/megamenu-pro.php') ) { //$header_links['rate_us'] = array( // 'url' => 'https://wordpress.org/support/plugin/megamenu/reviews/#new-post', // 'text' => __("If you like this plugin, please vote and support us!", "megamenu"), // 'target' => '_blank', // 'class' => 'mega-star' //); $header_links['pro'] = array( 'url' => 'https://www.megamenu.com/upgrade/?utm_source=free&utm_medium=settings&utm_campaign=pro', 'target' => '_mmmpro', 'text' => __("Upgrade to Pro", "megamenu"), 'class' => 'mega-highlight' ); } $versions = apply_filters( "megamenu_versions", array( 'core' => array( 'version' => MEGAMENU_VERSION, 'text' => __("Core version", "megamenu") ), 'pro' => array( 'version' => "not installed", 'text' => __("Pro extension", "megamenu") ) ) ); ?> init(); $style_manager = new Mega_Menu_Style_Manager(); $test = $style_manager->test_theme_compilation( $this->active_theme ); if ( is_wp_error( $test ) ) { echo "" . $test->get_error_message() . "
"; } if ( isset( $_GET['deleted'] ) && $_GET['deleted'] == 'false' ) { echo "" . __("Failed to delete theme. The theme is in use by a menu.", "megamenu") . "
"; } if ( isset( $_GET['clear_css_cache'] ) && $_GET['clear_css_cache'] == 'true' ) { echo "";
echo __("The cache has been cleared and the menu CSS has been regenerated.", "megamenu");
$active_plugins = max_mega_menu_get_active_caching_plugins();
if ( count( $active_plugins ) ) {
echo "
";
echo __("You may also need to clear the cache for any Caching, Minification or CDN plugin you have installed.", "megamenu");
}
echo "
" . __("All plugin data removed", "megamenu") . "
"; } if ( isset( $_GET['deleted'] ) && $_GET['deleted'] == 'true' ) { echo "" . __("Theme Deleted", "megamenu") . "
"; } if ( isset( $_GET['duplicated'] ) ) { echo "" . __("Theme Duplicated", "megamenu") . "
"; } if ( isset( $_GET['saved'] ) ) { echo "" . __("Changes Saved", "megamenu") . "
"; } if ( isset( $_GET['reverted'] ) ) { echo "" . __("Theme Reverted", "megamenu") . "
"; } if ( isset( $_GET['created'] ) ) { echo "" . __("New Theme Created. To apply this theme to a menu, go to Appearance > Menus > Max Mega Menu Settings and select this theme from the 'Theme' dropdown.", "megamenu") . "
"; } if ( isset( $_GET['add_location'] ) ) { echo "" . __("New Menu Location Created", "megamenu") . "
"; } if ( isset( $_GET['delete_location'] ) ) { echo "" . __("Menu Location Deleted", "megamenu") . "
"; } if ( isset( $_GET['theme_imported'] ) && $_GET['theme_imported'] == 'false' ) { echo "" . __("Theme Import Failed", "megamenu") . "
"; } if ( isset( $_POST['theme_export'] ) ) { echo "" . __("Theme Exported", "megamenu") . "
"; } if ( is_plugin_active('clearfy/clearfy.php') ) { if ( $clearfy_options = get_option('wbcr_clearfy_cache_options') ) { if ( $clearfy_options['disable_dashicons'] == true ) { echo "" . __("Please enable Dashicons in the Clearfy plugin options. Max Mega Menu requires Dashicons.", "megamenu") . "
"; } } } do_action("megamenu_print_messages"); } /** * Lists the available themes * * @since 1.0 */ public function theme_selector() { $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; } /** * Displays the theme editor form. * * @since 1.0 */ public function theme_editor_page( $saved_settings ) { $this->init(); $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' ) ) ); ?>
SCSS into the custom styling area. If using SCSS there are some variables and mixins you can use:"); ?>
#{$wrap} #{$menu} @include mobile|desktop { .. } #{$menu}', $string);
?>
/** Add text shadow to top level menu items on desktop AND mobile **/
#{$wrap} #{$menu} > li.mega-menu-item > a.mega-menu-link {
text-shadow: 1px 1px #000000;
}
/** Add text shadow to top level menu items on desktop only **/
@include desktop {
#{$wrap} #{$menu} > li.mega-menu-item > a.mega-menu-link {
text-shadow: 1px 1px #000000;
}
}