Ready to get started?Download WordPress


WP 3.0, initialize data while network activating a plugin (2 posts)

  1. laceous
    Posted 4 years ago #

    Hi, I'm trying to determine if the following issue is by design or a possible bug.

    Assume you have a 3.0 multisite install. A plugin you're trying to activate initializes some data in the database like this:

    function myplugin_activate() {
      update_option('key', 'value');
    register_activation_hook( __FILE__, 'myplugin_activate' );

    (Obviously this is a very simple example, but you get the idea)

    If you go to every site in your network and activate the plugin then the option will be added to the database for each site (wp_options, wp_2_options, wp_3_options, etc). However, if you choose the "network activate" option then the option is only added to the database for the current site (e.g. wp_2_options). Is this a bug or by design? I can understand how looping through each site in your network might be expensive, but maybe cron jobs could be generated?

    If this is by design, are there any recommended "best practices" for plugin authors?

    An obvious work-around is to not use the "active_" hook, but instead check for an option in the database on plugin/page load (e.g. get_option). If the data doesn't exist then go ahead and initialize it.

    Also, in certain cases you might want to use the get|add|update|delete_site_option functions instead (which uses the wp_sitemeta table for network-wide options).


  2. I *think* (from fuzzy memory here) what is supposed to happen is they plugin gets activated for real when the owner of the blog logs in to the backend of their blog (site).

    Depending on what the plugin does, you might consider placing it in the mu-plugins folder instead.

Topic Closed

This topic has been closed to new replies.

About this Topic