• Why is it that when I create a new blog in a multisite (subdomain), the scheme is always set to “http” instead of “https”? Look in the database:
    table: “options”, fields: “siteurl” and “home”.
    I figured out that this is hard-coded in the wp_initialize_site() function but I don’t understand why?

    https://developer.www.ads-software.com/reference/functions/wp_initialize_site/ -> line 712

    $home_scheme    = 'http';
    $siteurl_scheme = 'http';
    if ( ! is_subdomain_install() ) {
    if ( 'https' === parse_url( get_home_url( $network->site_id ), PHP_URL_SCHEME ) ) {
    $home_scheme = 'https';
    }
    if ( 'https' === parse_url( get_network_option( $network->id, 'siteurl' ), PHP_URL_SCHEME ) ) {
    $siteurl_scheme = 'https';
    }
    }
    • This topic was modified 2 months, 1 week ago by pepe80.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @pepe80,

    The reason why http is set by default for subdomains in the wp_initialize_site() function is related to the logic within WordPress’s handling of multisite installations. Here’s the explanation:

    Why http is Set for Subdomains:

    1. Default Scheme Assumption:
          • In WordPress, the default scheme (http or https) for a new site in a multisite network is initially set to http. This is a conservative default assumption, as not all servers or networks might have SSL (HTTPS) enabled by default, especially for subdomains.

          2. Subdomain-Specific Logic:

            • The relevant code in the wp_initialize_site() function starts with setting $home_scheme and $siteurl_scheme to http.
            • The logic that follows checks if the multisite installation is a subdirectory install (e.g., example.com/site1). If it is, and the main site uses https, it changes the scheme to https for new sites as well.
            • However, for subdomain installs (e.g., site1.example.com), this logic is bypassed, and the scheme remains http.

            3. Rationale:

              • The rationale behind this might be that subdomain installations can have more complex DNS and SSL configurations. WordPress doesn’t automatically assume that each subdomain will have https enabled, leaving it up to the site admin to configure SSL for each subdomain.

              4. Custom SSL Requirements:

                • Subdomains often require specific SSL certificates (like a wildcard SSL) to handle https properly. If WordPress were to default to https without verifying SSL setup, it could cause sites to break or produce security warnings.

                In summary, http is set by default for subdomain installations because WordPress doesn’t automatically assume SSL is configured for each subdomain, avoiding potential issues with SSL setup. This default behavior can be overridden with custom code if your network is fully configured to use https.

                Thread Starter pepe80

                (@pepe80)

                @siva_selva thank you for this detailed explanation! I use the wp_initialize_site() function for a script that creates a duplicate page in a multisite environment and then replaces all URL occurrences on the new page from:
                https://mainsite.com
                to:
                https://new.mainsite.com
                This is the troublesome moment. Too bad wp_initialize_site() doesn’t have an “ssl” input parameter where I could decide for myself whether it should be http or https. I handled it with a hook before I even replace the URLs:

                add_action('wp_initialize_site', 'mu_duplicator_new_site', 10, 1);

                function mu_duplicator_new_site($new_site) {

                if (! is_object($new_site)) return;
                switch_to_blog($new_site->id);
                update_option('siteurl', str_replace('https://', 'https://', get_option('siteurl')));
                update_option('home', str_replace('https://', 'https://', get_option('home')));
                restore_current_blog();
                }
              Viewing 2 replies - 1 through 2 (of 2 total)
              • You must be logged in to reply to this topic.