Try/strip custom block css without unfiltered html#76167
Closed
ramonjd wants to merge 5 commits into
Closed
Conversation
…bility - Added a function to remove block-level custom CSS when saving content for restricted users. - Introduced a warning message in the editor for blocks with custom CSS that will be stripped on save. - Updated styles to visually indicate blocks affected by this change. This ensures that users without the ability to use unfiltered HTML do not inadvertently save custom CSS that could lead to issues.
- Integrated BlockCustomCSSStripNotice component into the editor interface to provide users with warnings about custom CSS being stripped for those without unfiltered_html capability. - This enhances user awareness regarding the handling of custom CSS in the editor. This change supports the previous functionality of stripping custom CSS for restricted users by ensuring they receive appropriate notifications.
|
Size Change: +385 B (+0.01%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
ramonjd
commented
Mar 5, 2026
Comment on lines
+96
to
+98
| $blocks = parse_blocks( $content ); | ||
| $blocks = gutenberg_strip_custom_css_from_blocks( $blocks ); | ||
| return serialize_blocks( $blocks ); |
Member
Author
There was a problem hiding this comment.
is there a better / faster way to do this? I guess in the Core path it'll be working at the block level anyway:
https://github.com/wordpress/wordpress-develop/blob/trunk/src/wp-includes/blocks.php#L2078
6 tasks
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
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.
What
In this PR, for users without
unfiltered_htmlsave posts that contain block-level custom CSS, that CSS is now stripped (not passed through KSES), and the editor throws up a warning so they know it will be removed.Why
This avoids KSES corrupting
&and>in CSS (e.g. nesting/selectors) and makes the behavior explicit.How
pre_kses(priority 5), stripattrs.style.cssfrom all blocks for users withoutunfiltered_htmlso it is never run through KSES (lib/experimental/kses.php).Test steps
unfiltered_html). As Admin, create a post, add a block (e.g. Paragraph), open Advanced → Additional CSS, add e.g.color: blue; & p { color: red; }, save.&/>in saved content.