-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix: Update Raw <script> tags with wp_inline_script_tag() for bundled themes.
#9416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Update Raw <script> tags with wp_inline_script_tag() for bundled themes.
#9416
Conversation
…ction definition for backward compatibility
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
hbhalodia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the requested changes?
peterwilsoncc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few notes inline.
🔢 indicates the comment applies to similar code in other files too.
|
@Debarghya-Banerjee Hello! Have you seen the latest PR feedback yet? Also, note the comment I just added to the ticket, related the changes to Core-63887. |
|
Hi @westonruter , I have checked the comments and feedback, I am working on it, and will push the changes in sometime by today itself. Thanks. |
|
Hi @westonruter , Apologies for the late update. I’ve pushed the changes based on your and @sabernhardt 's feedback. Could you please take a look? Thanks! |
src/wp-content/themes/twentytwentyone/inc/template-functions.php
Outdated
Show resolved
Hide resolved
|
@Debarghya-Banerjee Are you planning to address the remaining feedback or should we start pushing up commits to this PR? Thanks! |
|
Hi @westonruter , I have addressed the feedback. Sorry for getting back late. Can you please check once? Thanks. |
This reverts commit 186e543.
|
I wrote a script that checked the output of rendered output of the homepages for each of the themes to verify that there were no regressions in the generated markup, and that only the expected changes occur:
|
… include `sourceURL` for JS. Instead of manually constructing the markup for `SCRIPT` tags, leverage `wp_print_inline_script_tag()` when available to do the construction while also ensuring filters may inject additional attributes on the `SCRIPT` tags, such as `nonce` for CSP. When the function is not available (prior to WP 5.7), fall back to the manual markup construction. This also adds the `sourceURL` comments to the inline scripts to facilitate debugging, per #63887. Developed in #9416. Follow-up to [60909], [60899]. Props debarghyabanerjee, westonruter, hbhalodia, peterwilsoncc, sabernhardt, poena. See #63887, #59446. Fixes #63806. git-svn-id: https://develop.svn.wordpress.org/trunk@60913 602fd350-edb4-49c9-b593-d223f7449a82
… include `sourceURL` for JS. Instead of manually constructing the markup for `SCRIPT` tags, leverage `wp_print_inline_script_tag()` when available to do the construction while also ensuring filters may inject additional attributes on the `SCRIPT` tags, such as `nonce` for CSP. When the function is not available (prior to WP 5.7), fall back to the manual markup construction. This also adds the `sourceURL` comments to the inline scripts to facilitate debugging, per #63887. Developed in WordPress/wordpress-develop#9416. Follow-up to [60909], [60899]. Props debarghyabanerjee, westonruter, hbhalodia, peterwilsoncc, sabernhardt, poena. See #63887, #59446. Fixes #63806. Built from https://develop.svn.wordpress.org/trunk@60913 git-svn-id: http://core.svn.wordpress.org/trunk@60249 1a063a9b-81f0-0310-95a4-ce76da25c4cd
… include `sourceURL` for JS. Instead of manually constructing the markup for `SCRIPT` tags, leverage `wp_print_inline_script_tag()` when available to do the construction while also ensuring filters may inject additional attributes on the `SCRIPT` tags, such as `nonce` for CSP. When the function is not available (prior to WP 5.7), fall back to the manual markup construction. This also adds the `sourceURL` comments to the inline scripts to facilitate debugging, per #63887. Developed in WordPress/wordpress-develop#9416. Follow-up to [60909], [60899]. Props debarghyabanerjee, westonruter, hbhalodia, peterwilsoncc, sabernhardt, poena. See #63887, #59446. Fixes #63806. Built from https://develop.svn.wordpress.org/trunk@60913 git-svn-id: https://core.svn.wordpress.org/trunk@60249 1a063a9b-81f0-0310-95a4-ce76da25c4cd
sabernhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I successfully checked each of these themes, both with the patch in trunk and with WordPress 5.6.
For completeness, I made diffs for the Customizer scripts, which only show differences in spacing (indentation).
Twenty Fifteen:
</script>
- <script type="text/html" id="tmpl-twentyfifteen-color-scheme">
- /* Color Scheme */
+ <script type="text/html" id="tmpl-twentyfifteen-color-scheme">
+ /* Color Scheme */
/* Background Color */...
}
- } </script>
- <script type="text/html" id="tmpl-customize-themes-details-view">
+ }
+</script>
+ <script type="text/html" id="tmpl-customize-themes-details-view">
<div class="theme-backdrop"></div>Twenty Sixteen:
</script>
- <script type="text/html" id="tmpl-twentysixteen-color-scheme">
- /* Color Scheme */
+ <script type="text/html" id="tmpl-twentysixteen-color-scheme">
+ /* Color Scheme */
/* Background Color */...
}
- </script>
- <script type="text/html" id="tmpl-customize-themes-details-view">
+</script>
+ <script type="text/html" id="tmpl-customize-themes-details-view">
<div class="theme-backdrop"></div>
Trac Ticket: Core-63806
This pull request updates all inline script outputs in the bundled themes to use WordPress’s script helper functions, specifically
wp_print_inline_script_tag(), in place of manually constructed<script>tags.✅ Why This Matters
As of #59446, WordPress Core has adopted the use of
wp_get_script_tag(),wp_get_inline_script_tag(), andwp_print_inline_script_tag()to eliminate manually constructed<script>tags. This change was made to:However, many default and third-party themes still use raw
<script>tags, which prevents them from fully benefiting from these improvements.🛠 What’s Changed
Replaced all instances of echo
'<script>...</script>'with calls towp_print_inline_script_tag().Added a fallback check: if the helper function does not exist, the code directly prints the
<script>tag.🔙 Backward Compatibility
On WordPress 5.7+, the new helper functions are used.
On earlier versions, where these functions do not exist, the scripts fall back to directly printing raw <script> tags.