Changeset 967250 for https-redirection
- Timestamp:
- 08/17/2014 08:27:58 AM (12 years ago)
- Location:
- https-redirection/trunk
- Files:
-
- 2 added
- 2 edited
-
https-redirection-settings.php (added)
-
https-redirection.php (modified) (1 diff)
-
https-rules-helper.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
https-redirection/trunk/https-redirection.php
r965010 r967250 1 1 <?php 2 2 /* 3 Plugin Name: HTTPS Redirection4 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 HQ7 Version: 1.2 8 Author URI: http://www.tipsandtricks-hq.com/9 License: GPLv2 or later10 */3 Plugin Name: HTTPS 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.3 8 Author URI: https://www.tipsandtricks-hq.com/ 9 License: GPLv2 or later 10 */ 11 11 12 /* © Copyright 2014 12 if (!defined('ABSPATH'))exit; //Exit if accessed directly 13 13 14 This program is free software; you can redistribute it and/or modify 15 it under the terms of the GNU General Public License, version 2, as 16 published by the Free Software Foundation. 14 include_once('https-rules-helper.php'); 15 include_once('https-redirection-settings.php'); 17 16 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 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 } 22 20 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 */ 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 } 27 28 28 if ( ! function_exists( 'add_httpsrdrctn_admin_menu' ) ) { 29 function add_httpsrdrctn_admin_menu() { 30 add_submenu_page( 'options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url( "images/px.png", __FILE__ ), 1001 ); 31 } 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; 32 98 } 33 99 34 100 35 if ( ! function_exists ( 'httpsrdrctn_plugin_init' ) ) { 36 function httpsrdrctn_plugin_init() { 37 global $httpsrdrctn_options; 38 /* Internationalization, first(!) */ 39 load_plugin_textdomain( 'https_redirection', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 40 if( empty( $httpsrdrctn_options ) ){ 41 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' ); 42 } 43 if( isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1' ){ 44 //Handle the appropriate content filters to force the static resources to use HTTPS URL 45 add_filter( 'the_content', 'httpsrdrctn_the_content' ); 46 add_filter( 'get_the_content', 'httpsrdrctn_the_content' ); 47 add_filter( 'the_excerpt', 'httpsrdrctn_the_content' ); 48 add_filter( 'get_the_excerpt', 'httpsrdrctn_the_content' ); 49 } 50 } 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 51 111 } 52 112 53 if ( ! function_exists ( 'httpsrdrctn_plugin_admin_init' ) ) { 54 function httpsrdrctn_plugin_admin_init() { 55 global $httpsrdrctn_plugin_info; 56 57 $httpsrdrctn_plugin_info = get_plugin_data( __FILE__, false ); 58 59 /* Check version on WordPress */ 60 httpsrdrctn_version_check(); 61 62 /* Call register settings function */ 63 if ( isset( $_GET['page'] ) && "https-redirection" == $_GET['page'] ) 64 register_httpsrdrctn_settings(); 65 } 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; 66 146 } 67 147 68 /* Function check if plugin is compatible with current WP version */ 69 if ( ! function_exists ( 'httpsrdrctn_version_check' ) ) { 70 function httpsrdrctn_version_check() { 71 global $wp_version, $httpsrdrctn_plugin_info; 72 $require_wp = "3.5"; /* Wordpress at least requires version */ 73 $plugin = plugin_basename( __FILE__ ); 74 if ( version_compare( $wp_version, $require_wp, "<" ) ) { 75 if ( is_plugin_active( $plugin ) ) { 76 deactivate_plugins( $plugin ); 77 wp_die( "<strong>" . $httpsrdrctn_plugin_info['Name'] . " </strong> " . __( 'requires', 'https_redirection' ) . " <strong>WordPress " . $require_wp . "</strong> " . __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'https_redirection') . "<br /><br />" . __( 'Back to the WordPress', 'https_redirection') . " <a href='" . get_admin_url( null, 'plugins.php' ) . "'>" . __( 'Plugins page', 'https_redirection') . "</a>." ); 78 } 79 } 80 } 81 } 148 if (!function_exists('httpsrdrctn_admin_head')) { 82 149 83 /* register settings function */ 84 if ( ! function_exists( 'register_httpsrdrctn_settings' ) ) { 85 function register_httpsrdrctn_settings() { 86 global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info; 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 } 87 156 88 $httpsrdrctn_option_defaults = array(89 'https' => 0,90 'https_domain' => 0,91 'https_pages_array' => array(),92 'force_resources' => 0,93 'plugin_option_version' => $httpsrdrctn_plugin_info["Version"]94 );95 96 /* Install the option defaults */97 if ( 1 == $wpmu ) {98 if ( ! get_site_option( 'httpsrdrctn_options' ) )99 add_site_option( 'httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes' );100 } else {101 if ( ! get_option( 'httpsrdrctn_options' ) )102 add_option( 'httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes' );103 }104 105 /* Get options from the database */106 if ( 1 == $wpmu )107 $httpsrdrctn_options = get_site_option( 'httpsrdrctn_options' );108 else109 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' );110 111 /* Array merge incase this version has added new options */112 if ( ! isset( $httpsrdrctn_options['plugin_option_version'] ) || $httpsrdrctn_options['plugin_option_version'] != $httpsrdrctn_plugin_info["Version"] ) {113 $httpsrdrctn_options = array_merge( $httpsrdrctn_option_defaults, $httpsrdrctn_options );114 $httpsrdrctn_options['plugin_option_version'] = $httpsrdrctn_plugin_info["Version"];115 update_option( 'httpsrdrctn_options', $httpsrdrctn_options );116 }117 }118 }119 120 if ( ! function_exists( 'httpsrdrctn_plugin_action_links' ) ) {121 function httpsrdrctn_plugin_action_links( $links, $file ) {122 /* Static so we don't call plugin_basename on every plugin row. */123 static $this_plugin;124 if ( ! $this_plugin )125 $this_plugin = plugin_basename(__FILE__);126 127 if ( $file == $this_plugin ) {128 $settings_link = '<a href="admin.php?page=https-redirection">' . __( 'Settings', 'https_redirection' ) . '</a>';129 array_unshift( $links, $settings_link );130 }131 return $links;132 }133 }134 /* End function httpsrdrctn_plugin_action_links */135 136 if ( ! function_exists( 'httpsrdrctn_register_plugin_links' ) ) {137 function httpsrdrctn_register_plugin_links( $links, $file ) {138 $base = plugin_basename( __FILE__ );139 if ( $file == $base ) {140 $links[] = '<a href="admin.php?page=https-redirection">' . __( 'Settings', 'https_redirection' ) . '</a>';141 }142 return $links;143 }144 }145 146 /* Function for display htaccess settings page in the admin area */147 if ( ! function_exists( 'httpsrdrctn_settings_page' ) ) {148 function httpsrdrctn_settings_page() {149 global $httpsrdrctn_admin_fields_enable, $httpsrdrctn_options;150 //global $wp_rewrite; echo "<pre>"; var_dump($wp_rewrite);151 $error = "";152 /* Save data for settings page */153 if ( isset( $_REQUEST['httpsrdrctn_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'httpsrdrctn_nonce_name' ) ) {154 $httpsrdrctn_options['https'] = isset( $_REQUEST['httpsrdrctn_https'] ) ? $_REQUEST['httpsrdrctn_https'] : 0 ;155 $httpsrdrctn_options['https_domain'] = isset( $_REQUEST['httpsrdrctn_https_domain'] ) ? $_REQUEST['httpsrdrctn_https_domain'] : 0 ;156 $httpsrdrctn_options['force_resources'] = isset( $_REQUEST['httpsrdrctn_force_resources'] ) ? $_REQUEST['httpsrdrctn_force_resources'] : 0 ;157 158 if( isset( $_REQUEST['httpsrdrctn_https_pages_array'] ) ){159 $httpsrdrctn_options['https_pages_array'] = array();160 //var_dump($httpsrdrctn_options['https_pages_array']);161 foreach( $_REQUEST['httpsrdrctn_https_pages_array'] as $httpsrdrctn_https_page ){162 if( ! empty( $httpsrdrctn_https_page ) && $httpsrdrctn_https_page != '' ){163 $httpsrdrctn_https_page = str_replace( 'https', 'http', $httpsrdrctn_https_page );164 $httpsrdrctn_options['https_pages_array'][] = trim( str_replace( home_url(), '', $httpsrdrctn_https_page ), '/' );165 }166 }167 }168 169 if ( "" == $error ) {170 /* Update options in the database */171 update_option( 'httpsrdrctn_options', $httpsrdrctn_options, '', 'yes' );172 $message = __( "Settings saved.", 'https_redirection' );173 httpsrdrctn_generate_htaccess();174 }175 }176 /* Display form on the setting page */177 ?>178 <div class="wrap">179 <div class="icon32 icon32-bws" id="icon-options-general"></div>180 <h2><?php _e( 'HTTPS Redirection Settings', 'https_redirection' ); ?></h2>181 <div class="error">182 <p><strong><?php _e( "Notice:", 'https_redirection' ); ?></strong> <?php _e( "It is very important to be extremely attentive when making changes to .htaccess file. This functionality will work if any permalinks except the default ones are set on the Settings -> Permalink page.", 'https_redirection' ); ?></p>183 <p><?php _e( "If after making changes your site stops functioning, please open .htaccess file in the root directory and delete this lines", 'https_redirection' ); ?>:<br />184 <IfModule mod_rewrite.c><br />185 RewriteEngine On<br />186 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]<br />187 RewriteCond %{HTTPS} !=on [NC]<br />188 RewriteRule ^/?(<?php _e( "in this line may be differences", 'https_redirection' ); ?>) [R,L] (or [R=301,QSA,L])<br />189 </IfModule><br />190 <?php _e( "Save file. Deactivate the plugin or rename the plugin folder.", 'https_redirection' ); ?></p>191 <p><?php _e( 'The changes will be applied immediately after saving the changes, if you are not sure - do not click the "Save changes" button.', 'https_redirection' ); ?></p>192 </div>193 <div id="httpsrdrctn_settings_notice" class="updated fade" style="display:none"><p><strong><?php _e( "Notice:", 'https_redirection' ); ?></strong> <?php _e( "The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'https_redirection' ); ?></p></div>194 <div class="updated fade" <?php if ( ! isset( $_REQUEST['httpsrdrctn_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>195 <div class="error" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><?php echo $error; ?></p></div>196 <form id="httpsrdrctn_settings_form" method="post" action="admin.php?page=https-redirection">197 <table class="form-table">198 <tr valign="top">199 <th scope="row"><?php _e( 'Automatic redirection to the "HTTPS"', 'https_redirection' ); ?></th>200 <td>201 <label><input type="checkbox" name="httpsrdrctn_https" value="1" <?php if ( '1' == $httpsrdrctn_options['https'] ) echo "checked=\"checked\" "; ?>/></label><br />202 <p class="description">Use this option to make your webpage(s) load in HTTPS version only. If someone enters a non-https URL in the browser's address bar then the plugin will automatically redirect to the HTTPS version of that URL.</p>203 204 <br />205 <p>You can apply a force HTTPS redirection on your entire domain or just a few pages.</p>206 <label <?php if( '0' == $httpsrdrctn_options['https'] ) echo 'class="hidden"'; ?>><input type="radio" name="httpsrdrctn_https_domain" value="1" <?php if ( '1' == $httpsrdrctn_options['https_domain'] ) echo "checked=\"checked\" "; ?>/> The whole domain</label><br />207 <label <?php if( '0' == $httpsrdrctn_options['https'] ) echo 'class="hidden"'; ?>><input type="radio" name="httpsrdrctn_https_domain" value="0" <?php if ( '0' == $httpsrdrctn_options['https_domain'] ) echo "checked=\"checked\" "; ?>/> A few pages</label><br />208 <?php foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ){ ?>209 <span class="<?php if( '1' == $httpsrdrctn_options['https_domain'] || '0' == $httpsrdrctn_options['https'] ) echo 'hidden'; ?>" >210 <?php echo str_replace( "http://", "https://", home_url() ); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="<?php echo $https_page; ?>" /> <span class="rewrite_delete_item"> </span> <span class="rewrite_item_blank_error"><?php _e( 'Please, fill field', 'list' ); ?></span><br />211 </span>212 <?php } ?>213 <span class="rewrite_new_item <?php if( '1' == $httpsrdrctn_options['https_domain'] || '0' == $httpsrdrctn_options['https'] ) echo 'hidden'; ?>" >214 <?php echo str_replace( "http://", "https://", home_url() ); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="" /> <span class="rewrite_add_item"> </span> <span class="rewrite_item_blank_error"><?php _e( 'Please, fill field', 'list' ); ?></span><br />215 </span>216 </td>217 </tr>218 <tr valign="top">219 <th scope="row"><?php _e( 'Force resources to use HTTPS URL', 'https_redirection' ); ?></th>220 <td>221 <label><input type="checkbox" name="httpsrdrctn_force_resources" value="1" <?php if ( isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1' ) echo "checked=\"checked\" "; ?>/></label><br />222 <p class="description">When checked, the plugin will force load HTTPS URL for any static resources in your content. Example: if you have have an image embedded in a post with a NON-HTTPS URL, this option will change that to a HTTPS URL.</p>223 </td>224 </tr>225 </table>226 <input type="hidden" name="httpsrdrctn_form_submit" value="submit" />227 <p class="submit">228 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />229 </p>230 <?php wp_nonce_field( plugin_basename(__FILE__), 'httpsrdrctn_nonce_name' ); ?>231 </form>232 </div>233 <?php }234 }235 236 if ( ! function_exists ( 'httpsrdrctn_mod_rewrite_rules' ) ) {237 function httpsrdrctn_mod_rewrite_rules( $rules ) {238 global $httpsrdrctn_options, $wpmu;239 if( empty( $httpsrdrctn_options ) ){240 if ( 1 == $wpmu )241 $httpsrdrctn_options = get_site_option( 'httpsrdrctn_options' );242 else243 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' );244 }245 $home_path = get_home_path();246 if ( ! file_exists( $home_path . '.htaccess' ) ) {247 if( $httpsrdrctn_options['https'] == '1' ){248 $rewrite_https_content = '<IfModule mod_rewrite.c>' . "\n";249 $rewrite_https_content .= 'RewriteEngine On' . "\n";250 if( '1' == $httpsrdrctn_options['https_domain'] ){251 $rewrite_https_content .= 'RewriteCond %{HTTPS} !=on' . "\n";252 $rewrite_https_content .= 'RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]' . "\n";253 }254 elseif( '0' == $httpsrdrctn_options['https_domain'] && ! empty( $httpsrdrctn_options['https_pages_array'] ) ){255 $rewrite_https_content .= 'RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]' . "\n";256 $rewrite_https_content .= 'RewriteCond %{HTTPS} !=on [NC]' . "\n";257 $rewrite_https_content .= 'RewriteRule ^/?(';258 259 foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ){260 $rewrite_https_content .= str_replace( '/', '\/', $https_page ) . '|';261 }262 $rewrite_https_content .= trim( $rewrite_https_content, '|' );263 $rewrite_https_content .= ').* https://' . $_SERVER['SERVER_NAME'] . '%{REQUEST_URI}%{QUERY_STRING} [R=301,QSA,L]' . "\n";264 }265 $rewrite_https_content .= "</IfModule>\n";266 $rules = $rewrite_https_content . $rules;267 }268 }269 return $rules;270 }271 }272 273 if ( ! function_exists ( 'httpsrdrctn_generate_htaccess' ) ) {274 function httpsrdrctn_generate_htaccess() {275 global $httpsrdrctn_options;276 $home_path = get_home_path();277 $htaccess_file = $home_path . '.htaccess';278 if ( file_exists( $htaccess_file ) ) {279 $handle = fopen( $htaccess_file, "r" );280 if ( $handle ) {281 $previous_line = $content = $current_line = '';282 $rewrite_flag = false;283 $write_rewrite_flag = false;284 if( $httpsrdrctn_options['https'] == '1' || $httpsrdrctn_options['https'] == '0' ){285 while ( ! feof( $handle ) ) {286 $current_line = fgets( $handle );287 if ( false !== stripos( $current_line, 'RewriteCond %{HTTPS} !=on [NC]' ) ) {288 $rewrite_flag = true;289 } else {290 if ( $rewrite_flag && ! $write_rewrite_flag ) {291 $write_rewrite_flag = true;292 if( $httpsrdrctn_options['https'] == '0' ){293 $current_line = ' ';294 }295 else{296 if( '1' == $httpsrdrctn_options['https_domain'] ){297 $home = trim( trim( trim( home_url(), 'http://' ), 'https://'), '/' );298 if( $_SERVER['SERVER_NAME'] != $home && ! empty( $home ) ){299 $url_segments = explode( '/', $home );300 unset( $url_segments[ array_search( $_SERVER['SERVER_NAME'], $url_segments ) ] );301 $url_segments = implode( '/', $url_segments );302 $url_segments .= '/';303 }304 else{305 $url_segments = '';306 }307 $current_line = 'RewriteRule ^/?(.*) https://%{SERVER_NAME}/'.$url_segments.'$1 [R,L]' . "\n";308 }309 elseif( '0' == $httpsrdrctn_options['https_domain'] ){310 if( ! empty( $httpsrdrctn_options['https_pages_array'] ) ){311 $current_line = 'RewriteRule ^/?(';312 313 foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ){314 $current_line .= str_replace( '/', '\/', $https_page ) . '|';315 }316 $current_line = trim( $current_line, '|' );317 $current_line .= ').* https://' . $_SERVER['SERVER_NAME'] . '%{REQUEST_URI}%{QUERY_STRING} [R=301,QSA,L]' . "\n";318 }319 else{320 $current_line = ' ';321 }322 }323 }324 }325 }326 $content .= trim( $current_line, "\n" ) . "\n";327 }328 if ( ! $rewrite_flag ) {329 $rewrite_https_content = '<IfModule mod_rewrite.c>' . "\n";330 $rewrite_https_content .= 'RewriteEngine On' . "\n";331 if( '1' == $httpsrdrctn_options['https_domain'] ){332 $rewrite_https_content .= 'RewriteCond %{HTTPS} !=on [NC]' . "\n";333 $home = trim( trim( trim( home_url(), 'http://' ), 'https://'), '/' );334 if( $_SERVER['SERVER_NAME'] != $home && ! empty( $home ) ){335 $url_segments = explode( '/', $home );336 unset( $url_segments[ array_search( $_SERVER['SERVER_NAME'], $url_segments ) ] );337 $url_segments = implode( '/', $url_segments );338 $url_segments .= '/';339 }340 else{341 $url_segments = '';342 }343 $rewrite_https_content .= 'RewriteRule ^/?(.*) https://%{SERVER_NAME}/'.$url_segments.'$1 [R,L]' . "\n";344 }345 elseif( '0' == $httpsrdrctn_options['https_domain'] ){346 $rewrite_https_content .= 'RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]' . "\n";347 $rewrite_https_content .= 'RewriteCond %{HTTPS} !=on [NC]' . "\n";348 if( ! empty( $httpsrdrctn_options['https_pages_array'] ) ){349 $rewrite_https_content .= 'RewriteRule ^/?(';350 351 foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ){352 $rewrite_https_content .= str_replace( '/', '\/', $https_page ) . '|';353 }354 $rewrite_https_content = trim( $rewrite_https_content, '|' );355 $rewrite_https_content .= ').* https://' . $_SERVER['SERVER_NAME'] . '%{REQUEST_URI}%{QUERY_STRING} [R=301,QSA,L]' . "\n";356 }357 else{358 $rewrite_https_content .= ' ' . "\n";359 }360 }361 $rewrite_https_content .= "</IfModule>" . "\n";362 $content = $rewrite_https_content . "\n" . $content;363 }364 $temp_file = tempnam( '/tmp','allow_' );365 $fp = fopen( $temp_file, 'w' );366 fwrite( $fp, $content );367 fclose( $fp );368 rename( $temp_file, $htaccess_file );369 }370 }371 fclose( $handle );372 } else {373 /**/374 }375 }376 }377 378 if ( ! function_exists ( 'httpsrdrctn_the_content' ) ) {379 function httpsrdrctn_the_content( $content ) {380 global $httpsrdrctn_options;381 if( empty( $httpsrdrctn_options ) ){382 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' );383 }384 if( $httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1 ){385 if( $httpsrdrctn_options['https_domain'] == 1 ){386 if( strpos( home_url(), 'https' ) !== false ){387 $http_domain = str_replace( 'https', 'http', home_url() );388 $https_domain = home_url();389 }390 else{391 $http_domain = home_url();392 $https_domain = str_replace( 'http', 'https', home_url() );393 }394 $content = str_replace( $http_domain, $https_domain, $content );395 }396 else if( ! empty( $httpsrdrctn_options['https_pages_array'] ) ) {397 foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ) {398 if( strpos( home_url(), 'https' ) !== false ){399 $http_domain = str_replace( 'https', 'http', home_url() );400 $https_domain = home_url();401 }402 else{403 $http_domain = home_url();404 $https_domain = str_replace( 'http', 'https', home_url() );405 }406 $content = str_replace( $http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content );407 }408 }409 }410 return $content;411 }412 }413 414 if ( ! function_exists ( 'httpsrdrctn_admin_head' ) ) {415 function httpsrdrctn_admin_head() {416 if ( isset( $_REQUEST['page'] ) && 'https-redirection' == $_REQUEST['page'] ) {417 wp_enqueue_style( 'httpsrdrctn_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );418 wp_enqueue_script( 'httpsrdrctn_script', plugins_url( 'js/script.js', __FILE__ ) );419 }420 }421 157 } 422 158 423 159 /* Function for delete delete options */ 424 if ( ! function_exists ( 'httpsrdrctn_delete_options' ) ) { 425 function httpsrdrctn_delete_options() { 426 delete_option( 'httpsrdrctn_options' ); 427 delete_site_option( 'httpsrdrctn_options' ); 428 } 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 429 167 } 430 168 431 add_action( 'admin_menu', 'add_httpsrdrctn_admin_menu');432 add_action( 'init', 'httpsrdrctn_plugin_init');433 add_action( 'admin_init', 'httpsrdrctn_plugin_admin_init');434 add_action( 'admin_enqueue_scripts', 'httpsrdrctn_admin_head');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'); 435 173 436 174 /* Adds "Settings" link to the plugin action page */ 437 add_filter( 'plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2);175 add_filter('plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2); 438 176 /* Additional links on the plugin page */ 439 add_filter( 'plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2);440 add_filter( 'mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules' ); 177 add_filter('plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2); 178 //add_filter('mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules');//TODO 5 441 179 442 register_uninstall_hook( __FILE__, 'httpsrdrctn_delete_options');180 register_uninstall_hook(__FILE__, 'httpsrdrctn_delete_options'); -
https-redirection/trunk/readme.txt
r965012 r967250 5 5 Requires at least: 3.5 6 6 Tested up to: 3.9.2 7 Stable tag: 1. 27 Stable tag: 1.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 90 90 == Changelog == 91 91 92 = v1.3 = 93 - Updated the htaccess rules for HTTPS redirection to be more robust to prevent errors on some servers. 94 92 95 = v1.2 = 93 96 - Added a new option to automatically force load static files using HTTPS URL.
Note: See TracChangeset
for help on using the changeset viewer.