-
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
Fluid typography: pass theme.json settings to override merged theme data #58362
Fluid typography: pass theme.json settings to override merged theme data #58362
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/block-supports/typography.php ❔ lib/class-wp-theme-json-gutenberg.php ❔ phpunit/block-supports/typography-test.php ❔ phpunit/class-wp-theme-json-test.php |
Size Change: +1 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 0417044. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7969791083
|
57167ab
to
713edfa
Compare
3f6da4d
to
80b31ba
Compare
80b31ba
to
35df3df
Compare
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: @costasovo. 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. |
35df3df
to
47cb65e
Compare
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 great for me @ramonjd, and the code looks good!
I was mostly testing just before your last update, so I can give it a quick re-test with the presets included. But so far:
✅ Post editor output is as on trunk
✅ Site editor output is as on trunk
✅ Refactorings look good
✅ Output with provided PHP snippet is looking good, too
Nice work 👍
I'm grateful for the testing! Sorry you had to go through that before the presets update 🙏🏻 I think that change is okay - seems like a useful addition (and fixes the output too!) but I pinged for a second opinion. Keen to hear your thoughts as well. 🍺 |
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.
Looking good to me, thanks for the updates!
Custom PHP presets handled with fluid
:
Custom PHP presets handled with fluid
set to false
:
...but I pinged for a second opinion. Keen to hear your thoughts as well.
Overall I really like the idea here, it makes a lot of sense to me to allow passing in of custom settings, and the way you've handled it for backcompat sounds reasonable to me, too 👍
Good call on getting a second opinion, but overall this LGTM! ✨
a1bb1db
to
03a7b0d
Compare
@@ -1824,7 +1825,7 @@ protected static function get_settings_values_by_slug( $settings, $preset_metada | |||
is_callable( $preset_metadata['value_func'] ) | |||
) { | |||
$value_func = $preset_metadata['value_func']; | |||
$value = call_user_func( $value_func, $preset ); | |||
$value = call_user_func( $value_func, $preset, $settings ); |
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.
Not sure yet, but this might also provide a path towards CSS var resolution for layout values. So,
"settings": {
"appearanceTools": true,
"layout": {
"contentSize": "var(--wp--custom--layout--content-size)",
"wideSize": "1100px"
},
"typography": {
"fluid": {
"maxViewportWidth": {
"ref": "settings.layout.contentSize"
},
"minViewportWidth": "600px"
}
}
},
See:
- Fluid typography: Numerical values shall support "ref" data type for better design synchronization e.g. typography.fluid.maxViewportWidth = "ref": "settings.layout.contentSize" #53525
- Typography: theme.json "layout" settings cannot be custom css variables or references, must be explicit values #55070
Tentative ping to cc @WordPress/gutenberg-core if folks have any opinions to the changes to class WP_Theme_JSON in this PR: TL;DR Passing theme.json See:
|
…raphy_font_size_value function. This is so that any stylesheets generated by the Theme_JSON class can use that class's theme_json instance.
…size_value (PHP) and getTypographyFontSizeValue (JS) Updated doc comment
Light refactoring Added extra test to check for empty objects/arrays
Added test for the above
0417044
to
73ae2ab
Compare
I'll go ahead and merge this one. If there's any contention about the approach then I'm happy revisit/revert. |
Sorry, I forgot to add co-contribs 😢
|
Fluid typography: pass theme.json settings to override merged theme data
Dev note for WordPress 6.6Some theme.json presets require custom logic to generate their values, for example, when converting font size preset values to The custom logic is handled by callback functions defined against the In WordPress 6.6, settings of the current In the case of font sizes presets, it fixes a bug whereby the callback function — |
This is a proof of concept so far. Once an approach is settled, I'll:
getTypographyFontSizeValue
)value_func
What?
Working on something that resolves #58135
Updates the second argument of
gutenberg_get_typography_font_size_value()
to be a theme_json settings array.Add a backwards compatibility condition to handle booleans.
Why?
To get fluid typography settings,
gutenberg_get_typography_font_size_value()
callsgutenberg_get_global_settings()
.gutenberg_get_global_settings()
fetches merged theme.json data viaWP_Theme_JSON_Resolver_Gutenberg
.However, to generate a stylesheet, theme.json settings are often passed directly to
WP_Theme_JSON_Gutenberg
.Consider the following (modified) example provided by @costasovo in #58135
Because typography block supports looks at the global settings only, the font sizes and CSS vars will have a
clamp()
value in the returned stylesheet if the current theme has fluid typography activated.This is despite the explicit "false" in
$themeJsonData
.How?
Passing theme.json settings to
gutenberg_get_typography_font_size_value()
as the second argument.These settings will override any global theme settings.
Currently the argument expects a boolean, so I've added a backwards compat check.
Testing Instructions
Using a theme that has activated fluid typography, add the above PHP snippet somewhere in the code (e.g., the theme's functions.php file) and log the output of
get_stylesheet()
.Check that you can override the global theme settings.
Because this PR touches all fluid typography functionality, we'll also need to test basic output:
For example, I've been comparing themes against trunk:
Also, run tests for glory!
JS
PHP
Testing Instructions for Keyboard
Screenshots or screencast