コード例 #1
0
ファイル: migration.php プロジェクト: WackoMako/stonedape
function ubermenu_migrate_menu_settings()
{
    if (!isset($_GET['migrate_control_panel']) || $_GET['migrate_control_panel'] != 'on') {
        //Don't migrate control panel
        return;
    }
    $main_ops = ubermenu_get_instance_options('main');
    $gen_ops = get_option(UBERMENU_PREFIX . 'general');
    //up( $main_ops , 2 );
    //up( $gen_ops , 2 );
    //Check for old settings
    $old_ops = get_option('wp-mega-menu-settings', false);
    // 'sparkops_ubermenu' );
    //Settings Don't Exist
    if (!$old_ops) {
        //TODO: MSG: No Settings to migrate
        return;
    }
    //Settings Exist -> CONFIRM: This will overwrite existing settings, are you sure you wish to proceed?
    //This will merge your UberMenu 2 settings into UberMenu3, giving precedence to UberMenu 2 settings
    //Get NEW settings
    //Keep in mind Extensions - Sticky, Icons || [Not:Flat, Conditionals]
    //$new_fields = ubermenu_get_settings_fields();
    //up( $new_fields  , 2 );
    //echo 'main:';
    $config_id = 'main';
    $instance_ops = ubermenu_get_instance_options($config_id);
    //up( $main_ops );
    //echo 'gen:';
    $gen_ops = ubermenu_get_instance_options('general');
    //get_option( UBERMENU_PREFIX.'general' );
    //up( $gen_ops );
    //Create a SIMPLE MIGRATE array where values are just copied 1:1
    /////////////////////
    // MENU INSTANCE
    /////////////////////
    $map_instance = array('skin' => 'wpmega-style-preset', 'orientation' => 'wpmega-orientation', 'vertical_submenu_width' => 'vertical-submenu-w', 'transition' => 'wpmega-transition', 'bar_width' => 'wpmega-container-w', 'bar_inner_center' => 'center-inner-menu', 'bar_inner_width' => 'inner-menu-width', 'descriptions_top_level' => 'wpmega-description-0', 'descriptions_headers' => 'wpmega-description-1', 'descriptions_normal' => 'wpmega-description-2', 'image_title_attribute' => 'wpmega-disable-img-tooltips', 'responsive' => 'responsive-menu', 'responsive_toggle' => 'responsive-menu-toggle', 'responsive_toggle_content' => 'responsive-menu-toggle-text', 'responsive_collapse' => 'responsive-menu-toggle', 'allow_shortcodes_in_labels' => 'title-shortcodes', 'theme_location_instance' => 'theme-loc-instance', 'icon_top_level_color' => 'umicons-color', 'icon_top_level_color_hover' => 'umicons-color-hover', 'icon_top_level_size' => 'umicons-font-size', 'icon_top_level_padding_v' => 'umicons-padding-vertical', 'icon_top_level_padding_h' => 'umicons-padding-horizontal', 'icon_header_color' => 'umicons-color-2', 'icon_header_color_hover' => 'umicons-color-hover-2', 'icon_header_size' => 'umicons-font-size-2', 'icon_header_padding_v' => 'umicons-padding-vertical-2', 'icon_header_padding_h' => 'umicons-padding-horizontal-2', 'icon_normal_color' => 'umicons-color-3', 'icon_normal_color_hover' => 'umicons-color-hover-3', 'icon_normal_size' => 'umicons-font-size-3', 'icon_normal_padding_v' => 'umicons-padding-vertical-3', 'icon_normal_padding_h' => 'umicons-padding-horizontal-3', 'sticky_offset' => 'ubersticky-top-spacing', 'sticky_full_width' => 'ubersticky-expand-menu-bar', 'sticky_clearfix' => 'ubersticky-clear', 'sticky_center_inner_width' => 'ubersticky-center-inner', 'sticky_mobile' => 'ubersticky-mobile', 'sticky_permanent' => 'ubersticky-permanent', 'sticky_apply_to' => 'ubersticky-apply-to');
    //Could Filter to allow flexibility
    foreach ($map_instance as $new_id => $old_id) {
        if (isset($old_ops[$old_id])) {
            $instance_ops[$new_id] = $old_ops[$old_id];
        }
    }
    //Handle more complex settings for Instance
    //Theme Location Activation
    $active = get_option('wp-mega-menu-nav-locations', array());
    if (is_array($active)) {
        $instance_ops['auto_theme_location'] = array();
        foreach ($active as $loc) {
            $instance_ops['auto_theme_location'][$loc] = $loc;
        }
    }
    //Trigger (hover_intent is different)
    if (isset($old_ops['wpmega-trigger'])) {
        if ($old_ops['wpmega-trigger'] == 'hoverIntent') {
            $instance_ops['trigger'] = 'hover_intent';
        } else {
            $instance_ops['trigger'] = $old_ops['wpmega-trigger'];
        }
    }
    //Transition duration (ms to s)  'transition_duration'		=> 'wpmega-animation-time',
    if (isset($old_ops['wpmega-animation-time'])) {
        if (is_numeric($old_ops['wpmega-animation-time'])) {
            $instance_ops['transition_duration'] = $old_ops['wpmega-animation-time'] . 'ms';
        }
    }
    //Menu Bar Alignment - bar_align (center-menubar, wpmega-menubar-full)
    if (isset($old_ops['wpmega-menubar-full']) && $old_ops['wpmega-menubar-full'] == 'on') {
        //Align Full Width
        $instance_ops['bar_align'] = 'full';
    } else {
        if (isset($old_ops['center-menubar']) && $old_ops['center-menubar'] == 'on') {
            //Align Center
            $instance_ops['bar_align'] = 'center';
        }
    }
    //Center Menu Items
    if (isset($old_ops['center-menuitems']) && $old_ops['center-menuitems'] == 'on') {
        $instance_ops['items_align'] = 'center';
    }
    //Image Sizing - 'image_width' - 'wpmega-image-width' (only set if wpmega-resizeimages == 'on' )
    if (isset($old_ops['wpmega-resizeimages']) && $old_ops['wpmega-resizeimages'] == 'on') {
        if (isset($old_ops['wpmega-image-width']) && $old_ops['wpmega-image-width']) {
            $instance_ops['image_width'] = $old_ops['wpmega-image-width'];
        }
        if (isset($old_ops['wpmega-image-height']) && $old_ops['wpmega-image-height']) {
            $instance_ops['image_height'] = $old_ops['wpmega-image-height'];
        }
    }
    //HTML5 Nav Tag 'container_tag' => wpmega-html5
    if (isset($old_ops['wpmega-html5'])) {
        if ($old_ops['wpmega-html5'] == 'on') {
            $instance_ops['container_tag'] = 'nav';
        } else {
            $instance_ops['container_tag'] = 'div';
        }
    }
    //Icons Extension
    if (isset($old_ops['umicons-position'])) {
        $instance_ops['icon_top_level_position'] = 'icon_' . $old_ops['umicons-position'];
        $instance_ops['icon_header_position'] = 'icon_' . $old_ops['umicons-position-2'];
        $instance_ops['icon_normal_position'] = 'icon_' . $old_ops['umicons-position-3'];
    }
    //Sticky Extension
    $instance_ops['sticky_enabled'] = 'on';
    //If Style Generator, map styles -- 'wpmega-style' = 'inline'
    if ($old_ops['wpmega-style'] == 'inline') {
        //NON COLOR SETTINGS
        $style_map = array('style_menu_bar_radius' => 'menu-bar-border-radius', 'style_top_level_font_size' => 'top-level-item-font-size', 'style_top_level_text_transform' => 'top-level-text-transform', 'style_top_level_font_weight' => 'top-level-text-weight', 'style_top_level_item_glow_opacity' => 'top-level-item-glow-opacity', 'style_top_level_item_glow_opacity_hover' => 'top-level-item-glow-opacity-hover', 'style_top_level_padding' => 'top-level-item-padding-y', 'style_top_level_horiz_padding' => 'top-level-item-padding-x', 'style_extra_submenu_indicator_padding' => 'on', 'style_submenu_minimum_column_width' => 'sub-level-column-width', 'style_header_font_size' => 'sub-level-header-font-size', 'style_header_font_weight' => 'sub-level-header-font-weight', 'style_normal_font_size' => 'sub-level-link-font-size', 'style_description_font_size' => 'menu-description-size', 'style_description_text_transform' => 'description-transform');
        foreach ($style_map as $new_id => $old_id) {
            if (isset($old_ops[$old_id])) {
                $val = $old_ops[$old_id];
                $instance_ops[$new_id] = $val;
            }
        }
        //COLOR SETTINGS
        $style_map_colors = array('style_menu_bar_background' => array('menu-bar-background', 'menu-bar-background-color2'), 'style_menu_bar_border' => 'menu-bar-border-color', 'style_top_level_font_color' => 'top-level-item-font-color', 'style_top_level_font_color_hover' => 'top-level-item-font-color-hover', 'style_top_level_font_color_current' => 'top-level-item-font-color-current', 'style_top_level_background_hover' => array('top-level-item-background-hover', 'top-level-item-background-hover-color2'), 'style_top_level_item_divider_color' => 'top-level-item-border', 'style_submenu_background_color' => 'sub-level-background', 'style_submenu_border_color' => 'sub-menu-border', 'style_submenu_fallback_font_color' => 'sub-level-item-font-color', 'style_submenu_highlight_font_color' => 'sub-level-highlight-color', 'style_header_font_color' => 'sub-level-header-font-color', 'style_header_font_color_hover' => 'sub-level-header-font-color-hover', 'style_header_border_color' => 'sub-level-header-border-color', 'style_normal_font_color' => 'sub-level-link-font-color', 'style_normal_font_color_hover' => 'sub-level-link-font-color-hover', 'style_normal_background_hover' => 'sub-level-link-background-hover', 'style_description_font_color' => 'menu-description-color', 'style_top_level_arrow_color' => 'top-level-arrow-color', 'style_submenu_arrow_color' => 'sub-level-arrow-color', 'style_search_color' => 'search-submit-text-color', 'style_search_placeholder_color' => 'search-submit-text-color', 'style_search_icon_color' => 'search-submit-text-color', 'style_search_background' => 'search-text-background', 'sticky_background_color' => 'ubersticky-background-color');
        foreach ($style_map_colors as $new_id => $old_id) {
            //Color Gradient, concatenate if necessary
            if (is_array($old_id)) {
                $color0 = $color1 = false;
                if (isset($old_id[0])) {
                    if (isset($old_ops[$old_id[0]])) {
                        $color0 = $old_ops[$old_id[0]];
                    }
                }
                if (isset($old_id[1])) {
                    if (isset($old_ops[$old_id[1]])) {
                        $color1 = $old_ops[$old_id[1]];
                    }
                }
                if ($color0[0] != '#') {
                    $color0 = '#' . $color0;
                }
                $color = $color0;
                if ($color1) {
                    if ($color1[0] != '#') {
                        $color1 = '#' . $color1;
                    }
                    $color .= ',' . $color1;
                }
                $instance_ops[$new_id] = $color;
            } else {
                if (isset($old_ops[$old_id])) {
                    $val = $old_ops[$old_id];
                    //It's a color/hex val
                    if (strlen($val) == 6) {
                        $color = $val;
                        if ($color[0] != '#') {
                            $color = '#' . $color;
                        }
                        $instance_ops[$new_id] = $color;
                    } else {
                        $instance_ops[$new_id] = $val;
                    }
                }
            }
        }
    }
    update_option(UBERMENU_PREFIX . $config_id, $instance_ops);
    ubermenu_save_all_menu_styles();
    /////////////////////
    // GENERAL SETTINGS
    /////////////////////
    $map_general = array('custom_tweaks' => 'wpmega-css-tweaks', 'load_custom_js' => 'custom-js', 'load_ubermenu_css' => 'include-basic-css', 'load_fontawesome' => 'umicons-load-fontawesome', 'load_google_maps' => 'load-google-maps', 'num_widget_areas' => 'wpmega-sidebars', 'widget_area_names' => 'sidebar-names', 'allow_top_level_widgets' => 'wpmega-top-level-widgets', 'reposition_on_load' => 'reposition-on-load', 'intent_delay' => 'wpmega-hover-timeout', 'intent_interval' => 'wpmega-hover-interval', 'remove_conflicts' => 'wpmega-remove-conflicts', 'strict_mode' => 'wpmega-strict', 'ubermenu_theme_location' => 'wpmega-easyintegrate', 'sticky_toolbar_footer' => 'ubersticky-wpadmin-bottom', 'sticky_disable_css' => 'ubersticky-disable-css');
    foreach ($map_general as $new_id => $old_id) {
        if (isset($old_ops[$old_id])) {
            $gen_ops[$new_id] = $old_ops[$old_id];
        }
    }
    //Handle more complex settings
    //GENERAL
    //'load_custom_css'			'wpmega-style' = custom
    if (isset($old_ops['wpmega-style'])) {
        if ($old_ops['wpmega-style'] == 'custom') {
            $gen_ops['load_custom_css'] = 'on';
            //Load custom CSS
            //$gen_ops['skin'] = 'none';		//Disable skin
        }
    }
    update_option(UBERMENU_PREFIX . 'general', $gen_ops);
    //Regenerate Style Settings
    //ubermenu_generate_custom_styles();
    delete_transient(UBERMENU_GENERATED_STYLE_TRANSIENT);
    $notice = __('Successfully migrated Control Panel Menu Settings', 'ubermenu');
    add_settings_error('menu-migration', 'migration-notice-menu-complete', $notice, 'updated');
}
コード例 #2
0
function ubermenu_reset_settings()
{
    if (isset($_GET['page']) && $_GET['page'] == 'ubermenu-settings') {
        if (!current_user_can('manage_options')) {
            die('You need to be an admin to do that');
        }
        if (isset($_GET['do']) && $_GET['do'] == 'reset-all') {
            $instances = ubermenu_get_menu_instances(true);
            foreach ($instances as $config_id) {
                delete_option(UBERMENU_PREFIX . $config_id);
            }
            delete_option(UBERMENU_PREFIX . 'general');
            ubermenu_save_all_menu_styles();
        } else {
            if (isset($_GET['do']) && $_GET['do'] == 'reset-styles') {
                $instances = ubermenu_get_menu_instances(true);
                $all_fields = ubermenu_get_settings_fields();
                foreach ($instances as $config_id) {
                    $ops = ubermenu_get_instance_options($config_id);
                    $fields = $all_fields[UBERMENU_PREFIX . $config_id];
                    //up( $fields , 2 );
                    foreach ($fields as $field) {
                        if ($field['group'] == 'style_customizations' && $field['type'] != 'header') {
                            $ops[$field['name']] = isset($field['default']) ? $field['default'] : '';
                        }
                    }
                    //up( $ops );
                    update_option(UBERMENU_PREFIX . $config_id, $ops);
                    ubermenu_save_all_menu_styles();
                }
            }
        }
    }
}