[wp-hackers] Plugins and network activations

John Blackbourn johnbillion+wp at gmail.com
Tue Jun 28 12:21:48 UTC 2011


On 28 June 2011 12:42, Dino Termini <dino at duechiacchiere.it> wrote:
> Hi all,
>
> I've developed a plugin for Wordpress that needs some extra tables in order
> to work properly. A few users have complained that when they try to
> "network-activate" it, it only works on the main blog.
>
> So I found this discussion about how Wordpress should support these
> activations, but I don't understand how we plugin developers should handle
> the activation process
>
> http://core.trac.wordpress.org/ticket/14170
>
> Can someone please elaborate on it, maybe posting an example or a snippet of
> code?

This [1] is the code I use in one of my plugins. Basically you detect
if the activation is network-wide or not, and loop over each blog,
installing the tables in turn.

*Beware* though, that this code is likely to timeout (ie. hit PHP's
script execution time limit) if you have hundreds of blogs in your
network, especially if you're adding tables to each blog. My plugin is
only deployed in controlled environments so I know it'll be fine. If
your plugin is going to be made publicly available you should look
into a method similar to what scribu does in his Proper Network
Activation plugin [2].

John

[1] http://pastebin.com/QeeXXRKD
[2] http://wordpress.org/extend/plugins/proper-network-activation/


More information about the wp-hackers mailing list