I'm trying to figure out some kind of mechanism to load plugins on demand, depending on the page url, to improve performance.

My primary concern is that I have some admin-ajax.php calls that are recurring while the user is active on the page. I tried profiling these calls, and discovered that the majority of plugins loaded for the ajax call were unnecessary.

While I could use is_admin() to identify an ajax call, I wish to leave WordPress and plugin code intact. Plus, is_admin() does not differentiate between an ajax call and admin panel.

I've been looking into the plugin loading procedure. I only saw 'muplugins_loaded', 'plugins_loaded' actions, no filters to tap into the loading process. I checked wp_get_active_and_valid_plugins and it appears the only way to change plugin loading is to update_option('active_plugins') explicitly, which is not a viable option. Other things are hard coded.

(I'd like to mention that this plugin http://wordpress.org/extend/plugins/selective-loading/ use the update_option method, which in my opinion is only suitable in a non-ajax environment, or otherwise the option change wouldn't be atomic.)

I'm wondering if there was still some way to implement selective plugin loading?

  • Give that the selective-loading plugin bases the loading of the URLs to the site it should be viable to use with AJAX as well, might be wrong though. Commented May 7, 2013 at 20:31

2 Answers 2


Filter option_active_plugins. You can change the result of get_option() here without actually changing the database.

if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
    add_filter( 'option_active_plugins', 'disable_plugins_temporary' );

function disable_plugins_temporary( $plugins )
    // unset plugins you don't need, then

    return $plugins;


wp_get_active_and_valid_plugins() calls get_option( 'active_plugins', array() ) to get the active plugins. In get_option( $option, $default = false ) we find this filter:

return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );

So the resulting name for our filter is option_active_plugins.


I'm not sure if this will help you with your ajax call, but Plugin Organizer is a well-supported plugin that enables the selective loading of other plugins based on URL. It works great on my site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.