update_option fails after switching blog (2 posts)

  1. virgodesign
    Posted 1 year ago #


    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)
      update_option('hw_option', 'hello word!');//fails to store into blog_id
      //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.

  2. David Sader
    Posted 1 year ago #

    I offer what I have used to set some new options when a new blog is created.

    I use the 'populate_options' action hook:

    add_action('populate_options', create_function('$a', 'return update_option("hw_option", "hello word!");'));

Topic Closed

This topic has been closed to new replies.

About this Topic