Skip to content

#65070: Move inline JS from admin_head hooks in options screens into options.js#11572

Open
aminuldeveloper wants to merge 2 commits intoWordPress:trunkfrom
aminuldeveloper:ticket-65070-move-options-inline-js
Open

#65070: Move inline JS from admin_head hooks in options screens into options.js#11572
aminuldeveloper wants to merge 2 commits intoWordPress:trunkfrom
aminuldeveloper:ticket-65070-move-options-inline-js

Conversation

@aminuldeveloper
Copy link
Copy Markdown

This pull request is for code review only.

Trac ticket: https://core.trac.wordpress.org/ticket/65070

Summary:

  • Moves inline JS from admin_head hooks for options screens into options.js
  • Centralizes the behavior in the enqueued JS file
  • Deprecates the old inline JS hook functions

Copilot AI review requested due to automatic review settings April 14, 2026 13:54
@github-actions
Copy link
Copy Markdown

Hi @aminuldeveloper! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props wpdevsxyz, mukesh27.

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

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes JavaScript behaviors used on core Settings/Options admin screens by moving legacy inline JS (previously printed via admin_head/admin_print_footer_scripts callbacks) into a single enqueued script, wp-admin/js/options.js, and deprecates the legacy helper functions.

Changes:

  • Registers a new options admin script handle and adds a new src/js/_enqueues/admin/options.js bundle output.
  • Updates Reading/Discussion/General settings screens to enqueue the new options script (and localize homeURL on General).
  • Removes the legacy inline-JS output functions from includes/options.php and adds deprecated stubs in includes/deprecated.php.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/wp-includes/script-loader.php Registers new options script handle for admin usage.
src/wp-admin/options-reading.php Enqueues options instead of hooking inline JS into admin_head.
src/wp-admin/options-general.php Enqueues options and localizes optionsL10n.homeURL for the new script.
src/wp-admin/options-discussion.php Enqueues options instead of hooking inline JS into footer scripts.
src/wp-admin/includes/options.php Removes the three inline-JS helper functions (legacy output).
src/wp-admin/includes/deprecated.php Introduces deprecated replacements for removed helper functions.
src/js/_enqueues/admin/options.js New centralized JS for options/settings screens.
Gruntfile.js Adds build output mapping for wp-admin/js/options.js.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* enqueued via {@see wp_enqueue_script()}.
*/
function options_general_add_js() {
_deprecated_function( __FUNCTION__, '7.1.0' );
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

options_general_add_js() is documented as displaying JS for the General Settings screen, but it now does nothing besides _deprecated_function(). For backwards compatibility, consider having this function enqueue options and localize optionsL10n.homeURL (matching the new options.js expectation) so callers still get the behavior they previously relied on.

Suggested change
_deprecated_function( __FUNCTION__, '7.1.0' );
_deprecated_function( __FUNCTION__, '7.1.0' );
wp_enqueue_script( 'options' );
wp_localize_script(
'options',
'optionsL10n',
array(
'homeURL' => home_url(),
)
);

Copilot uses AI. Check for mistakes.
* enqueued via {@see wp_enqueue_script()}.
*/
function options_reading_add_js() {
_deprecated_function( __FUNCTION__, '7.1.0' );
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

options_reading_add_js() previously printed the JS that enables/disables the static-front-page selects. As a deprecated public function it now no-ops, which can break any callers that invoke it outside of options-reading.php. Consider preserving behavior by enqueuing the new options script from here (similar to how other deprecated helpers in this file still run their legacy output).

Suggested change
_deprecated_function( __FUNCTION__, '7.1.0' );
_deprecated_function( __FUNCTION__, '7.1.0' );
wp_enqueue_script( 'options' );

Copilot uses AI. Check for mistakes.
Comment on lines +1600 to +1602
function options_discussion_add_js() {
_deprecated_function( __FUNCTION__, '7.1.0' );
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

These newly deprecated options_*_add_js() functions are now no-ops (they only call _deprecated_function()), which is a backwards-incompatible behavior change for any code that still calls them. In this file, other deprecated JS helpers (e.g. options_permalink_add_js()) continue to output their original behavior for back-compat. Consider keeping these functions functional by enqueuing options (and localizing optionsL10n where needed) instead of doing nothing, or update the docblock to clearly state they no longer output anything if that is intentional.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed backward compatibility issue raised in review — deprecated
functions now call wp_enqueue_script('options') (and
wp_localize_script() for options_general_add_js) so external
callers continue to work while still triggering the deprecation notice.

@aminuldeveloper
Copy link
Copy Markdown
Author

Fixed backward compatibility issue raised in review — deprecated
functions now call wp_enqueue_script('options') (and
wp_localize_script() for options_general_add_js) so external
callers continue to work while still triggering the deprecation notice.

@mukeshpanchal27
Copy link
Copy Markdown
Member

Thanks for the PR!

Make sure to add details which AI agent you use for the PR?

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