Make WordPress Core

#59302 closed enhancement (fixed)

Update script registration in default themes to use new function signature

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: has-patch
Focuses: performance Cc:

Description

This ticket is broken out of #58634, just to capture the work for updating the default theme calls to wp_register_script() and wp_enqueue_script() separately, given there is already a PR https://github.com/WordPress/wordpress-develop/pull/5073 that encompasses all of them.

The main ticket can then continue to be used to also update core's own usage accordingly.

cc @joemcgill

Change History (7)

#1 @flixos90
10 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56526:

Bundled Theme: Update default themes to use new script function signature.

In WordPress 6.3, the last parameter of wp_register_script() and wp_enqueue_script() was changed to an array rather than a boolean. While a boolean is still supported for backward compatibility, it makes sense to update the codebase to use the new signature.

The updates are fully backward compatible:

  • In places where true was provided, array( 'in_footer' => true ) will still be interpreted as a boolean true in WordPress versions prior to 6.3.
  • In places where false was provided, the parameter is omitted which will work correctly throughout all WordPress versions given that is and has been the default value anyway.

Props mrinal013, huzaifaalmesbah, niravsherasiya7707, joemcgill.
Fixes #59302.
See #58634.

#2 @spacedmonkey
10 months ago

@flixos90 Was this tested in WordPress 6.2-. These themes can and are used in older versions of WordPress?

#3 @peterwilsoncc
10 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Generally WP tries to keep bundled themes compatible with the WordPress version in which they were introduced. As an example of this, 2011 checks the block pattern functions exist prior to calling them.

I think these changes and those in #59316 will need to be modified to account for the older function signature.

I've reopened this to work on a PR.

#4 @flixos90
10 months ago

@peterwilsoncc Where specifically is the commit not compatible with the older WordPress versions? The old versions expect a boolean, and a non empty array is interpreted as true. That was considered in the implementation, so I don't see where there's an incompatibility. Could you please clarify the concern?

#5 @peterwilsoncc
10 months ago

@flixos90 It may have come from the follow up ticket but in 2011 one of the files was unintentionally moved from the header to footer. However, choosing to pass around the incorrect type doesn't seem like a great idea.

As I say, I'm working through a PR at the moment and will attach it to the ticket once it's ready for review.

#6 @oglekler
10 months ago

  • Keywords changes-requested added

From my point of view, you are trying to solve a problem where there is none. We have 7 days before the Beta 1, and I would have preferred to move this ticket into 6.5 for further discussion.

#7 @flixos90
10 months ago

  • Keywords changes-requested removed
  • Resolution set to fixed
  • Status changed from reopened to closed

Per the discussion in https://github.com/WordPress/wordpress-develop/pull/5196, closing this again. There is misalignment on how the changed signature should be approached in themes, however that is not a functional concern. The ticket can be reopened if there are other concerns.

There was one actual bug found as part of the discussion which was fixed in [56569]. As a result, all script changes were audited again, and other than that one, there are no breaking changes from the original commits.

Note: See TracTickets for help on using tickets.