Skip to content

Commit

Permalink
Fix fatal error in WP_Fonts_Resolver::get_settings() (#55981)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
anton-vlasenko authored and cbravobernal committed Nov 14, 2023
1 parent 452a1f3 commit bfd8fb2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/experimental/fonts-api/class-wp-fonts-resolver.php
Expand Up @@ -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.
Expand Down

0 comments on commit bfd8fb2

Please sign in to comment.