From c6bf4b951b60c5ed62458c67c1d39066f207063c Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Sun, 14 Jun 2015 17:36:21 +0000 Subject: [PATCH] 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 --- src/wp-includes/nav-menu.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index f59bd3bd24..578bf23e62 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -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 ); } /**