Title: Selective Plugin loading
Last modified: August 19, 2016

---

# Selective Plugin loading

 *  [zafrir_ron](https://wordpress.org/support/users/zafrir_ron/)
 * (@zafrir_ron)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/selective-plugin-loading/)
 * I noticed an old thread about it, never got a real discussion or solution.
 * The current plugin system is loading all active plugins regarless if they needed
   or not for the current page request (it can be admin only plugin or plugin that
   its process is done for specific page only).
 * The price of plugin load can be huge!!! (take wp-commerce plugin that you have
   a shop only on one page, this huge plugin is loaded for EVERY page request regardless
   if there is any shop related code on this page).
 * There must be a way to set up a selective plugin loading.

Viewing 1 replies (of 1 total)

 *  Thread Starter [zafrir_ron](https://wordpress.org/support/users/zafrir_ron/)
 * (@zafrir_ron)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/selective-plugin-loading/#post-1567215)
 * I suggest the following (sample) logic:
 * in “my_hacks.php” (or anywhere before wp-settings)
    set the load conditions (
   some will set a nice interface for this I suggest to add it as option to “Plugins
   Installed” page for every plugin to enable an option set of include/exclude comma
   separated url regexp )
 *     ```
       $uri = $_SERVER['REQUEST_URI'];
       $plugins_load = array(
       	'exclude-plugin.php' => array(
       		'exclude' => array('/.*url-part1.*/','/.*url-part2-page.*/')),
       	'include-plugin.php' => array(
       		'include' => array('/.*wp-admin.*/'))
       	) ; 
   
       function load_plugin($current_plugin) {
       	global $plugins_load;
       	$include = true;
       	foreach ($plugins_load as $plugin_name => $plugin) {
                       if ($current_plugin != $plugin) continue;
       		if (isset($plugin['include'])) {
       			$include = false;
       			foreach ($plugin['include'] as $inc) {
       				if (preg_match($inc,$uri)) $include = true;
       			}
       		}
       		if (isset($plugin['exclude'])) {
       			$include = true;
       			foreach ($plugin['exclude'] as $exc) {
       				if (preg_match($exc,$uri)) $include = false;
       			}
       		}
       	}
       	return $include;
       }
       ```
   
 * and in “wp-settings.php” inside the plugin loading loop add
    `|| !load_plugin(
   $plugin)` to the loading conditions by default all plugins will load as normal
   unless they added to the $plugins_load array.

Viewing 1 replies (of 1 total)

The topic ‘Selective Plugin loading’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [zafrir_ron](https://wordpress.org/support/users/zafrir_ron/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/selective-plugin-loading/#post-1567215)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
