From e40575aa99a7eb8095514d29999fd42407ebc745 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 7 Oct 2015 21:45:17 +0000 Subject: [PATCH] Correctly set the scheme of the `home` and `siteurl` options when creating a new site on multisite that uses some combination of HTTPS in the admin area or on the front end. Fixes #33620 Props tryon, johnbillion git-svn-id: https://develop.svn.wordpress.org/trunk@34916 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 19 ++++++-- tests/phpunit/tests/multisite/site.php | 61 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index a49432d3d8..49f55cfa8d 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -1317,7 +1317,7 @@ function insert_blog($domain, $path, $site_id) { * @param string $blog_title The title of the new site. */ function install_blog( $blog_id, $blog_title = '' ) { - global $wpdb, $wp_roles; + global $wpdb, $wp_roles, $current_site; // Cast for security $blog_id = (int) $blog_id; @@ -1339,10 +1339,21 @@ function install_blog( $blog_id, $blog_title = '' ) { // populate_roles() clears previous role definitions so we start over. $wp_roles = new WP_Roles(); - $url = untrailingslashit( $url ); + $siteurl = $home = untrailingslashit( $url ); - update_option( 'siteurl', $url ); - update_option( 'home', $url ); + if ( ! is_subdomain_install() ) { + + if ( 'https' === parse_url( get_network_option( 'siteurl' ), PHP_URL_SCHEME ) ) { + $siteurl = set_url_scheme( $siteurl, 'https' ); + } + if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) { + $home = set_url_scheme( $home, 'https' ); + } + + } + + update_option( 'siteurl', $siteurl ); + update_option( 'home', $home ); if ( get_site_option( 'ms_files_rewriting' ) ) update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index dd96afef39..c119415ed2 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -1000,6 +1000,67 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $blogaddress = get_blogaddress_by_id( 42 ); $this->assertEquals( '', $blogaddress ); } + + /** + * @ticket 33620 + * @dataProvider data_new_blog_url_schemes + */ + function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) { + $current_site = get_current_site(); + + $home = get_option( 'home' ); + $siteurl = get_site_option( 'siteurl' ); + $admin = force_ssl_admin(); + + // Setup: + update_option( 'home', set_url_scheme( $home, $home_scheme ) ); + update_site_option( 'siteurl', set_url_scheme( $siteurl, $siteurl_scheme ) ); + force_ssl_admin( $force_ssl_admin ); + + // Install: + $new = wpmu_create_blog( $current_site->domain, '/new-blog/', 'New Blog', get_current_user_id() ); + + // Reset: + update_option( 'home', $home ); + update_site_option( 'siteurl', $siteurl ); + force_ssl_admin( $admin ); + + // Assert: + $this->assertNotWPError( $new ); + $this->assertSame( $home_scheme, parse_url( get_blog_option( $new, 'home' ), PHP_URL_SCHEME ) ); + $this->assertSame( $siteurl_scheme, parse_url( get_blog_option( $new, 'siteurl' ), PHP_URL_SCHEME ) ); + } + + function data_new_blog_url_schemes() { + return array( + array( + 'https', + 'https', + false, + ), + array( + 'http', + 'https', + false, + ), + array( + 'https', + 'http', + false, + ), + array( + 'http', + 'http', + false, + ), + array( + 'http', + 'http', + true, + ), + ); + } + } endif;