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

Global Styles: Fix registration of theme style variation defined block styles #62495

Merged

Conversation

aaronrobertshaw
Copy link
Contributor

Addresses WordPress/wordpress-develop#6756 (comment)

What?

Ensures theme style variation defined block style variations are supported when saving global styles via the the REST API.

Why?

If block style variations aren't registered they are stripping out during the sanitization of theme json data. This makes it appear as though global style customizations have been lost until the editor is reloaded.

How?

When a theme style variation is selected, its values are copied into the user origin data to be saved. This includes the shared block style variation definitions that need registering.

The REST API has been updated to register shared block style variations prior to saving the global styles. This maintains the data for variations they weren't able to be registered via the normal init filter.

Testing Instructions

  1. Register style variations the styles/ember.json (theme style variation) file, paste the following under styles.blocks.variations:
"VariationDark": {
    "blockTypes": [
        "core/group",
        "core/columns"
    ],
    "color": {
            "background": "yellow"
    }
}
  1. Open the site editor, go to Styles, apply the "Ember" theme style variation AND DO NOT SAVE IT YET.
  2. Go to the site editor, select a group block, and verify the VariationDark is available:
  3. Update the VariationDark variation by going to "Global Styles > Blocks > Group > VariationDark". Modify the background color to something else.
  4. Save the post. The expected result is that the new background stays as it is and it's not reset.
  5. Confirm the global styles API unit tests pass:
    npm run test:unit:php:base -- --filter WP_REST_Global_Styles_Controller_Gutenberg_Test::test_update_item_with_custom_block_style_variations

Screenshots or screencast

Before After
Screen.Recording.2024-06-12.at.12.26.30.PM.mp4
Screen.Recording.2024-06-12.at.12.25.44.PM.mp4

@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jun 12, 2024
@aaronrobertshaw aaronrobertshaw self-assigned this Jun 12, 2024
Copy link

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/class-wp-rest-global-styles-controller-gutenberg.php
❔ phpunit/class-wp-rest-global-styles-controller-gutenberg-test.php

Copy link

github-actions bot commented Jun 12, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@aaronrobertshaw aaronrobertshaw merged commit bda08ff into trunk Jun 12, 2024
63 checks passed
@aaronrobertshaw aaronrobertshaw deleted the fix/variation-registration-for-theme-style-variations branch June 12, 2024 06:20
@github-actions github-actions bot added this to the Gutenberg 18.6 milestone Jun 12, 2024
@aaronrobertshaw
Copy link
Contributor Author

This will be included in the existing backport: WordPress/wordpress-develop#6756.

patil-vipul pushed a commit to patil-vipul/gutenberg that referenced this pull request Jun 17, 2024
…k styles (WordPress#62495)

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants