-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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() #56067
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,11 +200,6 @@ 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. | ||
|
@@ -219,7 +214,12 @@ private static function get_settings() { | |
); | ||
|
||
// Make sure there are no duplicates. | ||
$settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'] ); | ||
$settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'], SORT_REGULAR ); | ||
|
||
// The font families from settings might become null after running the `array_unique`. | ||
if ( ! isset( $settings['typography']['fontFamilies']['theme'] ) || ! is_array( $settings['typography']['fontFamilies']['theme'] ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should be before the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I agreed the check should be before the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arthur791004 You could modify this snippet and post a link to the new snippet here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is it: https://3v4l.org/v8DYU#v8.0.0, and I also mentioned the example here, #56067 (comment).
Yes, it removes duplicates. When you access the value after that, the value doesn't exist anymore and returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arthur791004, thank you for expanding on this so I can better understand the proposed idea.
Yes. And if an array element doesn't exist, it shouldn't be accessed directly, as accessing an undefined array element generally results in a PHP warning.
I respectfully disagree with that. In the WordPress context, |
||
$settings['typography']['fontFamilies']['theme'] = array(); | ||
} | ||
} | ||
|
||
return $settings; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to be in the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the existing behavior for a long time, so I think it's out of the scope of this PR to address the fatal error. We can plan to move it outside the loop in the follow-up PR. Does it make sense?
Additionally, I'm not sure why we want to remove the duplicates on
$settings['typography']['fontFamilies']
. Instead, I think doing it on$settings['typography']['fontFamilies']['theme']
makes more sense as we merge the variation settings into$settings['typography']['fontFamilies']['theme']
above and it might have the duplicates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, same. Thinking this is one of the problems here that caused the fatal error (see comment below). I'd be a +1 to fix that
array_unique()
as it seems to be a bug.