• hi,

    I’ve a wordpress multisite environment and in the functions.php of the primary blog I setup this action, that will run after a brand new blog is created.

    function register_new_blog_option($blog_id, $user_id, $domain, $path, $site_id, $meta)
    {
      switch_to_blog($blog_id);
      update_option('hw_option', 'hello word!');//fails to store into blog_id
      restore_current_blog();
    
      //this works and store value in wp_options
      update_option('hw_option', 'hello word!');
    }
    add_action('wpmu_new_blog','register_new_blog_option', 10, 6);

    But it doesn’t work.
    The action is executed but the option is not stored.
    Even if I use update_blog_option it fails.
    It seems like the switch_to_blog function fails or something goes wrong.

    Any ideas or am I missing something?
    Thank you very much in advance.

Viewing 1 replies (of 1 total)
  • I offer what I have used to set some new options when a new blog is created.

    I use the ‘populate_options’ action hook:

    <?php
    add_action('populate_options', create_function('$a', 'return update_option("hw_option", "hello word!");'));
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘update_option fails after switching blog’ is closed to new replies.