From dfd8657483d976df5829ed96adfc75a5175460e1 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Mon, 8 May 2023 14:08:45 -0500 Subject: [PATCH] Restore overwriting queue and done. Printing `$handles` does not work (for some reason that needs to be investigated further). Overwriting the queue and done properties does print and has been working since 6.2 alpha. This commit restores the overwriting properties approach. --- lib/experimental/fonts-api/fonts-api.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/experimental/fonts-api/fonts-api.php b/lib/experimental/fonts-api/fonts-api.php index 3c24d04ee1186..1d04f3aad2cca 100644 --- a/lib/experimental/fonts-api/fonts-api.php +++ b/lib/experimental/fonts-api/fonts-api.php @@ -184,8 +184,9 @@ function wp_register_font_provider( $name, $classname ) { * An empty array if none were processed. */ function wp_print_fonts( $handles = false ) { - $wp_fonts = wp_fonts(); - $registered = $wp_fonts->get_registered_font_families(); + $wp_fonts = wp_fonts(); + $registered = $wp_fonts->get_registered_font_families(); + $in_iframed_editor = true === $handles; // Nothing to print, as no fonts are registered. if ( empty( $registered ) ) { @@ -195,8 +196,12 @@ function wp_print_fonts( $handles = false ) { // Skip this reassignment decision-making when using the default of `false`. if ( false !== $handles ) { // When `true`, print all registered fonts for the iframed editor. - if ( true === $handles ) { - $handles = $registered; + if ( $in_iframed_editor ) { + $queue = $wp_fonts->queue; + $done = $wp_fonts->done; + $wp_fonts->done = array(); + $wp_fonts->queue = $registered; + $handles = false; } elseif ( empty( $handles ) ) { // When falsey, assign `false` to print enqueued fonts. $handles = false; @@ -205,7 +210,15 @@ function wp_print_fonts( $handles = false ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); - return $wp_fonts->do_items( $handles ); + $printed = $wp_fonts->do_items( $handles ); + + // Reset the API. + if ( $in_iframed_editor ) { + $wp_fonts->done = $done; + $wp_fonts->queue = $queue; + } + + return $printed; } }