[wp-hackers] Best practices for updating plugin options network-wide

Otto otto at ottodestruct.com
Thu Sep 8 14:36:19 UTC 2011

On Thu, Sep 8, 2011 at 8:40 AM, Dino Termini <dino at duechiacchiere.it> wrote:
> I've developed some plugins that have full support for WPMU. As for most
> plugins out there, I have some options to keep track of, so I stored them in
> the "local" options table for each blog in the network (add_option,
> get_option). Now some users are asking me to implement a functionality to
> allow them to change/override the value of some of these options
> network-wide, while keeping the freedom for single blog administrators to
> further customize them. How would you implement this? How about a foreach
> ($blogids as $blog_id) ?

Use add_site_option and get_site_option to store selected options
globally, then merge the local options with the global ones when you
load them.

Assuming you use arrays of options, something like this would work:

$options = wp_parse_args( get_option('my_options',array() ),
get_site_option('my_options',array() ) );

This way, if you have something in the sitewide array, it will be used
as the default unless the local options exists, in which case it
overrides it.


More information about the wp-hackers mailing list