The MU forums have moved to WordPress.org

How to convert regular Wordpress plugin to WPMU? (6 posts)

  1. c2h5oh
    Member
    Posted 15 years ago #

    Let's assume I've got a regular Wordpress plugin which I want to put in mu-plugins to be loaded automatically and I want to configure it once for all blogs. I can handle access control and menus, but can't figure out storing settings:

    If plugin tries to use it's own table(s) there is no problem - all I have to do is replace $wpdb->prefix/$table_prefix with $wpmuBaseTablePrefix in plugin code to have it use global tables (or change wpdb->prefix /table_prefix value before plugin code and restore it after).

    But what if all the settings are in options table? How do I force plugin to use wp_1_options or wp_options (after creating proper table)?

  2. lunabyte
    Member
    Posted 15 years ago #

    Don't use $wpmuBaseTablePrefix, use $wpdb->base_prefix.

    If a plugin needs its own tables, it may be storing data specific to an individual blog. If so, wpdb->prefix is fine, and what it should be.

    Change the xxx_option calls to xxx_site_option, and it grabs from the site options instead of the individual blogs, but only do that if there aren't setting a user can touch, or that would be relevant to specific blogs.

    Overall, every plugin is different. It depends on what it does, what it stores, and what a user can play with in terms of settings.

    As a note, however, use mu-plugins very sparingly. If it isn't something that every user needs on every single page load, leave it as a regular plugin.

  3. c2h5oh
    Member
    Posted 15 years ago #

    If a plugin needs its own tables, it may be storing data specific to an individual blog. If so, wpdb->prefix is fine, and what it should be.

    True. But I do want it to use a single, global set of tables, so $wpmuBaseTablePrefix is fine.

    Change the xxx_option calls to xxx_site_option, and it grabs from the site options instead of the individual blogs, but only do that if there aren't setting a user can touch, or that would be relevant to specific blogs.

    That's what I've been looking for! Thank you.

    As a note, however, use mu-plugins very sparingly. If it isn't something that every user needs on every single page load, leave it as a regular plugin.

    Sometimes on the other hand all the plugins will end up in mu-plugins - like my site with a roaring total of 3 plugins needed by every single user.

  4. lunabyte
    Member
    Posted 15 years ago #

    $wpmuBaseTablePrefix is not OK, it's deprecated.

    Use $wpdb->base_prefix instead.

    Yeah, three isn't bad. It's the ones where people just dump darn near everything in mu-plugins, and then wonder why their site runs so slow and runs thousands of db queries per page.

  5. c2h5oh
    Member
    Posted 15 years ago #

    I hear you. A while ago I've been doing some freelance - Joomla-based websites optimization - the worst site I've had contact with had 800+ queries AFTER caching has been enabled, 30 of them being 'like %$s%' on a table with ~ 20k rows..
    "I've got 1500 unique visitors a day and my dual xeon with 4gb ram can't handle it". Well duh. ;-)

  6. lunabyte
    Member
    Posted 15 years ago #

    Ewww... you said the J word. :)

About this Topic