-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Classic Themes: Enable Fonts and thus global styles #73971
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
base: trunk
Are you sure you want to change the base?
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.
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.3
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 142.0.0.0
- OS: Windows 10/11
- Theme: Twenty Seventeen 4.0
- MU Plugins: None activated
- Plugins:
- Gutenberg 22.3.0-rc.1
- Test Reports 1.2.1
Testing Instructions
- Go to Appearance > Fonts
- Upload a new font
- Create a new post
- Add a paragraph, and in Block > Typography select Font
- Select the uploaded font
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
- @youknowriad can you do a little overview of what is being introduced apart from adding fonts for classic themes? Like a more comprehensive list of items to be tested. Judging by the code, I feel that more things can be achieved apart from just what I tested.
Supplemental Artifacts
It's explained in the description. The only visible addition here is "fonts for classic themes" but to be able to do that, we had to lift some conditions to generate CSS out of global styles for classic themes. And my fear is whether the removal of these conditions has any unwanted effect on the frontend of sites using classic themes (with or without custom fonts). I have no way to know 100% outside testing classic themes and ensure the changes don't impact them. |
Yes, like all global styles changes, you have to go to the "fonts" page and "activate them" again. Making them persist with theme switches is out of scope. |
Ok, all good then 👍 |
|
Tested now in
|
| @@ -0,0 +1,144 @@ | |||
| <?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.
This whole file is only here to override the Core behavior, but in reality there's no really change here from core behavior outside calling the overridden Gutenberg theme.json functions...
| * @param WP_Theme $theme Theme object used to create response. | ||
| * @return WP_REST_Response Modified response object. | ||
| */ | ||
| function gutenberg_rest_theme_global_styles_link_rel_7_0( $response, $theme ) { |
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 just makes the global style id available in theme endpoint. I believe @t-hamano opened a trac ticket about this a few days ago as well.
|
Nice win! |
|
@youknowriad after experimenting a bit with Apart from this, for the rest all looking good to me. Maybe some collisions could appear with blocks or custom themes, but I could not find anything else. |
|
To be honest, I don't believe the tests add much value, especially since the main reason for the existing of the code is to override what code does by just calling the gutenberg functions. It's a code that is meant to be removed from Gutenberg (and core) and won't persist in any repo. |
|
Flaky tests detected in 6d5be3a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20171563157
|
Ok, I don't have all the context for the intention of these introdutions |
|
I really appreciate the help with both the automated tests and the testing. Thanks a lot :). I'm going to leave this PR open for a bit more feedback and testing and maybe we can move forward early next week. |
| foreach ( $settings['typography']['fontFamilies'] as $font_families ) { | ||
| foreach ( $font_families as $definition ) { | ||
| // Skip if "fontFace" is not defined, meaning there are no variations. | ||
| if ( empty( $definition['fontFace'] ) ) { |
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.
| if ( empty( $definition['fontFace'] ) ) { | |
| $font_faces = $definition['fontFace']; | |
| if ( empty( $font_faces ) ) { |
| if ( empty( $definition['fontFamily'] ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $font_family_name = $definition['fontFamily']; |
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.
| if ( empty( $definition['fontFamily'] ) ) { | |
| continue; | |
| } | |
| $font_family_name = $definition['fontFamily']; | |
| $font_family_name = $definition['fontFamily']; | |
| if ( empty( $font_family_name ) ) { | |
| continue; | |
| } | |
|
|
||
| // Convert font face properties. | ||
| $converted_font_faces = array(); | ||
| foreach ( $definition['fontFace'] as $font_face ) { |
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.
| foreach ( $definition['fontFace'] as $font_face ) { | |
| foreach ( $font_faces as $font_face ) { |
| if ( str_contains( $font_family_name, ',' ) ) { | ||
| $font_family_name = explode( ',', $font_family_name )[0]; | ||
| } | ||
| $font_family_name = trim( $font_family_name, "\"'" ); | ||
|
|
||
| // Skip if no font family is defined. | ||
| if ( empty( $font_family_name ) ) { | ||
| continue; | ||
| } |
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 get this section.
If the $font_family_name happens to be a string with comma separated font names, it will convert it into an array
But after conversion to array, it executes a trim? Maybe you were looking for an array_map('trim', ...)? I'm have not dug too much into the format of the fontFamily, but finally it checks again if it's empty. Is there any chance of having a fontFamily like this , ?
Additional TestingI've been playing around with a custom classic theme with a default global font: Here the playground testing environment: This is the raw blueprint: https://gist.githubusercontent.com/SirLouen/07cd5efa2e9ae0df553c933593f6feff/raw/8e184826660caeca70e72b9f3f4973d9b6b310a9/blueprint.json I've added a font to the custom theme. And then added a custom font to a paragraph of text But the font is not applying in ✅ But in the Template Code<!-- wp:paragraph -->
<p>Experimenting without font</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"fontFamily":"limelight"} -->
<p class="has-limelight-font-family">Experimenting with font</p>
<!-- /wp:paragraph -->Backend:
Frontend with the_excerpt
Frontend with the_content
|





What?
Closes #64409
This PR enables the Fonts page for classic themes. That said, the fonts page relies on Global styles working to be able to work properly:
This basically means that by enabling fonts, we're literally enabling all of global styles for classic themes (the UI for global styles remain hidden for the context of this PR).
I tested this briefly using 2019 theme, I installed some fonts, used them in some posts... Things are working decently to be honest. Now, I'm well aware that enabling global styles CSS generation can potentially have some side effects on these themes.
So I'd like some help from folks to test different kind of classic themes to see if this PR impacts frontend rendering in any way. Also check that you can install fonts and use them.