get_data(); $origin = 'default'; if ( empty( $raw_data['settings']['typography']['fontFamilies'][ $origin ] ) ) { $raw_data['settings']['typography']['fontFamilies'][ $origin ] = array(); } foreach ( $google_fonts_families as $font_family ) { $raw_data['settings']['typography']['fontFamilies'][ $origin ][] = $font_family; } $theme_json_class = get_class( $theme_json ); return new $theme_json_class( $raw_data, $origin ); } add_filter( 'wp_theme_json_data_default', 'jetpack_register_google_fonts_to_theme_json' ); /** * Filter out the deprecated font families that are from the jetpack-google-fonts provider. * * @param object[] $font_families The font families. * @return object[] The filtered font families. */ function jetpack_google_fonts_filter_out_deprecated_font_data( $font_families ) { return array_values( array_filter( $font_families, function ( $font_family ) { $has_deprecated_google_fonts_data = false; if ( isset( $font_family['fontFace'] ) ) { foreach ( $font_family['fontFace'] as $font_face ) { $provider = $font_face['provider'] ?? ''; if ( $provider === 'jetpack-google-fonts' ) { $has_deprecated_google_fonts_data = true; break; } } } return ! $has_deprecated_google_fonts_data; } ) ); } /** * Unregister the deprecated jetpack-google-fonts provider from theme json data that were stored * before we moved to the Font Library. * * @param WP_Theme_JSON_Data $theme_json The theme json data. * @return WP_Theme_JSON_Data The filtered theme json data. */ function jetpack_unregister_deprecated_google_fonts_from_theme_json_data( $theme_json ) { $raw_data = $theme_json->get_data(); $origin = 'theme'; if ( empty( $raw_data['settings']['typography']['fontFamilies'][ $origin ] ) ) { return $theme_json; } // Filter out the font definitions that are from the jetpack-google-fonts provider. $raw_data['settings']['typography']['fontFamilies'][ $origin ] = jetpack_google_fonts_filter_out_deprecated_font_data( $raw_data['settings']['typography']['fontFamilies'][ $origin ] ); $theme_json_class = get_class( $theme_json ); return new $theme_json_class( $raw_data, 'custom' ); } add_filter( 'wp_theme_json_data_theme', 'jetpack_unregister_deprecated_google_fonts_from_theme_json_data' ); add_filter( 'wp_theme_json_data_user', 'jetpack_unregister_deprecated_google_fonts_from_theme_json_data' ); // 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();