Skip to content

Upgrade: Use a nowdoc for the About WordPress redirect script - #16310

Open
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66856-update-core-inline-js
Open

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66856-update-core-inline-js

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac Ticket: #66856

Print the redirect script in _redirect_to_about_wordpress() through wp_print_inline_script_tag() and a NOWDOC wrapper.

Why

This is the remaining raw script-tag block listed for update-core.php.

How

The script is static, so it is a plain nowdoc with no wp_json_encode() arguments.

Testing Instructions

  • The function returns early on current WordPress, so it cannot be reached through a normal upgrade.

Use of AI tools:

  • Assisted by 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.

🟡 Changes recommended

The change can block upgrades with an undefined-function fatal error on legacy WordPress versions and a parse error on PHP 7.0–7.2 before compatibility checks run.

2 open issues
What changed in this PR

This PR replaces the raw redirect script in the legacy About WordPress upgrade callback with WordPress’s inline-script helper.

Changes:

  • Passes the static JavaScript through wp_print_inline_script_tag() using a nowdoc.
  • Preserves the redirect destination, about.php?updated.
File Description
src/​wp-admin/​includes/​update-core.php Changes script output in _redirect_to_about_wordpress() to use the helper and nowdoc.

Review effort: Balanced

Comment thread src/wp-admin/includes/update-core.php Resolved
Comment thread src/wp-admin/includes/update-core.php Resolved
@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.

Use an unindented nowdoc terminator so the file parses on PHP 7.0-7.2, and only call wp_print_inline_script_tag() when it exists, falling back to the raw script tag during upgrades from older WordPress versions.

Props copilot-pull-request-reviewer.

See #66856.

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.

🟡 Changes recommended

The added nowdoc syntax causes a parse error on PHP 5.2 before the upgrader can run its compatibility check, preventing the normal compatibility error from being returned.

1 open issue
2 resolved since last review

Review effort: Balanced

<script>

// The closing JS; marker must not be indented (PHP < 7.3 compatibility).
$redirect_script = <<<'JS'
@shail-mehta
shail-mehta marked this pull request as ready for review November 30, 2026 12:30
@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.

Comment on lines +2064 to +2074
// The closing JS; marker must not be indented (PHP < 7.3 compatibility).
$redirect_script = <<<'JS'
window.location = 'about.php?updated';
</script>
<?php
JS;

// wp_print_inline_script_tag() is not available when upgrading from WordPress versions older than 5.7.
if ( function_exists( 'wp_print_inline_script_tag' ) ) {
wp_print_inline_script_tag( $redirect_script );
} else {
echo "<script>\n{$redirect_script}\n</script>\n";
}

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.

This branch can never run. _redirect_to_about_wordpress() returns early unless the global $wp_version, the version being upgraded from, is older than 3.4-RC1 (line 2026), and wp_print_inline_script_tag() was added in 5.7. So the fallback always prints the same raw <script> as trunk. I'd keep trunk's tag with a comment explaining why it stays raw:

Suggested change
// The closing JS; marker must not be indented (PHP < 7.3 compatibility).
$redirect_script = <<<'JS'
window.location = 'about.php?updated';
</script>
<?php
JS;
// wp_print_inline_script_tag() is not available when upgrading from WordPress versions older than 5.7.
if ( function_exists( 'wp_print_inline_script_tag' ) ) {
wp_print_inline_script_tag( $redirect_script );
} else {
echo "<script>\n{$redirect_script}\n</script>\n";
}
// This only runs when upgrading from WordPress < 3.4, which predates wp_print_inline_script_tag() (5.7).
?>
<script>
window.location = 'about.php?updated';
</script>
<?php

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