Optimize mu-plugins folder?

This is probably a crazy idea, but anyway ... I will ask anyway :slight_smile:

So basically all plugins in the mu-plugin folder are being ran every time a page is loaded, if it is an admin page are not.

Is it possible and helpful to to something like that:

1. put all plugins in a subfolder, like mu-plugins/plugins

2. create one "plugin" file where you have conditions, when all the plugins should be used, like one conditions for dashboard, one for options-general.php ... and so on.

In that case only plugins would run when they are used.

What do you think? Does it make any sense?

  • Aaron
    • CTO

    I agree Andrew. Especially if you have a php accelerator/opcode cache installed. 90%+ of the opportunity for speeding things up is in tuning and minimizing db queries.

    That's where a plugin can really screw things up. Like looping through each blog and querying it's options without caching it.

  • Enseignement
    • Design Lord, Child of Thor

    Hello,
    I found, a few years ago (already :slight_smile: ), a pretty useful script that allows to have a plugin directory that is only available to me.

    In mu-plugin, i had this file my-plugin.php

    <?php
    define( 'MAINPLUGINDIR', 'wp-content/my-plugins' );
    if ( $blog_id == 1 ) {
    $plugins2 = glob( ABSPATH . MAINPLUGINDIR . '/*.php' );
    if( is_array( $plugins2 ) ) {
    foreach ( $plugins2 as $plugin2 ) {
    if( is_file( $plugin2 ) )
    include_once( $plugin2 );
    }
    }
    }
    ?>
    That allowed me to have a my-plugins dir, which is useful to test plugin first, but also to have only plugins not in mu-plugin but only for me.
    This worked until 2.6 version, but not anymore, I don't know why.

    Maybe good to see why and update the script. Please Share if you found the bug...

    Thanks

  • Ovidiu
    • Code Wrangler
    <?php
    /*
    Plugin Name: my-plugins folder hack
    */
    if ( $blog_id == 1 ) {
    $plugins2 = glob( ABSPATH . 'wp-content/my-plugins/*.php' );
    if( is_array( $plugins2 ) ) {
    foreach ( $plugins2 as $plugin2 ) {
    if( is_file( $plugin2 ) )
    include_once( $plugin2 );
    }
    }
    }
    ?>

    works for me. has been working actually for quite a while.

    additionally I have another folder admin-plugins which gets loaded only on the back end side of wpmu:

    <?php
    /*
    Plugin Name: WPMU Director
    Plugin URI: http://realestatetomato.com/wpmu-director
    Description: Adds an extra folder for mu admin-plugins
    Version: 1.0
    Author: Jason Benesch
    Author URI: http://realestatetomato.com/
    */
    
    if(is_admin()) {
    	if( defined( 'ADMINPLUGINDIR' ) == false )
    		define( 'ADMINPLUGINDIR', 'wp-content/admin-plugins' );
    
    	if( is_dir( ABSPATH . ADMINPLUGINDIR ) ) {
    		if( $dh2 = opendir( ABSPATH . ADMINPLUGINDIR ) ) {
    			while( ( $plugin = readdir( $dh2 ) ) !== false ) {
    				if( substr( $plugin, -4 ) == '.php' ) {
    					include_once( ABSPATH . ADMINPLUGINDIR . '/' . $plugin );
    				}
    			}
    		}
    	}
    }
    ?>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.