[wp-trac] [WordPress Trac] #31525: Request for filter hook for has_nav_menu()
WordPress Trac
noreply at wordpress.org
Wed Mar 4 22:34:57 UTC 2015
#31525: Request for filter hook for has_nav_menu()
--------------------------+-----------------------------
Reporter: dougwollison | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31525>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list