diff --git a/backport-changelog/6.8/8320.md b/backport-changelog/6.8/8320.md new file mode 100644 index 00000000000000..47fef38c64a158 --- /dev/null +++ b/backport-changelog/6.8/8320.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/8320 + +* https://github.com/WordPress/gutenberg/pull/69043 diff --git a/lib/compat/wordpress-6.8/site-editor.php b/lib/compat/wordpress-6.8/site-editor.php index 82ac118b013c16..db25d6382fed7d 100644 --- a/lib/compat/wordpress-6.8/site-editor.php +++ b/lib/compat/wordpress-6.8/site-editor.php @@ -136,6 +136,37 @@ 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. @@ -143,11 +174,11 @@ function gutenberg_styles_wp_die_handler( $default_handler ) { * @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( - __( 'Design', 'gutenberg' ), + _x( 'Design', 'Design menu item', 'gutenberg' ), 'edit_theme_options', 'site-editor.php', ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js index f4114782853cef..cabacb2ca60127 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js @@ -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 ( { isBlockBasedTheme && ( @@ -55,7 +61,7 @@ export function MainSidebarNavigationContent( { isBlockBasedTheme = true } ) { ) } - { ! isBlockBasedTheme && ( + { ! isBlockBasedTheme && showStylebookMenu && ( { - 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(), + }; + }, [] ); @@ -457,7 +465,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 ) ) { @@ -480,6 +487,18 @@ export const StyleBookPreview = ( { userConfig = {}, isStatic = false } ) => { [ globalStyles, siteEditorSettings, userConfig ] ); + if ( ! isBlockTheme && ! hasStyleBook ) { + return ( + + { __( + 'The theme you are currently using does not support the Stylebook.' + ) } + + ); + } + + const goTo = getStyleBookNavigationFromPath( section ); + return (