WordPress.org

Make WordPress Core

Changeset 15034


Ignore:
Timestamp:
05/28/2010 04:32:57 PM (8 years ago)
Author:
ryan
Message:

Unique menu container ids. Props filosofo. fixes #13597

File:
1 edited

Legend:

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

    r14971 r15034  
    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.
     
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.