Creating Tables on Network Activation

I’m working on a plugin which creates a new table. I’ve got it working fine on a single site install, but I’m not so sure about multisite.

How do I create a table for each blog on network activation?

Related posts

Leave a Reply

1 comment

  1. I would actually advise against doing that.

    If you create a table for each blog on network activation you’ll start running into scalability issues. Some Multisite networks are small (2-10 sites) and wouldn’t cause too many issues. But larger networks (1000+ sites) would add a lot to the database if they added their plugin.

    Instead, I’d recommend creating a single table and adding a “blog_ID” column to the table. If you’re running a single site installation, just set that column to be 0 and run everything normally. But on a Multisite installation, set that column to whatever blog is using that data.

    A single table is easier to manage.

    Besides, if you create a new table for each blog, not only do you need the massive creation script when first activating the plugin, but you need to hook into the site creation mechanism to create a new table whenever a site is created.