Repository navigation
Administration: Use script helpers and nowdocs in upgrade, setup-config, and customize - #16324
shail-mehta wants to merge 2 commits into
Conversation
…ig, and customize
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the inline-script helper updates supporting WordPress CSP compatibility.
No open issues 🎉
What changed in this PR
Updates the remaining raw inline scripts in three administration files to use wp_print_inline_script_tag(), supporting WordPress’s CSP compatibility work in Trac #66856.
Changes:
- Uses nowdocs for the setup focus/select script, network upgrade redirect, and scheduled Customizer save request.
- Replaces the network redirect’s string-based timer with a function callback.
- Prints the Customizer’s
ajaxurlandpagenowglobals through the script helper.
| File | Description |
|---|---|
src/wp-admin/setup-config.php |
Wraps the configuration textarea focus/select script in the helper using a nowdoc. |
src/wp-admin/network/upgrade.php |
Converts the next-batch redirect to a helper-generated script with a function-based timer. |
src/wp-admin/customize.php |
Converts the scheduled save request and global variable script to helper-generated output. |
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. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
mukeshpanchal27
left a comment
There was a problem hiding this comment.
LGTM. wp_print_inline_script_tag() is available here, since setup-config.php loads wp-settings.php without SHORTINIT. One optional cleanup inline.
| (function(){ | ||
| if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) { | ||
| var el = document.getElementById('wp-config'); | ||
| el.focus(); | ||
| el.select(); | ||
| } | ||
| })(); | ||
| JS | ||
| ); | ||
| ?> | ||
| <?php |
There was a problem hiding this comment.
Optional: the new ?> is followed right away by <?php, so the pair can go, and the JS could use core spacing:
| (function(){ | |
| if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) { | |
| var el = document.getElementById('wp-config'); | |
| el.focus(); | |
| el.select(); | |
| } | |
| })(); | |
| JS | |
| ); | |
| ?> | |
| <?php | |
| ( function () { | |
| if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) { | |
| var el = document.getElementById( 'wp-config' ); | |
| el.focus(); | |
| el.select(); | |
| } | |
| } )(); | |
| JS | |
| ); |
What
Trac ticket: #66856
Replaces the remaining raw
<script>blocks in three admin files withwp_print_inline_script_tag()and<<<'JS'nowdocs:src/wp-admin/network/upgrade.php: network upgrade next-page redirect script.src/wp-admin/setup-config.php:#wp-configtextarea focus/select script.src/wp-admin/customize.php: scheduled changesetcustomize_saveAJAX script and theajaxurl/pagenowglobal variable script.Why
#66856 lists
network/upgrade.php,setup-config.php, andcustomize.php(both scripts) as remaining raw<script>tags in Administration. Usingwp_print_inline_script_tag()removes raw<script>tags for CSP compatibility, and<<<'JS'nowdocs preserve IDE syntax highlighting.How
network/upgrade.php: convert the redirect script to a<<<'JS'nowdoc arrow function receiving the next URL viawp_json_encode( ..., JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), and pass a function (instead of a string) tosetTimeout().setup-config.php: print the existing IIFE throughwp_print_inline_script_tag( <<<'JS' … JS ).customize.php: convert thewp.ajax.post( 'customize_save', ... )script to a<<<'JS'nowdoc function withwp_json_encode(), and print theajaxurl/pagenowglobalvardeclaration viawp_print_inline_script_tag().Testing Instructions
php -lonsrc/wp-admin/network/upgrade.php,src/wp-admin/setup-config.php, andsrc/wp-admin/customize.phpand confirm there are no syntax errors.wp-admin/customize.php) and confirmajaxurlandpagenoware defined globally and the Customizer loads with no console errors.wp-admin/network/upgrade.php) with >5 sites and confirm it advances to the next batch automatically.wp-config.phpis not writable (wp-admin/setup-config.php), confirm the#wp-configtextarea is focused and selected on desktop.Use of AI Tools