Skip to content

Escape TinyMCE inline CSS in WP editor init - #3597

Merged
JanJakes merged 1 commit into
trunkfrom
wp-museum-tinymce
May 5, 2026
Merged

JanJakes merged 1 commit into
trunkfrom
wp-museum-tinymce

Conversation

@JanJakes

@JanJakes JanJakes commented May 4, 2026 •

Copy link
Copy Markdown
Member

What changed

Escapes the CSS that Playground inlines into TinyMCE content_style through the shared inline-tinymce-content-css.php mu-plugin.

The escape path uses PHP's json_encode() to produce a JavaScript string body, strips the outer quotes because _WP_Editors::_parse_init() adds them itself, and keeps a small PHP 5.2-compatible fallback for unexpected encoder failures.

The legacy WordPress boot suite now also checks the real browser new-post phase for classic TinyMCE bootstrap breakage and fails on tinyMCEPreInit / content_style / truetype JavaScript errors without waiting for TinyMCE itself to initialize.

Why

_WP_Editors::_parse_init() serializes TinyMCE settings by concatenating JavaScript strings without escaping. Playground's inlined editor CSS can contain quotes, backslashes, newlines, and closing script sequences, for example Dashicons CSS with format("truetype"). Those characters could break the inline tinyMCEPreInit script and leave the classic visual editor uninitialized.

Validation

  • npm exec nx -- run playground-wordpress:lint
  • node --check packages/playground/wordpress/tests/test-legacy-wp-version-boot.mjs
  • WP_ONLY=3.2,3.1,3.3,4.0,5.5,5.0,2.6,2.5,2.3,2.2,2.1,2.0,1.0 npm exec nx -- run playground-wordpress:test-legacy-wp-version-boot

Notes

The sampled legacy browser matrix and lint pass.

@JanJakes JanJakes changed the title Escape TinyMCE inline CSS for legacy WP Escape TinyMCE inline CSS in WP editor init May 4, 2026
@JanJakes
JanJakes force-pushed the wp-museum-tinymce branch 6 times, most recently from 0d5fea3 to 6550941 Compare May 4, 2026 15:01
Inline TinyMCE content CSS must be escaped before WordPress serializes it through _WP_Editors::_parse_init(), which wraps settings in JavaScript strings without escaping values. Use json_encode() for the normal path, keep a PHP 5.2-compatible fallback for non-UTF-8 CSS bytes, and cover the browser TinyMCE initialization path in the legacy boot suite.
@JanJakes
JanJakes force-pushed the wp-museum-tinymce branch from 6550941 to f471477 Compare May 4, 2026 15:22
@JanJakes
JanJakes marked this pull request as ready for review May 4, 2026 16:33
@JanJakes
JanJakes requested review from a team, Copilot and zaerl May 4, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@JanJakes
JanJakes merged commit eb81645 into trunk May 5, 2026
105 checks passed
@JanJakes
JanJakes deleted the wp-museum-tinymce branch May 5, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants