From 126b8baa31eec35621b69f6c05ab2c26db5b115b Mon Sep 17 00:00:00 2001 From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:43:53 -0600 Subject: [PATCH] (Jetpack)(PHP8)(GB 17.1.3) Make the check around `$google_fonts_data`'s array more resilient and return early if key or value is not of the right type (#34382) * Fallback when $google_fonts_data[fontFamilies] is null to avoid warnings and fatals * changelog * Update fix to avoid warnings in `jetpack_google_fonts_filter_out_deprecated_font_data`, make it a bit more DRY --------- Co-authored-by: Brandon Kraft --- .../changelog/make-load-google-fonts-more-resilient | 4 ++++ .../modules/google-fonts/current/load-google-fonts.php | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/make-load-google-fonts-more-resilient diff --git a/projects/plugins/jetpack/changelog/make-load-google-fonts-more-resilient b/projects/plugins/jetpack/changelog/make-load-google-fonts-more-resilient new file mode 100644 index 0000000000000..474a586957ceb --- /dev/null +++ b/projects/plugins/jetpack/changelog/make-load-google-fonts-more-resilient @@ -0,0 +1,4 @@ +Significance: patch +Type: compat + +Google Fonts: resolve occasional bug resulting in PHP 8 with latest Gutenberg. 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 193a439532aab..7181d00549e2e 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 @@ -46,7 +46,9 @@ function jetpack_get_google_fonts_data() { } } - return $data; + if ( is_array( $data ) && is_array( $data['fontFamilies'] ) ) { + return $data; + } } /** @@ -56,15 +58,11 @@ function jetpack_get_google_fonts_data() { * @return object[] The map of the the available Google Fonts. */ function jetpack_get_available_google_fonts_map( $google_fonts_data ) { - $font_families = isset( $google_fonts_data ) && isset( $google_fonts_data['fontFamilies'] ) - ? $google_fonts_data['fontFamilies'] - : array(); - $jetpack_google_fonts_list = array_map( function ( $font_family ) { return $font_family['name']; }, - $font_families + $google_fonts_data['fontFamilies'] ); /** This filter is documented in modules/google-fonts/wordpress-6.3/load-google-fonts.php */