Skip to content

Commit

Permalink
Jetpack Google Fonts: Fix the fonts provided by theme are still added (
Browse files Browse the repository at this point in the history
…#34608)

* Google Fonts: Ignore the fonts that are provied by the active theme

* changelog

* Update syntax
  • Loading branch information
arthur791004 authored Dec 18, 2023
1 parent db7fa7a commit 93aa805
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Jetpack Google Fonts: Don't print font definition if the font is provided by the active theme
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function get_fonts() {
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 = isset( $font['slug'] ) ? $font['slug'] : '';
$font_slug = $font['slug'] ?? '';
if ( $font_slug && ! array_key_exists( $font_slug, $fonts ) && array_key_exists( $font_family_name, $fonts ) ) {
$fonts[ $font_slug ] = $fonts[ $font_family_name ];
}
Expand All @@ -153,7 +153,7 @@ public function get_fonts() {
*
* @param array $font The font definition object.
*/
public function get_font_family_name( $font ) {
public static function get_font_family_name( $font ) {
$font_family = $font['fontFamily'];
if ( str_contains( $font_family, ',' ) ) {
$font_family = explode( ',', $font_family )[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
* @package automattic/jetpack
*/

if ( ! class_exists( 'Jetpack_Google_Font_Face' ) ) {
/**
* Load Jetpack Google Font Face
*/
require_once __DIR__ . '/class-jetpack-google-font-face.php';
}

/**
* Gets the Google Fonts data
*
Expand Down Expand Up @@ -94,8 +101,9 @@ function jetpack_get_theme_fonts_map() {

$theme_fonts_map = array();
foreach ( $raw_data['settings']['typography']['fontFamilies'] as $font_family ) {
if ( isset( $font_family['name'] ) ) {
$theme_fonts_map[ $font_family['name'] ] = true;
$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;
}
}

Expand Down Expand Up @@ -127,9 +135,7 @@ function ( $google_fonts_family ) use ( $available_google_fonts_map, $theme_font
return false;
}

return isset( $available_google_fonts_map[ $name ] )
? $available_google_fonts_map[ $name ]
: false;
return $available_google_fonts_map[ $name ] ?? false;
}
)
);
Expand Down Expand Up @@ -165,7 +171,7 @@ function ( $font_family ) {

if ( isset( $font_family['fontFace'] ) ) {
foreach ( $font_family['fontFace'] as $font_face ) {
$provider = isset( $font_face['provider'] ) ? $font_face['provider'] : '';
$provider = $font_face['provider'] ?? '';
if ( $provider === 'jetpack-google-fonts' ) {
$has_deprecated_google_fonts_data = true;
break;
Expand Down Expand Up @@ -203,13 +209,6 @@ function jetpack_unregister_deprecated_google_fonts_from_theme_json_data_user( $

add_filter( 'wp_theme_json_data_user', 'jetpack_unregister_deprecated_google_fonts_from_theme_json_data_user' );

if ( ! class_exists( 'Jetpack_Google_Font_Face' ) ) {
/**
* Load Jetpack Google Font Face
*/
require_once __DIR__ . '/class-jetpack-google-font-face.php';

// Initialize Jetpack Google Font Face to avoid printing **ALL** google fonts provided by this module.
// See p1700040028362329-slack-C4GAQ900P and p7DVsv-jib-p2
new Jetpack_Google_Font_Face();
}
// Initialize Jetpack Google Font Face to avoid printing **ALL** google fonts provided by this module.
// See p1700040028362329-slack-C4GAQ900P and p7DVsv-jib-p2
new Jetpack_Google_Font_Face();

0 comments on commit 93aa805

Please sign in to comment.