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

Section Styles: Register block style variations on init #62461

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jun 11, 2024

Fixes: #62303

What?

Moves registration of theme json provided block style variations from the wp_theme_json_* filters to the init action.

Note: This brings the changes proposed in WordPress/wordpress-develop#6756 to Gutenberg.

Why?

Using the wp_theme_json_data_* filters is problematic: in some scenarios (e.g.: ) variations end up not being registered because those filters were not dispatched, hence their styles are not generated. Using init is in line with what themes have been doing until now in their functions.php and makes sure the style variations are registered in all the places.

How?

  • Separates the registration of theme json provided block style variations from their resolution within their respective block types in the resulting theme.json data sets.
  • Registration now occurs via the init action
  • Updates test to ensure the registration is still triggered

Testing Instructions

  1. Register style variations in all the places the theme is allowed to (use TT4).

In the theme.json file of the theme, paste the following under styles.blocks.variations:

"ThemeDark": {
    "blockTypes": [
        "core/group",
        "core/columns"
    ],
    "color": {
            "background": "blue"
    }
}

In the styles/ember.json (theme style variation) file, paste the following under styles.blocks.variations:

"VariationDark": {
    "blockTypes": [
        "core/group",
        "core/columns"
    ],
    "color": {
            "background": "yellow"
    }
}

Create a new file called styles/partial.json (partial theme.json), and paste the following:

{
        "$schema": "https://schemas.wp.org/trunk/theme.json",
        "version": 2,
        "title": "PartialDark",
        "blockTypes": [ "core/group", "core/columns", "core/media-text" ],
        "styles": {
                "color": {
                        "background": "green"
                }
        }
}
  1. Open the site editor, go to Styles, apply the "Ember" theme style variation and save.
  2. Go to the site editor, select a group block, and verify the three new style variations are available
Screenshot 2024-06-11 at 2 19 59 PM
  1. Edit the styles of one of them, for example, PartialDark. Go to "Global Styles > Blocks > Group > PartialDark". Modify the background color to something else.
  2. Save the post. The expected result is that it stays as it is (it's not reset to the default).

Screenshots or screencast

Before After
Screen.Recording.2024-06-05.at.6.49.43.PM.mp4
Screen.Recording.2024-06-05.at.6.50.31.PM.mp4
Copy link

github-actions bot commented Jun 11, 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>
Co-authored-by: annezazu <annezazu@git.wordpress.org>

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

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/block-supports/block-style-variations.php
❔ phpunit/block-supports/block-style-variations-test.php
@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 11, 2024
// Trigger block style registration that occurs on `init` action.
// do_action( 'init' ) could be used here however this direct call
// means only the updates being tested are performed.
gutenberg_register_block_style_variations_from_theme();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it better to call the registration function direct here or call do_action( 'init' );?

@aaronrobertshaw
Copy link
Contributor Author

There's also an existing PR awaiting review to remove the core block style variation filters: #62090.

This PR then only adds the removal of core's init action for variation registration: a90b811

@aaronrobertshaw aaronrobertshaw merged commit faf5cba into trunk Jun 11, 2024
63 checks passed
@aaronrobertshaw aaronrobertshaw deleted the update/registration-of-block-style-variations branch June 11, 2024 06:11
@github-actions github-actions bot added this to the Gutenberg 18.6 milestone Jun 11, 2024
@aaronrobertshaw aaronrobertshaw added the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jun 12, 2024
patil-vipul pushed a commit to patil-vipul/gutenberg that referenced this pull request Jun 17, 2024
…62461)

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
ellatrix pushed a commit that referenced this pull request Jun 18, 2024
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
@ellatrix
Copy link
Member

I just cherry-picked this PR to the wp/6.6-beta-3 branch to get it included in the next release: d633a42

ellatrix pushed a commit that referenced this pull request Jun 18, 2024
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
@ellatrix ellatrix added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Jun 18, 2024
ellatrix pushed a commit that referenced this pull request Jun 18, 2024
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core 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
3 participants