[wp-hackers] populate_option : wpmu-upgrade vs freshly created blog

Raphaël Droz raphael.droz at gmail.com
Tue Mar 23 08:10:16 UTC 2010


Potkanski, Jason wrote:
> The Populate_options hook is called before the actual blog defaults are stored. Any defaults set here will just get overridden with schema defaults.
>   
In schema.php I saw this :
 if ( in_array($option, $existing_options) )
                        continue;
So if the option is set before it won't be overriden
(except for the blog_public option which is handled differently)
> If you are looking for how to set default blog options programmatically, hook wpmu_new_blog.
>
> Here is a code sample on how to hook into wpmu_new_blog:
>
> add_action( 'wpmu_new_blog', 'set_default_options', 10 , 2 );
>
> function set_default_options($blog_id, $user_id) {
>     set_default_general_settings($blog_id);
> }
>
> function set_default_general_settings($blog_id) {
>     update_blog_option($blog_id, 'timezone_string', 'America/New_York');
> }
>
> I set defaults for serialized plugin data like recaptcha as well. It's a pretty simple technique.
>   
update_blog_option avoid the need to switch_blog again that's right
> There is a "Blog Defaults" MU plugin out there as well.
>   
and for the theme, this plugin switch_blog() again but that no more appears
to me an inelegant step thus I will use it : with this hook I'm sure 
nothing will
mess up at upgrade time.

Thank you for the clarifications Jason,
my next step is to look around widgets but that's another story.

Raph
> --
>
> Jason Potkanski
> Tribune Technology
>
>
>
> On 3/22/10 10:53 AM, "Raphaël Droz" <raphael.droz at gmail.com> wrote:
>
> All is in the title,
> while I would like to change the default options of a blog  I observed
> that the populate_option hook is also used at upgrade.
>
> Should I use some kind of workaround like comparing the creation date ?
> Or should I forget about the wpdb->query and use update_option's in the
> wpmu_new_blog hook which, apparently until now, is only used at the blog
> creation time.
> In this latter case, I would be out-context and, to, eg, switch the theme or
> add a post, I would have to switch_blog() again.



More information about the wp-hackers mailing list