Version Description
Download this release
Release Info
| Developer | mra13 |
| Plugin | |
| Version | 1.6 |
| Comparing to | |
| See all releases | |
Code changes from version 1.5 to 1.6
- https-redirection.php +97 -42
- https-rules-helper.php +2 -2
- readme.txt +9 -3
https-redirection.php
CHANGED
|
@@ -1,27 +1,24 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/*
|
| 3 |
Plugin Name: Easy HTTPS (SSL) Redirection
|
| 4 |
-
Plugin URI:
|
| 5 |
Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site.
|
| 6 |
Author: Tips and Tricks HQ
|
| 7 |
-
Version: 1.
|
| 8 |
Author URI: https://www.tipsandtricks-hq.com/
|
| 9 |
License: GPLv2 or later
|
| 10 |
*/
|
| 11 |
|
| 12 |
-
if (!defined('ABSPATH'))
|
|
|
|
|
|
|
| 13 |
|
| 14 |
include_once('https-rules-helper.php');
|
| 15 |
include_once('https-redirection-settings.php');
|
| 16 |
|
| 17 |
-
function add_httpsrdrctn_admin_menu() {
|
| 18 |
-
add_submenu_page('options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url("images/px.png", __FILE__), 1001);
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
function httpsrdrctn_plugin_init() {
|
| 22 |
global $httpsrdrctn_options;
|
| 23 |
-
/* Internationalization, first(!) */
|
| 24 |
-
load_plugin_textdomain('https_redirection', false, dirname(plugin_basename(__FILE__)) . '/languages/');
|
| 25 |
if (empty($httpsrdrctn_options)) {
|
| 26 |
$httpsrdrctn_options = get_option('httpsrdrctn_options');
|
| 27 |
}
|
|
@@ -29,13 +26,32 @@ function httpsrdrctn_plugin_init() {
|
|
| 29 |
//Do force resource embedded using HTTPS
|
| 30 |
if (isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') {
|
| 31 |
//Handle the appropriate content filters to force the static resources to use HTTPS URL
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
}
|
|
|
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
function httpsrdrctn_plugin_admin_init() {
|
|
@@ -44,12 +60,13 @@ function httpsrdrctn_plugin_admin_init() {
|
|
| 44 |
$httpsrdrctn_plugin_info = get_plugin_data(__FILE__, false);
|
| 45 |
|
| 46 |
/* Call register settings function */
|
| 47 |
-
if (isset($_GET['page']) && "https-redirection" == $_GET['page']){
|
| 48 |
register_httpsrdrctn_settings();
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
-
/*
|
|
|
|
| 53 |
function register_httpsrdrctn_settings() {
|
| 54 |
global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info;
|
| 55 |
|
|
@@ -97,48 +114,81 @@ function httpsrdrctn_plugin_action_links($links, $file) {
|
|
| 97 |
return $links;
|
| 98 |
}
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
$base = plugin_basename(__FILE__);
|
| 105 |
-
if ($file == $base) {
|
| 106 |
-
$links[] = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>';
|
| 107 |
-
}
|
| 108 |
-
return $links;
|
| 109 |
}
|
| 110 |
-
|
| 111 |
}
|
| 112 |
|
| 113 |
-
/*
|
| 114 |
* Function that changes "http" embeds to "https"
|
| 115 |
* TODO - Need to make it better so it only does it for static resources like JS, CSS and Images
|
| 116 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
function httpsrdrctn_the_content($content) {
|
| 118 |
global $httpsrdrctn_options;
|
| 119 |
if (empty($httpsrdrctn_options)) {
|
| 120 |
$httpsrdrctn_options = get_option('httpsrdrctn_options');
|
| 121 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if ($httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1) {
|
| 123 |
if ($httpsrdrctn_options['https_domain'] == 1) {
|
| 124 |
-
|
| 125 |
-
$http_domain = str_replace('https', 'http', home_url());
|
| 126 |
-
$https_domain = home_url();
|
| 127 |
-
} else {
|
| 128 |
-
$http_domain = home_url();
|
| 129 |
-
$https_domain = str_replace('http', 'https', home_url());
|
| 130 |
-
}
|
| 131 |
-
$content = str_replace($http_domain, $https_domain, $content);
|
| 132 |
} else if (!empty($httpsrdrctn_options['https_pages_array'])) {
|
|
|
|
|
|
|
| 133 |
foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) {
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
$
|
| 137 |
-
} else {
|
| 138 |
$http_domain = home_url();
|
| 139 |
-
$https_domain = str_replace('http', 'https', home_url());
|
|
|
|
| 140 |
}
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
}
|
| 143 |
}
|
| 144 |
}
|
|
@@ -166,8 +216,11 @@ if (!function_exists('httpsrdrctn_delete_options')) {
|
|
| 166 |
|
| 167 |
}
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
add_action('admin_menu', 'add_httpsrdrctn_admin_menu');
|
| 170 |
-
add_action('init', 'httpsrdrctn_plugin_init');
|
| 171 |
add_action('admin_init', 'httpsrdrctn_plugin_admin_init');
|
| 172 |
add_action('admin_enqueue_scripts', 'httpsrdrctn_admin_head');
|
| 173 |
|
|
@@ -178,3 +231,5 @@ add_filter('plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2);
|
|
| 178 |
//add_filter('mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules');//TODO 5
|
| 179 |
|
| 180 |
register_uninstall_hook(__FILE__, 'httpsrdrctn_delete_options');
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/*
|
| 4 |
Plugin Name: Easy HTTPS (SSL) Redirection
|
| 5 |
+
Plugin URI: https://www.tipsandtricks-hq.com/development-center
|
| 6 |
Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site.
|
| 7 |
Author: Tips and Tricks HQ
|
| 8 |
+
Version: 1.6
|
| 9 |
Author URI: https://www.tipsandtricks-hq.com/
|
| 10 |
License: GPLv2 or later
|
| 11 |
*/
|
| 12 |
|
| 13 |
+
if (!defined('ABSPATH')) {
|
| 14 |
+
exit; //Exit if accessed directly
|
| 15 |
+
}
|
| 16 |
|
| 17 |
include_once('https-rules-helper.php');
|
| 18 |
include_once('https-redirection-settings.php');
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
function httpsrdrctn_plugin_init() {
|
| 21 |
global $httpsrdrctn_options;
|
|
|
|
|
|
|
| 22 |
if (empty($httpsrdrctn_options)) {
|
| 23 |
$httpsrdrctn_options = get_option('httpsrdrctn_options');
|
| 24 |
}
|
| 26 |
//Do force resource embedded using HTTPS
|
| 27 |
if (isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') {
|
| 28 |
//Handle the appropriate content filters to force the static resources to use HTTPS URL
|
| 29 |
+
if (is_admin()) {
|
| 30 |
+
add_action("admin_init", "httpsrdrctn_start_buffer");
|
| 31 |
+
} else {
|
| 32 |
+
add_action("init", "httpsrdrctn_start_buffer");
|
| 33 |
+
add_action("init", "httpsrdrctn_init_time_tasks");
|
| 34 |
+
}
|
| 35 |
+
add_action("shutdown", "httpsrdrctn_end_buffer");
|
| 36 |
}
|
| 37 |
+
}
|
| 38 |
|
| 39 |
+
function httpsrdrctn_start_buffer() {
|
| 40 |
+
ob_start("httpsrdrctn_the_content");
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function httpsrdrctn_end_buffer() {
|
| 44 |
+
if (ob_get_length())
|
| 45 |
+
ob_end_flush();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function httpsrdrctn_init_time_tasks() {
|
| 49 |
+
httpsrdrctn_load_language();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function httpsrdrctn_load_language() {
|
| 53 |
+
/* Internationalization */
|
| 54 |
+
load_plugin_textdomain('https_redirection', false, dirname(plugin_basename(__FILE__)) . '/languages/');
|
| 55 |
}
|
| 56 |
|
| 57 |
function httpsrdrctn_plugin_admin_init() {
|
| 60 |
$httpsrdrctn_plugin_info = get_plugin_data(__FILE__, false);
|
| 61 |
|
| 62 |
/* Call register settings function */
|
| 63 |
+
if (isset($_GET['page']) && "https-redirection" == $_GET['page']) {
|
| 64 |
register_httpsrdrctn_settings();
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
+
/* Register settings function */
|
| 69 |
+
|
| 70 |
function register_httpsrdrctn_settings() {
|
| 71 |
global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info;
|
| 72 |
|
| 114 |
return $links;
|
| 115 |
}
|
| 116 |
|
| 117 |
+
function httpsrdrctn_register_plugin_links($links, $file) {
|
| 118 |
+
$base = plugin_basename(__FILE__);
|
| 119 |
+
if ($file == $base) {
|
| 120 |
+
$links[] = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
+
return $links;
|
| 123 |
}
|
| 124 |
|
| 125 |
+
/*
|
| 126 |
* Function that changes "http" embeds to "https"
|
| 127 |
* TODO - Need to make it better so it only does it for static resources like JS, CSS and Images
|
| 128 |
*/
|
| 129 |
+
|
| 130 |
+
function httpsrdrctn_filter_content($content) {
|
| 131 |
+
//filter buffer
|
| 132 |
+
$home_no_www = str_replace("://www.", "://", get_option('home'));
|
| 133 |
+
$home_yes_www = str_replace("://", "://www.", $home_no_www);
|
| 134 |
+
$http_urls = array(
|
| 135 |
+
str_replace("https://", "http://", $home_yes_www),
|
| 136 |
+
str_replace("https://", "http://", $home_no_www),
|
| 137 |
+
"src='http://",
|
| 138 |
+
'src="http://',
|
| 139 |
+
);
|
| 140 |
+
$ssl_array = str_replace("http://", "https://", $http_urls);
|
| 141 |
+
//now replace these links
|
| 142 |
+
$str = str_replace($http_urls, $ssl_array, $content);
|
| 143 |
+
|
| 144 |
+
//replace all http links except hyperlinks
|
| 145 |
+
//all tags with src attr are already fixed by str_replace
|
| 146 |
+
|
| 147 |
+
$pattern = array(
|
| 148 |
+
'/url\([\'"]?\K(http:\/\/)(?=[^)]+)/i',
|
| 149 |
+
'/<link .*?href=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',
|
| 150 |
+
'/<meta property="og:image" .*?content=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',
|
| 151 |
+
'/<form [^>]*?action=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',
|
| 152 |
+
);
|
| 153 |
+
$str = preg_replace($pattern, 'https://', $str);
|
| 154 |
+
return $str;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
function httpsrdrctn_the_content($content) {
|
| 158 |
global $httpsrdrctn_options;
|
| 159 |
if (empty($httpsrdrctn_options)) {
|
| 160 |
$httpsrdrctn_options = get_option('httpsrdrctn_options');
|
| 161 |
}
|
| 162 |
+
|
| 163 |
+
$current_page = sanitize_post($GLOBALS['wp_the_query']->get_queried_object());
|
| 164 |
+
// Get the page slug
|
| 165 |
+
$slug = str_replace(home_url() . '/', '', get_permalink($current_page));
|
| 166 |
+
$slug = rtrim($slug, "/"); //remove trailing slash if it's there
|
| 167 |
+
|
| 168 |
if ($httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1) {
|
| 169 |
if ($httpsrdrctn_options['https_domain'] == 1) {
|
| 170 |
+
$content = httpsrdrctn_filter_content($content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
} else if (!empty($httpsrdrctn_options['https_pages_array'])) {
|
| 172 |
+
$pages_str = '';
|
| 173 |
+
$on_https_page = false;
|
| 174 |
foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) {
|
| 175 |
+
$pages_str.=preg_quote($https_page, '/') . '[\/|][\'"]|'; //let's add page to the preg expression string in case we'd need it later
|
| 176 |
+
if ($https_page == $slug) { //if we are on the page that is in the array, let's set the var to true
|
| 177 |
+
$on_https_page = true;
|
| 178 |
+
} else { //if not - let's replace all links to that page only to https
|
| 179 |
$http_domain = home_url();
|
| 180 |
+
$https_domain = str_replace('http://', 'https://', home_url());
|
| 181 |
+
$content = str_replace($http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content);
|
| 182 |
}
|
| 183 |
+
}
|
| 184 |
+
if ($on_https_page) { //we are on one of the https pages
|
| 185 |
+
$pages_str = substr($pages_str, 0, strlen($pages_str) - 1); //remove last '|'
|
| 186 |
+
$content = httpsrdrctn_filter_content($content); //let's change everything to https first
|
| 187 |
+
$http_domain = str_replace('https://', 'http://', home_url());
|
| 188 |
+
$https_domain = str_replace('http://', 'https://', home_url());
|
| 189 |
+
//now let's change all inner links to http, excluding those that user sets to be https in plugin settings
|
| 190 |
+
$content = preg_replace('/<a .*?href=[\'"]\K' . preg_quote($https_domain, '/') . '\/((?!' . $pages_str . ').)(?=[^\'"]+)/i', $http_domain . '/$1', $content);
|
| 191 |
+
$content = preg_replace('/' . preg_quote($https_domain, '/') . '([\'"])/i', $http_domain . '$1', $content);
|
| 192 |
}
|
| 193 |
}
|
| 194 |
}
|
| 216 |
|
| 217 |
}
|
| 218 |
|
| 219 |
+
function add_httpsrdrctn_admin_menu() {
|
| 220 |
+
add_submenu_page('options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url("images/px.png", __FILE__), 1001);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
add_action('admin_menu', 'add_httpsrdrctn_admin_menu');
|
|
|
|
| 224 |
add_action('admin_init', 'httpsrdrctn_plugin_admin_init');
|
| 225 |
add_action('admin_enqueue_scripts', 'httpsrdrctn_admin_head');
|
| 226 |
|
| 231 |
//add_filter('mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules');//TODO 5
|
| 232 |
|
| 233 |
register_uninstall_hook(__FILE__, 'httpsrdrctn_delete_options');
|
| 234 |
+
|
| 235 |
+
httpsrdrctn_plugin_init();
|
https-rules-helper.php
CHANGED
|
@@ -91,7 +91,7 @@ class HTTPSRDRCTN_RULES {
|
|
| 91 |
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
|
| 92 |
$rules .= 'RewriteEngine On' . PHP_EOL;
|
| 93 |
|
| 94 |
-
$rules .= 'RewriteCond %{
|
| 95 |
$rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL;
|
| 96 |
|
| 97 |
$rules .= '</IfModule>' . PHP_EOL;
|
|
@@ -106,7 +106,7 @@ class HTTPSRDRCTN_RULES {
|
|
| 106 |
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
|
| 107 |
$rules .= 'RewriteEngine On' . PHP_EOL;
|
| 108 |
|
| 109 |
-
$rules .= 'RewriteCond %{
|
| 110 |
|
| 111 |
$count = 0;
|
| 112 |
$total_pages = count($httpsrdrctn_options['https_pages_array']);
|
| 91 |
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
|
| 92 |
$rules .= 'RewriteEngine On' . PHP_EOL;
|
| 93 |
|
| 94 |
+
$rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off
|
| 95 |
$rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL;
|
| 96 |
|
| 97 |
$rules .= '</IfModule>' . PHP_EOL;
|
| 106 |
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
|
| 107 |
$rules .= 'RewriteEngine On' . PHP_EOL;
|
| 108 |
|
| 109 |
+
$rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off
|
| 110 |
|
| 111 |
$count = 0;
|
| 112 |
$total_pages = count($httpsrdrctn_options['https_pages_array']);
|
readme.txt
CHANGED
|
@@ -3,8 +3,8 @@ Contributors: Tips and Tricks HQ
|
|
| 3 |
Donate link: http://www.tipsandtricks-hq.com/development-center
|
| 4 |
Tags: redirection, https, automatic redirection, htaccess, ssl, https redirection, ssl certificate, secure page, secure, force ssl, force https
|
| 5 |
Requires at least: 3.5
|
| 6 |
-
Tested up to: 4.
|
| 7 |
-
Stable tag: 1.
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
|
@@ -22,7 +22,7 @@ This plugin will help you automatically setup a redirection to the https version
|
|
| 22 |
|
| 23 |
Lets say for example, you want to use HTTPS URL for the following page on your site:
|
| 24 |
|
| 25 |
-
example.com/checkout
|
| 26 |
|
| 27 |
This plugin will enforce that so if anyone uses an URL like the following in the browser's address bar:
|
| 28 |
http://www.example.com/checkout
|
|
@@ -50,6 +50,8 @@ This will help you make the webpage fully compatible with SSL.
|
|
| 50 |
* Actions: Do an auto redirect for a few pages. The user can enter the URLs that will be auto redirected to the HTTPS version.
|
| 51 |
* Force load static files (images, js, css etc) using a HTTPS URL.
|
| 52 |
|
|
|
|
|
|
|
| 53 |
== Installation ==
|
| 54 |
|
| 55 |
1. Upload `https-redirection` folder to the `/wp-content/plugins/` directory.
|
|
@@ -91,6 +93,10 @@ Here is an example for German language files.
|
|
| 91 |
|
| 92 |
== Changelog ==
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
= v1.5 =
|
| 95 |
- WordPress 4.6 compatibility.
|
| 96 |
|
| 3 |
Donate link: http://www.tipsandtricks-hq.com/development-center
|
| 4 |
Tags: redirection, https, automatic redirection, htaccess, ssl, https redirection, ssl certificate, secure page, secure, force ssl, force https
|
| 5 |
Requires at least: 3.5
|
| 6 |
+
Tested up to: 4.8
|
| 7 |
+
Stable tag: 1.6
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 22 |
|
| 23 |
Lets say for example, you want to use HTTPS URL for the following page on your site:
|
| 24 |
|
| 25 |
+
www.example.com/checkout
|
| 26 |
|
| 27 |
This plugin will enforce that so if anyone uses an URL like the following in the browser's address bar:
|
| 28 |
http://www.example.com/checkout
|
| 50 |
* Actions: Do an auto redirect for a few pages. The user can enter the URLs that will be auto redirected to the HTTPS version.
|
| 51 |
* Force load static files (images, js, css etc) using a HTTPS URL.
|
| 52 |
|
| 53 |
+
View more details on the [HTTPS Redirection plugin](https://www.tipsandtricks-hq.com/wordpress-easy-https-redirection-plugin) page.
|
| 54 |
+
|
| 55 |
== Installation ==
|
| 56 |
|
| 57 |
1. Upload `https-redirection` folder to the `/wp-content/plugins/` directory.
|
| 93 |
|
| 94 |
== Changelog ==
|
| 95 |
|
| 96 |
+
= v1.6 =
|
| 97 |
+
- Improved the "Force Load Static Files Using HTTPS" feature.
|
| 98 |
+
- The htaccess redirection is now detected based on SERVER_PORT (this is should work better on most servers).
|
| 99 |
+
|
| 100 |
= v1.5 =
|
| 101 |
- WordPress 4.6 compatibility.
|
| 102 |
|
