Skip to content

Commit

Permalink
Webfonts: redesign architecture to use WP_Dependencies (#43492)
Browse files Browse the repository at this point in the history
Complete redesign of the Webfonts API:

* The current implementation re-implements a lot of the concepts that are already handled by `WP_Dependencies` for the script and style loaders. The script loader classes already have the concepts of dependencies, enqueuing, and registering, as well as a way to "do_item()" (generate CSS or a tag with source, in this case).

* Includes a temporary backwards-compatible (BC) layer to give extenders time and information to upgrade their code to the new API data structures and functionality.

Props: hellofromtonya, aristath, desrosj, colorful-tones, ironprogrammer.
  • Loading branch information
Tonya Mork authored Dec 19, 2022
1 parent a556b69 commit 87c738e
Show file tree
Hide file tree
Showing 43 changed files with 6,452 additions and 1,047 deletions.
24 changes: 24 additions & 0 deletions lib/compat/wordpress-6.2/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ function gutenberg_resolve_assets_override() {

$scripts = ob_get_clean();

/*
* Generate web font @font-face styles for the site editor iframe.
* Use the registered font families for printing.
*/
if ( class_exists( 'WP_Web_Fonts' ) ) {
$wp_webfonts = wp_webfonts();
$registered = $wp_webfonts->get_registered_font_families();
if ( ! empty( $registered ) ) {
$queue = $wp_webfonts->queue;
$done = $wp_webfonts->done;

$wp_webfonts->done = array();
$wp_webfonts->queue = $registered;

ob_start();
$wp_webfonts->do_items();
$styles .= ob_get_clean();

// Reset the Web Fonts API.
$wp_webfonts->done = $done;
$wp_webfonts->queue = $queue;
}
}

return array(
'styles' => $styles,
'scripts' => $scripts,
Expand Down
Loading

1 comment on commit 87c738e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3731140249
📝 Reported issues:

Please sign in to comment.