Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Webfonts: register and enqueue fonts by font-family (#39559)
* Group registered webfonts by font family * Add registered font-family groups to theme.json * Separate between registering and enqueueing webfonts * Add wp_enqueue_webfont method * Fix wp_register_webfont description * Do not duplicate font families if registering from both theme.json and API * Rename font to webfont where appropriate * Add tests * Fix linter offenses * Fire gutenberg_register_webfonts_from_theme_json on init * Move webfonts logic from wordpress-6.0 to experimental The API, although looking really good, is not ready for Core. So we must move it from wordpress-6.0 to experimental, and only add it there when it's ready to enter WordPress. Relocate files to /lib/experimental. Per the Gutenberg PHP > File structure documentation https://github.com/WordPress/gutenberg/tree/trunk/lib#file-structure. * Update return types and comment for consistency and matching. * Use trigger_log instead of error_log(). * Fix tests with _doing_it_wrong. Tests for methods that have a `_doing_it_wrong()` require an `expectedIncorrectUsage` annotation, proper usage of test fixture methods, and the usage of `__METHOD__` when invoking `_doing_it_wrong()`. This commit: - Fixes the test fixtures to use snake_case format and calling of the parent fixtures. - Refactors `get_font_slug()` tests into data providers (preferred in Core) and separates tests that will trigger `_doing_it_wrong()` to use the annotation. - Uses `__METHOD__` instead of `__FUNCTION__` in each `_doing_it_wrong()` instance. * Add `get_webfonts_by_provider()` method to handle regrouping. The `WP_Webfonts::generate_styles()` should not be aware of how to reorganize the webfonts from grouped by font-family to grouped by provider. Why? This is a separate task from generating styles for the webfonts. This commit creates a private method called `get_webfonts_by_provider()` to encapsulate the know-how for this reorganizational work. It also includes a micro-optimization that eliminates an extra `foreach` loop and the building of an unnecessary `$webfonts` array of arrays. * Updates from code review. * Restore loading lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php. Co-authored-by: Jeremy Yip <jeremy.yip@automattic.com> Co-authored-by: hellofromtonya <tonya.mork@automattic.com>
- Loading branch information