Fix: Rest global styles controller accessing config that may not exist#36047
Merged
jorgefilipecosta merged 1 commit intotrunkfrom Oct 28, 2021
Merged
Conversation
youknowriad
approved these changes
Oct 28, 2021
Contributor
youknowriad
left a comment
There was a problem hiding this comment.
Do you think it's worth adding a unit test about this case?
Member
Author
Yes, I think testing this may be useful I will look into expanding our API test cases. |
Contributor
|
Looks like this PR introduced some linting issues on trunk |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
After a fix on #35801 the post is now created on the database by "get_user_data_from_custom_post_type" as
{"version": ' . WP_Theme_JSON_Gutenberg::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }. And I think it is right by default the user has no settings and styles.Our code was assuming that on the database existing settings and styles were always present by unconditionally doing
$config['settings'] = $existing_config['settings']when$existing_config['settings']may not exist.In the case where
$existing_config['settings']did not exist there would occur a PHP warning and on the database, we would then serialize{ settings: null }. Settings being null is not something the frontend code that compiles the styles accepts and as a consequence no global styles would be output at all. As a different issue, we need to make sure that if user global styles are not valid theme styles are still output.How has this been tested?
Delete the current global styles post if there is any.
Open the site editor and change the global background color.
Verify global styles are still output on the frontend (on trunk they are not).