[wp-hackers] Make a function available to other plugins

Mike Schinkel mikeschinkel at newclarity.net
Sun Sep 18 22:39:07 UTC 2011


> On Aug 10, 2011, at 6:12 AM, Alex Hempton-Smith wrote:
>> I'm developing a plugin that other plugins can integrate with, they will
>> need access to a function within my plugin. Obviously, if their plugin is
>> loaded before mine, it will result in an error. How do I ensure that my
>> plugin will be loaded first?
>> 
>> Likewise, if I want to build in some compatibility with another plugin
>> (BuddyPress), how do I make sure that is loaded before mine?
>> 
>> I could use 'plugins_loaded' with a high priority, but that doesn't seem
>> very foolproof to me?

Stephen Rider's suggestion to create your own hooks with "do_action()" is a great way to handle extensibility. 

However, you should also code your plugins such that they have no dependencies until ON or AFTER the 'plugins_loaded' and 'muplugins_loaded' hooks fire. And you should initialize the independent aspects of your plugin for each page load using the 'init' and 'admin_init' hooks so they are ready for the code that you want to run in the plugins_loaded hook.  

If you follow these approaches you should (almost never?) run into any conflicts with load order. Hope this helps.

-Mike


More information about the wp-hackers mailing list