Skip to content
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

Font face resolver: print font faces from font families defined in all theme.json origins #59376

Closed
wants to merge 3 commits into from

Conversation

matiasbenedetto
Copy link
Contributor

@matiasbenedetto matiasbenedetto commented Feb 26, 2024

What?

Port this PR from WordPress core repo: WordPress/wordpress-develop#6161

Font face resolver: If a font family name is repeated across theme.json origins (default, theme, custom), only the font faces from one origin are rendered, so the site lacks the other font faces added.

This problem was reported originally here: #58764

Why?

To print the missing font faces when a font family is defined in more than one place.
Fixes: #58764

How ?

The parse_settings method of the WP_Font_Face_Resolver class uses an associative array to list all the font families that must be printed on the page. This PR replaces it with an indexed array because the associative array prevents having more than one font family with the same name, causing the bug that this PR fixes and seems unnecessary.

Testing instruction

  1. Use a theme with at least one font family defined with some font faces.
  2. Using the font library, install a font family with the same name as the existing in the theme.
  3. Navigate the site's public frontend and check that all the font faces were printed to the page in the <style id="wp-fonts-local"></style> tag.

Copy link

github-actions bot commented Feb 26, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: arthur791004 <arthur791004@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: okmttdhr <okat@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@matiasbenedetto matiasbenedetto added [Type] Bug An existing feature does not function as intended [Feature] Typography Font and typography-related issues and PRs labels Feb 26, 2024
Copy link

github-actions bot commented Feb 26, 2024

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/compat/wordpress-6.5/fonts/font-face/class-wp-font-face-resolver.php
❔ lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php
❔ lib/compat/wordpress-6.4/fonts/fonts.php
❔ lib/load.php
❔ lib/compat/wordpress-6.5/fonts/font-face/class-wp-font-face.php

}

$fonts[ $font_family_name ] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
$fonts[] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should move to 6.5 folder now I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that because of this particular change or because of something else?

If you mean because of this particular change, this is my rationale:

I understand that the wordpress-6.4 folder holds the code needed to make the code work with the latest Gutenberg version running on WordPress < 6.4, right? That's still true, so I'm unsure why this should be moved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the wordpress-6.4 folder holds the code needed to make the code work with the latest Gutenberg version running on WordPress < 6.4, right?

no, wordpress-6.4 is the code that was backported during 6.4, so to make Gutenberg work with 6.3 and lower.

Copy link
Contributor Author

@matiasbenedetto matiasbenedetto Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wordpress-6.4 is the code that was backported during 6.4, so to make Gutenberg work with 6.3 and lower.

I think we said the same but with different words :)


Given this PR is only a bugfix, and these classes were merged in 6.4, and only one bugfix will be different in 6.5, should we still move all files to the WordPress-6.5 folder?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because the 6.4 folder will get removed once the minimum supported version for Gutenberg is going to be 6.4 but that particular fix will still be needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we don't figure out a way to override the 6.4 use-case properly, then there's no match point in "fixing" this bug in Gutenberg. Maybe we should just close this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

figure out a way to override the 6.4 use-case properly

The use 6.4 use-case would be printing all the font faces when running wp 6.4 + the latest GB plugin, but I don't understand the quote. Could you explain or add more context, please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your question :P

I'm saying that if we can't override the class properly on Gutenberg, why change it at all, the 6.4 code should match the code that was merged in 6.4 and we can't move it to 6.5 and update it because it will have no effect anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, thanks for explaining. In that case, the bug will be still there when running 6.4 + Gutenberg. Is that ok? If that's OK we can close the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok for me I think.

@matiasbenedetto
Copy link
Contributor Author

Closing this PR following @youknowriad 's rationale in this comment: #59376 (comment)

if we can't override the class properly on Gutenberg, why change it at all, the 6.4 code should match the code that was merged in 6.4 and we can't move it to 6.5 and update it because it will have no effect anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font Weight Conflicts Between Built-in and Installed Fonts
2 participants