Wordpress - In what order does WordPress load plugin files?

Answer to the First question:

  1. In wp-settings.php, WordPress first checks for any must-use plugins (plugins in the optional mu-plugins folder) and loads those.

  2. Then, if you're running a multisite installation, it checks for plugins that are network-activated and loads those.

  3. Then it checks for all other active plugins by looking at the active_plugins entry of the wp_options database table, and loops through those. The plugins will be listed alphabetically.

Here's the order WordPress loads pretty much everything: http://codex.wordpress.org/Action_Reference#Actions_Run_During_a_Typical_Request

The thing is, it usually doesn't matter what order each individual plugin is loaded in, because properly-written plugins will use WordPress hooks, which let you plug in functionality into specific points later in the WordPress startup. (Properly-written plugins will also prefix their functions and classes so that there aren't any conflicts.)

More info on plugin API: http://codex.wordpress.org/Plugin_API/

Answer to the Second question:

Totally depends on the plugin. WordPress only loads one file in the plugin, the one that's usually named the-plugin-name.php and contains the title, description, author, etc. at the top. It's up to the plugin to load the rest of its files, using require_once and wp_enqueue_script and whatnot.


I find that it is useful to include a 'late loading' action in my plugin that runs after all plugins have completed their load like this:

add_action('plugins_loaded', 'my_late_loader');

The function my_late_loader then is initiated after all other plugins which allows me to use hooks defined by other plugins in my own function my_other_function which is initiated within my_late_loader

/**
 * Late loading function for actions that must run after all plugins 
 * have loaded
 */
function my_late_loader(){
    add_action( 'some_hook', 'my_other_function', 10, 1);
}

Bit convoluted (I know), but this ensures that hooks in other plugins are created before being added irrespective of the plugin load order.

Tags:

Plugins