Skip to content

Commit 779b377

Browse files
committed
Try inline server-side version
1 parent ee88e67 commit 779b377

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

lib/compat/wordpress-7.0/command-palette.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ function gutenberg_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ):
2424
'id' => 'command-palette',
2525
'title' => $title,
2626
'href' => '#',
27-
'meta' => array( 'class' => 'hide-if-no-js' ),
27+
'meta' => array(
28+
'class' => 'hide-if-no-js',
29+
'onclick' => 'if ( window.wp && wp.data && wp.data.dispatch ) { var store = wp.data.dispatch( "core/commands" ); if ( store && typeof store.open === "function" ) { store.open(); } } return false;',
30+
),
2831
)
2932
);
3033
}

packages/core-commands/src/index.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
* WordPress dependencies
33
*/
44
import { createRoot, StrictMode } from '@wordpress/element';
5-
import { dispatch } from '@wordpress/data';
65
import { privateApis as routerPrivateApis } from '@wordpress/router';
7-
import { store as commandsStore, CommandMenu } from '@wordpress/commands';
6+
import { CommandMenu } from '@wordpress/commands';
87

98
/**
109
* Internal dependencies
@@ -16,8 +15,6 @@ export { privateApis } from './private-apis';
1615

1716
const { RouterProvider } = unlock( routerPrivateApis );
1817

19-
const ADMIN_BAR_TRIGGER_SELECTOR = '#wp-admin-bar-command-palette a';
20-
2118
// Register core commands and render the Command Palette.
2219
function CommandPalette( { settings } ) {
2320
const { menu_commands: menuCommands, is_network_admin: isNetworkAdmin } =
@@ -44,21 +41,4 @@ export function initializeCommandPalette( settings ) {
4441
<CommandPalette settings={ settings } />
4542
</StrictMode>
4643
);
47-
48-
function attachAdminBarTrigger() {
49-
const trigger = document.querySelector( ADMIN_BAR_TRIGGER_SELECTOR );
50-
if ( ! trigger ) {
51-
return;
52-
}
53-
trigger.addEventListener( 'click', ( event ) => {
54-
event.preventDefault();
55-
dispatch( commandsStore ).open();
56-
} );
57-
}
58-
59-
if ( document.readyState === 'loading' ) {
60-
document.addEventListener( 'DOMContentLoaded', attachAdminBarTrigger );
61-
} else {
62-
attachAdminBarTrigger();
63-
}
6444
}

0 commit comments

Comments
 (0)