Opened 10 years ago
Last modified 6 years ago
#32918 new defect (bug)
_wp_menu_item_classes_by_context does not generate "current-menu-ancestor" class when the menu structure was changed by e.g. a plugin
Reported by: | anaid | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2.2 |
Component: | Menus | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
I am the developer of Category Posts in Custom Menu. My plugin extends Walker_Nav_Menu_Edit in order to change the menu structure. At the end of the edit loop, my plugin calls _wp_menu_item_classes_by_context on the resulting new menu structure.
In a particular case, this results in a missing "current-menu-ancestor" class, because _wp_menu_item_classes_by_context retrieves the ancestors from the database (i.e. the unchanged menu structure) instead of from the $menu_items array that was passed in and may now reflect a different structure.
Steps to reproduce with my plugin:
- Appearances > Menus
- Add to the menu a Page
- Add to the menu, as child of Page, a Category that has posts
- Check "Create submenu containing links to posts in this category."
This will result in my plugin editing the menu structure, and adding all posts to the menu instead of a link to the Category. Now navigate to one of these posts. You will see that the Page does not receive the "current-menu-ancestor" class.
I have performed a quick change in nav-menu-template.php that I have only tested with my plugin so far, so it will obviously need a rewrite. I'm attaching it nonetheless because it will quickly show in a few lines of code what took me a few paragraphs to explain here... :)
Attachments (1)
Change History (4)
#1
@
10 years ago
In the steps to reproduce, a last step is needed: Set "Remove original menu item" to "Never", to obtain a three-layered menu. (Otherwise, only 'current-menu-parent' would be applicable)
Patch to retrieve ancestors from the $menu_items array instead of from the database