-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Menu optimizations #2018
Menu optimizations #2018
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2018 +/- ##
===========================================
+ Coverage 94.99% 95% +0.01%
Complexity 1567 1567
===========================================
Files 49 49
Lines 3694 3702 +8
===========================================
+ Hits 3509 3517 +8
Misses 185 185
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #2018 +/- ##
===========================================
+ Coverage 94.99% 95% +0.01%
Complexity 1567 1567
===========================================
Files 49 49
Lines 3694 3702 +8
===========================================
+ Hits 3509 3517 +8
Misses 185 185
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #2018 +/- ##
===========================================
+ Coverage 94.99% 95% +0.01%
Complexity 1567 1567
===========================================
Files 49 49
Lines 3694 3702 +8
===========================================
+ Hits 3509 3517 +8
Misses 185 185
Continue to review full report at Codecov.
|
Even if it's duplicative, I think we want to play nicely with how the filter normally works and where a dev is expecting to find that info
👍
My experience is that those WP functions are always cached. I think relying on that vs. a crazy chain of argument passing is better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found a little typo, and then responded to your considerations (tldr; I think the code as you have it is the right answers to those)
Ticket: #1959
Issue
See #1959.
Solution
This pull request:
theme_location
property to theTimber\Menu
class that is set when the menu is registered with a theme location.menu
property to theTimber\MenuItem
so it’s possible the parent menu object from a menu item. For this, the parent menu object is passed to the constructor ofTimber\MenuItem
.options
property to theTimber\Menu
class that holds an array of default options that can be adapted throughTimber\Menu
’s constructor. It also remove theTimber\Menu::set_options()
method and moves its content back to the constructor. I thought there’s no need to have a separate function for this.options
property as an object for the$args
parameter in the nav_menu_css_class filter.depth
from-1
to0
to match WordPress’s defaults inwp_nav_menu()
.Impact
Better parity with WordPress menu filters and defaults.
Usage Changes
It’s possible to access the theme location in various places, like in the
nav_menu_css_class
filter:And the
$args
parameter in that filter contains the options passed toTimber\Menu
.Considerations
Should we add the options for the args parameter in the
nav_menu_css_class
filter or is it obsolete, because the same options could be accessed through$item->menu->options
?I didn’t add
theme_location
toTimber\Menu::$options
, because whentheme_location
is used as an argument forwp_nav_menu()
, it’s a query to select only the menu from that location. But in Timber, you could pass this in the first argument ofTimber\Menu::__construct()
. So you would never use it as an option.In
Timber\Menu::init()
, I added$locations = get_nav_menu_locations();
to get theme the locations in order to set thetheme_location
property. We already useget_nav_menu_locations()
in theTimber\Menu::__construct()
, but it didn’t feel right to pass it down as a parameter inTimber\Menu::init()
. The locations should be cached by WordPress’s internal option handling, so I hope we’re fine here.Testing
Yes.