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

Move webfonts handling to internal only (not accessible) - WP 6.0 Stopgap #40472

Closed
7 tasks done
hellofromtonya opened this issue Apr 20, 2022 · 4 comments
Closed
7 tasks done
Assignees
Labels
[Priority] High Used to indicate top priority items that need quick attention

Comments

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Apr 20, 2022

What problem does this address?

Part of WordPress 6.0 is style variations to empower themers to define webfonts in their theme.json. Twenty Twenty-Two (TT2) introduces different styling options within its theme.json. Within this scope, theme.json defines its webfonts and needs mechanisms to (a) expose the fonts to the typography pickers for user customizations and (b) generate the @font-face declarations.

However, the current Webfonts API is still in development and not ready for inclusion in WordPress 6.0. It needs more discussion, development, testing, and feedback to mature before it's ready. There are concerns of rushing the API into Core before its ready as it will lock the API causing future needs limitations, backwards-compatibility issues, high maintenance burden, performance concerns (enqueuing only what is needed, handling of duplicate font variants, etc.), and plugin limitations for further customization (such as changing the font's source).

Style variations don't necessarily need a mature public API at this point. Rather, it needs the mechanisms to (a) wire fonts defined in theme.json to the pickers and (b) generate the font-face styles.

What is your proposed solution?

Provide a stopgap solution for 6.0 where:

  • only the theme's theme.json file defines webfonts.
  • move the webfonts handling mechanisms to be internal, private functionality within a theme.json handler.
  • prevent interaction with webfonts handling mechanisms in such a way that this code is not accessible outside of its container (such as closure or class).
  • continue working on Webfonts API within Gutenberg until it matures and is ready for Core in a future release.

Notes

Keeping the internals really private through abstraction or within a private container

From @peterwilsoncc:

I’d be pretty happy with an entirely private API for themes.json — not @private but actually private in a closure, a private final class, trust us this will be hard deprecated kind of way:

function(){
  $fn = function(){};
}

Basically go to some lengths to ensure that contributors don’t actually end up having to maintain two apis: the temporary one and the permanent one. Extenders often ignore @private (case in point, the million odd sites using a cron private function).

Empowering ongoing API development in Gutenberg

A mechanism (such as a constant or filter) will be needed to disable this stopgap / temporary implementation once it lands in Core. Then Gutenberg can turn off Core's internal webfonts handling to use the Webfonts API.

Props

Props to @desrosj and @peterwilsoncc for proposing a pared down stopgap approach.

Tasks

  • Identify the essential pieces from the API to support this stopgap.
  • Provide the means to switch between the stopgap version and the API.
  • Move all webfonts handling into a private / unaccessible container.
  • Remove all code not related to the theme.json file.

Status

@hellofromtonya
Copy link
Contributor Author

Current status: PR #40493 is ready for review and testing.

@hellofromtonya
Copy link
Contributor Author

Status Update:

  1. As agreed upon by @gzilio, @adamziel, and me,PR Webfonts: Add internal-only theme.json webfonts handler - WP 6.0 stopgap  #40493 will not be merged into Gutenberg. Why? Only Core needs the stopgap, not the plugin.
  2. The backport PR is created Backport: theme.json webfonts handler - WP 6.0 stopgap wordpress-develop#2622.
  3. A PR to turn off the stopgap in Core is coming for Gutenberg, i.e. allowing the Webfonts API to run instead of the stopgap in Core.

pento pushed a commit to WordPress/wordpress-develop that referenced this issue Apr 26, 2022
Adds `_wp_theme_json_webfonts_handler()` for handling `fontFace` declarations in a theme's `theme.json` file to generate the `@font-face` styles for both the editor and front-end.

Design notes:
* It is not a public API, but rather an internal, Core-only handler.
* It is a stopgap implementation that will be replaced when the public Webfonts API is introduced in Core.
* The code design is intentional, albeit funky, with the purpose of avoiding backwards-compatibility issues when the public Webfonts API is introduced in Core.
   * It hides the inter-workings.
   * Does not exposing API ins and outs for external consumption.
   * Only works for `theme.json`.
   * Does not provide registration or enqueuing access for plugins.

For more context on the decision to include this stopgap and the Webfonts API, see:
* Core's PR 40493 WordPress/gutenberg#40493
* Gutenberg's tracking issue 40472 WordPress/gutenberg#40472

Props aristath, hellofromTonya, peterwilsoncc, costdev, jffng, zieladam, gziolo, bph, jonoaldersonwp, desrosj.

See #55567, #46370.

git-svn-id: https://develop.svn.wordpress.org/trunk@53282 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Apr 26, 2022
Adds `_wp_theme_json_webfonts_handler()` for handling `fontFace` declarations in a theme's `theme.json` file to generate the `@font-face` styles for both the editor and front-end.

Design notes:
* It is not a public API, but rather an internal, Core-only handler.
* It is a stopgap implementation that will be replaced when the public Webfonts API is introduced in Core.
* The code design is intentional, albeit funky, with the purpose of avoiding backwards-compatibility issues when the public Webfonts API is introduced in Core.
   * It hides the inter-workings.
   * Does not exposing API ins and outs for external consumption.
   * Only works for `theme.json`.
   * Does not provide registration or enqueuing access for plugins.

For more context on the decision to include this stopgap and the Webfonts API, see:
* Core's PR 40493 WordPress/gutenberg#40493
* Gutenberg's tracking issue 40472 WordPress/gutenberg#40472

Props aristath, hellofromTonya, peterwilsoncc, costdev, jffng, zieladam, gziolo, bph, jonoaldersonwp, desrosj.

See #55567, #46370.
Built from https://develop.svn.wordpress.org/trunk@53282


git-svn-id: http://core.svn.wordpress.org/trunk@52871 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this issue Apr 26, 2022
Adds `_wp_theme_json_webfonts_handler()` for handling `fontFace` declarations in a theme's `theme.json` file to generate the `@font-face` styles for both the editor and front-end.

Design notes:
* It is not a public API, but rather an internal, Core-only handler.
* It is a stopgap implementation that will be replaced when the public Webfonts API is introduced in Core.
* The code design is intentional, albeit funky, with the purpose of avoiding backwards-compatibility issues when the public Webfonts API is introduced in Core.
   * It hides the inter-workings.
   * Does not exposing API ins and outs for external consumption.
   * Only works for `theme.json`.
   * Does not provide registration or enqueuing access for plugins.

For more context on the decision to include this stopgap and the Webfonts API, see:
* Core's PR 40493 WordPress/gutenberg#40493
* Gutenberg's tracking issue 40472 WordPress/gutenberg#40472

Props aristath, hellofromTonya, peterwilsoncc, costdev, jffng, zieladam, gziolo, bph, jonoaldersonwp, desrosj.

See #55567, #46370.
Built from https://develop.svn.wordpress.org/trunk@53282


git-svn-id: https://core.svn.wordpress.org/trunk@52871 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@hellofromtonya
Copy link
Contributor Author

Update: The stopgap implementation has been committed into WordPress Core's trunk ahead of 6.0 Beta 3 via commit https://core.trac.wordpress.org/changeset/53282.

All tasks are completed. Closing this issue.

Thank you everyone for contributing!

@sabernhardt
Copy link
Contributor

Follow-up: Trac 58454 proposes to include optional as a valid/allowed font-display value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Priority] High Used to indicate top priority items that need quick attention
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants