Repository navigation
Description
This is an epic ticket to share the ongoing roadmap including:
- the vision of how this supports typography features (e.g. see Global Styles Ongoing Roadmap #41232 and Global Styles/Typography: Managing fonts #45271).
- tracking of ongoing work and needs in preparation for WordPress 6.4.
Updates:
- 28 July 2022 After discussing with @mtias, added the Font Library and FAQ sections
- 18 Jan 2023 API renamed to Fonts API
- 19 Jun 2023 Scope changed, introduce Font Face, and deprecate Fonts API
Changed to Font Face: to server-side generate and print fonts' @font-face styles
With the introduction of the new Fonts Library, the role of the Fonts API has significantly changed as noted in #41479 (comment).
Previously, its roles were:
- Role 1: Generate and print the @font-face styles for all “enqueued” fonts.
- Role 2: Provide a means for plugins to present fonts to users, who can then decide whether to use these fonts (i.e. through the Site Editor).
Its new role is:
- Generate and print the @font-face styles for all theme defined and user activated fonts.
Fonts will be presented to users via the Fonts Library, rather than through the Fonts API.
Plugins will no longer interact with the Fonts API. Instead, they will integrate directly into the Font Library (once that capability exists).
Font Face "gets" the fonts to print from Theme JSON merged data layer. Fonts are no longer registered or enqueued directly with it.
A full API is no longer needed. Thus, Font Face replaces the Fonts API.
Vision
As part of fonts management and Fonts Library,
This API's job is to provide the backend capabilities to support the "font library" to include font management and dynamic building of the @font-face styles.
The "font library" feature will continue to be built, refined, stabilized, and tuned over multiple WordPress releases.
Font Library
See #50927.
The idea is to have the concept of a font library on a site to
- manage and catalogue fonts
- and then provide users an interface for them to select which fonts to use in the live site.
The fonts in the library can come from:
- a theme bundling them
- a user uploading fonts they purchased
- a plugin
The fonts to be used in the site are saved and available via Theme JSON merged data layer, i.e. WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings().
FAQ
What about classic sites?
Yes, supported ✅
Classic themes and plugins can have their @font-face styles generated and printed. How?
Classic themes have 2 options:
- Option 1: Add a callback function hooked in
'wp_head'and'admin_print_styles'and within that callback function, invoke a new print method and pass their fonts to it. - Option 2: Add a
theme.jsonfile that only defines the fonts. See issue [Fonts API] Proposal: classic themes define fonts in a theme.json file #51714 for more information.
Plugins supporting classic sites can use Option 1.
Ongoing work
Architecture
⭐ Required for Core introduction:
- Font Face: redesign the Fonts API to become only a font-face styles generator and printer #51769 ✅ Done 10 Jul 2023
- [Fonts API] Deprecate and remove all functionality (in favor of Font Face) #51819 ✅ Done 18 Jul 2023
- [Fonts API] Deprecate and remove all functionality (in favor of Font Face) #51819 🚫 until Fonts Library is merged
Performance
⭐ Required for Core introduction:
None
Feature needs
⭐ Required for Core introduction:
None
Future enhancements
- Add font management UI to Customizer for classic themes
Bugs
None
Documentation
Backports
Future.
Tracking key
✅ Done
⚪ WIP: work in progress
🟡 Experiment WIP
🍏 in testing or code review
🔴 Danger > immediate action needed
🚫 Blocked
⭐ Needed for WP Core introduction
Activity
hellofromtonya commentedon Jun 23, 2022
The vision for the font management through a formal Webfonts API is now available in the description of this roadmap (ie in the Vision section).
The first priority is to solidify the architecture as all other tasks will be affected by these architectural changes:
Once these 2 tasks are done, then the remaining tasks can be prioritized along with impacts to update each of them to fit within the architectural changes. I removed the priority labels from each of these other tasks.
azaozz commentedon Jun 24, 2022
This sounds great! A clear and well defined vision makes the tasks ahead much easier to understand.
Trying to get into a bit more details, perhaps "brainstorm" a little more. One of the hard performance related questions would be: What happens when somebody decides to register the whole collection from https://fontsource.org/ (more than 1600 fonts)? It's pretty pointless (will need a dedicated UI and still the users will have a pretty hard time selecting fonts from such a huge list) but that doesn't mean it's not going to happen.
That led to couple of questions:
For the first question, in most cases it seems registering can be done together with the enqueueing only for the fonts that are in use. That will speed things up and perhaps reduce complexity a little. Thinking a bit further implementation-wise: should registering a font be needed for enqueueing it? Seems not. A "prior art" is how scripts can be enqueued without a need to be registered.
The second question is harder. Are we talking about building UI similar to the Google's webfonts picker? Seems anything less may not be enough, perhaps. Not sure what a UI for picking one out of a hundred fonts may be, but thinking it would be best to have an idea about it before deciding on the back-end code, so the requirements of that (and future) UI are met.
adamsilverstein commentedon Jul 11, 2022
Great to see this overview issue @hellofromtonya - this is super helpful as I've been struggling to keep up with the Fonts API proposals & progress.
I noticed several features I see in other font APIs that aren't mentioned here and wanted to know if these are on your roadmap at all or would be something to propose for a future iteration:
desrosj commentedon Jul 14, 2022
One thing that's been bugging me is that I feel like "Webfonts" is wrong when I read it. I did some searching around, and my findings seem to point towards "Web fonts" as the preferred way to refer to this. I know this is a nit, but I think it's important to get it right and be consistent. here are some authoritative pages I found pointing to Web Fonts:
Other pages for Webfonts
azaozz commentedon Jul 27, 2022
@adamsilverstein Yeah, support for preloading is needed, but not sure what "downloading" has to do here? Thought is was decided that this API is for local fonts only. This has numerous advantages as discussed before. Downloading what, and from where? :)
I'd also think that if a plugin wants to use external fonts from a CDN, like Google fonts, it would still consider downloading the open source fonts as available at places like https://github.com/fontsource/fontsource and not trying to capture the CDN's output (which may also have some compatibility or licensing issues as it is closed source).
hellofromtonya commentedon Jul 28, 2022
@mtias and I discussed this roadmap for both block and classic themes. From that discussion, I've updated the description of this ongoing roadmap including the "font library" vision, technical details, and a new FAQ section.
The changes include publicly exposing
enqueueandremovefunctionality.hellofromtonya commentedon Jul 28, 2022
Bundled in the API is a local fonts provider. It does not include remote font foundry handling. It does provide the means for plugin authors to create custom providers, such as to handle (a) an alternative local fonts approach or (b) remotely hosted fonts.
IMO I don't think Core should force only local fonts.
cc @adamsilverstein @azaozz
adamsilverstein commentedon Jul 29, 2022
Thanks for clarifying @hellofromtonya and @azaozz
🎉 Great!
hellofromtonya commentedon Aug 1, 2022
I opened a separate issue for renaming consideration per @desrosj suggestion. Let's move the naming discussion to here #42868
hellofromtonya commentedon Aug 17, 2022
Tracking the block level typography consistency effort #43242
hellofromtonya commentedon Dec 19, 2022
⭐ Status Update:
Status: Blocked by architectural work.
DONE: ✅ The major architectural redesign (See #41481) is now merged. The new architecture is a code rewrite which has breaking changes. Some high level details:
NEXT: ⚪ There are 2 more architectural tasks that need to be completed to unblock the remaining bugs, performance, and feature work can continue.
👉 Where can you help?
hellofromtonya commentedon Jan 18, 2023
⭐ Status Update ⭐
18 Jan 2023
Status:
Big Picture
👉 It's a NEW API
The API has been completely redesigned with a new architecture and renamed including all publicly available functions, classes, and methods.
👉 BC Layer
A backwards-compatibility (BC) layer (with deprecations) was added to ensure sites using this API in production keep running while giving developers time to upgrade to the new API. This BC Layer will NOT be backported to Core.
Who's impacted?
Any external code (outside of Gutenberg) that is directly interfacing with the API.
While the BC Layer will keep sites running, extenders will need to upgrade their code to use the new API, especially once the API is backported to WP Core.
Theme's using
theme.jsonare NOT impacted.Why? This file is automatically ingested, processed, and defined fonts registered and enqueued within the API.
All open PRs (see below)
⭐ 👉 Next steps
These 2 issues are must-haves:
All open PRs are impacted. This means each open issue and any of its PRs must be evaluated one-by-one and if still relevant, rebased and rebuilt to apply changes to the new API.
TODO:
Each PR will need to be rebased on top of
trunkto bring the new API into its scope. In most cases (if not all), the PR will need to rebuilt.17 remaining items
hellofromtonya commentedon Jun 21, 2023
Sorry for the delay in responding to you @webd-uk.
If the user has already selected a plugin defined font, then that font should be saved in the database when saving those selections in the Site Editor. Those fonts then should be within the theme.json merged data, i.e.
WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings()within['typography']['fontFamilies'].Then when it's time to "print"
@font-facestyles, the new Fonts API (or whatever name it becomes) pulls fromWP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings()to extract the fonts to print.As for what gets "activated" in the Font Library, I think it's also using that same data.
What isn't there yet is the means for a plugin to "register" its defined fonts with the Font Library.
I'd suggest asking the question and contributing in the main issue #45271 or in the Font Library's WIP PR #50927.
webd-uk commentedon Jun 22, 2023
Thank you, @hellofromtonya! I will definitely be doing that but need to read up on everything first. Thanks again, Wordpress has needed this built-in feature for soooooooo long!
hellofromtonya commentedon Jun 22, 2023
Update 22 Jun 2023
New Learnings
New Learnings since my 19th Jun update:
What currently works with the Fonts Library?
WordPress Core ✅
Fonts API ❌
The stopgap code in WordPress Core since 6.0.0 works with the Fonts Library
_wp_theme_json_webfonts_handler()and supports classic themes adding atheme.jsonfile with only fonts defined. ✅However, the Fonts API in Gutenberg does not work with the Fonts Library and must be changed before the Fonts Library is merged. ❌
Should the Fonts API's architecture change?
Yes! ✅
It needs a near complete redesign.
Issue #51769 is for the redesign, transforming the Fonts API into only a Font Face styles generator and printer.
WIP PR #51770 is what I envision as the redesign.
What about classic sites?
Yes, supported ✅
Classic themes and plugins can have their
@font-facestyles generated without requiring register or enqueue. How?Classic themes have 2 options:
'wp_head'and'admin_print_styles'and within that callback function, invoke a new print method and pass their fonts to it.theme.jsonfile that only defines the fonts. See issue [Fonts API] Proposal: classic themes define fonts in a theme.json file #51714 for more information.Plugins supporting classic sites can use Option 1.
What about font-face property validation?
Yes, still required ✅
To support classic sites and potentially other needed customizations, the new Font Face design exposes a
print( $fonts )method that accepts an array of fonts. Those are the fonts that will be processed to generate and print the@font-facestyles.As any source could invoke that
print( $fonts )method, the passed in font-face properties still require validation. Why? To (a) protect the code from missing properties or invalid data types and (b) provide extenders guidance of where problems are in the array of fonts.What about "providers"?
Fonts Library only supports serving
@font-facesrcfrom local assets. It has Google Fonts built into it, but downloads the font files towp-content/fonts/for local access.To keep parity with the Fonts Library, the Fonts API support of custom providers will be removed. The new design will only support local font files. This change will ensure fonts work the same on all types of sites.
If enough of need is discovered, then a future enhancement could be to add custom provider support.
What about sites currently using the Fonts API?
The API is experimental. However, the API has taken the approach of supporting backward compatibility through the BC Layer to avoid sites breaking.
The new Font Face generation is a big big change. Care is needed to consider how to safeguard sites currently using the Fonts API while guiding developers towards where and what needs to change.
[-]Fonts API: Ongoing Roadmap (formerly the Webfonts API)[/-][+]Server-Side Font Face CSS Generation and Printing: Ongoing Roadmap (formerly the Fonts API)[/+]hellofromtonya commentedon Jul 18, 2023
The description of this roadmap is now updated for "Font Face", i.e. to define its new role in font management and its scope of work.
hellofromtonya commentedon Aug 21, 2023
Update
Font Face is ready to be introduced into WordPress Core. It is a direct replacement for
_wp_theme_json_webfonts_handler()in that it processes block themes with the same@font-facestyles while providing the means for classic themes and plugins to also print their font's@font-facestyles.TODO:
lib/compat/wordpress-6.4Font Face: Prepare for merge into Core. #53858hellofromtonya commentedon Aug 22, 2023
Here's the Core Trac ticket for merging Font Face into Core https://core.trac.wordpress.org/ticket/59165.
Introduce font-face styles generator and printer.
Introduce font-face styles generator and printer.
Introduce font-face styles generator and printer.
annezazu commentedon Mar 21, 2024
Closing this out as https://core.trac.wordpress.org/ticket/59165 shipped. Let me know if that's incorrect and I can reopen. Thanks for all the hard work here!