WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 2 years ago

#18588 closed enhancement (fixed)

Auto-select "Primary Menu " when switching themes

Reported by: azaozz Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

Now that we have auto-matching of sidebars when switching themes, it's time to do the same for at least the Primary Menu. This would improve the UX quite a bit.

While testing the widgets/sidebars had to switch themes many times and since my test install has few hundred pages, each time I've ended up with a huge menu on the front end. That of course looks completely broken.

Further to keeping the setting for Primary Menu on theme switching IMHO we should auto-set it as soon as a menu is created. This would fix the most unfriendly experience with the menus screen.

Attachments (1)

18588.diff (1.3 KB) - added by wonderboymusic 2 years ago.

Download all attachments as: .zip

Change History (12)

#1 @aaroncampbell
6 years ago

  • Cc aaroncampbell added

#2 @hanni
6 years ago

  • Cc hanni added

#3 @jane
6 years ago

I'm in. Looking like this will need to be 3.4, though, since there's no patch and today is freeze?

#4 @azaozz
6 years ago

  • Milestone changed from 3.3 to Future Release

Yes, it can use the same method as the sidebars transfer from the old theme to the new.

#5 @unsalkorkmaz
6 years ago

  • Cc unsalkorkmaz@… added

#6 @unsalkorkmaz
6 years ago

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 );
		
	}
 }

#7 @lkraav
5 years ago

  • Cc leho@… added

#8 @celloexpressions
4 years ago

#26662 was marked as a duplicate.

#9 @celloexpressions
4 years ago

  • Keywords needs-patch added

@wonderboymusic
2 years ago

#10 @wonderboymusic
2 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 4.4

#11 @wonderboymusic
2 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 33808:

Switching themes: if the new theme doesn't have nav_menu_locations defined, but the old theme does, copy the old theme's nav_menu_locations into the new theme's theme mods.

cc melchoyce

Fixes #18588.

Note: See TracTickets for help on using tickets.