From 2f0f46cb84e71acf657e247f1691a596c29a9283 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 5 Oct 2017 01:38:46 +0000 Subject: [PATCH] Menus: Introduce `wp_get_nav_menu_name()` to retrieve the name of a navigation menu as set in the admin. Props markoheijnen, christophherr, SpencerFinnell, wojtek.szkutnik, sagarprajapati, welcher, SergeyBiryukov. Fixes #13910. Built from https://develop.svn.wordpress.org/trunk@41766 git-svn-id: http://core.svn.wordpress.org/trunk@41600 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu.php | 32 ++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 7adf8e1a4e..53089a946b 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -184,6 +184,38 @@ function has_nav_menu( $location ) { return apply_filters( 'has_nav_menu', $has_nav_menu, $location ); } +/** + * Returns the name of a navigation menu. + * + * @since 4.9.0 + * + * @param string $location Menu location identifier. + * @return string Menu name. + */ +function wp_get_nav_menu_name( $location ) { + $menu_name = ''; + + $locations = get_nav_menu_locations(); + + if ( isset( $locations[ $location ] ) ) { + $menu = wp_get_nav_menu_object( $locations[ $location ] ); + + if ( $menu && $menu->name ) { + $menu_name = $menu->name; + } + } + + /** + * Filters the navigation menu name being returned. + * + * @since 4.9.0 + * + * @param string $menu_name Menu name. + * @param string $location Menu location identifier. + */ + return apply_filters( 'wp_get_nav_menu_name', $menu_name, $location ); +} + /** * Determines whether the given ID is a nav menu item. * diff --git a/wp-includes/version.php b/wp-includes/version.php index b7018cd4c6..e300c112de 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41765'; +$wp_version = '4.9-alpha-41766'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.