-
Notifications
You must be signed in to change notification settings - Fork 8
Blocks: Use get_block_wrapper_attributes for class attributes
#842
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
Merged
Conversation
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
…n no text or background colors selected
…d with the module / widget Prevents PHP warnings when using get_block_wrapper_attributes().
…h block styles (margin, padding, spacing etc)
WordPress Playground🚀 Your PR has been built and is ready for testing in WordPress Playground! |
This ensures the preview matches the output of the page
`visualizers` aren’t needed in the block editor. `fontSize` belongs within `typography`
Blocks: Add Typography Support
Blocks: Add Margin and Padding Support
6 tasks
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.
Summary
For blocks (broadcasts, form trigger, product button), uses WordPress'
get_block_wrapper_attributesmethod to define the block'sclassattributes automatically, based on a number of built-in block editor properties (text, link and background color). WordPress will automagically build CSS styles specific to each block based on these properties, removing the need for inline styles.Previously, code would manually build a
_css_classeskey in the block's attributes, outputting in theclassattribute. This is inflexible for adding support for built-in block properties in the future (such as margin, padding and block spacing, which builds on this PR here).Inline styles are still added to shortcodes, Elementor widgets and Divi modules, as these aren't part of the block editor.
This opens up supporting additional native block properties, such as margin and padding, added in this PR.
Testing
Existing tests pass. Confirmed no regressions in output between main branch and this PR, as well as confirming output the same for both blocks and shortcodes:
Blocks:

Shortcodes:

Tests
testBroadcastsBlockParameterEscaping,testFormTriggerBlockParameterEscapingandtestProductBlockParameterEscapingare removed, as inline styles on blocks are no longer needed. Parameter escaping tests for styles on e.g. shortcodes remain.Checklist