Skip to content

Commit

Permalink
Relocate from 6.2 script-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromtonya committed May 1, 2023
1 parent 8c04266 commit b6bcb12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
27 changes: 5 additions & 22 deletions lib/compat/wordpress-6.2/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,11 @@ 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.
*/
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->done = array();
$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;
}
// Generate font @font-face styles.
if ( function_exists( 'wp_print_fonts' ) ) {
ob_start();
wp_print_fonts( false, true );
$styles .= ob_get_clean();
}

return array(
Expand Down
36 changes: 31 additions & 5 deletions lib/experimental/fonts-api/fonts-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ function wp_register_font_provider( $name, $classname ) {
*
* @since X.X.X
*
* @param string|string[]|false $handles Optional. Items to be processed: queue (false),
* single item (string), or multiple items (array of strings).
* Default false.
* @param string|string[]|false $handles Optional. Items to be processed: queue (false),
* single item (string), or multiple items (array of strings).
* Default false.
* @param bool $for_iframed_editor Optional. Whether the fonts are for iframed editor.
* Default false.
* @return array|string[] Array of font handles that have been processed.
* An empty array if none were processed.
*/
function wp_print_fonts( $handles = false ) {
function wp_print_fonts( $handles = false, $for_iframed_editor = false ) {
global $wp_fonts;

if ( empty( $handles ) ) {
Expand All @@ -197,7 +199,31 @@ function wp_print_fonts( $handles = false ) {
}
}

return wp_fonts()->do_items( $handles );
$wp_fonts = wp_fonts();
$registered = $wp_fonts->get_registered_font_families();
// If nothing is registered, then nothing to print.
if ( empty( $registered ) ) {
return array();
}

// Print all registered fonts for the iframed editor.
if ( $for_iframed_editor ) {
$queue = $wp_fonts->queue;
$done = $wp_fonts->done;

$wp_fonts->done = array();
$wp_fonts->queue = $registered;
}

$printed_fonts = $wp_fonts->do_items( $handles );

// Reset after printing.
if ( $for_iframed_editor ) {
$wp_fonts->done = $done;
$wp_fonts->queue = $queue;
}

return $printed_fonts;
}
}

Expand Down

0 comments on commit b6bcb12

Please sign in to comment.