[wp-trac] [WordPress Trac] #32918: _wp_menu_item_classes_by_context does not generate "current-menu-ancestor" class when the menu structure was changed by e.g. a plugin
WordPress Trac
noreply at wordpress.org
Wed Jul 8 08:50:29 UTC 2015
#32918: _wp_menu_item_classes_by_context does not generate "current-menu-ancestor"
class when the menu structure was changed by e.g. a plugin
--------------------------+-----------------------------
Reporter: anaid | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 4.2.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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... :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32918>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list