Registering and enqueueing on the same action can cause enqueueing to happen before registering
|Reported by:||nbachiyski||Owned by:|
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 _enqueue_scripts action.
There is a chance that enqueueing in Plugin2 will happen before registering in Plugin1 and therefore fail.
- 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.