Plugin load order, and actions..

Hi there,

As some might know I have worked on a extended importer for MarketPress.

To extend the standard import function in MP I had to extend the 'MarketPress_Importer' class, but I got some problems due to the order the plugins loaded. At least, that was what I thought was the problem.. (my workaround was to replace the complete core file in MP).

When my plugin loaded I got an error saying the MarketPress_Importer class was not existing, so I assumed my plugin was loaded before MP was.. but I was wrong. Not wrong about the load order, but the importance of the plugins load order.
I assumed MP loaded the class directly, but MP uses the 'plugins_loaded' action to load the import function. This make sure all activated plugins is loaded before the functions is. So what I had to do was to load my extended importer the same way, but with a priority lower (higher number) than the standard function to make sure my was loaded after the standard one, to extend it.

The action who load the importer in MP has no priority set, so the default is set to 10. But to make sure my is loaded after this one no matter what the priority is set in MP core code, I have to make sure..

By using the php function 'has_action' I can read the priority from the action and set my action to a priority with a higher number.

$priority = has_action( 'plugins_loaded', 'load_importers');
if ($priority == '') $priority = 10;
add_action( 'plugins_loaded', 'load_ext_importers', $priority + 1);

This code make sure my action runs after the action in MP to create the 'MarketPress_Import' class.

So what have I learned in this lesson:
- how to make sure all plugins are loaded before my code is run
- how to check the priority of an existing action
- how to set priority of my own actions

I have also tested a nice plugin to find and to set the load order of all plugins: Plugin Organizer

Espen