public static function staticize_subdomain($url)
{
// Extract hostname from URL
$host = parse_url($url, PHP_URL_HOST);
// Explode hostname on '.'
$exploded_host = explode('.', $host);
// Retrieve the name and TLD
if (count($exploded_host) > 1) {
$name = $exploded_host[count($exploded_host) - 2];
$tld = $exploded_host[count($exploded_host) - 1];
// Rebuild domain excluding subdomains
$domain = $name . '.' . $tld;
} else {
$domain = $host;
}
// Array of Automattic domains
$domain_whitelist = array('wordpress.com', 'wp.com');
// Return $url if not an Automattic domain
if (!in_array($domain, $domain_whitelist)) {
return $url;
}
if (is_ssl()) {
return preg_replace('|https?://[^/]++/|', 'https://s-ssl.wordpress.com/', $url);
}
srand(crc32(basename($url)));
$static_counter = rand(0, 2);
srand();
// this resets everything that relies on this, like array_rand() and shuffle()
return preg_replace('|://[^/]+?/|', "://s{$static_counter}.wp.com/", $url);
}