WordPress.org

Make WordPress Core

Ticket #13597: unique-menu-container-ids.13597.diff

File unique-menu-container-ids.13597.diff, 2.4 KB (added by filosofo, 8 years ago)
  • wp-includes/nav-menu-template.php

     
    188188 * menu - The menu that is desired.  Accepts (matching in order) id, slug, name. Defaults to blank.
    189189 * menu_class - CSS class to use for the ul container of the menu list. Defaults to 'menu'.
    190190 * container - Whether to wrap the ul, and what to wrap it with. Defaults to 'div'.
    191  * conatiner_class - the class that is applied to the container. Defaults to blank.
     191 * container_class - the class that is applied to the container. Defaults to blank.
     192 * container_id - The ID that is applied to the container.  Defaults to the menu slug, incremented.
    192193 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
    193194 * before - Text before the link text.
    194195 * after - Text after the link text.
     
    205206 * @param array $args Arguments
    206207 */
    207208function wp_nav_menu( $args = array() ) {
    208         $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
    209         'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
     209        global $_wp_nav_menu_slugs;
     210        $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu',
     211        'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
    210212        'depth' => 0, 'walker' => '', 'context' => 'frontend', 'theme_location' => '' );
    211213
    212214        $args = wp_parse_args( $args, $defaults );
     
    269271        unset($sorted_menu_items);
    270272
    271273        // Attributes
    272         $attributes  = ' id="menu-' . $menu->slug . '"';
     274        $slug = 'menu-' . $menu->slug;
     275        if ( ! is_array( $_wp_nav_menu_slugs ) )
     276                $_wp_nav_menu_slugs = array();
     277
     278        while ( in_array( $slug, $_wp_nav_menu_slugs ) ) {
     279                if ( preg_match( '#-(\d+)$#', $slug, $matches ) )
     280                        $slug = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $slug);
     281                else
     282                        $slug = $slug . '-1';
     283        }
     284       
     285        $_wp_nav_menu_slugs[] = $slug;
     286               
     287        $attributes = ' id="' . ( empty( $args->container_id ) ? $slug : $args->container_id ) . '"';
    273288        $attributes .= $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
    274289
    275290        $nav_menu .= '<ul'. $attributes .'>';