Repository navigation
Customize: Use nowdocs for WP_Customize_Manager inline scripts - #16325
Draft
shail-mehta wants to merge 2 commits into
Draft
shail-mehta wants to merge 2 commits into
shail-mehta wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the Customizer inline-script generation refactor.
No open issues 🎉
What changed in this PR
Refactors inline-script generation in WP_Customize_Manager to use nowdocs and direct string construction, addressing the four methods identified in Trac #66856.
Changes:
- Replaces buffered
<script>blocks and surrounding-tag removal with directly constructed JavaScript. - Retains one-by-one setting and control serialization to limit peak memory usage.
- Preserves inline-script helpers and
sourceURLannotations.
| File | Description |
|---|---|
src/wp-includes/class-wp-customize-manager.php |
Updates script construction for error messaging, frameless-preview redirects, and preview/pane settings. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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
Trac ticket: #66856
Converts the four
WP_Customize_Managerinline scripts that used anob_start()template buffer withwp_remove_surrounding_empty_script_tags()towp_print_inline_script_tag()/wp_get_inline_script_tag()with<<<'JS'nowdocs:WP_Customize_Manager::wp_die()WP_Customize_Manager::remove_frameless_preview_messenger_channel()WP_Customize_Manager::customize_preview_settings()WP_Customize_Manager::customize_pane_settings()Why
#66856 lists these four methods as remaining
ob_start()+wp_remove_surrounding_empty_script_tags()blocks that should use nowdocs and direct string construction.How
wp_die(): the messenger error script is a<<<'JS'nowdoc arrow function receiving$settingsthroughwp_json_encode( ..., JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ). Theob_start()buffer forwp_enqueue_scripts()andwp_print_scripts()output is kept.remove_frameless_preview_messenger_channel(): the static script is passed directly towp_print_inline_script_tag()as a<<<'JS'nowdoc.customize_preview_settings(): static setup and closing lines are<<<'JS'nowdocs. Only the per-settingv[...]lines are built withsprintf().customize_pane_settings(): static initialization and the(function ( s ){,(function ( c ){, and closing lines are<<<'JS'nowdocs. Per-setting and per-control lines are still built one at a time to avoid peak memory spikes.\n//# sourceURL=is preserved on all four inline scripts.Testing Instructions
php -l src/wp-includes/class-wp-customize-manager.phpand confirm there are no syntax errors.wp-admin/customize.php), confirm the Customizer pane and preview iframe load normally, and verify changes preview and publish with no console errors.?customize_messenger_channel=preview-0outside an iframe, and confirm the parameter is removed vialocation.replace()._wpCustomizeSettingsandsourceURLinline scripts are printed correctly.Use of AI Tools