function ubermenu_migrate_item_settings() { if (isset($_GET['migrate_menu_ids'])) { $menus = wp_get_nav_menus(array('orderby' => 'name')); $_defined_settings = ubermenu_menu_item_settings(); //up( $_GET['migrate_menu_ids'] ); $map = array('custom_content' => 'menu-item-shortcode', 'highlight' => 'menu-item-highlight', 'disable_text' => 'menu-item-notext', 'disable_link' => 'menu-item-nolink', 'clear_row' => 'menu-item-verticaldivision', 'new_column' => 'menu-item-newcol', 'icon' => 'menu-item-icon', 'condition_1' => 'menu-item-condition', 'condition_parameter_1' => 'menu-item-condition_parameter'); //Find the selected menus to migrate $menu_ids = $_GET['migrate_menu_ids']; //For each menu foreach ($menu_ids as $menu_id) { //Get the menu items $items = wp_get_nav_menu_items($menu_id); //For each item foreach ($items as $item) { $top_level = false; if ($item->menu_item_parent === '0' || $item->menu_item_parent === 0) { $top_level = true; } //up( $item ); //Find the old options $old_key = '_uber_options'; $old_meta = get_post_meta($item->ID, $old_key, true); //up( $old_meta ); //Migrate options $new_meta = ubermenu_menu_item_setting_defaults(); // todo foreach ($map as $new_id => $old_id) { if (isset($old_meta[$old_id])) { $new_meta[$new_id] = $old_meta[$old_id]; } } //Special// //Header //'menu-item-isheader', if (isset($old_meta['menu-item-isheader']) && $old_meta['menu-item-isheader'] == 'on') { if (!$top_level) { $new_meta['item_display'] = 'header'; } } //Submenu Type //'menu-item-isMega', if (isset($old_meta['menu-item-isMega'])) { //Only for top level!! if ($top_level) { if ($old_meta['menu-item-isMega'] == 'on') { $new_meta['submenu_type'] = 'mega'; } else { $new_meta['submenu_type'] = 'flyout'; } } } //Submenu Column Default 'submenu_column_default'=> 'menu-item-numCols', if ($top_level) { if (isset($old_meta['menu-item-numCols'])) { $new_meta['submenu_column_default'] = '1-' . $old_meta['menu-item-numCols']; } } //Align Submenu //submenu_position //Ignore flyout //'menu-item-fullWidth', //'menu-item-alignSubmenu', if ($top_level) { if (isset($old_meta['menu-item-fullWidth']) && $old_meta['menu-item-fullWidth'] == 'on') { $new_meta['submenu_position'] = 'full_width'; } else { if (isset($old_meta['menu-item-alignSubmenu'])) { switch ($old_meta['menu-item-alignSubmenu']) { case 'center': $new_meta['submenu_position'] = 'center'; break; case 'left': $new_meta['submenu_position'] = 'left_edge_bar'; break; case 'right': $new_meta['submenu_position'] = 'right_edge_bar'; break; default: $new_meta['submenu_position'] = 'center'; break; } } } } //Item Alignment //'menu-item-floatRight', if ($top_level) { if (isset($old_meta['menu-item-floatRight'])) { if ($old_meta['menu-item-floatRight'] == 'on') { $new_meta['item_align'] = 'right'; } } } //Featured Image $thumb_id = get_post_thumbnail_id($item->ID); if ($thumb_id) { $new_meta['item_image'] = $thumb_id; } //Sidebars if (isset($old_meta['menu-item-sidebars']) && $old_meta['menu-item-sidebars']) { $sidebar_id = $old_meta['menu-item-sidebars']; if ($sidebar_id == 'wpmega-sidebar') { $sidebar_id = 'ubermenu-sidebar-1'; } else { $sidebar_id = str_replace('wpmega-sidebar-', 'ubermenu-sidebar-', $sidebar_id); } $new_meta['widget_area'] = $sidebar_id; //Widget areas are full width $new_meta['columns'] = 'full'; } //Update options update_post_meta($item->ID, UBERMENU_MENU_ITEM_META_KEY, $new_meta); //Run Callbacks foreach ($_defined_settings as $panel => $panel_settings) { foreach ($panel_settings as $_priority => $_setting) { if (isset($_setting['on_save'])) { $callback = 'ubermenu_item_save_' . $_setting['on_save']; if (function_exists($callback)) { //echo "$callback( $item->ID );<br/>"; $callback($item->ID, $_setting, $new_meta[$_setting['id']], $new_meta); } } } } do_action('ubermenu_after_menu_item_save'); } //$m = $menus[$menu_id]; foreach ($menus as $m) { if ($m->term_id == $menu_id) { $notice = __('Successfully migrated Menu Item Settings for Menu: ', 'ubermenu') . $m->name; add_settings_error('menu-migration', 'migration-notice-item-complete-' . $menu_id, $notice, 'updated'); } } } //up( $items , 2 ); } }
function ubermenu_save_menu_item_callback() { global $wpdb; // this is how you get access to the database //CHECK NONCE check_ajax_referer('ubermenu-menu-item-settings', 'ubermenu_nonce'); $menu_item_id = $_POST['menu_item_id']; $menu_item_id = substr($menu_item_id, 10); $serialized_settings = $_POST['settings']; $dirty_settings = array(); parse_str($serialized_settings, $dirty_settings); //CHECKBOXES //Since unchecked checkboxes won't be submitted, detect them and set the 'off' value $_defined_settings = ubermenu_menu_item_settings(); foreach ($_defined_settings as $panel => $panel_settings) { foreach ($panel_settings as $_priority => $_setting) { if ($_setting['type'] == 'checkbox') { $_id = $_setting['id']; if (!isset($dirty_settings[$_id])) { $dirty_settings[$_id] = 'off'; } } } } //up( $dirty_settings ); //die(); //ONLY ALLOW SETTINGS WE'VE DEFINED $settings = wp_parse_args($dirty_settings, ubermenu_menu_item_setting_defaults()); //SAVE THE SETTINGS update_post_meta($menu_item_id, UBERMENU_MENU_ITEM_META_KEY, $settings); //RUN CALLBACKS //Reset styles for this menu item here //ubermenu_reset_item_styles( $menu_item_id ); foreach ($_defined_settings as $panel => $panel_settings) { foreach ($panel_settings as $_priority => $_setting) { if (isset($_setting['on_save'])) { $callback = 'ubermenu_item_save_' . $_setting['on_save']; if (function_exists($callback)) { $callback($menu_item_id, $_setting, $settings[$_setting['id']], $settings); } } } } //Set Defaults if (isset($dirty_settings['ubermenu-meta-save-defaults']) && $dirty_settings['ubermenu-meta-save-defaults'] == 'on') { update_option(UBERMENU_MENU_ITEM_DEFAULTS_OPTION_KEY, $settings); } //Reset Defaults if (isset($dirty_settings['ubermenu-meta-reset-defaults']) && $dirty_settings['ubermenu-meta-reset-defaults'] == 'on') { delete_option(UBERMENU_MENU_ITEM_DEFAULTS_OPTION_KEY); } do_action('ubermenu_after_menu_item_save'); $response = array(); $response['settings'] = $settings; $response['menu_item_id'] = $menu_item_id; //send back nonce $response['nonce'] = ubermenu_menu_item_settings_nonce(); //print_r( $response ); echo json_encode($response); //echo $data; die; // this is required to return a proper result }