-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Section Styles: Switch away from using init for variation registration #62640
Section Styles: Switch away from using init for variation registration #62640
Conversation
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 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. |
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 is testing nicely for me, and like I mentioned on the core PR, I think it makes good sense to move this logic to be a side effect of resolving the data.
✅ Theme and Partials are working nicely in the post editor and site frontend
✅ Style variation applies correctly in the site editor and saves and is output by user global styles correctly
LGTM! 🚀
Good to merge? I'm cherry-picking for Beta 3 in a bit. |
✅ Done. Thanks Ella. Just confirmed the core PR should be committed shortly as well. |
Oh sorry, this is only PHP backports right? |
What?
Switches away from using
init
action to register block style variations.This PR is a backport to Gutenberg of changes proposed in WordPress/wordpress-develop#6844.
Why?
How?
The disadvantage is that these block style variations are not registered everywhere, so we have to do that in the specific places that are not yet covered:
Context
Initially, this feature worked by registering the block style variations using the
wp_theme_json_data_*
filters, see https://core.trac.wordpress.org/changeset/58264. This approach proved problematic for this flow: the user updates the styles of any of them via the global styles sidebar.This feature was updated to use the
init
hook at https://core.trac.wordpress.org/changeset/58394 The rationale was that this hook is what themes currently do to register the block styles variations via thefunctions.php
(example from TwentyTwentyFour). This approach raised issues: theinit
hook is called during installation, hence the database is not set up — which this feature requires, as it retrieves the existing global styles for user data.The approach in this PR is similar to how it initially worked, but with a couple of tweaks:
wp_theme_json_data_*
filters. Instead, this registers the variations directly in theWP_Theme_JSON_Resolver
, saving the extra processing required by the filters.Testing Instructions
Test
In the
theme.json
file of the theme, paste the following understyles.blocks.variations
:In the
styles/ember.json
(theme style variation) file, paste the following understyles.blocks.variations
:Create a new file called
styles/partial.json
(partial theme.json), and paste the following:Gravacao.do.ecra.2024-06-17.as.18.12.25.mov