function test_with_alias_defined_should_change_url()
 {
     define('HTTPS_DOMAIN_ALIAS', 'example.seravo.fi');
     $url = 'http://www.example.com/example/path';
     $should_url = 'https://' . HTTPS_DOMAIN_ALIAS . '/example/path';
     $domains = ['example.com'];
     $this->assertEquals($should_url, hstda_rewrite_url($url, $domains));
 }
/**
 * Same as above, but handles all domains in a multisite
 */
function htsda_mu_https_domain_rewrite($url, $status = 0)
{
    // Rewrite only if the request is https, or the user is logged in
    // to preserve cookie integrity
    if (substr($url, 0, 5) == 'https' || function_exists('is_user_logged_in') && is_user_logged_in() && !(defined('DISABLE_FRONTEND_SSL') && DISABLE_FRONTEND_SSL)) {
        // these won't change during the request
        static $domains;
        if (!isset($domains)) {
            $blogs = wp_get_sites();
            // get info from wp_blogs table
            $domains = array();
            // map the domains here
            $domains[] = hstda_trim_url(parse_url(get_site_url(1), PHP_URL_HOST), 'www.');
            // main site home
            // special case for wpmu domain mapping plugin
            if (function_exists('domain_mapping_siteurl')) {
                $domains[] = hstda_trim_url(parse_url(domain_mapping_siteurl(false), PHP_URL_HOST), 'www.');
            }
            foreach ($blogs as $blog) {
                $domains[] = hstda_trim_url($blog['domain'], 'www.');
            }
            // dedupe domains
            $domains = array_unique($domains);
        }
        // Rewrite the $url
        $url = hstda_rewrite_url($url, $domains);
    }
    return $url;
}
/**
 * Same as above, but handles all domains in a multisite
 */
function htsda_mu_https_domain_rewrite($url, $status = 0)
{
    if (!is_string($url)) {
        // do nothing if $url is not a string
        // the customizer view seems to sometimes pass an empty array to this filter for some reason.
        // this would crash the entire plugin
        return $url;
    }
    // Rewrite only if the request is https, or the user is logged in
    // to preserve cookie integrity
    if (substr($url, 0, 5) == 'https' || function_exists('is_user_logged_in') && is_user_logged_in() && !(defined('DISABLE_FRONTEND_SSL') && DISABLE_FRONTEND_SSL)) {
        // these won't change during the request
        static $domains;
        if (!isset($domains)) {
            $args = array('limit' => null);
            // do not limit the number of results
            $blogs = wp_get_sites($args);
            // get info from wp_blogs table
            $domains = array();
            // map the domains here
            $domains[] = hstda_trim_url(parse_url(get_site_url(1), PHP_URL_HOST), 'www.');
            // main site home
            // special case for wpmu domain mapping plugin
            if (function_exists('domain_mapping_siteurl')) {
                $domains[] = hstda_trim_url(parse_url(domain_mapping_siteurl(false), PHP_URL_HOST), 'www.');
            }
            foreach ($blogs as $blog) {
                $domains[] = hstda_trim_url($blog['domain'], 'www.');
            }
            // dedupe domains
            $domains = array_unique($domains);
        }
        // Rewrite the $url
        $url = hstda_rewrite_url($url, $domains);
    }
    return $url;
}