How make WP multisite create sites in https

Hey,
I would like to know how I can edit the core files of wordpress so that it automatically creates each subsite in https and not http.

How can this be done?

I have already tried to use the force ssl plugin but some of my plugins won't work properly because within the wp-admin/network/site-info.php?id=1 area my site still says http.

I know I can update the site manually from http to https but I am using the pro-sites plugin so I want it to create each site into https upon sign up.

Do you think this could work?

/*
Plugin Name: Make new sites in the network with https URLs
Description: Force new sites in a multisite network to use HTTPS as the scheme.
*/

add_action( 'wpmu_new_blog', 'mh_new_site_http', 10, 6 );

function mh_new_site_http( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {

        switch_to_blog( $blog_id );

        $mh_old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
        $mh_old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );

        $mh_new_home_url = preg_replace( '/^http:/' , 'https:' , $mh_old_home_url );
        $mh_new_site_url = preg_replace( '/^http:/' , 'https:' , $mh_old_site_url );

        update_option( 'home', $mh_new_home_url );
        update_option( 'siteurl', $mh_new_site_url );

        restore_current_blog();

}

Thank you,
Landon

  • Kasia Swiderska

    Hello Landon,

    To have subsites created properly for https you have to configure your network so it will be also https.

    I have already tried to use the force ssl plugin but some of my plugins won't work properly because within the wp-admin/network/site-info.php?id=1 area my site still says http.

    Have you left that on purpose or you haven't change it yet to https? You have to change its url to https in database in table wp_options (wp is default prefix for tables - it might be different on your site) for the primary site in siteurl and home fields. Then in wp_sitemeta table look for siteurl meta_key and also change url there for https.
    This way you won't need any custom code to have your subsites on https they will be automatically created like that.

    if you left your main site on http for purpose may I ask what is reason for doing that?

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.