[wp-trac] [WordPress Trac] #58634: Update uses of script registration functions to use new function signature

WordPress Trac noreply at wordpress.org
Mon Jun 26 17:59:52 UTC 2023


#58634: Update uses of script registration functions to use new function signature
----------------------------------------+-------------------------
 Reporter:  joemcgill                   |       Owner:  (none)
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  6.3
Component:  General                     |     Version:  trunk
 Severity:  normal                      |  Resolution:
 Keywords:  needs-patch good-first-bug  |     Focuses:  javascript
----------------------------------------+-------------------------
Description changed by joemcgill:

Old description:

> In [56033] the function signatures for `wp_register_scripts` and
> `wp_enqueue_scripts` are updated so that the sixth parameter,
> `$in_footer`, now accepts an array of args with the following shape:
>
> {{{#!php
>  * @param array|bool       $args     {
>  *      Optional. An array of additional script loading strategies.
> Default empty array.
>  *      Otherwise, it may be a boolean in which case it determines
> whether the script is printed in the footer. Default false.
>  *
>  *      @type string    $strategy     Optional. If provided, may be
> either 'defer' or 'async'.
>  *      @type bool      $in_footer    Optional. Whether to print the
> script in the footer. Default 'false'.
>  *
> }
> }}}
>
> There are several places in core (primarily default themes) where the
> previous boolean value of `true` is being used to indicate that those
> scripts should load in the footer (default is false). While this is still
> supported, we should update these occurrences to use the new preferred
> args shape as a good housekeeping task.
>
> ----
>
> Here's a list of current places where these could be updated:
>
> {{{
> src/wp-content/plugins/akismet/class.akismet.php:
>   1756                          ) {
>   1757:                         wp_register_script( 'akismet-frontend',
> plugin_dir_url( __FILE__ ) . '_inc/akismet-frontend.js', array(),
> filemtime( plugin_dir_path( __FILE__ ) . '_inc/akismet-frontend.js' ),
> true );
>   1758                          wp_enqueue_script( 'akismet-frontend' );
>
> src/wp-content/themes/twentyeleven/inc/theme-options.php:
>   675  function twentyeleven_customize_preview_js() {
>   676:  wp_enqueue_script( 'twentyeleven-customizer',
> get_template_directory_uri() . '/inc/theme-customizer.js', array(
> 'customize-preview' ), '20150401', true );
>   677  }
>
> src/wp-content/themes/twentyfifteen/functions.php:
>   446   // Skip-link fix is no longer enqueued by default.
>   447:  wp_register_script( 'twentyfifteen-skip-link-focus-fix',
> get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(),
> '20230526', true );
>   448
>
>   456
>   457:  wp_enqueue_script( 'twentyfifteen-script',
> get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
> '20221101', true );
>   458   wp_localize_script(
>
> src/wp-content/themes/twentyfifteen/inc/customizer.php:
>   361  function twentyfifteen_customize_control_js() {
>   362:  wp_enqueue_script( 'color-scheme-control',
> get_template_directory_uri() . '/js/color-scheme-control.js', array(
> 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20141216', true
> );
>   363   wp_localize_script( 'color-scheme-control', 'colorScheme',
> twentyfifteen_get_color_schemes() );
>
>   372  function twentyfifteen_customize_preview_js() {
>   373:  wp_enqueue_script( 'twentyfifteen-customize-preview',
> get_template_directory_uri() . '/js/customize-preview.js', array(
> 'customize-preview' ), '20141216', true );
>   374  }
>
> src/wp-content/themes/twentyfourteen/functions.php:
>   369   if ( is_front_page() && 'slider' === get_theme_mod(
> 'featured_content_layout' ) ) {
>   370:          wp_enqueue_script( 'twentyfourteen-slider',
> get_template_directory_uri() . '/js/slider.js', array( 'jquery' ),
> '20150120', true );
>   371           wp_localize_script(
>
>   380
>   381:  wp_enqueue_script( 'twentyfourteen-script',
> get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
> '20230526', true );
>   382  }
>
> src/wp-content/themes/twentyfourteen/inc/customizer.php:
>   144  function twentyfourteen_customize_preview_js() {
>   145:  wp_enqueue_script( 'twentyfourteen_customizer',
> get_template_directory_uri() . '/js/customizer.js', array( 'customize-
> preview' ), '20141015', true );
>   146  }
>
> src/wp-content/themes/twentyfourteen/inc/featured-content.php:
>   436   public static function enqueue_scripts() {
>   437:          wp_enqueue_script( 'featured-content-suggest',
> get_template_directory_uri() . '/js/featured-content-admin.js', array(
> 'jquery', 'suggest' ), '20211130', true );
>   438   }
>
> src/wp-content/themes/twentynineteen/functions.php:
>   261   if ( has_nav_menu( 'menu-1' ) ) {
>   262:          wp_enqueue_script( 'twentynineteen-priority-menu',
> get_theme_file_uri( '/js/priority-menu.js' ), array(), '20200129', true
> );
>   263:          wp_enqueue_script( 'twentynineteen-touch-navigation',
> get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(),
> '20221101', true );
>   264   }
>
> src/wp-content/themes/twentynineteen/inc/customizer.php:
>   127  function twentynineteen_customize_preview_js() {
>   128:  wp_enqueue_script( 'twentynineteen-customize-preview',
> get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-
> preview' ), '20181214', true );
>   129  }
>
>   135  function twentynineteen_panels_js() {
>   136:  wp_enqueue_script( 'twentynineteen-customize-controls',
> get_theme_file_uri( '/js/customize-controls.js' ), array(), '20181214',
> true );
>   137  }
>
> src/wp-content/themes/twentyseventeen/functions.php:
>   479   // Skip-link fix is no longer enqueued by default.
>   480:  wp_register_script( 'twentyseventeen-skip-link-focus-fix',
> get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(),
> '20161114', true );
>   481
>   482:  wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri(
> '/assets/js/global.js' ), array( 'jquery' ), '20211130', true );
>   483
>
>   488   if ( has_nav_menu( 'top' ) ) {
>   489:          wp_enqueue_script( 'twentyseventeen-navigation',
> get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ),
> '20210122', true );
>   490           $twentyseventeen_l10n['expand']   = __( 'Expand child
> menu', 'twentyseventeen' );
>
>   501
>   502:  wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri(
> '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.3', true );
>   503
>
> src/wp-content/themes/twentyseventeen/inc/customizer.php:
>   247  function twentyseventeen_customize_preview_js() {
>   248:  wp_enqueue_script( 'twentyseventeen-customize-preview',
> get_theme_file_uri( '/assets/js/customize-preview.js' ), array(
> 'customize-preview' ), '20161002', true );
>   249  }
>
>   255  function twentyseventeen_panels_js() {
>   256:  wp_enqueue_script( 'twentyseventeen-customize-controls',
> get_theme_file_uri( '/assets/js/customize-controls.js' ), array(),
> '20161020', true );
>   257  }
>
> src/wp-content/themes/twentysixteen/functions.php:
>   415   // Skip-link fix is no longer enqueued by default.
>   416:  wp_register_script( 'twentysixteen-skip-link-focus-fix',
> get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(),
> '20230526', true );
>   417
>
>   425
>   426:  wp_enqueue_script( 'twentysixteen-script',
> get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
> '20211130', true );
>   427
>
> src/wp-content/themes/twentysixteen/inc/customizer.php:
>   488  function twentysixteen_customize_control_js() {
>   489:  wp_enqueue_script( 'color-scheme-control',
> get_template_directory_uri() . '/js/color-scheme-control.js', array(
> 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20170530', true
> );
>   490   wp_localize_script( 'color-scheme-control', 'colorScheme',
> twentysixteen_get_color_schemes() );
>
>   499  function twentysixteen_customize_preview_js() {
>   500:  wp_enqueue_script( 'twentysixteen-customize-preview',
> get_template_directory_uri() . '/js/customize-preview.js', array(
> 'customize-preview' ), '20170530', true );
>   501  }
>
> src/wp-content/themes/twentythirteen/functions.php:
>   323   // Loads JavaScript file with functionality specific to Twenty
> Thirteen.
>   324:  wp_enqueue_script( 'twentythirteen-script',
> get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
> '20230526', true );
>   325
>
>   845  function twentythirteen_customize_preview_js() {
>   846:  wp_enqueue_script( 'twentythirteen-customizer',
> get_template_directory_uri() . '/js/theme-customizer.js', array(
> 'customize-preview' ), '20200516', true );
>   847  }
>
> src/wp-content/themes/twentytwelve/functions.php:
>   190   // Adds JavaScript for handling the navigation menu hide-and-show
> behavior.
>   191:  wp_enqueue_script( 'twentytwelve-navigation',
> get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ),
> '20141205', true );
>   192
>
>   694  function twentytwelve_customize_preview_js() {
>   695:  wp_enqueue_script( 'twentytwelve-customizer',
> get_template_directory_uri() . '/js/theme-customizer.js', array(
> 'customize-preview' ), '20200516', true );
>   696  }
>
> src/wp-content/themes/twentytwenty/functions.php:
>   433   // Enqueue the editor script.
>   434:  wp_enqueue_script( 'twentytwenty-block-editor-script',
> get_theme_file_uri( '/assets/js/editor-script-block.js' ), array( 'wp-
> blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
>   435  }
>
>   649
>   650:  wp_enqueue_script( 'twentytwenty-customize-preview',
> get_theme_file_uri( '/assets/js/customize-preview.js' ), array(
> 'customize-preview', 'customize-selective-refresh', 'jquery' ),
> $theme_version, true );
>   651   wp_localize_script( 'twentytwenty-customize-preview',
> 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
>
> src/wp-content/themes/twentytwentyone/functions.php:
>   472
>   473:  wp_enqueue_script( 'twentytwentyone-editor', get_theme_file_uri(
> '/assets/js/editor.js' ), array( 'wp-blocks', 'wp-dom' ),
> wp_get_theme()->get( 'Version' ), true );
>   474  }
>
> src/wp-includes/script-loader.php:
>   2712
>   2713:         wp_register_script( 'wp-block-styles', false, array( 'wp-
> blocks' ), true, true );
>   2714          wp_add_inline_script( 'wp-block-styles', $inline_script
> );
> }}}

New description:

 In [56033] the function signatures for `wp_register_script` and
 `wp_enqueue_script` are updated so that the sixth parameter, `$in_footer`,
 now accepts an array of args with the following shape:

 {{{#!php
  * @param array|bool       $args     {
  *      Optional. An array of additional script loading strategies.
 Default empty array.
  *      Otherwise, it may be a boolean in which case it determines whether
 the script is printed in the footer. Default false.
  *
  *      @type string    $strategy     Optional. If provided, may be either
 'defer' or 'async'.
  *      @type bool      $in_footer    Optional. Whether to print the
 script in the footer. Default 'false'.
  *
 }
 }}}

 There are several places in core (primarily default themes) where the
 previous boolean value of `true` is being used to indicate that those
 scripts should load in the footer (default is false). While this is still
 supported, we should update these occurrences to use the new preferred
 args shape as a good housekeeping task.

 ----

 Here's a list of current places where these could be updated:

 {{{
 src/wp-content/plugins/akismet/class.akismet.php:
   1756                          ) {
   1757:                         wp_register_script( 'akismet-frontend',
 plugin_dir_url( __FILE__ ) . '_inc/akismet-frontend.js', array(),
 filemtime( plugin_dir_path( __FILE__ ) . '_inc/akismet-frontend.js' ),
 true );
   1758                          wp_enqueue_script( 'akismet-frontend' );

 src/wp-content/themes/twentyeleven/inc/theme-options.php:
   675  function twentyeleven_customize_preview_js() {
   676:  wp_enqueue_script( 'twentyeleven-customizer',
 get_template_directory_uri() . '/inc/theme-customizer.js', array(
 'customize-preview' ), '20150401', true );
   677  }

 src/wp-content/themes/twentyfifteen/functions.php:
   446   // Skip-link fix is no longer enqueued by default.
   447:  wp_register_script( 'twentyfifteen-skip-link-focus-fix',
 get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(),
 '20230526', true );
   448

   456
   457:  wp_enqueue_script( 'twentyfifteen-script',
 get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
 '20221101', true );
   458   wp_localize_script(

 src/wp-content/themes/twentyfifteen/inc/customizer.php:
   361  function twentyfifteen_customize_control_js() {
   362:  wp_enqueue_script( 'color-scheme-control',
 get_template_directory_uri() . '/js/color-scheme-control.js', array(
 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20141216', true
 );
   363   wp_localize_script( 'color-scheme-control', 'colorScheme',
 twentyfifteen_get_color_schemes() );

   372  function twentyfifteen_customize_preview_js() {
   373:  wp_enqueue_script( 'twentyfifteen-customize-preview',
 get_template_directory_uri() . '/js/customize-preview.js', array(
 'customize-preview' ), '20141216', true );
   374  }

 src/wp-content/themes/twentyfourteen/functions.php:
   369   if ( is_front_page() && 'slider' === get_theme_mod(
 'featured_content_layout' ) ) {
   370:          wp_enqueue_script( 'twentyfourteen-slider',
 get_template_directory_uri() . '/js/slider.js', array( 'jquery' ),
 '20150120', true );
   371           wp_localize_script(

   380
   381:  wp_enqueue_script( 'twentyfourteen-script',
 get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
 '20230526', true );
   382  }

 src/wp-content/themes/twentyfourteen/inc/customizer.php:
   144  function twentyfourteen_customize_preview_js() {
   145:  wp_enqueue_script( 'twentyfourteen_customizer',
 get_template_directory_uri() . '/js/customizer.js', array( 'customize-
 preview' ), '20141015', true );
   146  }

 src/wp-content/themes/twentyfourteen/inc/featured-content.php:
   436   public static function enqueue_scripts() {
   437:          wp_enqueue_script( 'featured-content-suggest',
 get_template_directory_uri() . '/js/featured-content-admin.js', array(
 'jquery', 'suggest' ), '20211130', true );
   438   }

 src/wp-content/themes/twentynineteen/functions.php:
   261   if ( has_nav_menu( 'menu-1' ) ) {
   262:          wp_enqueue_script( 'twentynineteen-priority-menu',
 get_theme_file_uri( '/js/priority-menu.js' ), array(), '20200129', true );
   263:          wp_enqueue_script( 'twentynineteen-touch-navigation',
 get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(),
 '20221101', true );
   264   }

 src/wp-content/themes/twentynineteen/inc/customizer.php:
   127  function twentynineteen_customize_preview_js() {
   128:  wp_enqueue_script( 'twentynineteen-customize-preview',
 get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-
 preview' ), '20181214', true );
   129  }

   135  function twentynineteen_panels_js() {
   136:  wp_enqueue_script( 'twentynineteen-customize-controls',
 get_theme_file_uri( '/js/customize-controls.js' ), array(), '20181214',
 true );
   137  }

 src/wp-content/themes/twentyseventeen/functions.php:
   479   // Skip-link fix is no longer enqueued by default.
   480:  wp_register_script( 'twentyseventeen-skip-link-focus-fix',
 get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(),
 '20161114', true );
   481
   482:  wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri(
 '/assets/js/global.js' ), array( 'jquery' ), '20211130', true );
   483

   488   if ( has_nav_menu( 'top' ) ) {
   489:          wp_enqueue_script( 'twentyseventeen-navigation',
 get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ),
 '20210122', true );
   490           $twentyseventeen_l10n['expand']   = __( 'Expand child
 menu', 'twentyseventeen' );

   501
   502:  wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri(
 '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.3', true );
   503

 src/wp-content/themes/twentyseventeen/inc/customizer.php:
   247  function twentyseventeen_customize_preview_js() {
   248:  wp_enqueue_script( 'twentyseventeen-customize-preview',
 get_theme_file_uri( '/assets/js/customize-preview.js' ), array(
 'customize-preview' ), '20161002', true );
   249  }

   255  function twentyseventeen_panels_js() {
   256:  wp_enqueue_script( 'twentyseventeen-customize-controls',
 get_theme_file_uri( '/assets/js/customize-controls.js' ), array(),
 '20161020', true );
   257  }

 src/wp-content/themes/twentysixteen/functions.php:
   415   // Skip-link fix is no longer enqueued by default.
   416:  wp_register_script( 'twentysixteen-skip-link-focus-fix',
 get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(),
 '20230526', true );
   417

   425
   426:  wp_enqueue_script( 'twentysixteen-script',
 get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
 '20211130', true );
   427

 src/wp-content/themes/twentysixteen/inc/customizer.php:
   488  function twentysixteen_customize_control_js() {
   489:  wp_enqueue_script( 'color-scheme-control',
 get_template_directory_uri() . '/js/color-scheme-control.js', array(
 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20170530', true
 );
   490   wp_localize_script( 'color-scheme-control', 'colorScheme',
 twentysixteen_get_color_schemes() );

   499  function twentysixteen_customize_preview_js() {
   500:  wp_enqueue_script( 'twentysixteen-customize-preview',
 get_template_directory_uri() . '/js/customize-preview.js', array(
 'customize-preview' ), '20170530', true );
   501  }

 src/wp-content/themes/twentythirteen/functions.php:
   323   // Loads JavaScript file with functionality specific to Twenty
 Thirteen.
   324:  wp_enqueue_script( 'twentythirteen-script',
 get_template_directory_uri() . '/js/functions.js', array( 'jquery' ),
 '20230526', true );
   325

   845  function twentythirteen_customize_preview_js() {
   846:  wp_enqueue_script( 'twentythirteen-customizer',
 get_template_directory_uri() . '/js/theme-customizer.js', array(
 'customize-preview' ), '20200516', true );
   847  }

 src/wp-content/themes/twentytwelve/functions.php:
   190   // Adds JavaScript for handling the navigation menu hide-and-show
 behavior.
   191:  wp_enqueue_script( 'twentytwelve-navigation',
 get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ),
 '20141205', true );
   192

   694  function twentytwelve_customize_preview_js() {
   695:  wp_enqueue_script( 'twentytwelve-customizer',
 get_template_directory_uri() . '/js/theme-customizer.js', array(
 'customize-preview' ), '20200516', true );
   696  }

 src/wp-content/themes/twentytwenty/functions.php:
   433   // Enqueue the editor script.
   434:  wp_enqueue_script( 'twentytwenty-block-editor-script',
 get_theme_file_uri( '/assets/js/editor-script-block.js' ), array( 'wp-
 blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
   435  }

   649
   650:  wp_enqueue_script( 'twentytwenty-customize-preview',
 get_theme_file_uri( '/assets/js/customize-preview.js' ), array(
 'customize-preview', 'customize-selective-refresh', 'jquery' ),
 $theme_version, true );
   651   wp_localize_script( 'twentytwenty-customize-preview',
 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );

 src/wp-content/themes/twentytwentyone/functions.php:
   472
   473:  wp_enqueue_script( 'twentytwentyone-editor', get_theme_file_uri(
 '/assets/js/editor.js' ), array( 'wp-blocks', 'wp-dom' ),
 wp_get_theme()->get( 'Version' ), true );
   474  }

 src/wp-includes/script-loader.php:
   2712
   2713:         wp_register_script( 'wp-block-styles', false, array( 'wp-
 blocks' ), true, true );
   2714          wp_add_inline_script( 'wp-block-styles', $inline_script );
 }}}

--

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


More information about the wp-trac mailing list