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] Refactor theme.json to Fonts API handler global functions into static class wrapper #50250

Closed
hellofromtonya opened this issue May 2, 2023 · 1 comment · Fixed by #50811
Assignees
Labels
[Type] Code Quality Issues or PRs that relate to code quality [Type] Enhancement A suggestion for improvement.

Comments

@hellofromtonya
Copy link
Contributor

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:

  • Rename the file to class-wp-fonts-theme-json-handler.php.
  • Load the file into memory.
  • Add a Core-only static class wrapper called WP_Fonts_Theme_Json_Handler.
  • Add a public static method, coping the code from each global function.
  • Split each method into smaller single-purpose private static methods.
  • Update the tests.
  • Move the add_action( 'init', 'gutenberg_register_fonts_from_theme_json', 21 ); into the fonts-api.php file and update it to use the new static method instead of the global callback function.
  • Update where gutenberg_add_registered_fonts_to_theme_json() is used to now call its static method.
  • Update the DocBlocks as they are inaccurate.
@hellofromtonya hellofromtonya added [Type] Enhancement A suggestion for improvement. [Type] Code Quality Issues or PRs that relate to code quality [Feature] Fonts API labels May 2, 2023
@anton-vlasenko
Copy link
Contributor

PR: #50811

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants