[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
Mon Aug 11 11:26:38 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      |     Focuses:  javascript
---------------------------+-------------------------
Changes (by sabernhardt):

 * keywords:  good-first-bug has-patch => has-patch


Comment:

 1. The three `twenty*_skip_link_focus_fix` functions are deprecated; I
 prefer not to edit those at all.
 2. Polyfills might need updating later, and I think any site that opts in
 for a strict CSP should have a newer version of WordPress than 5.7. Could
 the existing theme functions simply check if the
 `wp_print_inline_script_tag` function exists and print/echo if not?
    {{{#!php
 /**
  * JavaScript Detection.
  *
  * Adds a `js` class to the root `<html>` element when JavaScript is
 detected.
  *
  * @since Twenty Fifteen 1.1
  * @since Twenty Fifteen 4.1 Added `wp_print_inline_script_tag()` support.
  */
 function twentyfifteen_javascript_detection() {
         $js = "(function(html){html.className = html.className.replace
 (/\bno-js\b/,'js')})(document.documentElement);";

         if ( function_exists( 'wp_print_inline_script_tag' ) ) {
                 wp_print_inline_script_tag( $js );
         } else {
                 printf( "<script>%s</script>\n", $js );
         }
 }
 add_action( 'wp_head', 'twentyfifteen_javascript_detection', 0 );
    }}}
 3. I think the auto-focus script in Twenty Ten's `404.php` template should
 be removed entirely. Screen readers currently announce the search form
 without the context of the heading and explanatory paragraph.
 4. Hopefully #58836 will remove the `html5.js` scripts from header
 templates.
 5. Neither PR addresses the Customizer CSS templates in Twenty Fifteen and
 Twenty Sixteen. The `wp_print_inline_script_tag()` function would include
 the attributes array for those, and the documentation should capitalize
 CSS.
    {{{#!php
 /**
  * Outputs an Underscore template for generating CSS for the color scheme.
  *
  * The template generates the CSS dynamically for instant display in the
 Customizer
  * preview.
  *
  * @since Twenty Fifteen 1.0
  * @since Twenty Fifteen 4.1 Added `wp_print_inline_script_tag()` support.
  */
 function twentyfifteen_color_scheme_css_template() {
         $colors = array(
                 'background_color'            => '{{ data.background_color
 }}',
                 'header_background_color'     => '{{
 data.header_background_color }}',
                 'box_background_color'        => '{{
 data.box_background_color }}',
                 'textcolor'                   => '{{ data.textcolor }}',
                 'secondary_textcolor'         => '{{
 data.secondary_textcolor }}',
                 'border_color'                => '{{ data.border_color
 }}',
                 'border_focus_color'          => '{{
 data.border_focus_color }}',
                 'sidebar_textcolor'           => '{{
 data.sidebar_textcolor }}',
                 'sidebar_border_color'        => '{{
 data.sidebar_border_color }}',
                 'sidebar_border_focus_color'  => '{{
 data.sidebar_border_focus_color }}',
                 'secondary_sidebar_textcolor' => '{{
 data.secondary_sidebar_textcolor }}',
                 'meta_box_background_color'   => '{{
 data.meta_box_background_color }}',
         );

         $css = twentyfifteen_get_color_scheme_css( $colors );

         if ( function_exists( 'wp_print_inline_script_tag' ) ) {
                 wp_print_inline_script_tag( $css, array( 'type' =>
 'text/html', 'id' => 'tmpl-twentyfifteen-color-scheme' ) );
         } else {
                 printf(
                         "<script %s>\n%s\n\t</script>\n",
                         'type="text/html" id="tmpl-twentyfifteen-color-
 scheme"',
                         $css
                 );
         }
 }
 add_action( 'customize_controls_print_footer_scripts',
 'twentyfifteen_color_scheme_css_template' );
    }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63806#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list