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 Nov 10, 2023
1 parent f6bd753 commit d998c7a
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
Original file line number Diff line number Diff line change
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

1 comment on commit d998c7a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in d998c7a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6828025789
📝 Reported issues:

Please sign in to comment.