From df11970e18df16d56427dedb700980dbdb6c9766 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Sun, 14 Jun 2015 17:37:25 +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. Built from https://develop.svn.wordpress.org/trunk@32764 git-svn-id: http://core.svn.wordpress.org/trunk@32735 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu.php | 31 +++++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index f59bd3bd24..578bf23e62 100644 --- a/wp-includes/nav-menu.php +++ b/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 ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 8b64198614..f852276de2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32763'; +$wp_version = '4.3-alpha-32764'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.