Skip to content

Commit

Permalink
Add command to navigate to site editor (#66722)
Browse files Browse the repository at this point in the history
* Add command to navigate to site editor

* No icon, improved label

* Modified code to display command other than Site editor

* Feedback and suggestion updates

---------

Co-authored-by: benazeer-ben <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: ramonjd <[email protected]>
  • Loading branch information
8 people authored Dec 17, 2024
1 parent 0f0f2a8 commit c5e8fd2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { store as noticesStore } from '@wordpress/notices';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import { store as interfaceStore } from '@wordpress/interface';
import { getPath } from '@wordpress/url';
import { decodeEntities } from '@wordpress/html-entities';

/**
Expand Down Expand Up @@ -90,6 +91,19 @@ const getEditorCommandLoader = () =>
const { openModal, enableComplementaryArea, disableComplementaryArea } =
useDispatch( interfaceStore );
const { getCurrentPostId } = useSelect( editorStore );
const { isBlockBasedTheme, canCreateTemplate } = useSelect(
( select ) => {
return {
isBlockBasedTheme:
select( coreStore ).getCurrentTheme()?.is_block_theme,
canCreateTemplate: select( coreStore ).canUser( 'create', {
kind: 'postType',
name: 'wp_template',
} ),
};
},
[]
);
const allowSwitchEditorMode =
isCodeEditingEnabled && isRichEditingEnabled;

Expand Down Expand Up @@ -271,6 +285,21 @@ const getEditorCommandLoader = () =>
},
} );
}
if ( canCreateTemplate && isBlockBasedTheme ) {
const isSiteEditor = getPath( window.location.href )?.includes(
'site-editor.php'
);
if ( ! isSiteEditor ) {
commands.push( {
name: 'core/go-to-site-editor',
label: __( 'Open Site Editor' ),
callback: ( { close } ) => {
close();
document.location = 'site-editor.php';
},
} );
}
}

return {
commands,
Expand Down

1 comment on commit c5e8fd2

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in c5e8fd2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12381505383
📝 Reported issues:

Please sign in to comment.