-
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() #55981
Fix fatal error in WP_Fonts_Resolver::get_settings() #55981
Conversation
array_merge() expects input parameters to be arrays.
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/fonts-api/class-wp-fonts-resolver.php |
Alternative #55974 |
// 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(); |
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.
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?
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, was going to comment there that it may make sense to check both values separately. This PR does that. The other thing I'm not sure about is what value(s) and type(s) are expected at |
…]['fontFamilies']['theme'] on every iteration of 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.
The changes here look good to me and I believe they'll prevent the fatal error in question. I'm happy to approve if needed, although this isn't my area of expertise.
Looking bit more at This is at the top of the loop:
Not sure why it only checks This is at the bottom of the loop:
What is it supposed to be checking for duplicates? We've likely added some array elements to |
@azaozz I noticed it too and agree with your concerns. |
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.
As this PR primarily focuses on resolving the fatal errors in WP_Fonts_Resolver::get_settings(), perhaps it would be better to address these concerns in another PR.
+1 to this, I think a refactor should be addressed after getting the fatal errors being thrown out of the way.
I've created an issue so that we don't lose track of the discussion.
I hope I didn't step on any toes here -- this issue has been causing quite a few problems, so getting it into a patch release feels urgent enough to warrant moving fast! |
* 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.
* 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.
* 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.
Regarding backporting to Core: this PR should be backported as part of a larger PR that includes backporting the |
To confirm further, this file is actually about to be removed and so will not require backporting at all. Please see this PR for more info: #57972 |
✅ I updated the PHP Sync Tracking Issue to note this PR does not require a backport. |
What?
This PR aims to fix a PHP fatal error that occurs within
WP_Fonts_Resolver::get_settings()
under certain conditions.Why?
Generally, the code should not trigger PHP fatal errors because certain variables do not match the expected type.
How?
This PR ensures that the
array_merge()
function insideWP_Fonts_Resolver::get_settings()
always receives arrays as input parameters.Testing instructions.
Pendant
block theme.to your config file.
3. Edit the src/wp-content/themes/pendant/styles/dark-navy.json file by replacing the following JSON block:
with
error in the admin panel.