Hooking in to plugins

@Ryan Elkins:

I guess the answer depends on how import each use-case is to you. In some cases it would be something you need quick-and-dirty, in others it might be a more significant use-case. Here are the two things that come to mind:

Look for Alternate Hooks within WordPress Core

If it’s something quick and dirty some times you can use other downstream hooks from core to modify what you need, or both upstream and downstream hooks via the use of ob_start()/ob_end_clean() (see @Todd Perkins answer to “Dealing with large HTML output via plugin code” for a code example.)

To track down the hooks you could use check out the Instrument Hooks plugin I posted yesterday to help you find the hooks that you can potentially use.

Submit a Patch with your Desired Hook to the Plugin Developer

If your use-case is more significant to you or the community I’d recommend going ahead and adding the hook that you need to the plugin. Then test it well to ensure it really addresses your use-case after which you can submit a patch to the plugin developer in hopes that he or she will apply it. This way you make it as easy as possible on them by giving them tested code and you get to work through the use-case yourself to ensure it is really what you need. I can’t tell you how often I thought I needed a certain hook only to find after trying to implement one I needed a hook but one that was different than I first envisioned.

If you are not familiar with creating a patch here is a good article on patching WordPress core for which most applies to patching plugins and for that which does not it will hopefully be obvious what to do:

Hope this helps?

P.S. One thing I find a bit disappointing and that your question addresses is the percentage of plugins that are designed only for end-users, i.e. that have no hooks of their own. Imagine if WordPress were designed like most plugins? It would be inflexible and a very niche solution.

Maybe things would be different if WordPress were to have the ability to auto-install plugins on which other plugins depended? As it is I typically have to write a lot of the functionality I need from scratch because clients want things a certain way and the available plugins, while 90% there don’t allow me the flexibility to update the remaining 10%.

I really do wish those leading the WordPress community would identify a way to ensure that plugins are rewarded for following best practices (such as adding in hooks for other developers) much like good answers are rewarded on a StackExchange site.

Leave a Comment