Nav menus: Introduce a `wp_get_nav_menu_object` filter in `wp_get_nav_menu_object()` to filter the retrieved nav_menu term.

props westonruter.
fixes #32629.

git-svn-id: https://develop.svn.wordpress.org/trunk@32764 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2015-06-14 17:36:21 +00:00
parent 6e54e12aed
commit c6bf4b951b
1 changed files with 21 additions and 10 deletions

View File

@ -16,21 +16,32 @@
* @return object|false False if $menu param isn't supplied or term does not exist, menu object if successful.
*/
function wp_get_nav_menu_object( $menu ) {
if ( ! $menu )
return false;
$menu_obj = false;
if ( $menu ) {
$menu_obj = get_term( $menu, 'nav_menu' );
$menu_obj = get_term( $menu, 'nav_menu' );
if ( ! $menu_obj ) {
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
}
if ( ! $menu_obj )
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
if ( ! $menu_obj ) {
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
}
}
if ( ! $menu_obj )
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
if ( ! $menu_obj )
if ( ! $menu_obj || is_wp_error( $menu_obj ) ) {
$menu_obj = false;
}
return $menu_obj;
/**
* Filter the nav_menu term retrieved for wp_get_nav_menu_object().
*
* @since 4.3.0
*
* @param object|false $menu_obj Term from nav_menu taxonomy, or false if nothing had been found.
* @param string $menu The menu ID, slug, or name passed to wp_get_nav_menu_object().
*/
return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu );
}
/**