Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error in WP_Fonts_Resolver::get_settings() #55981

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/experimental/fonts-api/class-wp-fonts-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,20 @@ private static function get_settings() {
$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.
$settings_font_families = ( isset( $settings['typography']['fontFamilies']['theme'] ) && is_array( $settings['typography']['fontFamilies']['theme'] ) )
? $settings['typography']['fontFamilies']['theme']
: array();
Copy link
Contributor

@azaozz azaozz Nov 9, 2023

Choose a reason for hiding this comment

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

Thinking this can be outside (above) the loop as $settings is not changed in the loop, just a bit of optimization.

At the same time not sure what is the expected default value (and value type) of $settings['typography']['fontFamilies']['theme'] when it is empty or not set. Same for $variation['settings']['typography']['fontFamilies']['theme']. Setting these to empty arrays when missing means that the final $settings['typography']['fontFamilies']['theme'] may be an empty array. Is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed in 8e94c1c and 061bafb.


// 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']
$settings_font_families,
$variation_font_families
);

// Make sure there are no duplicates.
Expand Down
Loading