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


  • Imperative Ideas
    • HummingBird

    That’s a great tip. I recently took a first read through Professional WordPress Plugin Development by Brad Williams, Ozh Richard, and Justin Tadlock. I now have to read it again, slower, and actually digest it all. This should be required reading for all plugin developers.

    The top reviewer on Amazon sums it up nicely:

    A formula for success:

    1. Put together an idea and outline for a book that hasn’t been covered in-depth before.

    2. Gather three of the most talented WordPress developers/writers and have them write the book.

    3. Release the book and watch the Elves return back to Middle Earth to rejoice with men.

    Anyhow, for an in depth look at loads more issues just like this – if you haven’t checked out the book – it’s worth owning (I bought mine for Kindle).

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.