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 9 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
22 changes: 18 additions & 4 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export default function EditSiteEditor( {
postWithTemplate ? context.postType : postType,
postWithTemplate ? context.postId : postId
);
const _isPreviewingTheme = isPreviewingTheme();
const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();
const iframeProps = useEditorIframeProps();
const isEditMode = canvas === 'edit';
Expand All @@ -183,6 +182,9 @@ export default function EditSiteEditor( {
],
[ settings.styles, canvas, currentPostIsTrashed ]
);

// Disable Reason: useDispatch needs to be before the early return.
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );
const { createSuccessNotice } = useDispatch( noticesStore );
const history = useHistory();
Expand Down Expand Up @@ -240,14 +242,26 @@ export default function EditSiteEditor( {
]
);

// Replace the title and icon displayed in the DocumentBar when there's an overlay visible.
const title = getEditorCanvasContainerTitle( editorCanvasView );

const isReady = ! isLoading;
const transition = {
duration: disableMotion ? 0 : 0.2,
};

// Do not render the editor preview for pages or navigation menus in classic themes,
// because editing these in the Site Editor is not supported.
// The wp_template post type is used in the condition because it is used on the page screen.
if (
! isBlockBasedTheme &&
( postType === 'wp_navigation' || postType === 'wp_template' )
) {
return null;
}

// Replace the title and icon displayed in the DocumentBar when there's an overlay visible.
const title = getEditorCanvasContainerTitle( editorCanvasView );

const _isPreviewingTheme = isPreviewingTheme();

return ! isBlockBasedTheme && isHomeRoute ? (
<SitePreview />
) : (
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ html.canvas-mode-edit-transition::view-transition-group(toggle) {
}
}

.edit-site-layout__area__404 {
.edit-site-layout__area__404,
.edit-site-layout__area__unsupported {
margin: $canvas-padding;
}

Expand Down
21 changes: 20 additions & 1 deletion packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
*/
import { __ } from '@wordpress/i18n';
import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
import { privateApis as corePrivateApis } from '@wordpress/core-data';
import {
privateApis as corePrivateApis,
store as coreStore,
} from '@wordpress/core-data';
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { addQueryArgs } from '@wordpress/url';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -189,6 +193,21 @@ export default function PageTemplates() {
}
} );

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

if ( ! isBlockBasedTheme ) {
return (
<p className="edit-site-layout__area__unsupported">
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</p>
);
}

return (
<Page
className="edit-site-page-templates"
Expand Down
15 changes: 15 additions & 0 deletions packages/edit-site/src/components/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ export default function PostList( { postType } ) {
closeModal();
};

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

if ( ! isBlockBasedTheme ) {
return (
<p className="edit-site-layout__area__unsupported">
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</p>
);
}

return (
<Page
title={ labels?.name }
Expand Down
13 changes: 13 additions & 0 deletions 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,20 @@ export default function DataViewsSidebarContent( { postType } ) {
query: { activeView = 'all', isCustom = 'false' },
} = useLocation();
const defaultViews = useDefaultViews( { postType } );

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

if ( ! postType ) {
return null;
}

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

const isCustomBoolean = isCustom === 'true';

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useViewportMatch } from '@wordpress/compose';
import { Button } 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 (
<p className="edit-site-layout__area__unsupported">
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</p>
);
}

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 @@ -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 (
<p className="edit-site-layout__area__unsupported">
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</p>
);
}

if ( isLoading ) {
return (
<SidebarNavigationScreenWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ export default function SidebarNavigationScreenNavigationMenus( { backPath } ) {

const hasNavigationMenus = !! navigationMenus?.length;

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

if ( ! isBlockBasedTheme ) {
return (
<p className="edit-site-layout__area__unsupported">
{ __(
'The theme you are currently using is not compatible with the Site Editor.'
) }
</p>
);
}

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,24 @@ 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.'
)
: null
}
backPath={ backPath }
content={ <DataviewsTemplatesSidebarContent /> }
content={
isBlockBasedTheme ? <DataviewsTemplatesSidebarContent /> : ''
}
/>
);
}
Loading