[wp-trac] [WordPress Trac] #35956: Script's dependencies are always moved to header

WordPress Trac noreply at wordpress.org
Fri Feb 26 04:08:05 UTC 2016

#35956: Script's dependencies are always moved to header
 Reporter:  stephenharris     |       Owner:  ocean90
     Type:  defect (bug)      |      Status:  reviewing
 Priority:  normal            |   Milestone:  4.5
Component:  Script Loader     |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:  needs-unit-tests  |     Focuses:

Comment (by gitlost):

 It's very confusing but the `$group` isn't always `false` for
 `WP_Dependencies::set_group()`, as it's set in `WP_Scripts::set_group()`.
 I think the problem is that the class variable `$this->group` in the
 `WP_Dependencies::set_group()` will be set to the first group in the
 dependencies, and if this happens to be zero then that's it.

 Note for instance that if you change the ordering of the dependences in
 @stephenharris 's example so that `child-footer` is listed before `child-
 head` then it works as expected:

 function my_enqueue_scripts() {
         wp_register_script( 'child-head', '/child-head.js', array(), null,
 false );
         wp_register_script( 'child-footer', '/child-footer.js', array(),
 null, true );
         wp_register_script( 'parent', '/parent.js', array( 'child-footer',
 'child-head' ), null, true );
         wp_enqueue_script( 'parent' );

 add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );

 Thus a way around this (though I'm sure there's better ways) would be to
 sort the dependencies (on recursion) from highest to lowest group when
 processing them in `all_deps()`. so that `set_group()` gets called in the
 appropriate order.

 I'll upload a demo diff.

Ticket URL: <https://core.trac.wordpress.org/ticket/35956#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list