← All changes
|
modules/google-fonts/current/load-google-fonts.php
+39
-3
13.7.2
→
16.3-a.1
View file →
| @@ -4,8 +4,12 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 11 | + | |
| 8 | 12 | if ( ! class_exists( 'Jetpack_Google_Font_Face' ) ) { |
| 9 | 13 | /** |
| 10 | 14 | * Load Jetpack Google Font Face |
| 11 | 15 | */ |
| @@ -14,9 +18,9 @@ | ||
| 14 | 18 | |
| 15 | 19 | /** |
| 16 | 20 | * Gets the Google Fonts data |
| 17 | 21 | * |
| 18 | - * @return object[] The collection data of the Google Fonts. | |
| 22 | + * @return array|null The collection data of the Google Fonts. | |
| 19 | 23 | */ |
| 20 | 24 | function jetpack_get_google_fonts_data() { |
| 21 | 25 | /** |
| 22 | 26 | * Filters the Google Fonts data before the default retrieval process. |
| @@ -86,10 +90,10 @@ | ||
| 86 | 90 | |
| 87 | 91 | /** |
| 88 | 92 | * Gets the map of the available Google Fonts |
| 89 | 93 | * |
| 90 | - * @param object[] $google_fonts_data The collection data of the Google Fonts. | |
| 91 | - * @return object[] The map of the the available Google Fonts. | |
| 94 | + * @param array $google_fonts_data The collection data of the Google Fonts. | |
| 95 | + * @return array The map of the the available Google Fonts. | |
| 92 | 96 | */ |
| 93 | 97 | function jetpack_get_available_google_fonts_map( $google_fonts_data ) { |
| 94 | 98 | $jetpack_google_fonts_list = array_map( |
| 95 | 99 | function ( $font_family ) { |
| @@ -209,8 +213,40 @@ | ||
| 209 | 213 | } |
| 210 | 214 | |
| 211 | 215 | add_filter( 'wp_theme_json_data_theme', 'jetpack_unregister_deprecated_google_fonts_from_theme_json_data' ); |
| 212 | 216 | add_filter( 'wp_theme_json_data_user', 'jetpack_unregister_deprecated_google_fonts_from_theme_json_data' ); |
| 217 | + | |
| 218 | +/** | |
| 219 | + * Clean up the Google Fonts data if either google fonts module is disabled or Jetpack is disabled. | |
| 220 | + */ | |
| 221 | +function jetpack_unregister_google_fonts() { | |
| 222 | + $post_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); | |
| 223 | + | |
| 224 | + // Get user config | |
| 225 | + $user_config = WP_Theme_JSON_Resolver::get_user_data(); | |
| 226 | + $user_config_raw_data = $user_config->get_raw_data(); | |
| 227 | + $user_config_raw_data['isGlobalStylesUserThemeJSON'] = true; | |
| 228 | + | |
| 229 | + // Prepare data for saving | |
| 230 | + if ( ! empty( $user_config_raw_data['settings']['typography']['fontFamilies']['default'] ) ) { | |
| 231 | + $user_config_raw_data['settings']['typography']['fontFamilies']['default'] = array(); | |
| 232 | + } | |
| 233 | + | |
| 234 | + if ( ! empty( $user_config_raw_data['settings']['typography']['fontFamilies']['theme'] ) ) { | |
| 235 | + $user_config_raw_data['settings']['typography']['fontFamilies']['theme'] = jetpack_google_fonts_filter_out_deprecated_font_data( | |
| 236 | + $user_config_raw_data['settings']['typography']['fontFamilies']['theme'] // @phan-suppress-current-line PhanTypeInvalidDimOffset, PhanTypeMismatchArgument | |
| 237 | + ); | |
| 238 | + } | |
| 239 | + | |
| 240 | + // Prepare changes | |
| 241 | + $changes = new stdClass(); | |
| 242 | + $changes->ID = $post_id; | |
| 243 | + $changes->post_content = wp_json_encode( $user_config_raw_data, JSON_UNESCAPED_SLASHES ); | |
| 244 | + | |
| 245 | + // Update user config | |
| 246 | + wp_update_post( wp_slash( (array) $changes ), true ); | |
| 247 | +} | |
| 248 | +add_action( 'jetpack_deactivate_module_google-fonts', 'jetpack_unregister_google_fonts' ); | |
| 213 | 249 | |
| 214 | 250 | // Initialize Jetpack Google Font Face to avoid printing **ALL** google fonts provided by this module. |
| 215 | 251 | // See p1700040028362329-slack-C4GAQ900P and p7DVsv-jib-p2 |
| 216 | 252 | new Jetpack_Google_Font_Face(); |