Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classic themes: prevent access to parts of the Site Editor #69005

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1c81aca
Classic themes: prevent access to parts of the Site Editor
carolinan Feb 3, 2025
c8b47f3
Merge branch 'trunk' into fix/classic-site-editor-access
carolinan Feb 14, 2025
9491499
Add spacing around the notice.
carolinan Feb 14, 2025
98212da
Limit access to the global styles options
carolinan Feb 14, 2025
855d93a
global styles: Make sure the notice is visible on narrow screens
carolinan Feb 14, 2025
a43d58c
Limit access to the navigation screen
carolinan Feb 14, 2025
9b01872
Prevent access to the pages screen
carolinan Feb 20, 2025
d00d248
Pages: Switch the returns so that the message shows on narrow screens.
carolinan Feb 20, 2025
6d8753f
Prevent access to the single navigation screen
carolinan Feb 20, 2025
47454e3
Merge branch 'trunk' into fix/classic-site-editor-access
carolinan Feb 21, 2025
a8bbf9a
Simplify conditions
carolinan Feb 21, 2025
0c744cd
Remove the limitation that was added to the editor
carolinan Feb 21, 2025
6db6501
Revert changes to EditSiteEditor
carolinan Feb 24, 2025
3443b65
Revert changes to EditSiteEditor
carolinan Feb 24, 2025
d497b8d
Use a warning notice for the compatibility warning
carolinan Feb 24, 2025
2f5b2ae
Try to update the templatesRoute instead of PageTemplates
carolinan Feb 24, 2025
f33f8f9
Try to update pagesRoute instead of PostList
carolinan Feb 24, 2025
c248e3c
Remove the unused CSS
carolinan Feb 24, 2025
621d6f7
Update NavigationItemRoute to hide the preview of the single navigati…
carolinan Feb 24, 2025
f99dd27
Hide the page preview
carolinan Feb 24, 2025
759ef87
Merge branch 'trunk' into fix/classic-site-editor-access
carolinan Feb 24, 2025
c0c0fc6
Merge branch 'trunk' into fix/classic-site-editor-access
carolinan Feb 28, 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
11 changes: 10 additions & 1 deletion packages/edit-site/src/components/sidebar-dataviews/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -19,9 +21,16 @@ export default function DataViewsSidebarContent( { postType } ) {
query: { activeView = 'all', isCustom = 'false' },
} = useLocation();
const defaultViews = useDefaultViews( { postType } );
if ( ! postType ) {

const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

if ( ! postType || ( ! isBlockBasedTheme && postType === 'page' ) ) {
return null;
}

const isCustomBoolean = isCustom === 'true';

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { __ } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useViewportMatch } from '@wordpress/compose';
import { Button } from '@wordpress/components';
import { Button, Notice } from '@wordpress/components';
import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
import { seen } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -73,6 +75,21 @@ export default function GlobalStylesUIWrapper() {
const isMobileViewport = useViewportMatch( 'medium', '<' );
const [ section, onChangeSection ] = useSection();

const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

if ( ! isBlockBasedTheme ) {
return (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
}

return (
<>
<Page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { addQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -45,6 +46,11 @@ export default function SidebarNavigationScreenGlobalStyles() {
);
const { set: setPreference } = useDispatch( preferencesStore );

const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

const openGlobalStyles = useCallback( async () => {
history.navigate( addQueryArgs( path, { canvas: 'edit' } ), {
transition: 'canvas-mode-edit-transition',
Expand All @@ -68,6 +74,10 @@ export default function SidebarNavigationScreenGlobalStyles() {
const shouldShowGlobalStylesFooter =
!! revisionsCount && ! isLoadingRevisions;

if ( ! isBlockBasedTheme ) {
return null;
}

return (
<>
<SidebarNavigationScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useEntityRecord, store as coreStore } from '@wordpress/core-data';
import { Spinner } from '@wordpress/components';
import { Spinner, Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
Expand Down Expand Up @@ -61,6 +61,21 @@ export default function SidebarNavigationScreenNavigationMenu( { backPath } ) {
const _handleSave = ( edits ) => handleSave( navigationMenu, edits );
const _handleDuplicate = () => handleDuplicate( navigationMenu );

const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

if ( ! isBlockBasedTheme ) {
return (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
}

if ( isLoading ) {
return (
<SidebarNavigationScreenWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { decodeEntities } from '@wordpress/html-entities';
import {
__experimentalItemGroup as ItemGroup,
Spinner,
Notice,
} from '@wordpress/components';
import { navigation } from '@wordpress/icons';

Expand Down Expand Up @@ -82,6 +83,21 @@ export default function SidebarNavigationScreenNavigationMenus( { backPath } ) {

const hasNavigationMenus = !! navigationMenus?.length;

const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

if ( ! isBlockBasedTheme ) {
return (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
}

if ( isLoading ) {
return (
<SidebarNavigationScreenWrapper backPath={ backPath }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -10,14 +12,23 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
import DataviewsTemplatesSidebarContent from './content';

export default function SidebarNavigationScreenTemplatesBrowse( { backPath } ) {
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);
return (
<SidebarNavigationScreen
title={ __( 'Templates' ) }
description={ __(
'Create new templates, or reset any customizations made to the templates supplied by your theme.'
) }
description={
isBlockBasedTheme &&
__(
'Create new templates, or reset any customizations made to the templates supplied by your theme.'
)
}
backPath={ backPath }
content={ <DataviewsTemplatesSidebarContent /> }
content={
isBlockBasedTheme && <DataviewsTemplatesSidebarContent />
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { Notice } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -12,12 +16,29 @@ import { unlock } from '../../lock-unlock';

const { useLocation } = unlock( routerPrivateApis );

const PreviewComponent = () => {
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

return isBlockBasedTheme ? (
<Editor />
) : (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
};

function MobileNavigationItemView() {
const { query = {} } = useLocation();
const { canvas = 'view' } = query;

return canvas === 'edit' ? (
<Editor />
<PreviewComponent />
) : (
<SidebarNavigationScreenNavigationMenu backPath="/navigation" />
);
Expand All @@ -30,7 +51,7 @@ export const navigationItemRoute = {
sidebar: (
<SidebarNavigationScreenNavigationMenu backPath="/navigation" />
),
preview: <Editor />,
preview: <PreviewComponent />,
mobile: <MobileNavigationItemView />,
},
};
41 changes: 35 additions & 6 deletions packages/edit-site/src/components/site-editor-routes/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { Notice } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -16,11 +19,40 @@ import { PostEdit } from '../post-edit';

const { useLocation } = unlock( routerPrivateApis );

const useIsBlockBasedTheme = () =>
useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

const ContentComponent = () => {
const isBlockBasedTheme = useIsBlockBasedTheme();

return isBlockBasedTheme ? (
<PostList postType="page" />
) : (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
};

const PreviewComponent = ( { query } ) => {
const isBlockBasedTheme = useIsBlockBasedTheme();
const isListView =
( query.layout === 'list' || ! query.layout ) &&
query.isCustom !== 'true';

return isListView && isBlockBasedTheme ? <Editor /> : null;
};

function MobilePagesView() {
const { query = {} } = useLocation();
const { canvas = 'view' } = query;

return canvas === 'edit' ? <Editor /> : <PostList postType="page" />;
return canvas === 'edit' ? <Editor /> : <ContentComponent />;
}

export const pagesRoute = {
Expand All @@ -34,12 +66,9 @@ export const pagesRoute = {
content={ <DataViewsSidebarContent postType="page" /> }
/>
),
content: <PostList postType="page" />,
content: <ContentComponent />,
preview( { query } ) {
const isListView =
( query.layout === 'list' || ! query.layout ) &&
query.isCustom !== 'true';
return isListView ? <Editor /> : undefined;
return <PreviewComponent query={ query } />;
},
mobile: <MobilePagesView />,
edit( { query } ) {
Expand Down
29 changes: 27 additions & 2 deletions packages/edit-site/src/components/site-editor-routes/templates.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import Editor from '../editor';
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
import PageTemplates from '../page-templates';

const ContentComponent = () => {
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);

return isBlockBasedTheme ? (
<PageTemplates />
) : (
<Notice status="warning" isDismissible={ false }>
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</Notice>
);
};

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