[wp-hackers] Prioritizing Function Hooks

Mike Schinkel mikeschinkel at newclarity.net
Wed Dec 7 15:59:02 UTC 2011


On Dec 7, 2011, at 10:47 AM, Alison Foxall wrote:
> How would you prioritize a function hook when the particular
> hook is used by multiple plugins?  e.g.
> 
> Plugin One:
> 
> add_action ("pre_user_query", "plugin_one_pre_user_query");
> 
> Plugin Two:
> 
> add_action ("pre_user_query", "plugin_two_pre_user_query");

Do they need to be prioritized?  Best if not, but if you must then the 3rd parameter sets priority, with the default priority being 10.  So to get Plugin One to fire AFTER Plugin Two use any number larger than 10:

Plugin One:
add_action ("pre_user_query", "plugin_one_pre_user_query", 11);

Plugin Two:
add_action ("pre_user_query", "plugin_two_pre_user_query");

Of course plugins that must be loaded before others should be avoided whenever possible because multiple plugins might get the order wrong and it can be a mess, although sometimes setting priority can't be avoided.

Hope this helps.

-Mike


More information about the wp-hackers mailing list