[wp-trac] [WordPress Trac] #54529: Allow for `wp_register_script()` to be called after `wp_enqueue_script()`.

WordPress Trac noreply at wordpress.org
Tue Dec 7 17:41:57 UTC 2021


#54529: Allow for `wp_register_script()` to be called after `wp_enqueue_script()`.
-------------------------------------------------+-------------------------
 Reporter:  dd32                                 |       Owner:  audrasjb
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  5.9
Component:  Script Loader                        |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests commit      |     Focuses:
  needs-dev-note                                 |
-------------------------------------------------+-------------------------
Changes (by audrasjb):

 * keywords:  has-patch has-unit-tests commit => has-patch has-unit-tests
     commit needs-dev-note


Comment:

 Tested using the above example:
 {{{
 // Classic Theme: This will be called first
 // FSE: This will be called second.
 add_action( 'wp_enqueue_scripts', function() {
    wp_register_script( 'example', 'https://example.com/example.js' );
 } );

 // Classic Theme: This function will be called second, and enqueue the
 above script
 // FSE: This function will be called first, and fail to enqueue
 add_filter( 'the_content', function( $content ) {
    wp_enqueue_script( 'example' );

    return $content;
 } );
 }}}

 **## Test results**

 Before patch:
 - On a block theme, the `example` script is not printed on front-end.
 - On a Classic Theme, the `example` is printed on front-end.

 After patch:
 - On a block theme, the `example` script is printed on front-end.
 - On a Classic Theme, the `example` is still printed on front-end.

 Tests look good.

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


More information about the wp-trac mailing list