https-redirection
Last commit date
css
12 years ago
images
12 years ago
js
12 years ago
languages
12 years ago
https-redirection-settings.php
9 years ago
https-redirection.php
9 years ago
https-rules-helper.php
11 years ago
https-utillity-functions.php
11 years ago
readme.txt
9 years ago
screenshot-1.png
12 years ago
https-redirection.php
181 lines
| 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.5 |
| 8 | Author URI: https://www.tipsandtricks-hq.com/ |
| 9 | License: GPLv2 or later |
| 10 | */ |
| 11 | |
| 12 | if (!defined('ABSPATH'))exit; //Exit if accessed directly |
| 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 | } |
| 28 | |
| 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 | //TODO 1 |
| 33 | add_filter( 'the_content', 'httpsrdrctn_the_content' ); |
| 34 | add_filter( 'get_the_content', 'httpsrdrctn_the_content' ); |
| 35 | add_filter( 'the_excerpt', 'httpsrdrctn_the_content' ); |
| 36 | add_filter( 'get_the_excerpt', 'httpsrdrctn_the_content' ); |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | |
| 41 | function httpsrdrctn_plugin_admin_init() { |
| 42 | global $httpsrdrctn_plugin_info; |
| 43 | |
| 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 | /* register settings function */ |
| 53 | function register_httpsrdrctn_settings() { |
| 54 | global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info; |
| 55 | |
| 56 | $httpsrdrctn_option_defaults = array( |
| 57 | 'https' => 0, |
| 58 | 'https_domain' => 0, |
| 59 | 'https_pages_array' => array(), |
| 60 | 'force_resources' => 0, |
| 61 | 'plugin_option_version' => $httpsrdrctn_plugin_info["Version"] |
| 62 | ); |
| 63 | |
| 64 | /* Install the option defaults */ |
| 65 | if (1 == $wpmu) { |
| 66 | if (!get_site_option('httpsrdrctn_options')) |
| 67 | add_site_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes'); |
| 68 | } else { |
| 69 | if (!get_option('httpsrdrctn_options')) |
| 70 | add_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes'); |
| 71 | } |
| 72 | |
| 73 | /* Get options from the database */ |
| 74 | if (1 == $wpmu) |
| 75 | $httpsrdrctn_options = get_site_option('httpsrdrctn_options'); |
| 76 | else |
| 77 | $httpsrdrctn_options = get_option('httpsrdrctn_options'); |
| 78 | |
| 79 | /* Array merge incase this version has added new options */ |
| 80 | if (!isset($httpsrdrctn_options['plugin_option_version']) || $httpsrdrctn_options['plugin_option_version'] != $httpsrdrctn_plugin_info["Version"]) { |
| 81 | $httpsrdrctn_options = array_merge($httpsrdrctn_option_defaults, $httpsrdrctn_options); |
| 82 | $httpsrdrctn_options['plugin_option_version'] = $httpsrdrctn_plugin_info["Version"]; |
| 83 | update_option('httpsrdrctn_options', $httpsrdrctn_options); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | function httpsrdrctn_plugin_action_links($links, $file) { |
| 88 | /* Static so we don't call plugin_basename on every plugin row. */ |
| 89 | static $this_plugin; |
| 90 | if (!$this_plugin) |
| 91 | $this_plugin = plugin_basename(__FILE__); |
| 92 | |
| 93 | if ($file == $this_plugin) { |
| 94 | $settings_link = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>'; |
| 95 | array_unshift($links, $settings_link); |
| 96 | } |
| 97 | return $links; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | if (!function_exists('httpsrdrctn_register_plugin_links')) { |
| 102 | |
| 103 | function httpsrdrctn_register_plugin_links($links, $file) { |
| 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 | if (strpos(home_url(), 'https') !== false) { |
| 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 | if (strpos(home_url(), 'https') !== false) { |
| 135 | $http_domain = str_replace('https', 'http', home_url()); |
| 136 | $https_domain = home_url(); |
| 137 | } else { |
| 138 | $http_domain = home_url(); |
| 139 | $https_domain = str_replace('http', 'https', home_url()); |
| 140 | } |
| 141 | $content = str_replace($http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | return $content; |
| 146 | } |
| 147 | |
| 148 | if (!function_exists('httpsrdrctn_admin_head')) { |
| 149 | |
| 150 | function httpsrdrctn_admin_head() { |
| 151 | if (isset($_REQUEST['page']) && 'https-redirection' == $_REQUEST['page']) { |
| 152 | wp_enqueue_style('httpsrdrctn_stylesheet', plugins_url('css/style.css', __FILE__)); |
| 153 | wp_enqueue_script('httpsrdrctn_script', plugins_url('js/script.js', __FILE__)); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | /* Function for delete delete options */ |
| 160 | if (!function_exists('httpsrdrctn_delete_options')) { |
| 161 | |
| 162 | function httpsrdrctn_delete_options() { |
| 163 | delete_option('httpsrdrctn_options'); |
| 164 | delete_site_option('httpsrdrctn_options'); |
| 165 | } |
| 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 | |
| 174 | /* Adds "Settings" link to the plugin action page */ |
| 175 | add_filter('plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2); |
| 176 | /* Additional links on the plugin page */ |
| 177 | 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'); |
| 181 |