Make WordPress Core

Ticket #38486: 38486.2.diff

File 38486.2.diff, 1.6 KB (added by florianbrinkmann, 8 years ago)
  • src/wp-includes/nav-menu-template.php

     
    447447                                $classes[] = 'menu-item-home';
    448448                }
    449449
     450                // Get the custom post types
     451                $custom_post_types = get_post_types( array(
     452                        '_builtin' => false,
     453                        'public'   => true,
     454                ),
     455                        'names', 'and' );
     456
    450457                // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
    451                 if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
     458                if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id && ! is_post_type_archive( $custom_post_types ) && ! is_singular( $custom_post_types ) )
    452459                        $classes[] = 'current_page_parent';
    453460
     461                // Check if we are on a single view of a custom post type
     462                if ( is_singular( $custom_post_types ) ) {
     463                        // get the post type.
     464                        $custom_post_type = get_post_type();
     465
     466                        // Check if the currently looped menu item is a post type archive item for this custom post type.
     467                        if ( 'post_type_archive' === $menu_item->type && $custom_post_type === $menu_item->object ) {
     468                                // add the current_page_parent class to the menu item.
     469                                $classes[] = 'current_page_parent';
     470                        }
     471                }
     472
    454473                $menu_items[$key]->classes = array_unique( $classes );
    455474        }
    456475        $active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );