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

Make it possible to opt-out of the classic theme Stylebook #69043

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
33 changes: 32 additions & 1 deletion lib/compat/wordpress-6.8/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,45 @@ function gutenberg_styles_wp_die_handler( $default_handler ) {
}
add_filter( 'wp_die_handler', 'gutenberg_styles_wp_die_handler' );

/**
* Registers the stylebook theme support.
* Ensures that the stylebook theme support is available in the editors by setting show_in_rest to true.
* Backports into wp-includes\theme.php create_initial_theme_features().
*/
add_action(
'setup_theme',
function () {
register_theme_feature(
'stylebook',
array(
'description' => __( 'Whether a classic theme uses the Stylebook.' ),
'show_in_rest' => true,
)
);
},
0
);

/**
* Enables the stylebook theme support.
* Backports into wp-includes\theme.php _add_default_theme_supports().
*/
add_action(
'after_setup_theme',
function () {
add_theme_support( 'stylebook' );
},
1
);

/**
* Add a Styles submenu under the Appearance menu
* for Classic themes.
*
* @global array $submenu
*/
function gutenberg_add_styles_submenu_item() {
if ( ! wp_is_block_theme() && ( current_theme_supports( 'editor-styles' ) || wp_theme_has_theme_json() ) ) {
if ( ! wp_is_block_theme() && current_theme_supports( 'stylebook' ) ) {
global $submenu;

$styles_menu_item = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

export function MainSidebarNavigationContent( { isBlockBasedTheme = true } ) {
const showStylebookMenu = useSelect(
( select ) =>
select( coreStore ).getThemeSupports()?.stylebook || false,
[]
);

return (
<ItemGroup className="edit-site-sidebar-navigation-screen-main">
{ isBlockBasedTheme && (
Expand Down Expand Up @@ -55,7 +61,7 @@ export function MainSidebarNavigationContent( { isBlockBasedTheme = true } ) {
</SidebarNavigationItem>
</>
) }
{ ! isBlockBasedTheme && (
{ ! isBlockBasedTheme && showStylebookMenu && (
<SidebarNavigationItem
uid="stylebook-navigation-item"
to="/stylebook"
Expand Down
24 changes: 21 additions & 3 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,15 @@ function StyleBook( {
* @return {Object} Style Book Preview component.
*/
export const StyleBookPreview = ( { userConfig = {}, isStatic = false } ) => {
const siteEditorSettings = useSelect(
( select ) => select( siteEditorStore ).getSettings(),
const { isBlockTheme, hasStyleBook, siteEditorSettings } = useSelect(
( select ) => {
const { getCurrentTheme, getThemeSupports } = select( coreStore );
return {
isBlockTheme: getCurrentTheme()?.is_block_theme,
hasStyleBook: !! getThemeSupports()?.stylebook,
siteEditorSettings: select( siteEditorStore ).getSettings(),
};
},
[]
);

Expand Down Expand Up @@ -457,7 +464,6 @@ export const StyleBookPreview = ( { userConfig = {}, isStatic = false } ) => {
: { examples: examplesForSinglePageUse };

const { base: baseConfig } = useContext( GlobalStylesContext );
const goTo = getStyleBookNavigationFromPath( section );

const mergedConfig = useMemo( () => {
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) {
Expand All @@ -480,6 +486,18 @@ export const StyleBookPreview = ( { userConfig = {}, isStatic = false } ) => {
[ globalStyles, siteEditorSettings, userConfig ]
);

if ( ! isBlockTheme && ! hasStyleBook ) {
return (
<p className="edit-site-style-book__unsupported">
{ __(
'The theme you are currently using does not support the Stylebook.'
) }
</p>
);
}

const goTo = getStyleBookNavigationFromPath( section );

return (
<div className="edit-site-style-book">
<BlockEditorProvider settings={ settings }>
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-site/src/components/style-book/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@

overflow: auto;
}

.edit-site-style-book__unsupported {
color: $gray-400;
margin: $canvas-padding;
}
Loading