'boolean', 'default'=>false));
register_setting('general', 'SitzzForceHttps_redirect_to_secure_site-id', array('type'=>'boolean', 'default'=>false));
}
/*
* theForceSettingsReplace: Returns the form element for the elemet replace setting
*
*/
public function theForceSettingsReplace()
{
$replChecked = get_option('SitzzForceHttps_replace_insecure_elements-id') ? ' checked="checked"' : '';
echo '';
}
/*
* theForceSettingsForm: Returns the form element for the redirect setting
*
*/
public function theForceSettingsRedirect()
{
$redirChecked = get_option('SitzzForceHttps_redirect_to_secure_site-id') ? ' checked="checked"' : '';
echo '';
}
/*
* theForceMagic: Magic function
* Replaces HTTP in links and references to internal resources with HTTPS
*/
public function theForceMagic($buffer)
{
if (!get_option('SitzzForceHttps_replace_insecure_elements-id')) {
return $buffer;
}
$content_type = null;
foreach (headers_list() as $header) {
if (strpos(strtolower($header), 'content-type:') === 0) {
$pieces = explode(':', strtolower($header));
$content_type = trim($pieces[1]);
break;
}
}
if (is_null($content_type) || substr($content_type, 0, 9) === 'text/html') {
// Take care of 'href' links
$buffer = str_replace('href=\'http://' . $_SERVER['HTTP_HOST'], 'href=\'https://' . $_SERVER['HTTP_HOST'], $buffer);
$buffer = str_replace('href="http://' . $_SERVER['HTTP_HOST'], 'href="https://' . $_SERVER['HTTP_HOST'], $buffer);
// Take care of 'src' references
$buffer = str_replace('src=\'http://' . $_SERVER['HTTP_HOST'], 'src=\'https://' . $_SERVER['HTTP_HOST'], $buffer);
$buffer = str_replace('src="http://' . $_SERVER['HTTP_HOST'], 'src="https://' . $_SERVER['HTTP_HOST'], $buffer);
// Take care or 'content' references
$buffer = str_replace('content=\'http://' . $_SERVER['HTTP_HOST'], 'content=\'https://' . $_SERVER['HTTP_HOST'], $buffer);
$buffer = str_replace('content="http://' . $_SERVER['HTTP_HOST'], 'content="https://' . $_SERVER['HTTP_HOST'], $buffer);
// Take care of 'url' links
$buffer = str_replace('url(\'http://' . $_SERVER['HTTP_HOST'], 'url(\'https://' . $_SERVER['HTTP_HOST'], $buffer);
$buffer = str_replace('url("http://' . $_SERVER['HTTP_HOST'], 'url("https://' . $_SERVER['HTTP_HOST'], $buffer);
// Take care of 'loaderUrl' references
$buffer = str_replace('http:\/\/' . $_SERVER['HTTP_HOST'], 'https:\/\/' . $_SERVER['HTTP_HOST'], $buffer);
// Take care of URLs in text - but attempt to ignore form data in admin pages
if (is_admin()) {
$buffer = str_replace('value="http://' . $_SERVER['HTTP_HOST'], 'value="ptth://' . $_SERVER['HTTP_HOST'], $buffer);
}
$buffer = str_replace('http://' . $_SERVER['HTTP_HOST'], 'https://' . $_SERVER['HTTP_HOST'], $buffer);
// Take care of Google URLs
$buffer = str_replace('http://fonts.googleapis.com', 'https://fonts.googleapis.com', $buffer);
$buffer = str_replace('http://maps.googleapis.com', 'https://maps.googleapis.com', $buffer);
$buffer = str_replace('http://ajax.googleapis.com', 'https://ajax.googleapis.com', $buffer);
$buffer = str_replace('http://storage.googleapis.com', 'https://storage.googleapis.com', $buffer);
// Fix for visible links
$buffer = str_replace('>http://' . $_SERVER['HTTP_HOST'], '>https://' . $_SERVER['HTTP_HOST'], $buffer);
// Remove any tmp:// left in there...
$buffer = str_replace('ptth://', 'http://', $buffer);
}
// Return the new contents...
return $buffer;
}
public function setSecureHooks($url)
{
// Replace HTTP with HTTPS if enabled
if (get_option('SitzzForceHttps_replace_insecure_elements-id')) {
return str_replace('http://', 'https://', $url);
}
}
}
/*
* Load class...
*/
new SitzzForceHttps();
add_filter('script_loader_src', array('SitzzForceHttps', 'setSecureHooks'));
add_filter('style_loader_src', array('SitzzForceHttps', 'setSecureHooks'));