Batch Import blog on wordpress multisite

There is a bug that deny to import blog in batch mode with wpmu_create_blog or create_empty_blog.

If you try this code:
define('WP_USE_THEMES', false);
require_once('../wp-blog-header.php');
if(!defined('WP_IMPORTING')) define('WP_IMPORTING', true); // required to bypass control existing_user_email
foreach($toImport as $blog) {
    $blog_id = wpmu_create_blog(
DOMAIN_CURRENT_SITE,
PATH_CURRENT_SITE . $blog['path'],
$blog['title'],
1,
'',
SITE_ID_CURRENT_SITE
);
}
It creates only first blog, with relative table wp_$blog_id_terms/options ..., caused by this bug.

I tried this patch with Wordpress 3.1.4  and it works.

The file to modify is wp-includes/wpmu-functions.php adding this line after function wpmu_create_blog:
global $wpdb, $wp_queries;
and after switch_to_blog($blog_id); this code:
if($wp_queries){
    $pattern = '/' . $wpdb->base_prefix . '(\d+)/';
    $prefix = $wpdb->base_prefix . $blog_id;
    $wp_queries = preg_replace($pattern,$prefix, $wp_queries);
 }
Same with create_empty_blog

Commenti