#31525 closed enhancement (duplicate)
Request for filter hook for has_nav_menu()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2 |
Component: | Menus | Keywords: | |
Focuses: | Cc: |
Description
I have a plugin that creates dummy copies of nav menu locations for the purpose of having separate menus assigned to the same location but in different languages.
The current hook adds callbacks to the after_setup_theme
and wp_nav_menu_args
filter hooks to achieve this, replacing the original location setup/requested with copies for each language registered by the plugin.
This largely works perfectly well on all my sites, but I've been informed of issues with it working in many stock themes. The issue has to do with the theme calling has_nav_menu()
to check if a menu is registered to a particular location. However, since no actual menu is assigned to that location, but rather the pseudo version for a particular language, it returns false.
My proposal is to add a filter to has_nav_menu()
so that plugins can filter the result. Something like this:
function has_nav_menu( $location ) { $registered_nav_menus = get_registered_nav_menus(); $result = isset( $registered_nav_menus[ $location ] ); if ( ! $result ) { $locations = get_nav_menu_locations(); $result = ! empty( $locations[ $location ] ); } return apply_filters( 'has_nav_menu', $result, $location ); }
Either that or a filter on get_registered_nav_menus()
or get_nav_menu_locations()
.
Closing this ticket as a duplicate of #32630.