-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Enable the command palette feature everywhere in WordPress #54515
base: trunk
Are you sure you want to change the base?
Changes from 9 commits
22a10aa
f24e68b
8e13379
0358348
4099e69
6de26eb
0096521
2873f18
a3c3e48
b708650
d381a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Experiment to enable Command Palette everywhere in WordPress. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Enqueue the command palette everywhere in WordPress. | ||
* | ||
* @package gutenberg | ||
*/ | ||
function gutenberg_enqueue_commands() { | ||
if ( ! is_user_logged_in() ) { | ||
return; | ||
} | ||
|
||
wp_enqueue_style( 'wp-commands' ); | ||
wp_enqueue_script( 'wp-core-commands' ); | ||
|
||
wp_add_inline_script( | ||
'wp-core-commands', | ||
<<<'EOT' | ||
const { useCommands } = wp.coreCommands.unlock(wp.coreCommands.privateApis); | ||
const { RouterProvider } = wp.coreCommands.unlock(wp.router.privateApis); | ||
const mountPoint = document.createElement('div'); | ||
|
||
mountPoint.id = 'wp-commands'; | ||
document.body.appendChild(mountPoint); | ||
|
||
const root = wp.element.createRoot(mountPoint); | ||
|
||
function CommandMenuWrapper() { | ||
useCommands(); | ||
|
||
return ( | ||
wp.element.createElement( | ||
RouterProvider, | ||
null, | ||
wp.element.createElement(wp.commands.CommandMenu, null) | ||
) | ||
); | ||
} | ||
|
||
root.render( | ||
wp.element.createElement(CommandMenuWrapper, null) | ||
); | ||
EOT | ||
); | ||
} | ||
|
||
add_action( 'wp_print_scripts', 'gutenberg_enqueue_commands', 1 ); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { unlock } from './lock-unlock'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this is not something we should export but it makes "private APIs" public for any third-party plugin and this shouldn't be the case. Maybe we should just export the CommandWrapper component like we used to do? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I exported a commands-menu-wrapper component from the core-commands packages and used a small inline script to register it on the page in d381a0d. I honestly would have preferred to this wrapper in the commands package instead but the circular dependency doesn't make this simple. |
||
export { privateApis } from './private-apis'; |
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.
We should probably move this to
lib/wordpress-6.4
(or 6.5) depending on when the PR lands.