Creating multiple blogs

Apparently a global variable is not properly updated. I found a fix based on blackriver’s reply here, it’s a little ugly but it works:

add_action('switch_blog', 'fix_wpmu_create_blog', 10, 2);
function fix_wpmu_create_blog($new_blog_id, $old_blog_id){
  global $wpdb, $wp_queries;

  if($wp_queries && defined('FIX_WPMU_CREATE_BLOG')){
    $old_pattern = $wpdb->base_prefix.$old_blog_id.'_';
    $new_pattern = $wpdb->base_prefix.$new_blog_id.'_';
    $wp_queries = str_replace($old_pattern, $new_pattern, $wp_queries);
    //echo '<pre>';
    //print_r($wp_queries);
    //echo '</pre>';
  }
}

and

define('FIX_WPMU_CREATE_BLOG', true);

somewhere in the code that’s using this function.

If someone has a better solution please post it so I can accept an answer 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)