From bfd8fb2e2fdae607b367b112b11baf0defb23186 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:46:48 +0100 Subject: [PATCH] Fix fatal error in WP_Fonts_Resolver::get_settings() (#55981) * Check variables before passing them to array_merge. array_merge() expects input parameters to be arrays. * Optimization: don't check for the existence of $settings['typography']['fontFamilies']['theme'] on every iteration of the loop. * Optimization: ternary is not needed here. --- .../fonts-api/class-wp-fonts-resolver.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/experimental/fonts-api/class-wp-fonts-resolver.php b/lib/experimental/fonts-api/class-wp-fonts-resolver.php index 144f7b30acc153..f2299c7c368311 100644 --- a/lib/experimental/fonts-api/class-wp-fonts-resolver.php +++ b/lib/experimental/fonts-api/class-wp-fonts-resolver.php @@ -200,12 +200,22 @@ private static function get_settings() { if ( $set_theme_structure ) { $set_theme_structure = false; $settings = static::set_tyopgraphy_settings_array_structure( $settings ); + + // Initialize the font families from settings if set and is an array, otherwise default to an empty array. + if ( ! isset( $settings['typography']['fontFamilies']['theme'] ) || ! is_array( $settings['typography']['fontFamilies']['theme'] ) ) { + $settings['typography']['fontFamilies']['theme'] = array(); + } } + // Initialize the font families from variation if set and is an array, otherwise default to an empty array. + $variation_font_families = ( isset( $variation['settings']['typography']['fontFamilies']['theme'] ) && is_array( $variation['settings']['typography']['fontFamilies']['theme'] ) ) + ? $variation['settings']['typography']['fontFamilies']['theme'] + : array(); + // Merge the variation settings with the global settings. $settings['typography']['fontFamilies']['theme'] = array_merge( $settings['typography']['fontFamilies']['theme'], - $variation['settings']['typography']['fontFamilies']['theme'] + $variation_font_families ); // Make sure there are no duplicates.