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

Update: Migrate global styles user database data on the rest endpoint #36747

Conversation

jorgefilipecosta
Copy link
Member

After merging #36674, I noticed although we were back-compatible on the frontend we were not being back-compatible on the site editor because our migration logic was not being called on the rest endpoint. This PR fixes the issue and makes sure that the data returned by the endpoint passes by the WP_Theme_JSON_Gutenberg constructor which includes migration and back-compatibility logic.

How has this been tested?

I made the global styles CPT equal to:

{"styles":{"color":{"background":"var:preset|color|red"}},"settings":{"color":{"palette":[{"color":"#000","name":"black","slug":"black"},{"color":"#f51b1b","name":"red","slug":"red"}]}},"isGlobalStylesUserThemeJSON":true,"version":2}

To force global styles CPT to have the previous value I changed show_ui to true in lib/class-wp-theme-json-resolver-gutenberg.php and opened the CPT on the editor and pasted the data. Changing the post using phpmyadmin or a similar tool is also ok.

I opened the site editor and verified everything looks as excepted and the palette provided is assumed to be the user one.

@jorgefilipecosta jorgefilipecosta added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 22, 2021
@jorgefilipecosta jorgefilipecosta force-pushed the update/automatically-migrate-global-styles-user-database-data-on-theme-json branch from 4ffbe2f to acd2881 Compare November 22, 2021 18:58
$is_global_styles_user_theme_json = isset( $config['isGlobalStylesUserThemeJSON'] ) && true === $config['isGlobalStylesUserThemeJSON'];
$raw_config = json_decode( $post->post_content, true );
$is_global_styles_user_theme_json = isset( $raw_config['isGlobalStylesUserThemeJSON'] ) && true === $raw_config['isGlobalStylesUserThemeJSON'];
$config;
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be set to something?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is not I'm just instantiating the variable because it is used outside the if condition where we set the variable.

@TimothyBJacobs
Copy link
Member

Feels like this would be a good candidate for wrapping up into a standalone function?

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

This fixes the issue I ran to as well. We need this fix asap to continue iterating on the GS code so I'm approving this.

I agree some of this code could be improved to be packed in utility functions. We can probably use the WP_Theme_JSON_Resolver::get_user_data and similar functions. Can be done in a follow-up PR to unblock related work.

@oandregal oandregal merged commit 28995aa into trunk Nov 23, 2021
@oandregal oandregal deleted the update/automatically-migrate-global-styles-user-database-data-on-theme-json branch November 23, 2021 09:36
@github-actions github-actions bot added this to the Gutenberg 12.1 milestone Nov 23, 2021
@oandregal
Copy link
Member

oandregal commented Nov 23, 2021

Related #36584

@noisysocks noisysocks removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 28, 2021
noisysocks pushed a commit that referenced this pull request Nov 29, 2021
…#36747)

* Update: Automatically migrate global styles user database data on the rest endpoint.

* Fix lint issues

Co-authored-by: André <583546+oandregal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants