Skip to content

Administration: Use script helpers and nowdocs in upgrade, setup-config, and customize - #16324

Open
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66856-admin-remaining-raw-scripts
Open

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66856-admin-remaining-raw-scripts

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #66856

Replaces the remaining raw <script> blocks in three admin files with wp_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-config textarea focus/select script.
  • src/wp-admin/customize.php: scheduled changeset customize_save AJAX script and the ajaxurl / pagenow global variable script.

Why

#66856 lists network/upgrade.php, setup-config.php, and customize.php (both scripts) as remaining raw <script> tags in Administration. Using wp_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 via wp_json_encode( ..., JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), and pass a function (instead of a string) to setTimeout().
  • setup-config.php: print the existing IIFE through wp_print_inline_script_tag( <<<'JS' … JS ).
  • customize.php: convert the wp.ajax.post( 'customize_save', ... ) script to a <<<'JS' nowdoc function with wp_json_encode(), and print the ajaxurl / pagenow global var declaration via wp_print_inline_script_tag().

Testing Instructions

  1. Run php -l on src/wp-admin/network/upgrade.php, src/wp-admin/setup-config.php, and src/wp-admin/customize.php and confirm there are no syntax errors.
  2. Open Appearance → Customize (wp-admin/customize.php) and confirm ajaxurl and pagenow are defined globally and the Customizer loads with no console errors.
  3. On Multisite, run Network Admin → Upgrade Network (wp-admin/network/upgrade.php) with >5 sites and confirm it advances to the next batch automatically.
  4. On a fresh setup where wp-config.php is not writable (wp-admin/setup-config.php), confirm the #wp-config textarea is focused and selected on desktop.

Use of AI Tools

  • Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 ajaxurl and pagenow globals 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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@shail-mehta
shail-mehta marked this pull request as ready for review November 30, 2026 12:54
@shail-mehta shail-mehta self-assigned this Nov 30, 2026
@github-actions

Copy link
Copy Markdown

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:

Props shailu25.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. wp_print_inline_script_tag() is available here, since setup-config.php loads wp-settings.php without SHORTINIT. One optional cleanup inline.

Comment on lines +466 to 476
(function(){
if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) {
var el = document.getElementById('wp-config');
el.focus();
el.select();
}
})();
JS
);
?>
<?php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: the new ?> is followed right away by <?php, so the pair can go, and the JS could use core spacing:

Suggested change
(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
);

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.

3 participants