Commit 4302a397c4 for wordpress.org
commit 4302a397c44f26601cc927ec29abb71726b0233a
Author: westonruter <westonruter@git.wordpress.org>
Date: Tue Sep 8 21:34:42 2026 +0000
Administration: Wrap more one-liner inline scripts.
Continuing the migration begun in r63481, the raw one-liner `SCRIPT` tags in `wp-admin/admin-footer.php`, `wp-admin/install.php` and `wp-admin/async-upload.php` now print through `wp_print_inline_script_tag()`, so `wp_inline_script_attributes` can attach a per-request nonce to these as well.
The upload error handler is reworked in the process:
1. Its data now crosses into JavaScript as a single `wp_json_encode()` object rather than being interpolated into the script text, which also removes the raw interpolation of the dismiss button's generated `id`.
2. The jQuery object arrives as an argument instead of being read from the global scope four times.
3. `setTimeout()` replaces the lone `_.delay()` call, which was all the snippet wanted from Underscore.
The two blocks that take an argument carry a JSDoc block naming its type, following the convention already used for the jQuery wrapper in `wp-admin/js`. These particular blocks are not reached by `lint:jsdoc`, which reads JavaScript files rather than heredocs embedded in PHP, but IDEs do check them.
Developed in https://github.com/WordPress/wordpress-develop/pull/13393.
Follow-up to r60263, r60520, r60681, r63481.
Props thanhtinpk, westonruter.
See #59446, #66033.
Built from https://develop.svn.wordpress.org/trunk@63545
git-svn-id: http://core.svn.wordpress.org/trunk@62721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/admin-footer.php b/wp-admin/admin-footer.php
index fef0c06bbf..32f24e536e 100644
--- a/wp-admin/admin-footer.php
+++ b/wp-admin/admin-footer.php
@@ -114,6 +114,14 @@ if ( function_exists( 'get_site_option' )
?>
<div class="clear"></div></div><!-- wpwrap -->
-<script>if(typeof wpOnload==='function')wpOnload();</script>
+<?php
+wp_print_inline_script_tag(
+ <<<'JS'
+ if ( typeof wpOnload === 'function' ) {
+ wpOnload();
+ }
+ JS
+);
+?>
</body>
</html>
diff --git a/wp-admin/async-upload.php b/wp-admin/async-upload.php
index 5fbdd370c5..0bd955e5d0 100644
--- a/wp-admin/async-upload.php
+++ b/wp-admin/async-upload.php
@@ -145,7 +145,42 @@ if ( is_wp_error( $id ) ) {
$_FILES['async-upload']['name']
);
- echo '<script>_.delay(function() {wp.a11y.speak(' . wp_json_encode( $speak_message, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ");}, 1500);jQuery( 'button#{$button_unique_id}' ).on( 'click', function() {jQuery(this).parents('div.media-item').slideUp(200, function(){jQuery(this).remove();wp.a11y.speak( wp.i18n.__( 'Error dismissed.' ) );jQuery( '#plupload-browse-button' ).trigger( 'focus' );})});</script>\n";
+ $js_function = <<<'JS'
+ /**
+ * Announces the upload failure and wires up its dismiss button.
+ *
+ * @param {JQueryStatic} $ The jQuery object.
+ * @param {Object} args PHP exports.
+ * @param {string} args.speakMessage Message announced to assistive technology.
+ * @param {string} args.buttonSelector Selector for the notice's dismiss button.
+ * @return {void}
+ */
+ ( $, { speakMessage, buttonSelector } ) => {
+ setTimeout( () => wp.a11y.speak( speakMessage ), 1500 );
+ $( buttonSelector ).on( 'click', function () {
+ $( this )
+ .parents( 'div.media-item' )
+ .slideUp( 200, function () {
+ $( this ).remove();
+ wp.a11y.speak( wp.i18n.__( 'Error dismissed.' ) );
+ $( '#plupload-browse-button' ).trigger( 'focus' );
+ } );
+ } );
+ }
+ JS;
+ wp_print_inline_script_tag(
+ sprintf(
+ '( %s )( jQuery, %s )',
+ $js_function,
+ wp_json_encode(
+ array(
+ 'speakMessage' => $speak_message,
+ 'buttonSelector' => 'button#' . $button_unique_id,
+ ),
+ JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
+ )
+ )
+ );
exit;
}
diff --git a/wp-admin/install.php b/wp-admin/install.php
index b6b7a08f2a..977e231ccc 100644
--- a/wp-admin/install.php
+++ b/wp-admin/install.php
@@ -470,17 +470,30 @@ switch ( $step ) {
}
if ( ! wp_is_mobile() ) {
- ?>
-<script>var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
- <?php
+ wp_print_inline_script_tag(
+ <<<'JS'
+ const t = document.getElementById( 'weblog_title' );
+ if ( t ) {
+ t.focus();
+ }
+ JS
+ );
}
wp_print_scripts( $scripts_to_print );
+
+wp_print_inline_script_tag(
+ <<<'JS'
+ /**
+ * Shows the content intended only for browsers with JS enabled.
+ *
+ * @param {JQueryStatic} $ The jQuery object.
+ */
+ jQuery( function ( $ ) {
+ $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
+ } );
+ JS
+);
?>
-<script>
-jQuery( function( $ ) {
- $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
-} );
-</script>
</body>
</html>
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 965db9dfe8..8f23752f32 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63544';
+$wp_version = '7.2-alpha-63545';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.