WordPress.org

Ready to get started?Download WordPress

Forums

writing a network plugin with custom database (12 posts)

  1. msolution
    Member
    Posted 3 years ago #

    hi,
    in the process of writing a plugin for > 3.0, and it has to be a network plugin, and im in the need of a custom database.

    the option page for this plugin has a list of links, where every blog owner should have the ability to build his own independent list. (add/edit/delete),

    Objective: i want to restrict it to one database for all sites

    there are loads of tutorials for using custom database for wordpress, but none found for wpmu, if any one could point me in the right direction.

  2. A completely separate database, or do you mean a separate table (or group of tables) which would be easier.

  3. msolution
    Member
    Posted 3 years ago #

    oops,.... sorry ... i meant tables :)

    also some light on
    $network_id vs $site_id vs $blog_id

    :)

  4. site_id is the ID of the entire network. Not an individual site.

    Blog_is is one of the included sites on the network.

    basically, you'll be making a global table, and not putting it in the blog-specific tables. also, you'll want to either force network activation or have it run from the mu-plugins folder.

  5. msolution
    Member
    Posted 3 years ago #

    no comprehendo :(

    by "site" do u mean restricted to one domain, like
    http://www.domain.com/blog1/
    http://www.domain.com/blog2/
    http://www.domain.com/blog3/
    ...
    ...

    or is it just a classification? then what is network_id,

    also ... so in my "table", i would just have to add a column "blog_id"?

    M.

  6. msolution
    Member
    Posted 3 years ago #

    i am forcing network activation, while it is still in the plugin folder.

  7. also ... so in my "table", i would just have to add a column "blog_id"?

    Yes, that would correlate to each of these:

    http://www.domain.com/blog1/
    http://www.domain.com/blog2/
    http://www.domain.com/blog3/

  8. msolution
    Member
    Posted 3 years ago #

    ok,

    and again do we have any write ups somewhere for network_id and site_id, am still not clear on those.... if you could help.

    M.

  9. You won't need network id, it's just a variable. site_id is the ID of the entire network. unless you want to support multiple networks, you won't need that either.

    current_site maybe.

    (No, there's no decent write ups)

    If you're letting each user create a list of links - why not use the internal Link Manager (blogroll)?

  10. msolution
    Member
    Posted 3 years ago #

    :) /links/ ... i did look into it, but i need a tad more elbow space here....

    Thanx for your help :)

    M.

  11. Ryan Willis
    Member
    Posted 3 years ago #

    If your plugin is not a "must-use" plugin and is installed to the plugins directory rather than mu-plugins, you'll need to keep a couple things in mind when creating your global tables.

    1. If you create the tables through a register_activation_hook callback, use $wpdb->base_prefix and not $wpdb->prefix to prefix your tables.
    2. If you register a deactivation hook to remove your tables, know that it will remove the tables when the plugin is deactivated for any blog, so you will need to add some kind of check to make sure the plugin is not activated elsewhere. I increment a site option whenever the plugin is activated in a blog and decrement it when it is deactivated in a blog. If the option is 0 or less, I remove the tables. I'm not sure this is the most efficient method but it does work.

    Hope this helps!

  12. msolution
    Member
    Posted 3 years ago #

    you'll want to either force network activation

    so how do i do that again?? :feelinDumb:

    completing the whole plugin i find my plugin still active for only the main site!

    what i have:

    deactivate_plugins($plugin);
    ....
    stuff : wp 3.0 =>wpmu
    ....
    activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, true);

    but since MULTISITE is already defined 'false' is wp-settings.php, it falls back to activating it for the site :(

    do we have a way out for this?

    @Ryan Willis - im just using hard coded prefix ('wpp_mpp_'), keeps away and still smells wordpress

    2. still have to test it but am using 'deactivate_plugin' action hook, and is_super_admin() and is_main_site() to skip things.

    the above is not a work-for-all solution, but the way my plugin works, this is what i found to be good (NOT tested though)

Topic Closed

This topic has been closed to new replies.

About this Topic