-
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
Implementing a Webfonts API #36394
Implementing a Webfonts API #36394
Conversation
32d78d7
to
0093e68
Compare
ba075b3
to
4f02f12
Compare
c0d08ad
to
23ee03e
Compare
phpunit/webfonts-api/class-wp-webfonts-schema-validator-test.php
Outdated
Show resolved
Hide resolved
dc8f0a4
to
dd6eb0b
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.
👋 The global styles API is not ready yet to add filters. If the goal is to register webfonts that are present in the theme theme.json
, can we do that directly in the resolver?
6e9d938
to
c576b33
Compare
Thank you for the review @oandregal!
Done 👍 |
Posting this here and will post at WordPress/wordpress-develop#1736 as well (having 2 PRs for the same thing is hard/confusing...). Been looking at this implementation for a while. It seems that it can be made a lot better by removing the "providers" abstraction. Few reasons:
Advantages of using local webfonts (from Fontsource):
In these terms my recommendations are:
|
Just FYI: still thinking this will benefit from being a feature plugin, just like any new WP feature that needs more testing. Having it merged with the Gutenberg's PHP code may help a little with testing it from Gutenberg, but can prevent testing from outside of Gutenberg... In any case, if this API is simplified significantly (as recommended above), perhaps it would be okay to bypass the standard WP development process, and any errors and omissions can be fixed later. |
Co-authored-by: Tonya Mork <[email protected]>
This reverts commit e552897.
cddda59
to
56dcf19
Compare
@aristath Hi, would you be able to make the changes as suggested above (remove the "providers" abstraction and all associated code, hard-code local webfonts, and move param type validation to the actual function |
That is no different than what happens in other WP APIs. The same script can be registered from multiple sources/CDNs, it can be registered from multiple plugins and so on. Same thing applies to styles.
Actually, the Adobe API can be used just fine, as it supported the Typekit API: https://fonts.adobe.com/docs/api. There's even some ready-to-use PHP libraries.
I agree 100% with all those points. But that doesn't mean we need to remove the providers abstraction, we can just do better and download remove webfonts to the server, and serve them locally from there.
The Google fonts class was removed from this PR 2 weeks ago 👍
Removing the providers abstraction would make it impossible to add & extend the implementation in the future to support other providers like Adobe, Google and others, either in plugins or in core. Instead of removing it, maybe we could implement them properly, enforcing locally-hosted webfonts to improve performance & privacy? This way we'd be setting a good example, and we'd see a significant performance & privacy improvement in the WP ecosystem as themes & plugins that currently use Google-fonts, Adobe-fonts and whatnot will start to adopt the API.
I submitted an alternative, simplified version of the API in #37140. EDIT: |
@aristath Thanks for the tests and alternate PRs! Really appreciate your work on this :)
Correct, but why have more edge cases when can have less or none? :)
Hmmm, seems that API is not intended for serving fonts as a CDN:
It seems intended for an Adobe user to access their Adobe account and change their (fonts) settings. However don't think that is intended to be happening on every page load of the user's website. In any case, seems best if this functionality (loading webfonts from third-party CDNs) is implemented later, ideally after WP has a User Consent API in place.
Still thinking that for now it will be best to support local fonts only which removes the need for the providers abstraction. That includes all fonts available from the Google CDN. They can be downloaded from https://fontsource.org/ or included as NPM packages (which is very handy for a lot of developers). This means that "out of the box" WordPress will support all webfonts that are available form Google plus some more open source fonts that are available only from Fontsource, plus all fonts that are purchased/downloaded from one of the fonts foundries. Unfortunately it seems support for the Adobe webfonts would have to wait for now as it seems impossible to download the webfonts you have purchased (I think I've read somewhere that it is possible to download them, but cannot find it now). Looking again at the list of advantages for using local webfonts, in practice the providers abstraction will only be needed to let plugins to add support for the Adobe webfonts CDN (if at all possible). It seems the best practice would be to use local copies of the webfonts that are available from the Google CDN. If at some point WP decides to support external CDNs that abstraction (or the filters replacing it) can be added to this API as an update. As I mentioned before this should ideally happen after there is a User Consent API in place so accessing the external webfonts CDN(s) can be made to require user consent. |
Yeah, thought about that too but not sure it will be possible for Adobe fonts. Can try to figure out if their licenses would allow it. Also don't think it is needed for Google fonts. A (much) better option would be to include these fronts as NPM dependencies or download them directly from https://github.com/fontsource/fontsource and add them in the theme/plugin. |
I agree that would be better. However, that assumes that the theme/plugin has a single font they want to use - or at most a couple of them. That is not a viable option in the wild because themes allow users to make their own decisions. |
Yes, you're right, that's a lot of extra files.
Right. This is a good optimization. It seems to have limitations that may need a "deeper look" (mostly around font licenses, etc. when using proprietary fonts for example from Adobe which might need to be excluded at first). Perhaps this can be the next step for this API. Another idea there would be to (auto) download the font files from the GitHub repo, not from the Google CDN. Yet another idea would be to let users upload fonts the same way they upload other media files (with or without using the WP uploader and/or the media library). There is another optimization/enhancement that needs addressing (perhaps at a later time too). It concerns both this API and any UI for selecting fonts or font settings. Generally the "typography" fonts are the big, multi-file fonts that support all locales. However many decorative fonts support only a limited number of locales. So both this API and the UI will need to be made "locale aware", and themes and plugins that add fonts should "know" how to "do it properly" for all locales. For now I'm thinking a possible nice enhancement may be to include few of the "big", most commonly used open source fonts in WordPress. Quite a few people probably remember that wp-admin used to use Open Sans several years ago. Eventually it was switched to use the system fonts for better speed and because of user privacy concerns. But perhaps it's time to add few fonts and switch to using one of then in wp-admin again? :) |
Hi @aristath! I was only able to skim this PR and will take a closer look tomorrow, but I'm wondering if there are any blockers for continuing work on these code changes? The only sticking point I saw after reading some of the conversations dealt with the addition / removal of the provider abstraction. cc @zaguiini |
Hey there @jeyip! |
Closing this one, as #37140 was merged |
1 similar comment
Closing this one, as #37140 was merged |
Description
This PR ports port the webfonts API to Gutenberg:
Porting the PR from Core:
Ports the API from WordPress/wordpress-develop#1736.
That patch was thoroughly discussed with core & theme developers and approved by core committers (@felixarntz, @hellofromtonya, @SergeyBiryukov), but the API was not merged in core on time for WP 5.9.
It was deemed a better choice to port the API to Gutenberg, where it can be implemented for
theme.json
and the font-family pickers (see comment on https://core.trac.wordpress.org/ticket/46370#comment:111)Note: Only the
local
provider is ported - which is the default. Other providers (such as google-fonts etc) can be discussed and implemented in additional, separate pull-requests.theme.json
implementationFollowing the comment by @jorgefilipecosta on #35591 (comment), the
theme.json
implementation was placed undersettings.typography.fontFamilies.[].fontFace
:Any webfonts registered via
theme.json
or PHP will appear in the font-family pickers.To test registering webfonts via PHP and confirm they are correctly added to the editor you can use the snippet below:
How has this been tested?
theme.json
file and PHP using the snippets above, then confirmed the following:Checklist:
I've tested my changes with keyboard and screen readers.I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all*.native.js
files for terms that need renaming or removal).