[wp-trac] [WordPress Trac] #21134: Registering and enqueueing on the same action can cause enqueueing to happen before registering
WordPress Trac
wp-trac at lists.automattic.com
Mon Jul 2 11:00:17 UTC 2012
#21134: Registering and enqueueing on the same action can cause enqueueing to
happen before registering
--------------------------+-----------------------------
Reporter: nbachiyski | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.4
Severity: normal | Keywords:
--------------------------+-----------------------------
We have two plugins, plugin1 and plugin2. Plugin1 registers a script,
Plugin2 wants to enqueue this script. Both of these routines are executed
on the [http://wpdevel.wordpress.com/2011/12/12/use-wp_enqueue_scripts-
not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/
_enqueue_scripts] action.
There is a chance that enqueueing in Plugin2 will happen before
registering in Plugin1 and therefore fail.
Possible fixes:
* Every time we enqueue a script, registered in another plugin, we use a
higher priority. I am not a fan of this approach, because it is opaque –
we need to document each enqueue like this, because the next developer
might not know why did we use higher priority.
* Every time we register a script, we use a lower priority. I am not a fan
of this either, because we will have to do this for almost every register,
because we can't know if another plugin won't try to enqueue our scripts.
* Violate core recommendation and register the script on an earlier hook.
I am not a fan of approach for obvious reasons.
* Add {{{_register_scripts}}} hooks and recommend plugin authors to
register their scripts at this time.
I would prefer if we added another set of hooks, because it both makes
sense to register on a register hook (as opposed to enqueue hook) and it
separates the two actions, so that we can execute them at different times.
When we agree on a solution, I would be happy to write the patch.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21134>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list