-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation block: update fallback nav creation to most recently created menu #46286
Conversation
Size Change: -18 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
@@ -277,6 +277,7 @@ function block_core_navigation_get_classic_menu_fallback() { | |||
} | |||
|
|||
// Otherwise return the most recently created classic menu. | |||
usort( $classic_nav_menus, fn( $a, $b) => $b->term_id - $a->term_id ); |
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.
I think this syntax was introduced in PHP 7.4. WordPress says it requires PHP 7.4, but I don't see any use of arrow functions in WordPress or Gutenberg, so maybe it's better to avoid them?
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.
Fixed in 3871774f423eed36338a57633418c3e8be4a3f6f
@@ -305,7 +305,8 @@ function Navigation( { | |||
if ( a.locations < b.locations ) { | |||
return 1; | |||
} | |||
if ( a.locations > b.locations ) { | |||
// If no locations are assigned, we compare the term_id to determine and sort by the most recently created. | |||
else if ( a.locations > b.locations || a.term_id < b.term_id ) { |
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.
Why are locations in this part of the calculation?
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.
Good question, I realized the logic was convoluted. Cleaned this up in 9abfcd5
3871774
to
6dc44f0
Compare
This wasn't working for me in the editor as navigation menus have an |
Thanks for the fixes, this is testing correctly for me. Any other feedback to address? |
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.
LGTM
…ed menu (WordPress#46286) * Sort fallback classic menu conversion by most recently created. * Separate sorting calc from location calc. * Use standard anonymous function syntax. * Format php. * change the property name and simplify the functions Co-authored-by: Ben Dwyer <[email protected]>
What?
This PR sorts the classic menus so the most recently created menu is used in the series of fallback nav creation.
If there is a menu named primary or has a primary location, that menu still takes precedence.
Why?
Before #45976, a navigation would only be created if the site had a single classic menu. Now that the fallback system can handle multiple cases, we need to consider which menu should be prioritized in the fallback order.
The WP function that get classic menus returns an array of menus sorted by name, alphabetically by default. So we need to instead sort by their
term_id
if we want the most recently created.How?
See above.
Testing Instructions
wp_navigation
s previouslywp_navigation
, repeat step 4 but visiting the front-end first, then the editor.Testing Instructions for Keyboard
Screenshots or screencast