-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
What problem does this address?
Both Themes and Plugins can add Global Styles font families via the Webfonts API .
Sometimes we might want to deprecate font in such way that it continues to work for users who are already using the font at their site, but isn't available for the rest. There isn't obvious way to do so.
Deprecating font is needed when a plugin, theme, or host is offering tightly curated list of fonts and wants to make changes to the curated list by removing some of the fonts without breaking existing sites.
There could also be situations were a theme was created for a specific company or brand. Theme uses a brand font that is deprecated, and sites' users shouldn't be able to pick it. Meanwhile the font has to continue working on some pages for historical reasons.
What is your proposed solution?
Couple solutions come to mind:
- Allow marking font "deprecated" when registering, and Gutenberg would continue registering it only if the font is actually in-use
- Allow registering fonts as before, but add a filter to final list presented at UI, allowing us filter out fonts no longer needed.
I also looked at building custom solution by filtering fonts from blocks (WP_Theme_JSON_Resolver::get_block_data()) & user (WP_Theme_JSON_Resolver::get_user_data()), comparing those with the list of deprecated fonts and the un-registering font if the font wasn't present in blocks or user styles.
Problems:
- There aren't methods for un-registering fonts so I'd have to resort filtering them out from
wp_theme_json_data_theme. - For reasons I don't fully understand, fonts appear in few different formats in user and block style objects: could be sometimes just "Noto Sans JP", or
var:preset|font-family|noto-sans-jp. - Filtering through multi-layered arrays isn't very performant
FYI @hellofromtonya @aristath for consideration as part of fonts API roadmap.