-
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
[Fonts API] Automatically enqueue all user-selected fonts picked in Global Styles. #40363
Comments
Should this be part of the scope of this PR: Webfonts: enqueue fonts listed in theme.json ? IIRC the goal was to enqueue fonts that were saved in theme json (global styles cpt is the saved theme json customizations), so fonts in the base theme.json or saved theme.json/global-styles cpt should be enqueued? |
Reopening this enhancement as more time is needed to understand and discuss the user selected global fonts identification. Why? @oandregal alerted me that #50297 was reverted (via #50512) to get tests working again in |
I've updated this enhancement's description for its scope and intent. |
How should the Fonts API Resolver identify the user-selected global fonts? @oandregal proposed using
Aha, I understand now. Rather than using Is it only for the global user data? Yes, as it fetches the CPT. I'll recreate the enhancement PR for the Resolver using a combination of PR #50297 and #50499. I'll also look at more test datasets to ensure there's plenty of scenario coverage. |
I've started to look into the fonts API to understand what we are trying to do here. From what I've learned so far, I see three issues:
1. The Font Families API works differently than any other preset.I've described at #50576 a major issue I've seen: the font families API only works with the This makes the API do things that are contrary to the 2. How extenders can provide more font families.
When the font families API works with any origin this is already solved. There are a few approaches and we can discuss them when this first issue is addressed. I'm sharing some that I see now to kick-start the conversation:
function register_font_families_from_plugin( $theme_json ){
$new_data = array(
'version' => 2,
'settings' => array(
'typography' => array(
'fontFamilies' => array( /* New font family */
array(
'slug' => 'new-font-family',
'name' => __( 'New font family', 'translation-domain' ),
'fontFamily' => '...',
'fontFace' => array( ... )
),
),
),
),
);
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'register_font_families_from_plugin' );
3. How to enqueue only the font families in use.A third topic is: how do we make sure we only enqueue the fonts in use instead of them all. This is important when plugins extend the font family list to add hundreds of them from different providers (google, type foundries, etc.). This is also easily solved when the 1st issue is addressed. The approach would be what Tonya developed for #50529 We inspect the |
Plugins and themes without a
I think this is best answered by sharing the scope and vision @mtias laid out (shared in the Ongoing Roadmap's description). The Fonts API will:
This issue is focused on the custom enqueueing of user-selected fonts (that were picked in the Site Editor > Styles > Typography) that are not defined in the theme's
I'm not seeing how though this is a blocker for the scope of this specific enhancement (i.e. the automatic detection and enqueueing of user-selected global fonts). Rather, please correct if I'm wrong @oandregal, it seems more like a broader discussion of the vision and scope of the Fonts API. Maybe that discussion should shift to #50576, rather than blocking this enhancement. Why? If #50576 results in a broader change, it will impact more than enqueuing. Right? It'll impact the registration process and widen the detection of merged origins for automatic enqueuing. Also noting, the output of the Fonts API is the @oandregal can you provide more specifics on how or why this is blocking this specific enhancement with its scope? |
I had a conversation with Tonya where she shared more of the context and how the font API works. This is what I've learned:
|
Based on what I learned:
When a plugin registers more fonts, these are available in any typography panel control: both in the "global styles sidebar" AND in the block inspector of any block that supports font family. If core wants to help plugins, it's not enough to enqueue the fonts picked by the user in the "global styles sidebar", core also needs to enqueue the fonts picked by the user for a given block via its block inspector. It sounds like 50529 addresses the former, but not the latter. |
Thank you @oandregal for summarizing our conversation. I think there's a misunderstanding though:
This PR is enqueuing the user-selected fonts at the global level, making them available for block level typography selection. All registered fonts are shown in the Site Editor > Styles > Typography for user selection as "global fonts". These are the fonts that get enqueued by this PR.
Thinking through the fonts layers:
Does this make sense @oandregal? |
Thanks for the additional context. I expected that we'd do differently: all registered fonts would be available in every design tool (global styles and block inspector) and only the fonts in use would be enqueued in the front-end (any available in
I see now how the goal is different from this. If we don't allow fonts for 2 (or only the subset that are also selected at 1), we don't need that code. 50529 would be enough when 40362 is also implemented. However, I find that we may run into some edge cases with the model we aim to implement. For example:
What does happen at this point? If we only enqueue the fonts that are selected in the global styles sidebar, |
Also, please, don't feel #50529 should be blocked by this conversation. I see it has two approvals from people that know fonts more than I do. It should be fine to ship. We can iterate if this conversation uncovers issues. |
I've talked with Matías and learned a few more things about what we aim to do with the font library:
Font library work can be seen at #45271 and related issues. The core idea is that fonts in use by the blocks (serialized as post content) would be abstracted (font-1, font-2, etc.) and not the font family itself (dm-mono, ibm-plex, etc.) Hence, if a font family is unregistered, there will be another that will be picked up. In this model, there's still the edge case of having 5 fonts registered that the user picks for specific blocks, then the user switches to only 3 fonts registered. By that point, font-4 and font-5 won't be available. This is an issue that can be looked at later, when we cross that bridge. I'll comment on #50576 about the data flow, so it doesn't hijack this issue no longer. |
Double-checking with you @oandregal. After your conversation with Matías, are you okay with this PR's scope and implementation? Do you still feel it is no longer blocked? |
Enhancement Scope:
To add automatic detection and enqueueing of all user-selected global fonts before printing the fonts (likely within
wp_print_fonts()
).What are "user-selected global fonts"?
Fonts that a user selected and saved from the Site Editor > Styles > Typography UI.
They are "global" because a selection in this UI is intended for global availability throughout the website and content.
How are these fonts made available for user selection?
Fonts defined within a theme's
theme.json
file are already automatically registered and enqueued within the Fonts API.For plugins and theme's without a
theme.json
file, the API does not provide the mechanism to detect or enqueue their fonts when a user selects them.What problem does this address?
🔹 Plugins and theme's without a
theme.json
file have been required to provide the detection and enqueuing of their user-selected fonts. This enhancement moves that mechanism and functionality into the Fonts API so that detection and enqueuing are within the API.Why are the benefits?
What is your proposed solution?
Before printing the fonts (likely within the
wp_fonts_print()
, i.e. as late as possible:The text was updated successfully, but these errors were encountered: