Skip to content

Commit

Permalink
Classic themes: prevent access to parts of the Site Editor (#69473)
Browse files Browse the repository at this point in the history
* Classic themes: prevent access to parts of the Site Editor

* Fix black screen

* e2e: Activate block theme for "Block Hooks in Navigation Menu" tests

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ockham <[email protected]>
Co-authored-by: Rishit30G <[email protected]>
  • Loading branch information
6 people authored Mar 10, 2025
1 parent abf6d41 commit 66394c4
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 35 deletions.
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,29 @@ 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 />
) : (
<SidebarNavigationScreenUnsupported />
);
},
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,35 @@
*/
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 />
) : (
<SidebarNavigationScreenUnsupported />
);
},
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
4 changes: 3 additions & 1 deletion test/e2e/specs/editor/plugins/block-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ test.describe( 'Block Hooks API', () => {
'<!-- wp:navigation-link {"label":"wordpress.org","url":"https://wordpress.org","kind":"custom"} /-->',
} );

// The navigation menu in the site editor is only supported in block themes.
await requestUtils.activateTheme( 'emptytheme' );
await requestUtils.activatePlugin( 'gutenberg-test-block-hooks' );

// We need a container to hold our Navigation block instance.
Expand All @@ -303,8 +305,8 @@ test.describe( 'Block Hooks API', () => {
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
await requestUtils.deactivatePlugin( 'gutenberg-test-block-hooks' );

await requestUtils.deleteAllPages();
await requestUtils.deleteAllMenus();
} );
Expand Down

0 comments on commit 66394c4

Please sign in to comment.