-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
base: trunk
Are you sure you want to change the base?
Conversation
-Registers and enables a new theme support called stylebook. - Introduces a check for the theme support in the Site Editor sidebar and Stylebook preview. - The sidebar menu hides the Styles menu item if it is unsupported. - The stylebook preview displays a notice at the top of the page if it is unsupported. - Classic themes can opt.out by using remove_theme_support( 'stylebook' );
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @BowFarmer. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +178 B (+0.01%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in 14aff92. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13179898863
|
Thanks for the PR! In the site editor, we're not only publishing the stylebook, but we're also making changes to path-based URLs, and changing the wp_die handler, so I'm trying to understand what order to proceed in. Perhaps the core backport PR for adding the Design submenu (WordPress/wordpress-develop#7865), needs to resolve the conflict and be merged first. I'll look into this a bit more and think about how to address this issue sometime this week. |
Note, the changes to the paths and the wp_die handler are not part of this PR, they are references to changes that are already merged into Gutenberg trunk and 6.8. This PR manages access to the Stylebook in the JavaScript files, not PHP. |
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.
From my understanding, the backport to core is not yet sufficient. See this comment.
I think we need to submit a new backport PR that replaces WordPress/wordpress-develop#7865, include the following, and link that PR to this one:
- Add
stylebook
feature to thecreate_initial_theme_features
function (if we want it enabled by default) - Override the "Patterns" submenu with the "Design" submenu if the theme supports the StyleBook. We probably need to update the logic around here.
The reason for not only removing the Design menu item from Appearance is that if you open the Patterns page, and then go back one step using the button with the arrow icon, you would see the Styles menu item and would be able to access the Stylebook from there.
For classic themes that do not support StyleBook, we should be able to stop navigating to the Styles page.
Example code
gutenberg/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js
Line 103 in 26ba1a3
export default function SidebarNavigationScreenPatterns( { backPath } ) { |
export default function SidebarNavigationScreenPatterns() {
// ...
// If isRoot is true, the back button will be a link to the dash board.
// This prevents unintentional navigation to the Styles page in classic themes that do not support StyleBook.
const isRoot = ! isBlockTheme && ! showStylebookMenu;
// The backpath determines which page in the site editor you will navigate to.
const backPath = isRoot ? undefined : '/';
return (
<SidebarNavigationScreen
title={ __( 'Patterns' ) }
isRoot={ isRoot }
backPath={ backPath }
// ...
/>
);
}
However, we will also need to update the SiteHubMobile
component for the mobile layout.
Indeed, I did not create the backport since the comment on the issue said a decision was still needed. |
I have not found any issues with the back button with this approach that makes it possible to check for the theme support in the Site Editor.
With this comment, I tried to refer to the first approach that only changed the menu item in the PHP file. With that approach, the stylebook was still reachable if you navigated to it manually. |
global $submenu; | ||
|
||
$styles_menu_item = array( | ||
__( 'Design', 'gutenberg' ), | ||
_x( 'Design', 'Design menu item', 'gutenberg' ), |
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.
Adding this PR to the 6.8 project board for visibility. |
I am not sure we need both the issue and PR on the board The solution for limiting the access to the screen should mirror #69005. |
What?
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.
The Stylebook is available to all classic themes because this PR registers a new theme support called
stylebook
, and then enables it by default. Because, you can't remove a theme support that doesn't exist.Classic themes can then opt-out of the Stylebook by removing the theme support:
remove_theme_support( 'stylebook' );
To enable checking for the new theme support in the Site Editor, I needed to make it available in the themes REST API endpoint, which is why I am using https://developer.wordpress.org/reference/functions/register_theme_feature/ with
show_in_rest
set to true.The reason for not only removing the Design menu item from Appearance is that if you open the Patterns page, and then go back one step using the button with the arrow icon, you would see the Styles menu item and would be able to access the Stylebook from there.
Closes #68036
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.
Open Patterns. Go back one step using the button in the sidebar.
Confirm that there is no Styles menu.
Go to: wp-admin/site-editor.php?p=%2Fstylebook
The Sidebar will still show the description, but the main content of the page is a notice saying that the Stylebook is not supported.
Screenshots or screencast
When the Stylebook is not supported, a notice is showing:
