From caca8e5fe6964e587fc956e75f4447c97a1be68b Mon Sep 17 00:00:00 2001 From: arthur791004 Date: Thu, 25 Apr 2024 10:48:13 +0800 Subject: [PATCH] Google Fonts: Prevent the default fonts from overridden by the theme fonts (#37050) * Google Fonts: Avoid theme fonts overriding the default fonts * changelog --- .../feat-dont-override-default-fonts | 4 +++ .../class-jetpack-google-font-face.php | 2 +- .../current/load-google-fonts.php | 36 +------------------ 3 files changed, 6 insertions(+), 36 deletions(-) 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 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; } )