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
This commit is contained in:
John Blackbourn 2015-10-07 21:45:17 +00:00
parent 6705184dcc
commit e40575aa99
2 changed files with 76 additions and 4 deletions

View File

@ -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" );

View File

@ -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;