-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add custom CSS for block style variations. #62526
Conversation
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-theme-json-gutenberg.php |
368ea61
to
fabfbad
Compare
Size Change: +556 B (+0.03%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Testing this with the extended style variations that shipped in #57908, I see it's mostl_ working except when it comes to nested blocks. So, for example, adding the following snippet to theme.json under
The |
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.
Thanks for fixing this one @tellthemachines 👍
The code looks good and it tests well for me!
✅ Custom CSS applies on the frontend and both editors
✅ Custom CSS from theme.json displays within the Advanced panel field
✅ Custom CSS updated through Global Styles is applied correctly on frontend and editors
✅ Theme style variation supplied custom CSS applies correctly
✅ Works for both core block style variations and custom definitions
There's a tiny flash of the custom CSS from the theme.json in the post editor before Global Styles customizations take effect but I believe that might be taken care of when the redundant block style variation styles are removed.
Screen.Recording.2024-06-14.at.9.54.34.AM.mp4
Ah good catch! I only checked the top level of custom variations. |
Ok I think I've fixed it now. The nested styles weren't coming in under the style variations condition which was a bit confusing. My testing shows it working correctly, but might be good to make sure there are no unintended side-effects to this change 😅 |
Thanks for the quick iteration for the inner block custom CSS for variations 🚀 I can confirm this is working for me using the following definition within my theme.json: "styles": {
"blocks": {
"variations": {
"Custom": {
"blockTypes": [ "core/group" ],
"blocks": {
"core/group": {
"css": "background-image: url('data:image/svg+xml;base64,77u/PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnICB3aWR0aD0nMTA5JyBoZWlnaHQ9JzEwOScgdmlld0JveD0nMCAwIDIwIDIwJz48cmVjdCBmaWxsPScjMDQwNzMzJyB3aWR0aD0nMjAnIGhlaWdodD0nMjAnLz48ZyBmaWxsLW9wYWNpdHk9JzEnPjxwb2x5Z29uICBmaWxsPScjMEYzNTVCJyBwb2ludHM9JzIwIDEwIDEwIDAgMCAwIDIwIDIwJy8+PHBvbHlnb24gIGZpbGw9JyMwRjM1NUInIHBvaW50cz0nMCAxMCAwIDIwIDEwIDIwJy8+PC9nPjwvc3ZnPg==');"
}
}
}
}
}
} |
Awesome, thanks for retesting @aaronrobertshaw ! I'll go ahead and merge this and add the backport label. The PHP PR still needs a review, but that should be fine to do next week. |
It appears the custom css for a variation's inner block types doesn't work in the editor for a non-admin user. I came across this while testing the backport (WordPress/wordpress-develop#6797). There I don't see the styles apply in the editor which was expected, as the JS updates aren't in core yet, but I also don't see the styles on the frontend 🤔 Perhaps some unit tests covering the style generation or sanitization of the custom css in variations would help? What I'm seeing in Gutenberg: Screen.Recording.2024-06-16.at.12.54.57.PM.mp4 |
🤦 False alarm sorry. I forgot that the test variation I was using set the background via a base64 encoded svg that I'd been testing sanitization with and of course that is stripped by kses for non-admin users in the editor. The fact it still showed on the frontend caught me out. |
Noting that the corresponding PHP sync PR was committed in https://core.trac.wordpress.org/changeset/58421. |
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: matiasbenedetto <[email protected]>
I just cherry-picked this PR to the wp/6.6-beta-3 branch to get it included in the next release: aac8874 |
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: matiasbenedetto <[email protected]>
What?
Fixes #62415 by adding custom CSS output for block style variations.
Testing Instructions
styles.blocks
:Testing Instructions for Keyboard
Screenshots or screencast