Skip to content

Commit 8dc4b2a

Browse files
committed
Script Loader: Add sourceURL comments to inline SCRIPT tags manually constructed in wp-includes.
This applies to tags constructed without `wp_get_inline_script_tag()`/`wp_print_inline_script_tag()`. Developed in WordPress/wordpress-develop#9955. Props westonruter, jonsurrell. See #63887. Built from https://develop.svn.wordpress.org/trunk@60909 git-svn-id: http://core.svn.wordpress.org/trunk@60245 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 434404c commit 8dc4b2a

11 files changed

Lines changed: 17 additions & 14 deletions

wp-includes/class-wp-customize-manager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ protected function wp_die( $ajax_message, $message = null ) {
479479
} )( wp.customize, <?php echo wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
480480
</script>
481481
<?php
482-
$message .= wp_get_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
482+
$message .= wp_get_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
483483
}
484484

485485
wp_die( $message );
@@ -2105,7 +2105,7 @@ public function remove_frameless_preview_messenger_channel() {
21052105
} )();
21062106
</script>
21072107
<?php
2108-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
2108+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
21092109
}
21102110

21112111
/**
@@ -2227,7 +2227,7 @@ public function customize_preview_settings() {
22272227
})( _wpCustomizeSettings.values );
22282228
</script>
22292229
<?php
2230-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
2230+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
22312231
}
22322232

22332233
/**
@@ -5022,7 +5022,7 @@ public function customize_pane_settings() {
50225022
?>
50235023
</script>
50245024
<?php
5025-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
5025+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
50265026
}
50275027

50285028
/**

wp-includes/class-wp-customize-nav-menus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ public function export_preview_data() {
15561556
$exports = array(
15571557
'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args,
15581558
);
1559-
wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) );
1559+
wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
15601560
}
15611561

15621562
/**

wp-includes/class-wp-customize-widgets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ public function export_preview_data() {
13351335
unset( $registered_widget['callback'] ); // May not be JSON-serializable.
13361336
}
13371337
wp_print_inline_script_tag(
1338-
sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) )
1338+
sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ )
13391339
);
13401340
}
13411341

wp-includes/comment-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ function wp_comment_form_unfiltered_html_nonce() {
13741374

13751375
if ( current_user_can( 'unfiltered_html' ) ) {
13761376
wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
1377-
wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();" );
1377+
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__ ) );
13781378
}
13791379
}
13801380

wp-includes/customize/class-wp-customize-selective-refresh.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function export_preview_data() {
193193
);
194194

195195
// Export data to JS.
196-
wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) );
196+
wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
197197
}
198198

199199
/**

wp-includes/embed.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,9 @@ function get_post_embed_html( $width, $height, $post = null ) {
518518
* will fail to match and everything will be matched by `.*` and not included in the group. This regex issue goes
519519
* back to WordPress 4.4, so in order to not break older installs this script must come at the end.
520520
*/
521+
$js_path = '/js/wp-embed' . wp_scripts_get_suffix() . '.js';
521522
$output .= wp_get_inline_script_tag(
522-
file_get_contents( ABSPATH . WPINC . '/js/wp-embed' . wp_scripts_get_suffix() . '.js' )
523+
trim( file_get_contents( ABSPATH . WPINC . $js_path ) ) . "\n//# sourceURL=" . includes_url( $js_path )
523524
);
524525

525526
/**
@@ -1090,8 +1091,9 @@ function wp_enqueue_embed_styles() {
10901091
* @since 4.4.0
10911092
*/
10921093
function print_embed_scripts() {
1094+
$js_path = '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js';
10931095
wp_print_inline_script_tag(
1094-
file_get_contents( ABSPATH . WPINC . '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js' )
1096+
trim( file_get_contents( ABSPATH . WPINC . $js_path ) ) . "\n//# sourceURL=" . includes_url( $js_path )
10951097
);
10961098
}
10971099

wp-includes/functions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,6 +7797,7 @@ function wp_post_preview_js() {
77977797
window.addEventListener( 'pagehide', function() { window.name = ''; } );
77987798
}
77997799
}());
7800+
//# sourceURL=<?php echo rawurlencode( __FUNCTION__ ); ?>
78007801
</script>
78017802
<?php
78027803
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );

wp-includes/theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,7 @@ function wp_customize_support_script() {
38153815
}());
38163816
</script>
38173817
<?php
3818-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
3818+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __FUNCTION__ ) );
38193819
}
38203820

38213821
/**

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.9-alpha-60908';
19+
$wp_version = '6.9-alpha-60909';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

wp-includes/widgets/class-wp-widget-archives.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function onSelectChange() {
120120
})();
121121
</script>
122122
<?php
123-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
123+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
124124
} else {
125125
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
126126

0 commit comments

Comments
 (0)