Skip to content

Administration: Use script helpers for misc.php inline JS - #16305

Open
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:add/66856-misc-inline-js
Open

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:add/66856-misc-inline-js

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #66856

Migrates the three items in src/wp-admin/includes/misc.php off raw script tags:

  • wp_color_scheme_settings()
  • wp_admin_canonical_url()
  • wp_page_reload_on_back_button_js()

Why

#66856 lists these under remaining raw script tags. wp_print_inline_script_tag() is required when removing that markup.

How

  • wp_color_scheme_settings(): echoed var _wpColorScheme = … now goes through wp_print_inline_script_tag(). Still wp_json_encode(). No nowdoc; the ticket says a nowdoc adds little for this kind of data export.
  • wp_admin_canonical_url(): keep the canonical <link>; print the history.replaceState JS as a <<<'JS' nowdoc. Unchanged except indentation.
  • wp_page_reload_on_back_button_js(): same nowdoc pattern. Unchanged except indentation.

Testing Instructions

  1. php -l src/wp-admin/includes/misc.php
  2. Any admin screen: _wpColorScheme is still set; menu icons still follow the color scheme.
  3. After saving settings (URL has settings-updated=true), the address bar is cleaned and the canonical link is still present.
  4. Posts → Add New: back-button reload behavior is unchanged. No console errors.

Use of AI Tools

  • Cursor

@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.

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 block the migration of the three inline scripts in misc.php to WordPress’s script-tag helper.

No open issues 🎉

What changed in this PR

Migrates the three remaining raw inline script blocks in misc.php to WordPress’s wp_print_inline_script_tag() helper, supporting the work tracked in Trac #66856 without changing their JavaScript logic.

Changes:

  • Routes _wpColorScheme output through the helper while preserving JSON encoding.
  • Converts canonical URL and back-button reload scripts to nowdoc strings.
  • Preserves the canonical link markup.
File Description
src/​wp-admin/​includes/​misc.php Uses the inline script helper for color-scheme settings, canonical URL cleanup, and back-button reload behavior.

Review effort: Balanced

@shail-mehta shail-mehta self-assigned this Nov 30, 2026
@shail-mehta
shail-mehta marked this pull request as ready for review November 30, 2026 08:39
@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. The replaceState script still prints right after the canonical link, and the color scheme data keeps the JSON flags.

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