Skip to content

Commit

Permalink
[Font API] Use registered fonts for Block Editor iframe. (#49646)
Browse files Browse the repository at this point in the history
* Use queue for Site Editor

* Capture site editor check in variable.

To capture the site editor identification condition in one place.

Why?

To improve readability and maintability, especially if the identification
logic changes in the future.
  • Loading branch information
Tonya Mork authored Apr 11, 2023
1 parent 65d6cd2 commit d39f350
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/compat/wordpress-6.2/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,33 @@ function gutenberg_resolve_assets_override() {
$scripts = ob_get_clean();

/*
* Generate font @font-face styles for the site editor iframe.
* Use the registered font families for printing.
* Generate font @font-face styles for the iframe.
*
* For the Site Editor, use the registered fonts.
* For the Block Editor, use the enqueued fonts.
*/
if ( class_exists( 'WP_Fonts' ) ) {
$wp_fonts = wp_fonts();
$registered = $wp_fonts->get_registered_font_families();
if ( ! empty( $registered ) ) {
$queue = $wp_fonts->queue;
$done = $wp_fonts->done;
$wp_fonts = wp_fonts();
$registered = $wp_fonts->get_registered_font_families();
$is_site_editor = 'site-editor.php' === $pagenow;

$wp_fonts->done = array();
$wp_fonts->queue = $registered;
if ( ! empty( $registered ) ) {
$done = $wp_fonts->done;
$wp_fonts->done = array();
if ( $is_site_editor ) {
$queue = $wp_fonts->queue;
$wp_fonts->queue = $registered;
}

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

// Reset the Web Fonts API.
$wp_fonts->done = $done;
$wp_fonts->queue = $queue;
// Reset the Fonts API.
$wp_fonts->done = $done;
if ( $is_site_editor ) {
$wp_fonts->queue = $queue;
}
}
}

Expand Down

1 comment on commit d39f350

@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 in d39f350.
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/4664340217
📝 Reported issues:

Please sign in to comment.