Opened 11 years ago
Closed 10 years ago
#27735 closed defect (bug) (fixed)
unregister_nav_menu leaves menu visible after it has been set
Reported by: | mbootsman | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | 3.8.1 |
Component: | Menus | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
When setting a menu on the primary or secondary locations the menu's are displayed according to the theme specs. When removing the menu location with unregister_nav_menu, the menu is still displayed on the front, but cannot be edited in the back-end, since we just unregistered it.
Desired behavior would be: Do not display an unregistered menu location, even if it has been set with a menu previously.
Attachments (2)
Change History (12)
#2
@
11 years ago
Andrew, thanks for your reply.
I realize the naming is a bit confusing, but I get that ;)
Since I am using Genesis, and added the unregister_nav_menu to the init hook, I have tested this with twentyfourteen too to filter out theme-specific code. And it gives the same result.
Let me clarify by the following steps, using the twentyfourteen theme:
- Create a menu
- Assign menu to both primary and secondary locations via Appearance - Menus
- View frontpage, this will show the same menu on the primary/secondary location
- Edit functions.php and add unregister_nav_menu( 'secondary' );
- Refresh frontpage, this will show both menu locations filled with the created menu
- Refresh the Appearance - Menus locations tab, this only shows Primary location
I don't know if this a bug or as-designed, but I just doesn't feel right.
#4
@
11 years ago
- Keywords has-patch added
Confirmed. unregister_nav_menu()
has no effect on has_nav_menu()
or wp_nav_menu()
.
has_nav_menu()
description says: "Whether a registered nav menu location has a menu assigned to it", but it doesn't actually check if the location is registered: tags/3.9.1/src/wp-includes/nav-menu.php#L125.
27735.patch fixes that. Perhaps the same check should be added to wp_nav_menu()
where it checks for a menu based on theme_location
: tags/3.9.1/src/wp-includes/nav-menu-template.php#L276.
#7
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 28836:
#8
@
10 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
[28836] can actually use get_registered_nav_menus() here.
#9
@
10 years ago
27735.2.patch uses get_registered_nav_menus()
.
Hi mbootsman, thanks for the report. register_nav_menu() and unregister_nav_menu() actually is for registering "locations", despite the slightly more generic name. If unregister_nav_menu() isn't removing the menu, then it sounds like one of two things: