-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 style book available to classic themes #8320
base: trunk
Are you sure you want to change the base?
Conversation
Make style book available to classic themes by registering a new theme support called "stylebook". The stylebook is enabled by default. Classic themes can opt-out by removing the theme support. When the stylebook theme support is enabled, the "Patterns" menu item under Appearance changes to "Design". When the Design link is activated, the Site Editor shows a preview of the homepage and two menu items: Styles and Patterns.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Include the stylebook in the list of theme supports.
src/wp-admin/menu.php
Outdated
if ( current_theme_supports( 'stylebook' ) ) { | ||
$submenu['themes.php'][6] = array( _x( 'Design', 'patterns and stylebook menu item' ), 'edit_theme_options', 'site-editor.php' ); | ||
} else { | ||
$submenu['themes.php'][6] = array( _x( 'Patterns', 'patterns menu item' ), 'edit_theme_options', 'site-editor.php?p=pattern' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach to modifying the default menu label seems good to me. One nitpick is that I would modify the translator context passed in _x( 'Design', ... )
to say "design menu item" so that the text doesn't need to be updated if additional features are exposed inside the design panel in the future.
* @access private | ||
*/ | ||
function _add_default_theme_supports() { | ||
add_theme_support( 'stylebook' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be the first instance where we are explicitly registering default theme support option in core for all themes? If memory serves, traditionally a feature was only added behind a theme_supports
flag in the past if it could only safely be supported as an opt-in feature. I'm happy to go with this approach during beta, but if we intend to ship this feature as a default, we may want to consider a different API rather than theme_supports
, unless removing theme_supports will also remove support for the stylebook from block themes as well so the API is applied consistently.
It looks like when the Patterns menu was added, it used the be opt in based on the return value of current_theme_supports( 'block-template-parts' );
but that opt in was removed in https://core.trac.wordpress.org/changeset/58278.
One thing that is missing from this PR is the die handler from https://github.com/WordPress/gutenberg/pull/66851/files#diff-83bd9cbda7dbd9cebb20f6f75ef5a110859f5e81649c43fc6b3823ba30d1098cR119 if the stylebook URL is visited directly from a theme that does not support the stylebook. However, even with that in place it looks like there are issues that need to be addressed with the UI of the editor because even when the menu item is not exposed, the UI is still present once you open the patterns page in the editor.
With theme support:
Screen.Recording.2025-02-22.at.6.02.19.PM.mov
Without theme support registered:
Screen.Recording.2025-02-22.at.6.00.34.PM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right: Like I wrote in the description, this is not complete without the JavaScript changes. And those can not be added in this PR, they need to be part of an editor package update.
I share the concern about enabling a theme support only to be able to remove it: It is backwards. The logic is reversed compared to what is normally done.
But since I brought that up in the Gutenberg issue, nobody has been able to share alternative approaches.
I would be very hesitant to introduce a brand new way to opt-out of features.
It is already difficult for extenders to keep track of which method to use to remove or enable features.
So if it is not theme support, in my opinion, it needs to be a different method that already exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The die handler change is not part of this PR because it is not compatible with the changes to the path management in #7903.
There was a similar attempt here, but it was closed after review because it was not an ideal solution: WordPress/gutenberg#68959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly for or against opting out of the block theme style book. The reason why it was not a focus is because of the short amount of time until Beta 1.
There is a separate open Gutenberg Github issue and PR about users of classic themes being able to access the Site Editor if they enter the path to the screen manually: |
Thanks for the additional context, @carolinan! We've already done an initial sync of editor packages to trunk, but any additional changes that have been made in the last few weeks will likely come over in the next sync. We can double check the remaining UI issues at that point. Personally, I love this feature for classic themes, and would love to see it included in we can iron out the details so folks can hide it in contexts where it's not desired. |
It hasn't been committed to Gutenberg yet. |
What we need to decide are these two things? I might have missed something.
|
For an initial commit of the underlying theme_support changes that are required (i.e., this PR), I'm happy for this to be enabled by default during the beta period. I would defer to @carolinan and the other editor leads about whether being able to opt-out by removing theme support should also remove theme support for block themes, but my gut says that the API should work consistently regardless of theme type. |
This PR is the PHP backport of WordPress/gutenberg#69043.
It is not fully functional without the JavaScript changes.
In this alternative for the stylebook in classic themes, all classic themes have a menu under Appearance called Design.
Design opens the preview of the homepage, and the sidebar has two menu items: Patterns and Styles.
Styles opens the Stylebook. This stylebook is not interactive: not yet. It is a preview of the color palette, blocks etc.
In other words, there is no opt-in for the stylebook, it is available by default.
The PR enables access to the stylebook by:
show_in_rest
set to true.In addition, the PR updates the path to the patterns page, following the recent change to the site editor URLs.
Trac ticket:
https://core.trac.wordpress.org/ticket/62509
Testing Instructions
Activate any classic theme.
Go to Appearance > Design > Styles.
The Stylebook should display correctly.
Add
remove_theme_support( 'stylebook' );
to the theme, for example in the themes functions.php file, in the theme setup.Check that the Appearance menu now has Patterns instead of Design.
(This is the part that needs the JavaScript changes: When you activate the Patterns link, and go back one step, you will see that the style book is still available even though the theme support has been removed.)
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.