Make WordPress Core

Changeset 34916


Ignore:
Timestamp:
10/07/2015 09:45:17 PM (11 years ago)
Author:
johnbillion
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-functions.php

    r34912 r34916  
    13181318 */
    13191319function install_blog( $blog_id, $blog_title = '' ) {
    1320         global $wpdb, $wp_roles;
     1320        global $wpdb, $wp_roles, $current_site;
    13211321
    13221322        // Cast for security
     
    13401340        $wp_roles = new WP_Roles();
    13411341
    1342         $url = untrailingslashit( $url );
    1343 
    1344         update_option( 'siteurl', $url );
    1345         update_option( 'home', $url );
     1342        $siteurl = $home = untrailingslashit( $url );
     1343
     1344        if ( ! is_subdomain_install() ) {
     1345
     1346                if ( 'https' === parse_url( get_network_option( 'siteurl' ), PHP_URL_SCHEME ) ) {
     1347                        $siteurl = set_url_scheme( $siteurl, 'https' );
     1348                }
     1349                if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) {
     1350                        $home = set_url_scheme( $home, 'https' );
     1351                }
     1352
     1353        }
     1354
     1355        update_option( 'siteurl', $siteurl );
     1356        update_option( 'home', $home );
    13461357
    13471358        if ( get_site_option( 'ms_files_rewriting' ) )
  • trunk/tests/phpunit/tests/multisite/site.php

    r34902 r34916  
    10011001                $this->assertEquals( '', $blogaddress );
    10021002        }
     1003
     1004        /**
     1005         * @ticket 33620
     1006         * @dataProvider data_new_blog_url_schemes
     1007         */
     1008        function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
     1009                $current_site = get_current_site();
     1010
     1011                $home    = get_option( 'home' );
     1012                $siteurl = get_site_option( 'siteurl' );
     1013                $admin   = force_ssl_admin();
     1014
     1015                // Setup:
     1016                update_option( 'home', set_url_scheme( $home, $home_scheme ) );
     1017                update_site_option( 'siteurl', set_url_scheme( $siteurl, $siteurl_scheme ) );
     1018                force_ssl_admin( $force_ssl_admin );
     1019
     1020                // Install:
     1021                $new = wpmu_create_blog( $current_site->domain, '/new-blog/', 'New Blog', get_current_user_id() );
     1022
     1023                // Reset:
     1024                update_option( 'home', $home );
     1025                update_site_option( 'siteurl', $siteurl );
     1026                force_ssl_admin( $admin );
     1027
     1028                // Assert:
     1029                $this->assertNotWPError( $new );
     1030                $this->assertSame( $home_scheme, parse_url( get_blog_option( $new, 'home' ), PHP_URL_SCHEME ) );
     1031                $this->assertSame( $siteurl_scheme, parse_url( get_blog_option( $new, 'siteurl' ), PHP_URL_SCHEME ) );
     1032        }
     1033
     1034        function data_new_blog_url_schemes() {
     1035                return array(
     1036                        array(
     1037                                'https',
     1038                                'https',
     1039                                false,
     1040                        ),
     1041                        array(
     1042                                'http',
     1043                                'https',
     1044                                false,
     1045                        ),
     1046                        array(
     1047                                'https',
     1048                                'http',
     1049                                false,
     1050                        ),
     1051                        array(
     1052                                'http',
     1053                                'http',
     1054                                false,
     1055                        ),
     1056                        array(
     1057                                'http',
     1058                                'http',
     1059                                true,
     1060                        ),
     1061                );
     1062        }
     1063
    10031064}
    10041065
Note: See TracChangeset for help on using the changeset viewer.