fix(editor): exclude Customizer Additional CSS from iframed editor#4750
Open
miguelpeixe wants to merge 2 commits into
Open
fix(editor): exclude Customizer Additional CSS from iframed editor#4750miguelpeixe wants to merge 2 commits into
miguelpeixe wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents Customizer Additional CSS from being applied inside the WP 7.0+ iframed block editor canvas by removing the specific core-injected “user” CSS entry from the editor settings styles array, while leaving front-end output intact. It also introduces a filter to allow sites to opt out of this behavior.
Changes:
- Hooks
block_editor_settings_allto remove the Customizer “Additional CSS” style entry from$settings['styles']. - Adds an escape-hatch filter
newspack_strip_customizer_css_in_editorto disable the stripping when desired.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
All Submissions:
Changes proposed in this Pull Request:
WordPress 7.0 iframes the post editor whenever every block in the post uses Block API v3+. The iframed editor pulls in the front-end style pipeline, which includes the Customizer's Additional CSS. Any front-end rule that targets `body { ... }` (or other broad selectors) therefore lands on the editor canvas itself, distorting the editing UX on sites that have customized the body element.
This PR filters
block_editor_settings_allto drop the specific entry WP core injects for Customizer Additional CSS — identified by__unstableType === 'user'ANDisGlobalStyles === false. The front-end is unaffected: the CSS is still printed bywp_custom_css_cb()onwp_head.A new
newspack_strip_customizer_css_in_editorfilter is exposed as an escape hatch for sites that intentionally want Customizer CSS in the editor.Scope notes:
isGlobalStyles === true) is left untouched.How to test the changes in this Pull Request:
body { background: red; }in Appearance → Customize → Additional CSS.release: the editor canvas turns red. After this fix: the editor canvas stays normal; the front-end is still red.add_filter( 'newspack_strip_customizer_css_in_editor', '__return_false' );in mu-plugins → editor canvas turns red again.Other information: