The MU forums have moved to WordPress.org

Supporting subdirectories in mu-plugins (8 posts)

  1. zappoman
    Member
    Posted 17 years ago #

    I've written a mu-plugin that adds the behavior of loading plugins from subdirectories. More info here...

    http://heftagaub.wordpress.com/2007/04/06/supporting-subdirectory-plugins-in-wordpressmu/

  2. drmike
    Member
    Posted 17 years ago #

    Interesting. I thought there was a reason why we didn't have subdirectories within mu-plugins though.

  3. zappoman
    Member
    Posted 17 years ago #

    Well, so far this works for me. There are some other differences. Mu just loads all php files... (this code acts like MU in that regard)... WP normal plugins, checks for Plugin info, etc.

    I guess the reason to cut down on some of these features for the mu-plugins directory is so that you don't go crazy adding lots of plugins, since as has been discussed many times before, mu-plugins are loaded on every page, etc. etc.

    But, that being said, if you're still paying attention to what you add, this small change just gives a little more flexibility.

  4. zappoman
    Member
    Posted 17 years ago #

    There are definitely other details about plugin behavior that this plugin doesn't handle. So if people just assume they can drop this in, and *everything* will work perfectly out of the box... well... that's just not how life works.

    For example, I just noticed one obscure corner case... this is obscure, because the codex advises against people doing this anyway for style reasons... but if you add a new Top Level admin page, then MU will require that the pages "file" (the 4th parameter to add_menu_page) must be in the mu-plugins directory. It will not work if it's in a subdirectory.

    So, maybe Dr. Mike, the reason that mu doesn't support subdirectory based plugins by default has to do with this any many other small details that the core mu team decided weren't worth the trouble in v1.x to implement.

    I would tend to agree with them...

  5. Ovidiu
    Member
    Posted 17 years ago #

    btw. when I first tried this, sk2 (the modified wpmu version) went crazy, it seems like this plugin tried to load all sorts of files from the sk2 folder situated in mu-plugins.

    can't give more details as I was workign from my mobile phone and had to abort the test...

  6. zappoman
    Member
    Posted 17 years ago #

    Ovidiu,

    This is likely because the mu-plugins will 'include' ALL php files in the directory... that's the behavior I kept. I suspect SK2 is more designed as a normal plugin where only the file's with a plugin header are assumed to be included.

    It would be easy to make another version that only loads those plugins with plugin headers. I was also considering making something like the plugin management UI that allows site admins to specify which plugins they want turned on.

    If I do this, then I'd also want to take it a step further and let you from the admin panel control which blogs the plugins run for. It would be a cool way of implementing "paid for upgrades"... basically as a site admin, you could turn on some plugins for blogs that have paid for the "bonus package" or something.

    Anyway, that's down my feature list a ways.

  7. Ovidiu
    Member
    Posted 17 years ago #

    WOW - thats all one could wish for a system were one also can pay for features...

  8. zappoman
    Member
    Posted 17 years ago #

    I've updated the subdir-mu-plugins Plugin to behave a little bit more like WordPress's plugins and a little less like WordPress MU's plugins. The latest version (0.42.2) can be found here.

    More detail about this plugin and the change can be found here:

    http://heftagaub.wordpress.com/2007/04/26/new-version-of-sub-directory-plugin-now-acts-more-like-wordpress/

    Here's a little background:

    WordPress single instance will only load files that have the “Plugin Name:” directive. This is partly related to the fact that WordPress supports disabling plugins through a user interface. WordPressMU supports this feature as well for the plugins placed in the "wp-content/plugins" directory. But these plugins are enabled and disabled on a blog by blog basis. For those plugins in "wp-conten/mu-plugins" it will load all PHP files. So for example, if a plugin has extra support PHP files that aren’t safe to load all the time (but can be loaded at the right time by the plugin for example) these types of plugins don’t work well in WordPressMU.

    My original version of this subdirectory plugin was intended to mimic the original WordPressMU behavior of loading all php files. Well, this seemed like a good idea at the time, but really the point of this plugin was to allow you to use more WordPress (non-MU) designed plugins... those that lived in subdirectories. And well, many of those plugins also depend on WordPress's behavior of not loading PHP files that don't contain the "Plugin Name:" directive. So I've decided this original behavior wasn't the best idea.

    The new version will scan subdirectories and attempt to read the plugin-info from all PHP files and only load those PHP files who have a "Plugin Name" directive.

    I’ve now changed the behavior of this subdirectory loading plugin to behave a little more like WordPress. Namely it will only load files from subdirectories that have a “Plugin Name” directive.

About this Topic

  • Started 17 years ago by zappoman
  • Latest reply from zappoman