Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9620 closed defect (bug) (fixed)

problems with the new footer script loader

Reported by: Denis-de-Bernardy Owned by: azaozz
Milestone: 2.8 Priority: normal
Severity: major Version: 2.8
Component: JavaScript Keywords: has-patch dev-feedback
Focuses: Cc:


I ran into this while trying to figure out why one of my admin js wasn't working on the widgets screen. I was running the following:

wp_enqueue_script('jquery-livequery', $plugin_path . 'jquery.livequery.js', array('jquery'),  '1.1');
wp_enqueue_script('jquery-ui-droppable', $plugin_path . 'ui.droppable.js', array('jquery-ui-draggable'), '1.7.1');
wp_enqueue_script('nav-menus', $plugin_path . 'admin.js', array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-livequery'),  '20090422');

I eventually tossed everything into the footer and things worked fine:

wp_enqueue_script('jquery-livequery', $plugin_path . 'jquery.livequery.js', array('jquery'),  '1.1', true );
wp_enqueue_script('jquery-ui-droppable', $plugin_path . 'ui.droppable.js', array('jquery-ui-draggable'), '1.7.1', true);
wp_enqueue_script('nav-menus', $plugin_path . 'admin.js', array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-livequery'),  '20090422', true);

... but I still believe it's a genuine bug.

My script depends on draggable and sortable, both of which land in the footer according to WP. Mine would seek to initialize before the footer scripts, and would miserably fail as a result.

To maintain backwards compatibility, footer scripts that are depends of scripts that are required in the header should be treated as header scripts.

Attachments (2)

9620.diff (1.7 KB) - added by Denis-de-Bernardy 9 years ago.
break-widgets.zip (869 bytes) - added by Denis-de-Bernardy 9 years ago.

Download all attachments as: .zip

Change History (8)

#1 @Denis-de-Bernardy
9 years ago

attached is a potential fix, which works. but I just thought of a better way.

specifically, instead of being overriding when registered, they should be overridden when enqueued.

#2 @Denis-de-Bernardy
9 years ago

  • Keywords has-patch dev-feedback added

#3 @azaozz
9 years ago

This is handled in the WP_Dependency class and seems to work properly here. Perhaps it's failing somewhere else. Some more info would help.

#4 follow-up: @Denis-de-Bernardy
9 years ago

the attached plugin will hopefully convince you.



#5 @azaozz
9 years ago

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

(In [11058]) Queue all default scripts for the head when a custom script lists them as dependencies, fixes #9620

#6 in reply to: ↑ 4 @azaozz
9 years ago

Replying to Denis-de-Bernardy:

the attached plugin will hopefully convince you.

It was moving only the first level of dependencies so in custom_scr->ui.draggable->ui.core->jquery only the ui.draggable would have been moved from the footer to the head.

Note: See TracTickets for help on using tickets.