Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
19f65b1
initial draft: move navigation commands to core commands
yashjawale Aug 25, 2025
b4c4600
Merge branch 'trunk' into fix/command-palette-navigation-commands-ava…
yashjawale Aug 26, 2025
44debcf
Merge branch 'trunk' into fix/command-palette-navigation-commands-ava…
yashjawale Aug 28, 2025
c6bf218
Editor: Update command palette test for custom CSS navigation
yashjawale Aug 28, 2025
a8da2d5
Merge branch 'trunk' into fix/command-palette-navigation-commands-ava…
yashjawale Sep 3, 2025
a61d7dd
fix: move custom css commands back to edit-site
yashjawale Sep 3, 2025
dc564bd
fix: update custom CSS command label
yashjawale Sep 5, 2025
08d18c6
fix: update go to styles command label
yashjawale Sep 5, 2025
a12b460
fix: update navigation command labels with colon
yashjawale Sep 5, 2025
1b85abf
fix: move commands from separate file to existing ones
yashjawale Sep 5, 2025
652a29f
Merge branch 'trunk' into fix/command-palette-navigation-commands-ava…
yashjawale Sep 5, 2025
8fcbf58
fix: re-add global styles navigation commands to site editor
yashjawale Sep 5, 2025
24ad592
fix: remove redundant global styles navigation command from site editor
yashjawale Sep 5, 2025
44f7f04
fix: implement pages override command in site editor to resolve Menu …
yashjawale Sep 8, 2025
324876f
Merge branch 'trunk' into fix/command-palette-navigation-commands-ava…
yashjawale Sep 8, 2025
4612e34
fix: filter Pages command in site editor navigation
yashjawale Sep 8, 2025
ba25952
Revert "fix: filter Pages command in site editor navigation"
yashjawale Sep 9, 2025
8b561d7
revert: remove pages command override
yashjawale Sep 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/core-commands/src/admin-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
import { useCommandLoader } from '@wordpress/commands';
import { __, sprintf } from '@wordpress/i18n';
import { external } from '@wordpress/icons';
import { useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

const getAdminNavigationCommands = ( menuCommands ) =>
function useAdminBasicNavigationCommands() {
Expand Down Expand Up @@ -33,9 +36,48 @@ const getAdminNavigationCommands = ( menuCommands ) =>
};
};

const getViewSiteCommand = () =>
function useViewSiteCommand() {
const homeUrl = useSelect( ( select ) => {
// Site index.
return select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
)?.home;
}, [] );

const commands = useMemo( () => {
if ( ! homeUrl ) {
return [];
}

return [
{
name: 'core/view-site',
label: __( 'View site' ),
icon: external,
callback: ( { close } ) => {
close();
window.open( homeUrl, '_blank' );
},
},
];
}, [ homeUrl ] );

return {
isLoading: false,
commands,
};
};

