Skip to content

Commit 8c2ec29

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 #9955. Props westonruter, jonsurrell. See #63887. git-svn-id: https://develop.svn.wordpress.org/trunk@60909 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 117f23f commit 8c2ec29

10 files changed

Lines changed: 16 additions & 13 deletions

src/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
/**

src/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
/**

src/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

src/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

src/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
/**

src/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

src/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() ) );

src/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
/**

src/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

src/wp-includes/widgets/class-wp-widget-categories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function onCatChange() {
108108
</script>
109109

110110
<?php
111-
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
111+
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
112112
} else {
113113
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
114114

0 commit comments

Comments
 (0)