WordPress.org

Make WordPress Core

Changeset 14900


Ignore:
Timestamp:
05/25/2010 06:54:42 PM (8 years ago)
Author:
ryan
Message:

Back compat menu classes. see #12812 #13379

File:
1 edited

Legend:

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

    r14891 r14900  
    7171        $classes = $value = '';
    7272
    73         $classes = array( 'menu-item', 'menu-item-type-' . $item->type, $item->classes );
     73        $classes = array( 'menu-item', 'menu-item-type-' . $item->type );
     74        if ( !empty($item->classes) )
     75            $classes = array_merge($classes, explode(' ', $item->classes) );
    7476
    7577        if ( 'custom' != $item->type ) {
    7678            $classes[] = 'menu-item-object-' . $item->object;
    7779            $classes[] = 'menu-item-object-' . $item->type . '-' . $item->object_id;
     80            if ( 'post_type' == $item->type && 'page' == $item->object ) {
     81                // Back compat classes for pages to match wp_page_menu()
     82                $classes[] = 'page_item';
     83                $classes[] = 'page-item-' . $item->object_id;
     84                if ( !empty($item->classes) ) {
     85                    if ( in_array('current-menu-item', $classes) )
     86                        $classes[] = 'current_page_item';
     87                    if ( in_array('current-menu-parent', $classes) )
     88                        $classes[] = 'current_page_parent';
     89                    if ( in_array('current-menu-ancestor', $classes) )
     90                        $classes[] = 'current_page_ancestor';
     91                }
     92            }
     93        } elseif ( 'custom' == $item->type && in_array('current-menu-item', $classes) && in_array('menu-item-home', $classes) ) {
     94            // Back compat for home limk to match wp_page_menu()
     95            $classes[] = 'current_page_item';
    7896        }
    7997
     
    304322    $possible_object_parents = array_filter( $possible_object_parents );
    305323
    306     foreach( (array) $menu_items as $key => $menu_item ) {
     324    foreach ( (array) $menu_items as $key => $menu_item ) {
    307325        // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
    308326        if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
     
    330348            if ( $item_url == $current_url ) {
    331349                $menu_items[$key]->classes = trim( $menu_item->classes . ' ' . 'current-menu-item' );
     350                if ( untrailingslashit($current_url) == home_url() )
     351                    $menu_items[$key]->classes .= ' menu-item-home';
    332352                $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
    333353                $active_parent_object_ids[] = (int) $menu_item->post_parent;
     
    341361
    342362    // set parent's class
    343     foreach( (array) $menu_items as $key => $parent_item ) {
    344         if ( 'post_type' == $parent_item->type && is_post_type_hierarchical( $queried_object->post_type ) && in_array( $parent_item->object_id, $queried_object->ancestors ) ) 
     363    foreach ( (array) $menu_items as $key => $parent_item ) {
     364        if ( 'post_type' == $parent_item->type && is_post_type_hierarchical( $queried_object->post_type ) && in_array( $parent_item->object_id, $queried_object->ancestors ) )
    345365            $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $queried_object->post_type . '-ancestor' );
    346366        if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
Note: See TracChangeset for help on using the changeset viewer.