-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Theme JSON: Fix handling of default presets at block level #72916
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
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. |
|
I think this is testing ok for me now and ready for an initial review. I'll get the backport PR sorted tomorrow morning. |
|
@aaronrobertshaw Thank you so much for jumping at it right away. I tested it with my gallery aspect ratio presets and it works as expected now! 🎉 |
ramonjd
left a comment
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.
|
Just needs a backport PR too. 👍🏻 |
|
Flaky tests detected in 8d9b8ca. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19066823529
|
t-hamano
left a comment
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.
Sorry for the late reply. This pull request appears to be working as expected.
As one edge case, I defined presets with the same slug at both the global and block levels:
{
"version": 3,
"settings": {
"appearanceTools": true,
"typography": {
"defaultFontSizes": false,
"fontSizes": [
{
"name": "Small",
"slug": "small",
"size": "1em"
}
]
},
"blocks":{
"core/paragraph": {
"typography": {
"defaultFontSizes": false,
"fontSizes": [
{
"name": "Small",
"slug": "small",
"size": "2em"
}
]
}
}
}
}
}The preset UI is displayed correctly at both the global and block levels, and the global styles are also output correctly.
:root {
--wp--preset--font-size--small: 1em;
}
p {
--wp--preset--font-size--small: 2em;
}|
Thanks for all the testing and reviews 🙇 |
Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: bph <[email protected]>
|
I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 6763520 |







What?
Fixes: #72810
Prevents an issue where block level presets do not work correctly when:
Why?
Without this fix theme authors are forced to define presets only at the global level or fudge block-level preset definition slugs. This leads to a poorer end user experience.
How?
The naming and shape of these preset configs can be a bit confusing but the fix itself is rather straightforward. When merging the block level config for default presets is preferred, only falling back to the global config value if it hasn't been set.
Ensuring the correct default preset config from the block level is used prevents incorrect filtering of theme presets.
Testing Instructions
For each theme.json example config below:
Duotone
In the image block, only the "Dark grayscale" duotone preset should be available
{ "version": 3, "appearanceTools": true, "settings": { "blocks":{ "core/image": { "color": { "defaultDuotone": false, "duotone": [ { "name": "Dark grayscale", "colors": [ "#000000", "#7f7f7f" ], "slug": "dark-grayscale" } ] } } } } }Shadow
In the image block, only the "Natural" shadow preset should be available
{ "version": 3, "settings": { "appearanceTools": true, "blocks":{ "core/image": { "shadow": { "defaultPresets": false, "presets": [ { "name": "Natural", "slug": "natural", "shadow": "6px 6px 9px rgba(0, 0, 0, 0.2)" } ] } } } } }Font Size
In the Paragraph block, only the "Small" duotone preset should be available
{ "version": 3, "settings": { "appearanceTools": true, "blocks":{ "core/paragraph": { "typography": { "defaultFontSizes": false, "fontSizes": [ { "name": "Small", "slug": "small", "size": "13px" } ] } } } } }Screenshots or screencast