Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Classic themes: prevent access to parts of the Site Editor
  • Loading branch information
t-hamano committed Mar 6, 2025
commit 6550696d0c023c315fc7bfabd9608a1f46c16c42
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Notice, __experimentalSpacer as Spacer } from '@wordpress/components';

export default function SidebarNavigationScreenUnsupported() {
return (
<Spacer padding={ 3 }>
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using does not support this screen.'
) }
</Notice>
</Spacer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
*/
import Editor from '../editor';
import SidebarNavigationScreenNavigationMenu from '../sidebar-navigation-screen-navigation-menu';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
import { unlock } from '../../lock-unlock';

const { useLocation } = unlock( routerPrivateApis );
Expand All @@ -27,10 +28,25 @@ export const navigationItemRoute = {
name: 'navigation-item',
path: '/wp_navigation/:postId',
areas: {
sidebar: (
<SidebarNavigationScreenNavigationMenu backPath="/navigation" />
),
preview: <Editor />,
mobile: <MobileNavigationItemView />,
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreenNavigationMenu backPath="/navigation" />
) : (
<SidebarNavigationScreenUnsupported />
);
},
preview( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? <Editor /> : undefined;
},
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<MobileNavigationItemView />
) : (
<SidebarNavigationScreenUnsupported />
);
},
},
};
24 changes: 21 additions & 3 deletions packages/edit-site/src/components/site-editor-routes/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
*/
import Editor from '../editor';
import SidebarNavigationScreenNavigationMenus from '../sidebar-navigation-screen-navigation-menus';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
import { unlock } from '../../lock-unlock';

const { useLocation } = unlock( routerPrivateApis );
Expand All @@ -27,8 +28,25 @@ export const navigationRoute = {
name: 'navigation',
path: '/navigation',
areas: {
sidebar: <SidebarNavigationScreenNavigationMenus backPath="/" />,
preview: <Editor />,
mobile: <MobileNavigationView />,
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreenNavigationMenus backPath="/" />
) : (
<SidebarNavigationScreenUnsupported />
);
},
preview( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? <Editor /> : undefined;
},
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<MobileNavigationView />
) : (
<SidebarNavigationScreenUnsupported />
);
},
},
};
38 changes: 29 additions & 9 deletions packages/edit-site/src/components/site-editor-routes/page-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,39 @@ import { __ } from '@wordpress/i18n';
import Editor from '../editor';
import DataViewsSidebarContent from '../sidebar-dataviews';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';

export const pageItemRoute = {
name: 'page-item',
path: '/page/:postId',
areas: {
sidebar: (
<SidebarNavigationScreen
title={ __( 'Pages' ) }
backPath="/"
content={ <DataViewsSidebarContent postType="page" /> }
/>
),
mobile: <Editor />,
preview: <Editor />,
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreen
title={ __( 'Pages' ) }
backPath="/"
content={ <DataViewsSidebarContent postType="page" /> }
/>
) : (
<SidebarNavigationScreenUnsupported />
);
},
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<Editor />
) : (
<SidebarNavigationScreenUnsupported />
);
},
preview( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<Editor />
) : (
<SidebarNavigationScreenUnsupported />
);
},
},
};
40 changes: 30 additions & 10 deletions packages/edit-site/src/components/site-editor-routes/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
*/
import Editor from '../editor';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
import DataViewsSidebarContent from '../sidebar-dataviews';
import PostList from '../post-list';
import { unlock } from '../../lock-unlock';
Expand All @@ -27,21 +28,40 @@ export const pagesRoute = {
name: 'pages',
path: '/page',
areas: {
sidebar: (
<SidebarNavigationScreen
title={ __( 'Pages' ) }
backPath="/"
content={ <DataViewsSidebarContent postType="page" /> }
/>
),
content: <PostList postType="page" />,
preview( { query } ) {
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreen
title={ __( 'Pages' ) }
backPath="/"
content={ <DataViewsSidebarContent postType="page" /> }
/>
) : (
<SidebarNavigationScreenUnsupported />
);
},
content( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? <PostList postType="page" /> : undefined;
},
preview( { query, siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
if ( ! isBlockTheme ) {
return undefined;
}
const isListView =
( query.layout === 'list' || ! query.layout ) &&
query.isCustom !== 'true';
return isListView ? <Editor /> : undefined;
},
mobile: <MobilePagesView />,
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<MobilePagesView />
) : (
<SidebarNavigationScreenUnsupported />
);
},
edit( { query } ) {
const hasQuickEdit =
( query.layout ?? 'list' ) !== 'list' && !! query.quickEdit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
*/
import Editor from '../editor';
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';

export const templateItemRoute = {
name: 'template-item',
path: '/wp_template/*postId',
areas: {
sidebar: <SidebarNavigationScreenTemplatesBrowse backPath="/" />,
mobile: <Editor />,
preview: <Editor />,
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreenTemplatesBrowse backPath="/" />
) : (
<SidebarNavigationScreenUnsupported />
);
},
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? <Editor /> : undefined;
},
preview( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<Editor />
) : (
<SidebarNavigationScreenUnsupported />
);
},
},
};
30 changes: 26 additions & 4 deletions packages/edit-site/src/components/site-editor-routes/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@
*/
import Editor from '../editor';
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
import PageTemplates from '../page-templates';

export const templatesRoute = {
name: 'templates',
path: '/template',
areas: {
sidebar: <SidebarNavigationScreenTemplatesBrowse backPath="/" />,
content: <PageTemplates />,
preview( { query } ) {
sidebar( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<SidebarNavigationScreenTemplatesBrowse backPath="/" />
) : (
<SidebarNavigationScreenUnsupported />
);
},
content( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? <PageTemplates /> : undefined;
},
preview( { query, siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
if ( ! isBlockTheme ) {
return undefined;
}
const isListView = query.layout === 'list';
return isListView ? <Editor /> : undefined;
},
mobile: <PageTemplates />,
mobile( { siteData } ) {
const isBlockTheme = siteData.currentTheme?.is_block_theme;
return isBlockTheme ? (
<PageTemplates />
) : (
<SidebarNavigationScreenUnsupported />
);
},
},
widths: {
content( { query } ) {
Expand Down
Loading