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

Fonts API: allow deprecating fonts #46434

Open
simison opened this issue Dec 9, 2022 · 0 comments
Open

Fonts API: allow deprecating fonts #46434

simison opened this issue Dec 9, 2022 · 0 comments
Labels
[Feature] Font Library [Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.

Comments

@simison
Copy link
Member

simison commented Dec 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Font Library [Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.
4 participants