export function useAdminNavigationCommands( menuCommands ) {
useCommandLoader( {
name: 'core/admin-navigation',
hook: getAdminNavigationCommands( menuCommands ),
} );

useCommandLoader( {
name: 'core/view-site',
hook: getViewSiteCommand(),
} );
}
15 changes: 8 additions & 7 deletions packages/core-commands/src/site-editor-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
) {
result.push( {
name: 'core/edit-site/open-template-parts',
label: __( 'Template parts' ),
label: __( 'Go to: Template parts' ),
icon: symbolFilled,
callback: ( { close } ) => {
if ( isSiteEditor ) {
Expand Down Expand Up @@ -299,9 +299,10 @@ const getSiteEditorBasicNavigationCommands = () =>
const result = [];

if ( canCreateTemplate && isBlockBasedTheme ) {
// Go to Styles command
result.push( {
name: 'core/edit-site/open-styles',
label: __( 'Styles' ),
label: __( 'Go to: Styles' ),
icon: styles,
callback: ( { close } ) => {
if ( isSiteEditor ) {
Expand All @@ -320,7 +321,7 @@ const getSiteEditorBasicNavigationCommands = () =>

result.push( {
name: 'core/edit-site/open-navigation',
label: __( 'Navigation' ),
label: __( 'Go to: Navigation' ),
icon: navigation,
callback: ( { close } ) => {
if ( isSiteEditor ) {
Expand All @@ -339,7 +340,7 @@ const getSiteEditorBasicNavigationCommands = () =>

result.push( {
name: 'core/edit-site/open-pages',
label: __( 'Pages' ),
label: __( 'Go to: Pages' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it appears that the label overlaps with a command registered via the Menu API. Ideally, it should be moved to site-editor.php?p=%2Fpage in the site editor, but we may have no choice but to delete this command and move it to edit.php?post_type=page.

Image

cc @youknowriad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to remove the command for now.

The alternative is to override the other command (unregister it and register this one instead when we're in the site editor)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to override the other command (unregister it and register this one instead when we're in the site editor)

@yashjawale Would you like to try this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll give that a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me unregistering didn't seem to work, it was getting registered again...
Instead I've tried to filter commands in admin-navigation-commands.js itself which worked

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I realized that we need a lot of code to override. In this PR, how about removing the "Go to: Pages" command from the edit-site and respecting the menu command? Perhaps we can try a better approach in a follow-up PR.

icon: page,
callback: ( { close } ) => {
if ( isSiteEditor ) {
Expand All @@ -358,7 +359,7 @@ const getSiteEditorBasicNavigationCommands = () =>

result.push( {
name: 'core/edit-site/open-templates',
label: __( 'Templates' ),
label: __( 'Go to: Templates' ),
icon: layout,
callback: ( { close } ) => {
if ( isSiteEditor ) {
Expand All @@ -378,7 +379,7 @@ const getSiteEditorBasicNavigationCommands = () =>
if ( canCreatePatterns ) {
result.push( {
name: 'core/edit-site/open-patterns',
label: __( 'Patterns' ),
label: __( 'Go to: Patterns' ),
icon: symbol,
callback: ( { close } ) => {
if ( canCreateTemplate ) {
Expand All @@ -394,7 +395,7 @@ const getSiteEditorBasicNavigationCommands = () =>
}
close();
} else {
// If a user cannot access the site editor
// If a user cannot access the site editor.
document.location.href =
'edit.php?post_type=wp_block';
}
Expand Down
82 changes: 8 additions & 74 deletions packages/edit-site/src/hooks/commands/use-common-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
import { useMemo } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { __, isRTL } from '@wordpress/i18n';
import {
rotateLeft,
rotateRight,
backup,
help,
styles,
external,
brush,
} from '@wordpress/icons';
import { useCommandLoader, useCommand } from '@wordpress/commands';
import { rotateLeft, rotateRight, help, brush, backup } from '@wordpress/icons';
import { useCommandLoader } from '@wordpress/commands';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as preferencesStore } from '@wordpress/preferences';
Expand All @@ -28,45 +20,6 @@ import { store as editSiteStore } from '../../store';
const { useGlobalStylesReset } = unlock( blockEditorPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );

const getGlobalStylesOpenStylesCommands = () =>
function useGlobalStylesOpenStylesCommands() {
const { openGeneralSidebar } = unlock( useDispatch( editSiteStore ) );
const { params } = useLocation();
const { canvas = 'view' } = params;
const history = useHistory();
const isBlockBasedTheme = useSelect( ( select ) => {
return select( coreStore ).getCurrentTheme().is_block_theme;
}, [] );

const commands = useMemo( () => {
if ( ! isBlockBasedTheme ) {
return [];
}

return [
{
name: 'core/edit-site/open-styles',
label: __( 'Open styles' ),
callback: ( { close } ) => {
close();
if ( canvas !== 'edit' ) {
history.navigate( '/styles?canvas=edit', {
transition: 'canvas-mode-edit-transition',
} );
}
openGeneralSidebar( 'edit-site/global-styles' );
},
icon: styles,
},
];
}, [ history, openGeneralSidebar, canvas, isBlockBasedTheme ] );

return {
isLoading: false,
commands,
};
};

const getGlobalStylesToggleWelcomeGuideCommands = () =>
function useGlobalStylesToggleWelcomeGuideCommands() {
const { openGeneralSidebar } = unlock( useDispatch( editSiteStore ) );
Expand Down Expand Up @@ -171,7 +124,7 @@ const getGlobalStylesOpenCssCommands = () =>
return [
{
name: 'core/edit-site/open-styles-css',
label: __( 'Customize CSS' ),
label: __( 'Open custom CSS' ),
icon: brush,
callback: ( { close } ) => {
close();
Expand All @@ -192,6 +145,7 @@ const getGlobalStylesOpenCssCommands = () =>
canEditCSS,
canvas,
] );

return {
isLoading: false,
commands,
Expand All @@ -213,6 +167,7 @@ const getGlobalStylesOpenRevisionsCommands = () =>
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;

return !! globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count;
}, [] );

Expand All @@ -223,8 +178,8 @@ const getGlobalStylesOpenRevisionsCommands = () =>

return [
{
name: 'core/edit-site/open-global-styles-revisions',
label: __( 'Style revisions' ),
name: 'core/edit-site/open-styles-revisions',
label: __( 'Open style revisions' ),
icon: backup,
callback: ( { close } ) => {
close();
Expand All @@ -241,10 +196,10 @@ const getGlobalStylesOpenRevisionsCommands = () =>
},
];
}, [
hasRevisions,
history,
openGeneralSidebar,
setEditorCanvasContainerView,
hasRevisions,
canvas,
] );

Expand All @@ -255,27 +210,6 @@ const getGlobalStylesOpenRevisionsCommands = () =>
};

export function useCommonCommands() {
const homeUrl = useSelect( ( select ) => {
// Site index.
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.home;
}, [] );

useCommand( {
name: 'core/edit-site/view-site',
label: __( 'View site' ),
callback: ( { close } ) => {
close();
window.open( homeUrl, '_blank' );
},
icon: external,
} );

useCommandLoader( {
name: 'core/edit-site/open-styles',
hook: getGlobalStylesOpenStylesCommands(),
} );

useCommandLoader( {
name: 'core/edit-site/toggle-styles-welcome-guide',
hook: getGlobalStylesToggleWelcomeGuideCommands(),
Expand Down
10 changes: 3 additions & 7 deletions test/e2e/specs/site-editor/command-center.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ test.describe( 'Site editor command palette', () => {
await page
.getByRole( 'button', { name: 'Open command palette' } )
.click();
await page.keyboard.type( 'Customize' );
await page.getByRole( 'option', { name: 'customize css' } ).click();
await expect(
page
.getByRole( 'region', { name: 'Editor settings' } )
.getByLabel( 'Additional CSS' )
).toBeVisible();
await page.keyboard.type( 'custom CSS' );
await page.getByRole( 'option', { name: 'Open custom CSS' } ).click();
await expect( page.getByLabel( 'Additional CSS' ) ).toBeVisible();
} );
} );
Loading