Skip to content

Commit

Permalink
Ensure font-face styles are printed in iframe editors. (#54313)
Browse files Browse the repository at this point in the history
Loads the plugin's `fonts.php` file and moves the hooked code for `'block_editor_settings_all'` out of the guard to ensure the `@font-face` styels are printed in the iframe editors when Gutenberg overrides Core.
  • Loading branch information
hellofromtonya authored Sep 12, 2023
1 parent af22ab4 commit 0cf7898
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
30 changes: 15 additions & 15 deletions lib/compat/wordpress-6.4/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ function wp_print_font_faces( $fonts = array() ) {
$wp_font_face = new WP_Font_Face();
$wp_font_face->generate_and_print( $fonts );
}
}

// @core-merge: do not merge this code into Core.
add_filter(
'block_editor_settings_all',
static function( $settings ) {
ob_start();
// @core-merge: add only this line into Core's `_wp_get_iframed_editor_assets()` function after `wp_print_styles()`.
wp_print_font_faces();
$styles = ob_get_clean();
// @core-merge: do not merge this code into Core.
add_filter(
'block_editor_settings_all',
static function( $settings ) {
ob_start();
// @core-merge: add only this line into Core's `_wp_get_iframed_editor_assets()` function after `wp_print_styles()`.
wp_print_font_faces();
$styles = ob_get_clean();

// Add the font-face styles to iframed editor assets.
$settings['__unstableResolvedAssets']['styles'] .= $styles;
return $settings;
},
11
);
}
// Add the font-face styles to iframed editor assets.
$settings['__unstableResolvedAssets']['styles'] .= $styles;
return $settings;
},
11
);
8 changes: 7 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ function gutenberg_is_experiment_enabled( $name ) {
if ( ! class_exists( 'WP_Font_Face' ) ) {
require __DIR__ . '/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php';
require __DIR__ . '/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php';
require __DIR__ . '/compat/wordpress-6.4/fonts/fonts.php';
}

/*
* As _gutenberg_get_iframed_editor_assets_6_4() overrides Core's _wp_get_iframed_editor_assets(),
* load this file to ensure wp_print_font_faces() is invoked to load the styles into the
* iframed editor.
*/
require __DIR__ . '/compat/wordpress-6.4/fonts/fonts.php';

// Load the BC Layer to avoid fatal errors of extenders using the Fonts API.
// @core-merge: do not merge the BC layer files into WordPress Core.
require __DIR__ . '/experimental/fonts/font-face/bc-layer/class-wp-fonts-provider.php';
Expand Down

0 comments on commit 0cf7898

Please sign in to comment.