wp_nav_menu check both hierarchy fail?

This is correct behavior as far as I can tell,

Imagine a scenario where you have a menu with top level items, Page A and Page B, each of which have Category 1 attached as a sub-menu item.

Scenario 1


When viewing Post Example X, Attached to Category 1 And Where Category 1 appears twice in the menu under different top level items, we see;

/*
- Page A              = no ancestor class!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B              = no ancestor class!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
*/

If you view a Post, let’s call it Post Example X, then which top level menu item should receive the current-menu-ancestor class?

  1. Should it be both Page A and Page B?
  2. Should it be Page A?
  3. Should it be Page B?

WordPress decides neither. Its better not to assume what the users intent is unless specified differently, otherwise if you have special styling associated with that class then it would be applied to all top level menu items and beyond causing unexpected results.

But if you say to me that Category 1 only appears beneath Page A top level menu ONLY and no where else, it still doesn’t matter… check out these scenarios.

Scenario 2


When viewing Post Example X, Attached to Category 1 Where Post Example X does NOT appear in the same menu tree as the top level Page A or any other top level tree, we see;

/*
- Page A              = no ancestor class, still!
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B              = not related to post
  - Category 2        = not related to post
*/

Scenario 3


When viewing Post Example X which is also, Attached to Category 1 or in the same tree as the top level Page A, we see;

/*
- Page A              = current-menu-ancestor
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
    - Post Example X  = current-menu-item
- Page B              = not related to post
  - Category 2        = not related to post
*/

Scenario 4


When viewing Post Example X which is also, Attached to Category 1 or in the same tree as the top level Page A but where Category 1 also appears beneath Page B but itself does not contain our post, we see;

/*
- Page A              = current-menu-ancestor
  - Category 1        = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
    - Post Example X  = current-menu-item
- Page B              = not related to post
  - Category         = current-menu-ancestor, current-menu-parent, current-post-parent
*/

I’m just writing this to give a general idea how it works, next I’ll take a look at the filters for nav_menu_css_class and wp_get_nav_menu_items.

My understanding behind the logic of the menu handling process is a bit fuzzy, possibly someone else will jump in and help too in the meantime.