• 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

    (@zafrir_ron)

    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.