-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Prevent access to the Design/Styles screen from classic …
…themes without StyleBook support
- Loading branch information
Showing
7 changed files
with
148 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/edit-site/src/components/sidebar-navigation-screen-unsupported/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 current screen.' | ||
) } | ||
</Notice> | ||
</Spacer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 30 additions & 21 deletions
51
packages/edit-site/src/components/site-editor-routes/patterns.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SidebarNavigationScreenPatterns from '../sidebar-navigation-screen-patterns'; | ||
import PagePatterns from '../page-patterns'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
function MobilePatternsView() { | ||
const { query = {} } = useLocation(); | ||
const { categoryId } = query; | ||
|
||
return !! categoryId ? ( | ||
<PagePatterns /> | ||
) : ( | ||
<SidebarNavigationScreenPatterns backPath="/" /> | ||
); | ||
} | ||
import { isClassicThemeStyleBookSupported } from './utils'; | ||
|
||
export const patternsRoute = { | ||
name: 'patterns', | ||
path: '/pattern', | ||
areas: { | ||
sidebar: <SidebarNavigationScreenPatterns backPath="/" />, | ||
sidebar( { siteData } ) { | ||
const backPath = isClassicThemeStyleBookSupported( siteData ) | ||
? undefined | ||
: '/'; | ||
const isRoot = isClassicThemeStyleBookSupported( siteData ); | ||
|
||
return ( | ||
<SidebarNavigationScreenPatterns | ||
backPath={ backPath } | ||
isRoot={ isRoot } | ||
/> | ||
); | ||
}, | ||
content: <PagePatterns />, | ||
mobile: <MobilePatternsView />, | ||
mobile( { siteData, query } ) { | ||
const { categoryId } = query; | ||
const backPath = isClassicThemeStyleBookSupported( siteData ) | ||
? undefined | ||
: '/'; | ||
const isRoot = isClassicThemeStyleBookSupported( siteData ); | ||
|
||
return !! categoryId ? ( | ||
<PagePatterns /> | ||
) : ( | ||
<SidebarNavigationScreenPatterns | ||
backPath={ backPath } | ||
isRoot={ isRoot } | ||
/> | ||
); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/edit-site/src/components/site-editor-routes/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Check if the classic theme supports the stylebook. | ||
* | ||
* @param {Object} siteData - The site data provided by the site editor route area resolvers. | ||
* @return {boolean} True if the stylebook is supported, false otherwise. | ||
*/ | ||
export function isClassicThemeStyleBookSupported( siteData ) { | ||
const isBlockTheme = siteData.currentTheme?.is_block_theme; | ||
const supportsEditorStyles = | ||
siteData.currentTheme?.theme_supports[ 'editor-styles' ]; | ||
// supportsLayout is equivalent to the `wp_theme_has_theme_json()` PHP function. | ||
const hasThemeJson = siteData.editorSettings?.supportsLayout; | ||
return ! isBlockTheme && ( supportsEditorStyles || hasThemeJson ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters