It has been an enjoyable experience delving into the inner workings of WordPress of late. And it has been during the development of one of our recent projects, the ‘WP Content Filter’, our first WordPress Plugin by the way , that we have come across some unanticipated subtleties.
For instance, any WordPress Plugin is free to access hooks that are exposed by the core WordPress code. Well, this is the whole point isn’t it? To be able to customise the functionality of your blog site over the default WordPress installation.
However, what happens when two Plugins access the same filter hook to, say, do some custom formatting of post comments. If there is an overlap in two (or more) Plugins functionality then it is likely they will all want to access a common WordPress Plugin hook. In this case which one is run first? Is there anyway to force you Plugins code to run before (or after) any others? Would that even be ethical. Or, is it completely ambiguous and decided by the Plugin attributes (such as the order that Plugins were installed on your WordPress blog).
As far as I am aware there are no hooks exposed by WordPress to control this. Perhaps more unpredictable is the behaviour resulting from action Plugin hooks. Plugin code running on a WordPress ‘event’ for more than one Plugin could have very strange results, and the likely culprit for conflicts between Plugins.
Perhaps in the future of WordPress there could be some way to allow the user of Plugins (i.e. site administrators) to be able to set which Plugins have priority over other Plugins. This could be handled in two ways:
- At at a more basic level, simply specifying which Plugins had precedence (assuming Plugins access common hooks) over other.
- Or, at a more advanced level, allowing the administrator to control precedence on a hook by hook basis – specifying which Plugins accessing these hooks have priority.
This would give administrators more flexibility by giving them an option to change Plugin execution order, rather than just having one course of action – namely, to uninstall one or more Plugins to prevent conflicts occuring.
I stated above that this would have to be controlled by the site administrator and not the Plugin developer, as every developer would want to add their Plugin to be of highest priority! Wouldn’t they? Such functionality would probably have to be added to the WordPress core as it may not be a good idea (for the above reasons) to expose Plugin execution priority as a new hook.
Anyway, enough rambling. Any thoughts…?