Make WordPress Core

Changeset 60909


Ignore:
Timestamp:
10/07/2025 01:23:00 AM (10 months ago)
Author:
westonruter
Message:

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 https://github.com/WordPress/wordpress-develop/pull/9955.

Props westonruter, jonsurrell.
See #63887.

Location:
trunk/src/wp-includes
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r60681 r60909  
    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
     
    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
     
    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
     
    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
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r60815 r60909  
    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
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r60802 r60909  
    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        }
  • trunk/src/wp-includes/comment-template.php

    r60779 r60909  
    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}
  • trunk/src/wp-includes/customize/class-wp-customize-selective-refresh.php

    r60681 r60909  
    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
  • trunk/src/wp-includes/embed.php

    r60783 r60909  
    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
     
    10911092 */
    10921093function 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}
  • trunk/src/wp-includes/functions.php

    r60809 r60909  
    77987798                }
    77997799        }());
     7800        //# sourceURL=<?php echo rawurlencode( __FUNCTION__ ); ?>
    78007801        </script>
    78017802        <?php
  • trunk/src/wp-includes/theme.php

    r60681 r60909  
    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
  • trunk/src/wp-includes/widgets/class-wp-widget-archives.php

    r56748 r60909  
    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';
  • trunk/src/wp-includes/widgets/class-wp-widget-categories.php

    r56748 r60909  
    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';
Note: See TracChangeset for help on using the changeset viewer.