#65070: Move inline JS from admin_head hooks in options screens into options.js#11572
#65070: Move inline JS from admin_head hooks in options screens into options.js#11572aminuldeveloper wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
Hi @aminuldeveloper! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to 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 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 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. |
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. |
There was a problem hiding this comment.
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
optionsadmin script handle and adds a newsrc/js/_enqueues/admin/options.jsbundle output. - Updates Reading/Discussion/General settings screens to enqueue the new
optionsscript (and localizehomeURLon General). - Removes the legacy inline-JS output functions from
includes/options.phpand adds deprecated stubs inincludes/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' ); |
There was a problem hiding this comment.
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.
| _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(), | |
| ) | |
| ); |
| * enqueued via {@see wp_enqueue_script()}. | ||
| */ | ||
| function options_reading_add_js() { | ||
| _deprecated_function( __FUNCTION__, '7.1.0' ); |
There was a problem hiding this comment.
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).
| _deprecated_function( __FUNCTION__, '7.1.0' ); | |
| _deprecated_function( __FUNCTION__, '7.1.0' ); | |
| wp_enqueue_script( 'options' ); |
| function options_discussion_add_js() { | ||
| _deprecated_function( __FUNCTION__, '7.1.0' ); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Fixed backward compatibility issue raised in review — deprecated |
|
Thanks for the PR! Make sure to add details which AI agent you use for the PR? |
This pull request is for code review only.
Trac ticket: https://core.trac.wordpress.org/ticket/65070
Summary: