From 868d7466875b7c9381c4069c6df4a57ab77b5fb6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 18 Sep 2025 17:38:47 -0700 Subject: [PATCH 1/4] Add sourceURL comments for directly constructed inline scripts in wp-includes --- src/wp-includes/blocks/categories.php | 1 + src/wp-includes/class-wp-customize-manager.php | 8 ++++---- src/wp-includes/class-wp-customize-nav-menus.php | 2 +- src/wp-includes/class-wp-customize-widgets.php | 2 +- src/wp-includes/comment-template.php | 2 +- .../customize/class-wp-customize-selective-refresh.php | 2 +- src/wp-includes/embed.php | 6 ++++-- src/wp-includes/formatting.php | 4 +++- src/wp-includes/functions.php | 1 + src/wp-includes/theme.php | 2 +- src/wp-includes/widgets/class-wp-widget-archives.php | 2 +- src/wp-includes/widgets/class-wp-widget-categories.php | 2 +- 12 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/wp-includes/blocks/categories.php b/src/wp-includes/blocks/categories.php index 60a29713b4660..c392c2b56b148 100644 --- a/src/wp-includes/blocks/categories.php +++ b/src/wp-includes/blocks/categories.php @@ -110,6 +110,7 @@ function onCatChange() { } dropdown.onchange = onCatChange; })(); + //# sourceURL= ', '' ), '', ob_get_clean() ) ); diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 0a8c743019d80..edfd3b4c7072c 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -479,7 +479,7 @@ protected function wp_die( $ajax_message, $message = null ) { } )( wp.customize, ); $this->preview_nav_menu_instance_args, ); - wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) ); + wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) ); } /** diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index f9a428dd537fc..6961bbb82d0e7 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -1334,7 +1334,7 @@ public function export_preview_data() { unset( $registered_widget['callback'] ); // May not be JSON-serializable. } wp_print_inline_script_tag( - sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) + sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) ); } diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index b5d37f5aae081..0b5db1d37d507 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -1374,7 +1374,7 @@ function wp_comment_form_unfiltered_html_nonce() { if ( current_user_can( 'unfiltered_html' ) ) { wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); - wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();" ); + wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();\n//# sourceURL=" . __FUNCTION__ ); } } diff --git a/src/wp-includes/customize/class-wp-customize-selective-refresh.php b/src/wp-includes/customize/class-wp-customize-selective-refresh.php index f695338657828..011be0b82c904 100644 --- a/src/wp-includes/customize/class-wp-customize-selective-refresh.php +++ b/src/wp-includes/customize/class-wp-customize-selective-refresh.php @@ -193,7 +193,7 @@ public function export_preview_data() { ); // Export data to JS. - wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) ); + wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) ); } /** diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 6ef190d0ea600..414fd7219a7e4 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -518,8 +518,9 @@ function get_post_embed_html( $width, $height, $post = null ) { * will fail to match and everything will be matched by `.*` and not included in the group. This regex issue goes * back to WordPress 4.4, so in order to not break older installs this script must come at the end. */ + $js_path = '/js/wp-embed' . wp_scripts_get_suffix() . '.js'; $output .= wp_get_inline_script_tag( - file_get_contents( ABSPATH . WPINC . '/js/wp-embed' . wp_scripts_get_suffix() . '.js' ) + file_get_contents( ABSPATH . WPINC . $js_path ) . "\n//# sourceURL=" . includes_url( $js_path ) ); /** @@ -1090,8 +1091,9 @@ function wp_enqueue_embed_styles() { * @since 4.4.0 */ function print_embed_scripts() { + $js_path = '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js'; wp_print_inline_script_tag( - file_get_contents( ABSPATH . WPINC . '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js' ) + file_get_contents( ABSPATH . WPINC . $js_path ) . "\n//# sourceURL=" . includes_url( $js_path ) ); } diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index e46e5d82ad590..9442b06dc1830 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -6018,9 +6018,11 @@ function _print_emoji_detection_script() { ); } + $emoji_loader_script_path = '/js/wp-emoji-loader' . wp_scripts_get_suffix() . '.js'; wp_print_inline_script_tag( sprintf( 'window._wpemojiSettings = %s;', wp_json_encode( $settings ) ) . "\n" . - file_get_contents( ABSPATH . WPINC . '/js/wp-emoji-loader' . wp_scripts_get_suffix() . '.js' ) + file_get_contents( ABSPATH . WPINC . $emoji_loader_script_path ) . "\n" . + '//# sourceURL=' . includes_url( $emoji_loader_script_path ) ); } diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index e30ac7ff2570e..fc47c20f56a20 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7797,6 +7797,7 @@ function wp_post_preview_js() { window.addEventListener( 'pagehide', function() { window.name = ''; } ); } }()); + //# sourceURL= Date: Mon, 29 Sep 2025 20:37:05 -0700 Subject: [PATCH 2/4] Add rawurlencode() to __FUNCTION__ and __METHOD__ for sourceURL comments --- src/wp-includes/blocks/categories.php | 2 +- src/wp-includes/class-wp-customize-manager.php | 8 ++++---- src/wp-includes/class-wp-customize-nav-menus.php | 2 +- src/wp-includes/class-wp-customize-widgets.php | 2 +- .../customize/class-wp-customize-selective-refresh.php | 2 +- src/wp-includes/functions.php | 2 +- src/wp-includes/widgets/class-wp-widget-archives.php | 2 +- src/wp-includes/widgets/class-wp-widget-categories.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/blocks/categories.php b/src/wp-includes/blocks/categories.php index c392c2b56b148..8bd0032221388 100644 --- a/src/wp-includes/blocks/categories.php +++ b/src/wp-includes/blocks/categories.php @@ -110,7 +110,7 @@ function onCatChange() { } dropdown.onchange = onCatChange; })(); - //# sourceURL= + //# sourceURL= ', '' ), '', ob_get_clean() ) ); diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index edfd3b4c7072c..3026d3b039136 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -479,7 +479,7 @@ protected function wp_die( $ajax_message, $message = null ) { } )( wp.customize, ); $this->preview_nav_menu_instance_args, ); - wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) ); + wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) ); } /** diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index fa637b20532b8..6420e2202865d 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -1335,7 +1335,7 @@ public function export_preview_data() { unset( $registered_widget['callback'] ); // May not be JSON-serializable. } wp_print_inline_script_tag( - sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) + sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) ); } diff --git a/src/wp-includes/customize/class-wp-customize-selective-refresh.php b/src/wp-includes/customize/class-wp-customize-selective-refresh.php index 011be0b82c904..f51b1e6dc7627 100644 --- a/src/wp-includes/customize/class-wp-customize-selective-refresh.php +++ b/src/wp-includes/customize/class-wp-customize-selective-refresh.php @@ -193,7 +193,7 @@ public function export_preview_data() { ); // Export data to JS. - wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . str_replace( ':', '_', __METHOD__ ) ); + wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) ); } /** diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 29e62e1a000d5..42d029c78ae1f 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7797,7 +7797,7 @@ function wp_post_preview_js() { window.addEventListener( 'pagehide', function() { window.name = ''; } ); } }()); - //# sourceURL= + //# sourceURL= Date: Mon, 29 Sep 2025 20:39:33 -0700 Subject: [PATCH 3/4] Add rawurlencode() to remaining instances --- src/wp-includes/comment-template.php | 2 +- src/wp-includes/theme.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 0b5db1d37d507..143920f3c3fdc 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -1374,7 +1374,7 @@ function wp_comment_form_unfiltered_html_nonce() { if ( current_user_can( 'unfiltered_html' ) ) { wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); - wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();\n//# sourceURL=" . __FUNCTION__ ); + wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();\n//# sourceURL=" . rawurlencode( __FUNCTION__ ) ); } } diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index f9401c433eeeb..c2a3a7e838ef9 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -3815,7 +3815,7 @@ function wp_customize_support_script() { }()); Date: Fri, 3 Oct 2025 21:25:35 -0700 Subject: [PATCH 4/4] Revert change to block which will come from Gutenberg --- src/wp-includes/blocks/categories.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/blocks/categories.php b/src/wp-includes/blocks/categories.php index 8bd0032221388..60a29713b4660 100644 --- a/src/wp-includes/blocks/categories.php +++ b/src/wp-includes/blocks/categories.php @@ -110,7 +110,6 @@ function onCatChange() { } dropdown.onchange = onCatChange; })(); - //# sourceURL= ', '' ), '', ob_get_clean() ) );