-
Notifications
You must be signed in to change notification settings - Fork 3.4k
#65070: Move inline JS from admin_head hooks in options screens into options.js #11572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
28ffeea
e9ced2c
44eb442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * Scripts for the options/settings administration screens. | ||
| * | ||
| * @output wp-admin/js/options.js | ||
| */ | ||
|
|
||
| /* global ajaxurl */ | ||
|
|
||
| jQuery( function( $ ) { | ||
| var $showAvatars = $( '#show_avatars' ), | ||
| $avatarSettings = $( '.avatar-settings' ), | ||
| $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(), | ||
| $siteIconPreview = $( '#site-icon-preview-site-title' ), | ||
| $languageSelect = $( '#WPLANG' ), | ||
| $frontStaticPages = $( '#front-static-pages' ), | ||
| homeURL = ( ( window.optionsL10n && window.optionsL10n.homeURL ) || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' ); | ||
|
|
||
| // options-discussion.php: Toggle avatar settings when 'Show Avatars' is changed. | ||
| $showAvatars.on( 'change', function() { | ||
| $avatarSettings.toggleClass( 'hide-if-js', ! this.checked ); | ||
| } ); | ||
|
|
||
| // options-general.php: Update admin bar site name and site icon preview on title input. | ||
| $( '#blogname' ).on( 'input', function() { | ||
| var title = $.trim( $( this ).val() ) || homeURL; | ||
|
|
||
| // Truncate to 40 characters. | ||
| if ( 40 < title.length ) { | ||
| title = title.substring( 0, 40 ) + '\u2026'; | ||
| } | ||
|
|
||
| $siteName.text( title ); | ||
| $siteIconPreview.text( title ); | ||
| } ); | ||
|
|
||
| // options-general.php: Date and time format pickers. | ||
| $( 'input[name="date_format"]' ).on( 'click', function() { | ||
| if ( 'date_format_custom_radio' !== $( this ).attr( 'id' ) ) { | ||
| $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); | ||
| } | ||
| } ); | ||
|
|
||
| $( 'input[name="date_format_custom"]' ).on( 'click input', function() { | ||
| $( '#date_format_custom_radio' ).prop( 'checked', true ); | ||
| } ); | ||
|
|
||
| $( 'input[name="time_format"]' ).on( 'click', function() { | ||
| if ( 'time_format_custom_radio' !== $( this ).attr( 'id' ) ) { | ||
| $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); | ||
| } | ||
| } ); | ||
|
|
||
| $( 'input[name="time_format_custom"]' ).on( 'click input', function() { | ||
| $( '#time_format_custom_radio' ).prop( 'checked', true ); | ||
| } ); | ||
|
|
||
| $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() { | ||
| var format = $( this ), | ||
| fieldset = format.closest( 'fieldset' ), | ||
| example = fieldset.find( '.example' ), | ||
| spinner = fieldset.find( '.spinner' ); | ||
|
|
||
| // Debounce the event callback while users are typing. | ||
| clearTimeout( $.data( this, 'timer' ) ); | ||
| $( this ).data( 'timer', setTimeout( function() { | ||
| // If custom date is not empty. | ||
| if ( format.val() ) { | ||
| spinner.addClass( 'is-active' ); | ||
|
|
||
| $.post( ajaxurl, { | ||
| action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format', | ||
| date: format.val() | ||
| }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } ); | ||
| } | ||
| }, 500 ) ); | ||
| } ); | ||
|
|
||
| // options-general.php: Language install spinner. | ||
| $( 'form' ).on( 'submit', function() { | ||
| /* | ||
| * Don't show a spinner for English and installed languages, | ||
| * as there is nothing to download. | ||
| */ | ||
| if ( $languageSelect.length && ! $languageSelect.find( 'option:selected' ).data( 'installed' ) ) { | ||
| $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' ); | ||
| } | ||
| } ); | ||
|
|
||
| // options-reading.php: Enable/disable page selects based on 'Your homepage displays' radio. | ||
| if ( $frontStaticPages.length ) { | ||
| var $staticPage = $frontStaticPages.find( 'input:radio[value="page"]' ), | ||
| $selects = $frontStaticPages.find( 'select' ), | ||
| checkDisabled = function() { | ||
| $selects.prop( 'disabled', ! $staticPage.prop( 'checked' ) ); | ||
| }; | ||
| checkDisabled(); | ||
| $frontStaticPages.find( 'input:radio' ).on( 'change', checkDisabled ); | ||
| } | ||
| } ); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1589,3 +1589,40 @@ function image_attachment_fields_to_save( $post, $attachment ) { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return $post; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Output JavaScript to toggle display of additional settings if avatars are disabled. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @since 4.2.0 | ||||||||||||||||||||||||
| * @deprecated 7.1.0 Inline JavaScript has been moved to wp-admin/js/options.js, | ||||||||||||||||||||||||
| * enqueued via {@see wp_enqueue_script()}. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| function options_discussion_add_js() { | ||||||||||||||||||||||||
| _deprecated_function( __FUNCTION__, '7.1.0' ); | ||||||||||||||||||||||||
| wp_enqueue_script( 'options' ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Display JavaScript on the General Settings screen. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @since 3.5.0 | ||||||||||||||||||||||||
| * @deprecated 7.1.0 Inline JavaScript has been moved to wp-admin/js/options.js, | ||||||||||||||||||||||||
| * enqueued via {@see wp_enqueue_script()}. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| function options_general_add_js() { | ||||||||||||||||||||||||
| _deprecated_function( __FUNCTION__, '7.1.0' ); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| _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
AI
Apr 14, 2026
There was a problem hiding this comment.
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).
| _deprecated_function( __FUNCTION__, '7.1.0' ); | |
| _deprecated_function( __FUNCTION__, '7.1.0' ); | |
| wp_enqueue_script( 'options' ); |
There was a problem hiding this comment.
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 enqueuingoptions(and localizingoptionsL10nwhere 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.
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')(andwp_localize_script()foroptions_general_add_js) so externalcallers continue to work while still triggering the deprecation notice.