From 7406b44f53832696d7ecc0f92aad7d2acb7531be Mon Sep 17 00:00:00 2001 From: arthur Date: Wed, 24 Apr 2024 18:40:40 +0800 Subject: [PATCH 1/2] Google Fonts: Avoid theme fonts overriding the default fonts --- .../class-jetpack-google-font-face.php | 2 +- .../current/load-google-fonts.php | 36 +------------------ 2 files changed, 2 insertions(+), 36 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 44f3551c534cf..4afdedb76679a 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 @@ -72,7 +72,7 @@ function ( $font_slug ) use ( $font_slug_aliases ) { foreach ( $fonts as $font_faces ) { $font_family = $font_faces[0]['font-family'] ?? ''; if ( in_array( $this->format_font( $font_family ), $fonts_in_use, true ) ) { - $fonts_to_print[ $font_family ] = $font_faces; + $fonts_to_print[] = $font_faces; } } diff --git a/projects/plugins/jetpack/modules/google-fonts/current/load-google-fonts.php b/projects/plugins/jetpack/modules/google-fonts/current/load-google-fonts.php index f6f952e637c60..0648caf962a25 100644 --- a/projects/plugins/jetpack/modules/google-fonts/current/load-google-fonts.php +++ b/projects/plugins/jetpack/modules/google-fonts/current/load-google-fonts.php @@ -83,33 +83,6 @@ function ( $font_family ) { return $available_google_fonts_map; } -/** - * Gets the font families of the active theme - * - * @return object[] The font families of the active theme. - */ -function jetpack_get_theme_fonts_map() { - if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) { - return array(); - } - - $theme_json = WP_Theme_JSON_Resolver::get_theme_data(); - $raw_data = $theme_json->get_data(); - if ( empty( $raw_data['settings']['typography']['fontFamilies'] ) ) { - return array(); - } - - $theme_fonts_map = array(); - foreach ( $raw_data['settings']['typography']['fontFamilies'] as $font_family ) { - $font_family_name = $font_family['name'] ?? Jetpack_Google_Font_Face::get_font_family_name( $font_family ); - if ( $font_family_name ) { - $theme_fonts_map[ $font_family_name ] = true; - } - } - - return $theme_fonts_map; -} - /** * Register google fonts to the theme json data * @@ -123,18 +96,11 @@ function jetpack_register_google_fonts_to_theme_json( $theme_json ) { } $available_google_fonts_map = jetpack_get_available_google_fonts_map( $google_fonts_data ); - $theme_fonts_map = jetpack_get_theme_fonts_map(); $google_fonts_families = array_values( array_filter( $google_fonts_data['fontFamilies'], - function ( $google_fonts_family ) use ( $available_google_fonts_map, $theme_fonts_map ) { + function ( $google_fonts_family ) use ( $available_google_fonts_map ) { $name = $google_fonts_family['name']; - - // Filter out the fonts that are provided by the active theme. - if ( isset( $theme_fonts_map[ $name ] ) && $theme_fonts_map[ $name ] ) { - return false; - } - return $available_google_fonts_map[ $name ] ?? false; } ) From 57d23119dd6d0ae59115c4bd76ad080d4545b43e Mon Sep 17 00:00:00 2001 From: arthur Date: Wed, 24 Apr 2024 18:42:41 +0800 Subject: [PATCH 2/2] changelog --- .../jetpack/changelog/feat-dont-override-default-fonts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/feat-dont-override-default-fonts diff --git a/projects/plugins/jetpack/changelog/feat-dont-override-default-fonts b/projects/plugins/jetpack/changelog/feat-dont-override-default-fonts new file mode 100644 index 0000000000000..7547e596f08aa --- /dev/null +++ b/projects/plugins/jetpack/changelog/feat-dont-override-default-fonts @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Google Fonts: Avoid theme fonts overriding the default fonts so fonts with a specific font weight that are not supported by the provided theme can be rendered correctly