From ba79e04c10c89e71fa0438e778b8cc3eb44063ed Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 15 Oct 2012 21:41:29 +0000 Subject: [PATCH] In populate_network(), distinguish between upgrading from single to multisite and creating a new network in an existing multisite environment. When creating a new network steps related to setting up the main site must be skipped since the main site is created after populate_network() runs. Further, the global should not be modified since populating a new network does not involve switching to that network and making it current. fixes #22090 git-svn-id: http://core.svn.wordpress.org/trunk@22240 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index d70790b149..7347290230 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -926,25 +926,27 @@ We hope you enjoy your new site. Thanks! } $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); - $current_site = new stdClass; - $current_site->domain = $domain; - $current_site->path = $path; - $current_site->site_name = ucfirst( $domain ); - - if ( !is_multisite() ) { + // When upgrading from single to multisite, assume the current site will become the main site of the network. + // When using populate_network() to create another network in an existing multisite environment, + // skip these steps since the main site of the new network has not yet been created. + if ( ! is_multisite() ) { + $current_site = new stdClass; + $current_site->domain = $domain; + $current_site->path = $path; + $current_site->site_name = ucfirst( $domain ); $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) ); - $blog_id = $wpdb->insert_id; + $current_site->blog_id = $blog_id = $wpdb->insert_id; update_user_meta( $site_user->ID, 'source_domain', $domain ); update_user_meta( $site_user->ID, 'primary_blog', $blog_id ); + + if ( $subdomain_install ) + $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + else + $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); + + flush_rewrite_rules(); } - if ( $subdomain_install ) - $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); - else - $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); - - flush_rewrite_rules(); - if ( $subdomain_install ) { $vhost_ok = false; $errstr = '';