<?php
/**
* Plugin Name: Force HTTP / HTTPS on new Sub Sites
* Plugin URI: https://premium.wpmudev.org/project/pro-sites/
* Description: Force all new sub sites to use http/https when they are created. Change the protocol of the domain in the database.
* Author: Lindeni Mahlalela @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/mahlamusa
* License: GPLv2 or later
*/
if ( ! function_exists( 'force_https_for_new_signups') ) {
add_action('wpmu_new_blog', 'force_https_for_new_signups', 10, 6 );
function force_https_for_new_signups( $blog_id, $user_id, $domain, $path, $site_id, $meta ){
switch_to_blog( $blog_id );
$home = str_replace("http://", "https://", get_option( "home" ) ); //force https, interchange http & https too force the other
$siteurl = str_replace("http://", "https://", get_option( "siteurl" ) ); //force https, interchange http & https too force the other
update_option( "home", $home );
update_option( "siteurl", $siteurl );
restore_current_blog();
}
}