Skip to content

fix(editor): exclude Customizer Additional CSS from iframed editor#4750

Open
miguelpeixe wants to merge 2 commits into
releasefrom
fix/customizer-css-editor-iframe
Open

fix(editor): exclude Customizer Additional CSS from iframed editor#4750
miguelpeixe wants to merge 2 commits into
releasefrom
fix/customizer-css-editor-iframe

Conversation

@miguelpeixe
Copy link
Copy Markdown
Member

@miguelpeixe miguelpeixe commented May 21, 2026

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_all to drop the specific entry WP core injects for Customizer Additional CSS — identified by __unstableType === 'user' AND isGlobalStyles === false. The front-end is unaffected: the CSS is still printed by wp_custom_css_cb() on wp_head.

A new newspack_strip_customizer_css_in_editor filter is exposed as an escape hatch for sites that intentionally want Customizer CSS in the editor.

Scope notes:

  • Only the Customizer entry is removed. The block-theme Global Styles → Additional CSS entry (isGlobalStyles === true) is left untouched.
  • Per-block Custom CSS introduced in WP 7.0 is not affected — that's scoped to individual blocks.

How to test the changes in this Pull Request:

  1. On a site running WP 7.0, add a rule like body { background: red; } in Appearance → Customize → Additional CSS.
  2. Open a post or page that contains only Block API v3+ blocks (the default for current core blocks).
  3. Before this fix on release: the editor canvas turns red. After this fix: the editor canvas stays normal; the front-end is still red.
  4. Confirm the escape hatch: add add_filter( 'newspack_strip_customizer_css_in_editor', '__return_false' ); in mu-plugins → editor canvas turns red again.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally? (PHPCS clean)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_all to remove the Customizer “Additional CSS” style entry from $settings['styles'].
  • Adds an escape-hatch filter newspack_strip_customizer_css_in_editor to disable the stripping when desired.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/class-patches.php Outdated
@miguelpeixe miguelpeixe marked this pull request as ready for review May 21, 2026 19:59
@miguelpeixe miguelpeixe requested a review from a team as a code owner May 21, 2026 19:59
@miguelpeixe miguelpeixe self-assigned this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants