The MU forums have moved to WordPress.org

Modified Main Site plugin hack. mu-plugins per blog (5 posts)

  1. nolageek
    Member
    Posted 16 years ago #

    I've been using this code the last few days:

    /////////// my-plugins hack
    
    $plugins2 = glob( ABSPATH . 'wp-content/mu-'.$blog_id.'-plugins/*.php' );
    if( is_array( $plugins2 ) ) {
    foreach ( $plugins2 as $plugin2 ) {
    if( is_file( $plugin2 ) )
    include_once( $plugin2 );
    }
    }
    
    /////////// end my-plugins hack

    This way i can create a diretory called mu-x-plugins where x is the blog_id - to fine tune any plugins that I need to. Working great so far. put it right after this bit of code in wp-settings.php:

    $plugins = glob( ABSPATH . MUPLUGINDIR . '/*.php' );
    if( is_array( $plugins ) ) {
    	foreach ( $plugins as $plugin ) {
    		if( is_file( $plugin ) )
    			include_once( $plugin );
    	}
    }

    I'm only using it for a few blogs, but has been useful to clear out the mu-plugins folder a bit.

  2. lunabyte
    Member
    Posted 16 years ago #

    For those not desiring to hack a core file, you can create something like zzz.php in mu-plugins (zzz so it loads last), and use it that way.

    We discussed it in the original thread.
    http://mu.wordpress.org/forums/topic.php?id=3026&page&replies=43

    Although, I'd have to say with the minimum amount of code it requires, it's more efficient than reading in another file.

  3. nolageek
    Member
    Posted 16 years ago #

    luna, I took it s step forward so theoretically you could create a special 'mu-plugins' for each blog, just by creating a directory using the blog_id - such as mu-21-plugins or mu-17-plugins. Obvious to some, but I just did it so i figured I'd put it out there. You could do this as a plugin as well, I supposed.

    I toyed with doing the same with regular plugin type directory (that would allow you to create these directories but the kind where they'd show up in only the one blog's Plugin menu, to be activated, but that didn't work as I planned. :)

  4. lunabyte
    Member
    Posted 16 years ago #

    Right, which is cool and a nice improvement.

    Just wanted to throw out that it "could" be placed in mu-plugins vice editing a file (queue the dreadful music), which it seems some people have a real problem against.

    Although for something of this nature, I'd rather edit a file. It's small enough that it's more efficient than reading in yet another file every time. If it was a couple hundred lines, in this situation I'd opt for the second file, but only a couple makes more sense to edit it, and add it to your list of changes durning an upgrade.

  5. andrea_r
    Moderator
    Posted 16 years ago #

    I second the cool factor. I thought it was a great idea. :)

About this Topic

  • Started 16 years ago by nolageek
  • Latest reply from andrea_r