From 46ecc04b53256f326608e24f6224e08b966e3fcd Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Wed, 13 Sep 2023 12:00:08 -0500 Subject: [PATCH] Font Face: backport from Core [56500] (#54218) * Merges the changes made in Core while retaining plugin specifics. * Adds `@core-merge` notes where appropriate. References: * https://core.trac.wordpress.org/changeset/56500 * https://core.trac.wordpress.org/changeset/56540 --- .../font-face/class-wp-font-face-resolver.php | 4 +- .../fonts/font-face/class-wp-font-face.php | 110 ++++++++++-------- lib/compat/wordpress-6.4/fonts/fonts.php | 29 ++++- phpunit/tests/fonts/font-face/base.php | 73 ++---------- .../font-face/wpFontFace/generateAndPrint.php | 10 +- .../getFontsFromThemeJson.php | 12 +- .../fonts/font-face/wpPrintFontFaces.php | 36 ++++-- 7 files changed, 143 insertions(+), 131 deletions(-) diff --git a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php index 84375b6c52f5d4..7f397663df961b 100644 --- a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php +++ b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php @@ -5,6 +5,8 @@ * @package WordPress * @subpackage Fonts * @since 6.4.0 + * + * @core-merge: this file is located in `wp-includes/fonts/`. */ if ( class_exists( 'WP_Font_Face_Resolver' ) ) { @@ -33,7 +35,7 @@ public static function get_fonts_from_theme_json() { $settings = gutenberg_get_global_settings(); // Bail out early if there are no font settings. - if ( empty( $settings['typography'] ) || empty( $settings['typography']['fontFamilies'] ) ) { + if ( empty( $settings['typography']['fontFamilies'] ) ) { return array(); } diff --git a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php index 0489fe4f4fbd52..8bb1d55414854f 100644 --- a/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php +++ b/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php @@ -5,6 +5,8 @@ * @package WordPress * @subpackage Fonts * @since 6.4.0 + * + * @core-merge: this file is located in `wp-includes/fonts/`. */ if ( class_exists( 'WP_Font_Face' ) ) { @@ -82,23 +84,6 @@ class WP_Font_Face { * @since 6.4.0 */ public function __construct() { - /** - * Filters the font-face property defaults. - * - * @since 6.4.0 - * - * @param array $defaults { - * An array of required font-face properties and defaults. - * - * @type string $provider The provider ID. Default 'local'. - * @type string $font-family The font-family property. Default empty string. - * @type string $font-style The font-style property. Default 'normal'. - * @type string $font-weight The font-weight property. Default '400'. - * @type string $font-display The font-display property. Default 'fallback'. - * } - */ - $this->font_face_property_defaults = apply_filters( 'wp_font_face_property_defaults', $this->font_face_property_defaults ); - if ( function_exists( 'is_admin' ) && ! is_admin() && @@ -113,7 +98,9 @@ function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5' * * @since 6.4.0 * - * @param array $fonts The fonts to generate and print @font-face styles. + * @param array[][] $fonts Optional. The font-families and their font variations. + * See {@see wp_print_font_faces()} for the supported fields. + * Default empty array. */ public function generate_and_print( array $fonts ) { $fonts = $this->validate_fonts( $fonts ); @@ -123,10 +110,21 @@ public function generate_and_print( array $fonts ) { return; } - printf( - $this->get_style_element(), - $this->get_css( $fonts ) - ); + $css = $this->get_css( $fonts ); + + /* + * The font-face CSS is contained within and open a + +CSS; + $this->expectOutputString( $expected_output ); + + wp_print_font_faces( $fonts ); + } + public function test_should_print_fonts_in_merged_data() { switch_theme( static::FONTS_THEME );