Prevent error in Menu location checkbox settings#10859
Prevent error in Menu location checkbox settings#10859sabernhardt wants to merge 8 commits intoWordPress:trunkfrom
Conversation
…bedby` for checkboxes
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
@sabernhardt Request some changes on PR. |
src/wp-admin/nav-menus.php
Outdated
| foreach ( $locations as $location => $description ) : | ||
| $checked = false; | ||
| $checked = false; | ||
| $aria_describedby = ''; |
There was a problem hiding this comment.
The $aria_describedby variable is defined at the top of the foreach loop. When I tried setting the variable conditionally, checking isset() pulled values from other display locations (the variable was set earlier in the loop).
There was a problem hiding this comment.
Pull request overview
Updates the nav menus admin screen to avoid errors when a theme location is assigned to an invalid menu ID, and improves accessibility by associating the “currently set to” text with the location checkbox via aria-describedby.
Changes:
- Add fallback display text when a theme location points to an invalid menu ID (avoids fatal when accessing
->name). - Add
idto the “currently set to”<span>and conditionally addaria-describedbyon the corresponding checkbox.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/wp-admin/nav-menus.php
Outdated
| _x( '(Currently set to: %s)', 'menu location' ), | ||
| wp_get_nav_menu_object( $menu_locations[ $location ] )->name | ||
| is_nav_menu( $menu_locations[ $location ] ) ? wp_get_nav_menu_object( $menu_locations[ $location ] )->name : __( 'an invalid menu ID' ) |
There was a problem hiding this comment.
This uses is_nav_menu() and then calls wp_get_nav_menu_object() again, which results in duplicate lookups (since is_nav_menu() already calls wp_get_nav_menu_object()). Consider fetching the menu object once, validating it, and then using its name to avoid redundant work and simplify the expression.
src/wp-admin/nav-menus.php
Outdated
| <span class="theme-location-set" id="theme-location-set-<?php echo esc_attr( $location ); ?>"> | ||
| <?php | ||
| printf( | ||
| /* translators: %s: Menu name. */ |
There was a problem hiding this comment.
The translator comment says %s is a menu name, but in the invalid-ID case %s becomes a fallback message instead. Please update the translator comment (or refactor) so it accurately describes all possible substitution values.
| /* translators: %s: Menu name. */ | |
| /* translators: %s: Menu name or a message indicating an invalid menu ID. */ |
There was a problem hiding this comment.
The text would depend on whether the message changes, but possibly:
Menu name or a message indicating that the menu was not found.
- edit fallback message and translator comment - add `esc_html()` (for `$description` as well as for the menu name) - change indentation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Weston Ruter <[email protected]>
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks. Looks good to go. Left one non blocking feedback.
|
@westonruter Let's commit this one. It's 10 year old 👴 ticket |
|
@audrasjb Are you intending to commit? |
|
@westonruter yep |
|
fixed |


idandaria-describedbyto the connect thespanwith the checkboxes.Trac 37026
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.