[wp-trac] [WordPress Trac] #25247: WP_Dependencies unsets a to do item when it isn't loaded
WordPress Trac
noreply at wordpress.org
Fri Dec 12 16:53:15 UTC 2014
#25247: WP_Dependencies unsets a to do item when it isn't loaded
-------------------------------------------------+-------------------------
Reporter: markoheijnen | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
Component: Script Loader | Release
Severity: normal | Version: 3.6
Keywords: has-patch dev-feedback needs- | Resolution:
testing | Focuses:
-------------------------------------------------+-------------------------
Comment (by gitlost):
I think the no src issue is a bit of a red herring. The real problem here
is that the do_items() loop is removing an item from the to_do list
whether or not it succeeded. An issue reported by helgatheviking on WP
stackexchange
([http://wordpress.stackexchange.com/questions/168688/loading-a-script-
with-a-dependency-is-unloading-another-scripts-dependency Loading a script
with a dependency, is unloading another script's dependency] is another
symptom of the problem, which can be seen simply with this setup:
{{{
$scripts = new WP_Scripts;
$scripts->add( 'jquery-ui-datepicker', 'one', array(),
'v1', 1 );
$scripts->add( 'wc-admin-meta-boxes', 'two', array(
'jquery-ui-datepicker' ) );
$scripts->add( 'My_Plugin_Metabox', 'three', array( 'wc-
admin-meta-boxes' ), 'v1', 1 );
$scripts->enqueue( array( 'My_Plugin_Metabox' ) );
$scripts->do_items( false, 0 );
$scripts->do_items( false, 1 );
}}}
Note the mismatch in groups between 'wc-admin-meta-boxes' and 'jquery-ui-
datepicker', If you run this, 'jquery-ui-datepicker' won't be outputted,
it's just appended to the $in_footer array in WP_Scripts and left there,
and since the array is no longer used in do_footer_items(), it gets lost.
Basically it seems that when the code was changed to do two passes of
do_items() instead of one, the loop wasn't updated. The fix is simple,
only remove the item from the to_do list when it's successfully added (or
when the src is null).
The helgatheviking scenario also shows up another issue, in that although
with the loop fix 'jquery-ui-datepicker' will get outputted, it will
output in the footer, after the dependent 'wc-admin-meta-boxes' which gets
outputted in the head. To fix this it would seem best to force any
dependencies to the lowest common group, which can I think be achieved by
setting the class $this->group when recursing in set_group().
I'll attach a patch and unit tests with these changes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/25247#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list