Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#65070 new enhancement

Move inline JS from admin_head hooks in options screens into options.js

Reported by: anukasha's profile anukasha Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: javascript, administration Cc:

Description

src/wp-admin/includes/options.php contains three functions that print inline <script> blocks via admin_head hooks:

  1. options_discussion_add_js() — hooked in options-discussion.php
  2. options_general_add_js() — hooked in options-general.php
  3. options_reading_add_js() — hooked in options-reading.php

These should be migrated into src/js/_enqueues/admin/options.js, which was introduced in https://github.com/WordPress/wordpress-develop/pull/10927 as the central enqueued JS file for options screens.

Attachments (1)

65070.patch (12.8 KB) - added by wpdevsxyz 5 weeks ago.

Download all attachments as: .zip

Change History (6)

@wpdevsxyz
5 weeks ago

#1 @wpdevsxyz
5 weeks ago

  • Focuses javascript administration added
  • Keywords has-patch added; needs-patch removed

This patch moves the three inline <script> blocks from admin_head hooks into
a new enqueued file: src/js/_enqueues/admin/options.js.

Changes:

  • Created src/js/_enqueues/admin/options.js with all three JS blocks combined
  • Registered 'options' script handle in script-loader.php (jquery dependency, footer)
  • options-general.php: wp_enqueue_script('options') + wp_localize_script() to pass homeURL
  • options-discussion.php: wp_enqueue_script('options')
  • options-reading.php: wp_enqueue_script('options')
  • Deprecated options_discussion_add_js(), options_general_add_js(), options_reading_add_js() in 7.1.0

This ticket was mentioned in PR #11572 on WordPress/wordpress-develop by @wpdevsxyz.


5 weeks ago
#2

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

@wpdevsxyz commented on PR #11572:


5 weeks ago
#3

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.

@mukesh27 commented on PR #11572:


5 weeks ago
#4

Thanks for the PR!

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

@wpdevsxyz commented on PR #11572:


5 weeks ago
#5

Thanks for the feedback!

The code changes were made manually. I used Claude as an AI assistant to help understand the codebase and plan the approach, but all the actual code was written and reviewed by me.

Note: See TracTickets for help on using tickets.