Skip to content
Snippets Groups Projects
Commit b3073907 authored by sand's avatar sand
Browse files

Initial import

parents
Branches
Tags
No related merge requests found
# noblogs-wp-ssl
A Wordpress plugin that rewrite the protocol of all internal links to use https.
It's shamlessy copied from https://wordpress.org/plugins/cloudflare/
<?php
/*
Heavily copied from: https://wordpress.org/plugins/cloudflare/
*/
if ( !function_exists('add_action') ) {
echo "This is a Wordpress plugin and should not be called directly";
exit;
}
function wp_ssl_buffer_wrapup($buffer) {
// skip rewrite if not on HTTPS
if (empty($_SERVER['HTTPS'])) {
return $buffer;
}
// Check for a Content-Type header. Currently only apply rewriting to "text/html" or undefined
$headers = headers_list();
$content_type = null;
foreach ($headers 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') {
// replace href or src attributes within script, link, base, and img tags with just "//" for protocol
$re = "/(<(?:script|link|base|img|form)(?:[^>]*)(?:href|src|action)=[\"'])http:\\/\\/([^.]+\.noblogs\.org)/i";
$subst = "$1https://$2";
$return = preg_replace($re, $subst, $buffer);
// on regex error, skip overwriting buffer
if ($return) {
$buffer = $return;
}
}
return $buffer;
}
function wp_ssl_buffer_init() {
ob_start('wp_ssl_buffer_wrapup');
}
add_action('plugins_loaded', 'wp_ssl_buffer_init');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment