[wp-trac] [WordPress Trac] #18588: Auto-select "Primary Menu " when switching themes

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 14 16:50:29 UTC 2012


#18588: Auto-select "Primary Menu " when switching themes
-------------------------+-----------------------------
 Reporter:  azaozz       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Menus        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |
-------------------------+-----------------------------

Comment (by unsalkorkmaz):

 This is not a full solution for this problem but if you looking for a
 temporary solution for similar theme switches that have same theme
 locations (child themes etc):

 http://wordpress.stackexchange.com/questions/58164/assign-menus-to-theme-
 locations-with-theme-activation
 {{{
 /*
  This action copies old theme's theme location saves to
  new theme if new theme doesnt have saves before.
  */
  add_action( 'after_switch_theme',  'ajx_theme_locations_rescue' );
  function ajx_theme_locations_rescue() {
         // bug report / support: http://www.unsalkorkmaz.com/
         // We got old theme's slug name
         $old_theme = get_option( 'theme_switched' );
         // Getting old theme's settings
         $old_theme_mods = get_option("theme_mods_{$old_theme}");
         // Getting old theme's theme location settings
         $old_theme_navs = $old_theme_mods['nav_menu_locations'];
         // Getting new theme's theme location settings
         $new_theme_navs = get_theme_mod( 'nav_menu_locations' );

         // If new theme's theme location is empty (its not empty if theme
 was activated and set some theme locations before)
         if (!$new_theme_navs) {
                 // Getting registered theme locations on new theme
                 $new_theme_locations = get_registered_nav_menus();

                 foreach ($new_theme_locations as $location => $description
 ) {
                         // We setting same nav menus for each theme
 location
                         $new_theme_navs[$location] =
 $old_theme_navs[$location];
                 }

                 set_theme_mod( 'nav_menu_locations', $new_theme_navs );

         }
  }

 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18588#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list