WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/05/2017 01:37:39 AM (23 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r41237 r41766  
    183183     */
    184184    return apply_filters( 'has_nav_menu', $has_nav_menu, $location );
     185}
     186
     187/**
     188 * Returns the name of a navigation menu.
     189 *
     190 * @since 4.9.0
     191 *
     192 * @param string $location Menu location identifier.
     193 * @return string Menu name.
     194 */
     195function wp_get_nav_menu_name( $location ) {
     196    $menu_name = '';
     197
     198    $locations = get_nav_menu_locations();
     199
     200    if ( isset( $locations[ $location ] ) ) {
     201        $menu = wp_get_nav_menu_object( $locations[ $location ] );
     202
     203        if ( $menu && $menu->name ) {
     204            $menu_name = $menu->name;
     205        }
     206    }
     207
     208    /**
     209     * Filters the navigation menu name being returned.
     210     *
     211     * @since 4.9.0
     212     *
     213     * @param string $menu_name Menu name.
     214     * @param string $location  Menu location identifier.
     215     */
     216    return apply_filters( 'wp_get_nav_menu_name', $menu_name, $location );
    185217}
    186218
Note: See TracChangeset for help on using the changeset viewer.