[Fonts API] Refactor theme.json to Fonts API handler global functions into static class wrapper #50250
Labels
[Type] Code Quality
Issues or PRs that relate to code quality
[Type] Enhancement
A suggestion for improvement.
Part of #41484
What problem does this address?
There are 2 global functions within the
lib/experimental/fonts-api/register-fonts-from-theme-json.php
file that will be needed in Core as part of the API. These functions are large and doing multiple tasks, as such are difficult to debug and understand.Their role is to handle the interactions between the global theme.json settings (which includes the user selected typography from Site Editor's > Global Styles > Typography UI) and the Fonts API. But that role is not clearly defined with the file and function naming.
To improve code quality, readability, and prepare these functionality for future and Core, this file and its functions need a redesign / refactoring. It's a better fit for a Core-only static class wrapper pattern (i.e. a class with static methods).
What is your proposed solution?
Refactor the global functions:
class-wp-fonts-theme-json-handler.php
.WP_Fonts_Theme_Json_Handler
.add_action( 'init', 'gutenberg_register_fonts_from_theme_json', 21 );
into thefonts-api.php
file and update it to use the new static method instead of the global callback function.gutenberg_add_registered_fonts_to_theme_json()
is used to now call its static method.The text was updated successfully, but these errors were encountered: