WordPress.org

Make WordPress Core

Changeset 15544


Ignore:
Timestamp:
08/27/10 16:13:39 (7 years ago)
Author:
nbachiyski
Message:

Make menus manipulation easier for plugin developers

  • Add a wp_nav_menu_objects filter, which gets a sorted list of all menu node objects in the currently rendered menu
  • Add current, current_item_ancestor and current_item_parent boolean member variables to each menu node object, which are true when the item has the current-menu-item, current-menu-ancestor or current-menu-parent CSS class respectively
File:
1 edited

Legend:

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

    r15407 r15544  
    197197 
    198198    unset($menu_items); 
     199     
     200    $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); 
    199201 
    200202    $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); 
     
    313315 
    314316    foreach ( (array) $menu_items as $key => $menu_item ) { 
     317         
     318        $menu_items[$key]->current = false; 
     319         
    315320        $classes = (array) $menu_item->classes; 
    316321        $classes[] = 'menu-item'; 
     
    333338        ) { 
    334339            $classes[] = 'current-menu-item'; 
     340            $menu_items[$key]->current = true; 
    335341            $_anc_id = (int) $menu_item->db_id; 
    336342 
     
    360366            if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) { 
    361367                $classes[] = 'current-menu-item'; 
     368                $menu_items[$key]->current = true; 
    362369                $_anc_id = (int) $menu_item->db_id; 
    363370 
     
    395402    foreach ( (array) $menu_items as $key => $parent_item ) { 
    396403        $classes = (array) $parent_item->classes; 
    397  
     404        $menu_items[$key]->current_item_ancestor = false; 
     405        $menu_items[$key]->current_item_parrent = false; 
     406         
    398407        if ( 
    399408            isset( $parent_item->type ) && 
     
    420429        if ( in_array(  intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) { 
    421430            $classes[] = 'current-menu-ancestor'; 
    422         } 
    423         if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) 
     431            $menu_items[$key]->current_item_ancestor = true; 
     432        } 
     433        if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) { 
    424434            $classes[] = 'current-menu-parent'; 
     435            $menu_items[$key]->current_item_parent = true; 
     436        } 
    425437        if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) 
    426438            $classes[] = 'current-' . $active_object . '-parent'; 
     
    466478} 
    467479add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); 
    468  
    469 ?> 
Note: See TracChangeset for help on using the changeset viewer.