-
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
Make sure theme families are array before attempting to merge them #56050
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Excuse me, but I don't understand why this change is necessary.
If
$settings['typography']['fontFamilies']['theme']
isnull
, it will be set to an array here (around line 205):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.
My best guess is that it's needed because the line you mention depends on us being within the editor:
gutenberg/lib/experimental/fonts-api/class-wp-fonts-resolver.php
Line 190 in 787f8ea
gutenberg/lib/experimental/fonts-api/class-wp-fonts-resolver.php
Line 200 in 787f8ea
gutenberg/lib/experimental/fonts-api/class-wp-fonts-resolver.php
Line 201 in 787f8ea
If I understand that logic correctly, the second time we go through this condition,
$set_theme_structure
could befalse
, hence$settings['typography']['fontFamilies']['theme']
never getting initialized as an array. Another solution would be to move that initialization out of the conditional on$set_theme_structure
.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.
Yes,
$set_theme_structure
isfalse
on the second iteration of theforeach
loop.However, I don't understand how this affects
$settings['typography']['fontFamilies']['theme']
.$settings['typography']['fontFamilies']['theme']
is set to an array during the first iteration of the loop and remains an array in subsequent iterations.array_merge()
always returns an array value.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.
gutenberg/lib/experimental/fonts-api/class-wp-fonts-resolver.php
Line 222 in 787f8ea
After
array_unique
on line 222,$settings['typography']['fontFamilies']['theme']
is goingnull
, and it doesn't get reset on the next iteration. It's probably goingnull
becausearray_unique
is getting rid of a duplicatekey
that contains the thetheme
array, because the function isn't really comparing the value? I don't thinkarray_unique
works well with multidimensional arrays.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.
Yes, the main issue is the
$settings['typography']['fontFamilies']['theme']
becomesnull
afterarray_unique
as it removes the key with the duplicate value.Hence, I proposed #56067 to
array_unique
toSORT_REGULAR
. The default flag isSORT_STRING
and it means that the elements are converted to a string to do the comparison. However, the value after the conversion becomesArray
and it leads to$settings['typography']['fontFamilies']['theme']
beingnull
if the$settings['typography']['fontFamilies']
contains multiple keys.$settings['typography']['fontFamilies']['theme']
after thearray_unique
call to avoid it becomingnull
in the next iteration. WDYT?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.
@vcanales
I'm not able to reproduce this.
Can you provide the values of
$settings
and$variations
at which this issue occurs? Please see this code snippet: https://3v4l.org/InOuS#v7.3.0Can you provide an example of such behavior? Specifically, what exact array should I pass to
array_unique()
in order to make$settings['typography']['fontFamilies']['theme']
anull
value?