[wp-trac] [WordPress Trac] #63806: Bundled themes: Scripts are printed directly without using wp_print_script_tag()/wp_print_inline_script_tag()
WordPress Trac
noreply at wordpress.org
Fri Sep 19 00:51:39 UTC 2025
#63806: Bundled themes: Scripts are printed directly without using
wp_print_script_tag()/wp_print_inline_script_tag()
-----------------------------------------+-------------------------
Reporter: westonruter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.9
Component: Bundled Theme | Version: 5.7
Severity: normal | Resolution:
Keywords: has-patch changes-requested | Focuses: javascript
-----------------------------------------+-------------------------
Changes (by westonruter):
* keywords: has-patch => has-patch changes-requested
Comment:
Note: Now with #63887, I think it makes sense to include the `sourceURL`
comments for these inline scripts in the patch as well.
For example, in `Twenty_Twenty_One_Dark_Mode::the_script()` there is:
{{{#!php
<?php
public function the_script() {
echo '<script>';
include get_template_directory() . '/assets/js/dark-mode-
toggler.js'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
echo '</script>';
}
}}}
This method can address the CSP issue and the lack of a `sourceURL`
comment by being changed to:
{{{#!php
<?php
public function the_script() {
wp_print_inline_script_tag(
file_get_contents( get_template_directory() .
'/assets/js/dark-mode-toggler.js' ) .
"\n//# sourceURL=" . trailingslashit(
get_template_directory_uri() ) . 'assets/js/dark-mode-toggler.js'
);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63806#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list