Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetpack Google Fonts: Fix the fonts provided by theme are still added #34608

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Loading