Skip to content

Commit

Permalink
Restore overwriting queue and done.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hellofromtonya committed May 8, 2023
1 parent fd7ce33 commit dfd8657
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/experimental/fonts-api/fonts-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down

0 comments on commit dfd8657

Please sign in to comment.