WordPress.org

Make WordPress Core

Changeset 15408


Ignore:
Timestamp:
07/13/10 21:31:20 (4 years ago)
Author:
nacin
Message:

Prevent the same menu item from receiving duplicate IDs if the menu is used twice. All menu items now get a class with their post ID; only the first item now gets an ID. fixes #13976 for 3.0.

File:
1 edited

Legend:

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

    r15321 r15408  
    7272 
    7373        $classes = empty( $item->classes ) ? array() : (array) $item->classes; 
     74        $classes[] = 'menu-item-' . $item->ID; 
    7475 
    7576        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); 
    7677        $class_names = ' class="' . esc_attr( $class_names ) . '"'; 
    7778 
    78         $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; 
     79        $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); 
     80        $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; 
     81 
     82        $output .= $indent . '<li' . $id . $value . $class_names .'>'; 
    7983 
    8084        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : ''; 
     
    438442 * 
    439443 * @uses Walker_Nav_Menu to create HTML list content. 
    440  * @since 2.1.0 
     444 * @since 3.0.0 
    441445 * @see Walker::walk() for parameters and return description. 
    442446 */ 
     
    448452} 
    449453 
     454/** 
     455 * Prevents a menu item ID from being used more than once. 
     456 * 
     457 * @since 3.0.1 
     458 * @access private 
     459 */ 
     460function _nav_menu_item_id_use_once( $id, $item ) { 
     461    static $_used_ids = array(); 
     462    if ( in_array( $item->ID, $_used_ids ) ) 
     463        return ''; 
     464    $_used_ids[] = $item->ID; 
     465    return $id; 
     466} 
     467add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); 
     468 
    450469?> 
Note: See TracChangeset for help on using the changeset viewer.