CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Command Palette: Register menu navigation based on Core Menu API #71476
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
Conversation
164ef77
to
1ca0e6f
Compare
Size Change: -608 B (-0.03%) Total Size: 1.93 MB
ℹ️ View Unchanged
|
Flaky tests detected in 50869df. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17480311542
|
8889f19
to
d6739e1
Compare
while ( preg_match( '/<[^>]*>/', $menu_label ) ) { | ||
$menu_label = preg_replace( '/<[^>]*>.*?<\/[^>]*>|<[^>]*\/>|<[^>]*>/s', '', $menu_label ); | ||
} |
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.
This process was a bit tedious. For example, the "Comments" menu is actually made up of the following HTML, which includes text for screen readers:

Comments <span class="awaiting-mod count-0"><span class="pending-count" aria-hidden="true">0</span><span class="comments-in-moderation-text screen-reader-text">0 Comments in moderation</span></span>
The command palette cannot handle labels that contain HTML, so I had to remove the HTML and the content within it.
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.
Isn't there already wp functions to do this kind of things like strip_tags or something.
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.
Unfortunately, as far as I could find, there is no such function, either in WP or PHP functions 😅
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.
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.
The wp_strip_all_tags
removes text only inside style
or script
tag:
echo wp_strip_all_tags( 'Hello<span>World</span>' ); // HelloWorld
echo wp_strip_all_tags( 'Hello<script>World</script>' ); // Hello
echo wp_strip_all_tags( 'Hello<style>World</style>' ); // Hello
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.
Ignore me then :)
ee8a8c4
to
9283fcf
Compare
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
} | ||
$menu_label = trim( $menu_label ); | ||
|
||
// Only add the menu item if the menu_slug point to a PHP file. |
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.
Can you explain what other cases exist?
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.
The menu_slug
can be just a PHP file, an external URL, or just a string as an identifier. Initially, I intended to allow menus that are only PHP files, but I was able to handle all that properly in 1efec2c.
1bded6855dd67c45995d2465248a7661.mp4
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.
This is really cool. I love all the red. I wonder if we should have icons for these "go to" commands, maybe like arrows or something but I'm not sure.
The other thing is that there's a lot of existing custom navigation commands that should probably also be updated to use "go to" (like the ones navigating to specific templates, pages...). I think we need consistency there but these can be addressed separately.
I see, I would like to address the above as a follow-up PR. |
Part of #71318
See: #71318 (comment)
Core backport PR: https://github.com/WordPress/wordpress-develop/pull/9542/files (Needs to be updated along with this PR)
What?
This PR automatically registers screen navigation commands based on the global
$menu
and$submenu
variables.Why?
This approach has many advantages, but also some disadvantages.
Pros
current_user_can
are registered on the server side, and we don't need to performcanUser
checks on the client side.Cons
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast