From 369a54b4128b16630f7b195a01ca1eb203b52dbf Mon Sep 17 00:00:00 2001 From: arthur791004 Date: Tue, 27 Feb 2024 20:11:50 +0800 Subject: [PATCH 1/2] Revert "Google Fonts: Update the implementation of the print_font_faces (#35890)" This reverts commit 44bf11ec9b43533c73e412bad09bc0e46324c5d5. --- .../class-jetpack-google-font-face.php | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php b/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php index 07c21709e790..93e36a1349bc 100644 --- a/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php +++ b/projects/plugins/jetpack/modules/google-fonts/current/class-jetpack-google-font-face.php @@ -54,21 +54,13 @@ public function current_screen() { * Print fonts that are used in global styles or block-level settings. */ public function print_font_faces() { - $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json(); - $font_slug_aliases = $this->get_font_slug_aliases(); - $fonts_to_print = array(); + $fonts = $this->get_fonts(); + $fonts_to_print = array(); $this->collect_global_styles_fonts(); - $fonts_in_use = array_values( array_unique( $this->fonts_in_use, SORT_STRING ) ); - $fonts_in_use = array_map( - function ( $font_slug ) use ( $font_slug_aliases ) { - return $font_slug_aliases[ $font_slug ] ?? $font_slug; - }, - $this->fonts_in_use - ); - + $this->fonts_in_use = array_values( array_unique( $this->fonts_in_use, SORT_STRING ) ); foreach ( $fonts as $font_family => $font_faces ) { - if ( in_array( $this->format_font( $font_family ), $fonts_in_use, true ) ) { + if ( in_array( $this->format_font( $font_family ), $this->fonts_in_use, true ) ) { $fonts_to_print[ $font_family ] = $font_faces; } } @@ -149,27 +141,26 @@ public function format_font( $font_slug ) { } /** - * Get the font slug aliases that maps the font slug to the font family if they are different. - * - * The font definition may define an alias slug name, so we have to add the map from the slug name to the font family. - * See https://github.com/WordPress/twentytwentyfour/blob/df92472089ede6fae5924c124a93c843b84e8cbd/theme.json#L215. + * Get all font definitions from theme json. */ - public function get_font_slug_aliases() { - $font_slug_aliases = array(); + public function get_fonts() { + $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json(); + // The font definition might define an alias slug name, so we have to add the map from the slug name to font faces. + // See https://github.com/WordPress/twentytwentyfour/blob/df92472089ede6fae5924c124a93c843b84e8cbd/theme.json#L215. $theme_json = WP_Theme_JSON_Resolver::get_theme_data(); $raw_data = $theme_json->get_data(); if ( ! empty( $raw_data['settings']['typography']['fontFamilies'] ) ) { foreach ( $raw_data['settings']['typography']['fontFamilies'] as $font ) { $font_family_name = $this->get_font_family_name( $font ); $font_slug = $font['slug'] ?? ''; - if ( $font_slug && $font_slug !== $font_family_name && ! array_key_exists( $font_slug, $font_slug_aliases ) ) { - $font_slug_aliases[ $font_slug ] = $font_family_name; + if ( $font_slug && ! array_key_exists( $font_slug, $fonts ) && array_key_exists( $font_family_name, $fonts ) ) { + $fonts[ $font_slug ] = $fonts[ $font_family_name ]; } } } - return $font_slug_aliases; + return $fonts; } /** From 2e28c5b628e9394eeab65e23013044279137071e Mon Sep 17 00:00:00 2001 From: arthur Date: Tue, 27 Feb 2024 20:31:31 +0800 Subject: [PATCH 2/2] changelog --- .../revert-35890-update-google-fonts-print-font-faces | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/revert-35890-update-google-fonts-print-font-faces diff --git a/projects/plugins/jetpack/changelog/revert-35890-update-google-fonts-print-font-faces b/projects/plugins/jetpack/changelog/revert-35890-update-google-fonts-print-font-faces new file mode 100644 index 000000000000..447f8bfa291b --- /dev/null +++ b/projects/plugins/jetpack/changelog/revert-35890-update-google-fonts-print-font-faces @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Revert 35890 to resolve the font display issue