In my plugin, I want to test to see if jQuery or Prototype (or both) are going to be loaded by another plugin. So, have wp_enqueue_script('jquery')
or wp_enqueue_script('prototype')
has already been called.
I have code appropriate to my plugin in files plugin.prototype.js
and plugin.jquery.js
and if Prototype is queued, my plugin will use plugin.prototype.js
. This way I avoid loading more than necessary into the site. If neither has loaded, I will queue up whichever is smaller.
How can I test to see what has been queued up? How do I make sure my code runs last?
Use
wp_script_is()
to check if a script is in the queue.To make sure your code runs after jQuery or Prototype is loaded, use the
$deps
parameter towp_enqueue_script
, and pass eitherarray('jquery')
orarray('prototype')
. If you want to know whether a script is in the queue, you can use thequery()
method ofWP_Dependencies
(which is the superclass ofWP_Scripts
). So something like this should work:Of course, plugins could enqueue them after you decided on one, so try to make sure you execute this check at the last possible moment.