WordPress HTTPS (SSL) - Version 1.0.1

Version Description

  • Bug fix.
Download this release

Release Info

Developer Mvied
Plugin Icon wp plugin WordPress HTTPS (SSL)
Version 1.0.1
Comparing to
See all releases

Code changes from version 0.5.1 to 1.0.1

Files changed (2) hide show
  1. readme.txt +30 -8
  2. wordpress-https.php +130 -46
readme.txt CHANGED
@@ -1,19 +1,23 @@
1
- === Plugin Name ===
2
  Contributors: Mvied
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG
4
  Tags: encrypted, ssl, http, https
5
  Requires at least: 2.1.0
6
  Tested up to: 3.0.1
7
- Stable tag: 0.5.1
8
 
9
- This plugin ensures that all elements on a page are accessed through HTTPS if the page is being accessed via HTTPS.
10
 
11
  == Description ==
12
 
13
- Some, but not all, plugins check for HTTPS when adding the extra scripts and stylesheets to your pages. The ones that do not will cause the page to be loaded insecurely. This is due to the way in which the plugin developer adds the elements to your pages.
14
-
15
- Adding JavaScript files to the header and footer of your site by manually adding them to your template files with static URL's, or loading external scripts over HTTP such as JavaScript libraries from the <a href="http://code.google.com/apis/libraries/">Google Libraries API</a> will also cause this issue.
16
 
 
 
 
 
 
 
17
  == Installation ==
18
 
19
  1. Upload `wordpress-https.php` to the `/wp-content/plugins/` directory
@@ -21,11 +25,21 @@ Adding JavaScript files to the header and footer of your site by manually adding
21
 
22
  == Frequently Asked Questions ==
23
 
 
 
 
 
 
 
 
 
24
  = What does this plugin do? =
25
 
26
  Sometimes when a page is loaded via HTTPS, the elements on that page (images, scripts, and stylesheets) may not also be loaded via HTTPS. This plugin ensures that that happens.
27
 
28
- = Why does that happen? =
 
 
29
 
30
  Some, but not all, plugins check for HTTPS when adding the extra scripts and stylesheets to your pages. The ones that do not will cause the page to be loaded insecurely. This is due to the way in which the plugin developer adds the elements to your pages.
31
 
@@ -37,6 +51,11 @@ My plugin simply replaces HTTP with HTTPS in the source code where it needs to b
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
40
  = 0.5.1 =
41
  * Bug fix.
42
  = 0.5 =
@@ -52,7 +71,10 @@ My plugin simply replaces HTTP with HTTPS in the source code where it needs to b
52
  * Initial Release.
53
 
54
  == Upgrade Notice ==
55
-
 
 
 
56
  = 0.5.1 =
57
  Fixes `PHP Warning: Invalid argument supplied for foreach()` error.
58
  = 0.3 =
1
+ === WordPress HTTPS ===
2
  Contributors: Mvied
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG
4
  Tags: encrypted, ssl, http, https
5
  Requires at least: 2.1.0
6
  Tested up to: 3.0.1
7
+ Stable tag: 1.0.1
8
 
9
+ Prevents HTTPS pages from loading non-HTTPS elements. Also gives the option to disable WordPress 3.0+ from changing links to HTTPS.
10
 
11
  == Description ==
12
 
13
+ This plugin in intended to be the all-in-one solution to the partially encrypted error that many people see on their WordPress sites when using HTTPS. Here are the currently available features:
 
 
14
 
15
+ <ul>
16
+ <li>Automatically changes all internal scripts, stylesheets and images to HTTPS if the page is being viewed via HTTPS.</li>
17
+ <li>The option to change external elements to HTTPS. The plugin will check for the existence of the external elements over HTTPs, and if it's available, will change the source to HTTPS.</li>
18
+ <li>The option to override the external element HTTPS check. If you know that all external elements can be loaded over HTTPS, this option will save some load time on your pages.</li>
19
+ <li>The option to disable WordPress 3.0+ from changing all of your page, category and post links to HTTPS.</li>
20
+ </ul>
21
  == Installation ==
22
 
23
  1. Upload `wordpress-https.php` to the `/wp-content/plugins/` directory
25
 
26
  == Frequently Asked Questions ==
27
 
28
+ = How do I make my whole website HTTPS? =
29
+
30
+ To make your entire website HTTPS, you simply need to change your home url and site url to HTTPS instead of HTTP. Read this to learn <a href="http://codex.wordpress.org/Changing_The_Site_URL">how to change the site url</a>.
31
+
32
+ = How do I make only my administration panel HTTPS? =
33
+
34
+ WordPress already has the process well documented. Read this to learn <a href="http://codex.wordpress.org/Administration_Over_SSL">how to set up administration over SSL</a>.
35
+
36
  = What does this plugin do? =
37
 
38
  Sometimes when a page is loaded via HTTPS, the elements on that page (images, scripts, and stylesheets) may not also be loaded via HTTPS. This plugin ensures that that happens.
39
 
40
+ This plugin also provides the option to disable WordPress 3.0+ from changing all of your page, category and post links to HTTPS.
41
+
42
+ = Why do elements not automatically load over HTTPS? =
43
 
44
  Some, but not all, plugins check for HTTPS when adding the extra scripts and stylesheets to your pages. The ones that do not will cause the page to be loaded insecurely. This is due to the way in which the plugin developer adds the elements to your pages.
45
 
51
 
52
  == Changelog ==
53
 
54
+ = 1.0.1 =
55
+ * Bug fix.
56
+ = 1.0 =
57
+ * Major modifications to plugin structure, efficiency, and documentation.
58
+ * Added the option to disable WordPress 3.0+ from changing all of your page, category and post links to HTTPS.
59
  = 0.5.1 =
60
  * Bug fix.
61
  = 0.5 =
71
  * Initial Release.
72
 
73
  == Upgrade Notice ==
74
+ = 1.0.1 =
75
+ Version 1.0.1 fixes a bug in 1.0 that made it to release. Apologies!
76
+ = 1.0 =
77
+ Version 1.0 gives you the ability to disable WordPress 3.0+ from changing all of your page, category and post links to HTTPS.
78
  = 0.5.1 =
79
  Fixes `PHP Warning: Invalid argument supplied for foreach()` error.
80
  = 0.3 =
wordpress-https.php CHANGED
@@ -2,38 +2,77 @@
2
  /*
3
  Plugin Name: WordPress HTTPS
4
  Plugin URI: http://mvied.com/projects/wordpress-https/
5
- Description: This plugin ensures that <em>all</em> elements on a page are accessed through HTTPS if the page is being accessed via HTTPS.
6
  Author: Mike Ems
7
- Version: 0.5.1
8
  Author URI: http://mvied.com/
9
  */
10
 
 
 
 
 
 
 
 
 
11
  if ( !class_exists('WordPressHTTPS') ) {
12
  class WordPressHTTPS {
13
- // Deafault Options
14
- private $options_default = array(
15
- 'wordpress-https_externalurls' => 0, // Option to change external URL's to HTTPS
16
- 'wordpress-https_bypass' => 0 // Bypass option to check if external elements can be loaded via HTTPS
 
 
 
 
 
 
17
  );
18
 
 
 
 
 
 
 
19
  function __construct() {
20
  if ( is_admin() ) {
21
  add_action('admin_menu', array(&$this, 'menu'));
22
 
23
- foreach ( $this->options_default as $option => $value ) {
24
- if ( get_option($option) === FALSE ) {
25
- add_option($option, $value);
26
- }
27
- }
28
  }
 
29
  add_action('plugins_loaded', array(&$this, 'buffer_start'));
30
- add_action('wp_footer', array(&$this, 'buffer_end'));
 
 
 
 
 
 
31
  }
32
 
 
 
 
 
 
 
33
  function menu() {
34
  add_options_page('WordPress HTTPS Settings', 'WordPress HTTPS', 'manage_options', 'wordpress-https', array(&$this, 'settings'));
35
  }
36
 
 
 
 
 
 
 
37
  function settings() {
38
  if ( !current_user_can('manage_options') ) {
39
  wp_die( __('You do not have sufficient permissions to access this page.') );
@@ -42,23 +81,19 @@ if ( !class_exists('WordPressHTTPS') ) {
42
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
43
  $errors = array();
44
 
45
- if ( $_POST['wordpress-https_bypass'] == 1 ) {
46
- update_option('wordpress-https_bypass', 1);
47
- } else {
48
- update_option('wordpress-https_bypass', 0);
49
- }
50
-
51
- if ( $_POST['wordpress-https_externalurls'] == 1 ) {
52
- if ( get_option('wordpress-https_bypass') != 1 && ini_get('allow_url_fopen') != 1 ) {
53
- $errors[] = 'PHP configuration error: allow_url_fopen must be enabled to allow the conversion of external elements to HTTPS.';
54
- update_option('wordpress-https_externalurls', 0);
55
  } else {
56
- update_option('wordpress-https_externalurls', 1);
 
 
 
 
 
57
  }
58
- } else {
59
- update_option('wordpress-https_externalurls', 0);
60
  }
61
-
62
  }
63
  ?>
64
  <div class="wrap">
@@ -73,11 +108,10 @@ if ( !class_exists('WordPressHTTPS') ) {
73
  }
74
  echo " </ul>\n";
75
  } else {
76
- echo " <div class=\"updated fade\" id=\"message\"><p><strong>Settings saved.</strong></p></div>\n";
77
  }
78
  }
79
  ?>
80
-
81
  <form name="form" action="options-general.php?page=wordpress-https" method="post">
82
  <?php settings_fields('wordpress-https'); ?>
83
  <table class="form-table">
@@ -97,14 +131,22 @@ if ( !class_exists('WordPressHTTPS') ) {
97
  <fieldset>
98
  <legend class="screen-reader-text"><span>Disable the option to check if an external element can be loaded over HTTPS.</span></legend>
99
  <label for="wordpress-https_bypass"><input name="wordpress-https_bypass" type="checkbox" id="wordpress-https_bypass" value="1"<?php echo ((get_option('wordpress-https_bypass')) ? ' checked="checked"' : ''); ?> /> Disable the option to check if an external element can be loaded over HTTPS.</label>
100
- <p class="description">Bypassing the HTTPS check for external elements may cause elements to not load at all. Only enable this option if you know that all external elements can be loaded over HTTPS.</p>
101
  </fieldset>
102
  </td>
103
  </tr>
104
- <tr>
 
 
105
  <td>
 
 
 
 
 
106
  </td>
107
  </tr>
 
108
  </table>
109
  <p class="submit"><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
110
  <p>This plugin was created by <a href="http://mvied.com/" target="_blank">Mike Ems</a>.</p>
@@ -115,24 +157,34 @@ if ( !class_exists('WordPressHTTPS') ) {
115
  <?php
116
  }
117
 
 
 
 
 
 
 
118
  function process($buffer) {
119
  if ( !empty($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443 ) {
120
- $httpsUrl = str_replace('http://', 'https://', get_bloginfo('siteurl'));
121
- $httpUrl = str_replace('https://', 'http://', get_bloginfo('siteurl'));
122
-
123
- preg_match_all('/\<(script|link|img)(.*)http:\/\/[-\w\.]+[^\"\']*/im',$buffer,$matches);
124
- foreach ($matches[0] as $match) {
125
- if ( ( strpos($match, 'link') !== false && strpos($match, 'stylesheet') !== false ) || strpos($match, 'script') !== false || strpos($match, 'img') !== false ) {
126
- if ( strpos($match,$httpUrl) !== false ) {
127
- $buffer = str_replace($match, str_replace('http://', 'https://', $match), $buffer);
128
- } elseif ( get_option('wordpress-https_externalurls') == '1' ) {
129
- preg_match_all('/http:\/\/[-\w\.]+[^\"\']*/im', $match, $urlMatches);
130
- foreach ( $urlMatches[0] as $urlMatch ) {
131
- if ( get_option('wordpress-https_bypass') == 1 ) {
132
- $buffer = str_replace($urlMatch, str_replace('http://', 'https://', $urlMatch), $buffer);
133
- } else if (@file_get_contents(str_replace('http://', 'https://', $urlMatch))) {
134
- $buffer = str_replace($urlMatch, str_replace('http://', 'https://', $urlMatch), $buffer);
135
- }
 
 
 
 
136
  }
137
  }
138
  }
@@ -141,6 +193,12 @@ if ( !class_exists('WordPressHTTPS') ) {
141
  return $buffer;
142
  }
143
 
 
 
 
 
 
 
144
  function buffer_start() {
145
  if ( get_option('wordpress-https_externalurls') == 1 && get_option('wordpress-https_bypass') != 1 ) {
146
  @ini_set('allow_url_fopen', 1);
@@ -148,10 +206,36 @@ if ( !class_exists('WordPressHTTPS') ) {
148
  ob_start(array(&$this, 'process'));
149
  }
150
 
 
 
 
 
 
 
151
  function buffer_end() {
152
  ob_end_flush();
153
  }
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  } // End WordPressHTTPS Class
156
  }
157
 
2
  /*
3
  Plugin Name: WordPress HTTPS
4
  Plugin URI: http://mvied.com/projects/wordpress-https/
5
+ Description: Prevents HTTPS pages from loading non-HTTPS elements. Also gives the option to disable WordPress 3.0+ from changing links to HTTPS.
6
  Author: Mike Ems
7
+ Version: 1.0.1
8
  Author URI: http://mvied.com/
9
  */
10
 
11
+ /**
12
+ * Class for the WordPress plugin WordPress HTTPS
13
+ *
14
+ * @author Mike Ems
15
+ * @package WordPressHTTPS
16
+ * @copyright Copyright 2010
17
+ */
18
+
19
  if ( !class_exists('WordPressHTTPS') ) {
20
  class WordPressHTTPS {
21
+
22
+ /**
23
+ * Default options
24
+ *
25
+ * @private array
26
+ */
27
+ private $options_default = array(
28
+ 'wordpress-https_externalurls' => 0, // Option to change external URL's to HTTPS
29
+ 'wordpress-https_bypass' => 0, // Bypass option to check if external elements can be loaded via HTTPS
30
+ 'wordpress-https_disable_autohttps' => 0 // Disable the feature in WordPress 3.0+ that makes all links HTTPS if the page is being viewed via HTTPS.
31
  );
32
 
33
+ /**
34
+ * Initialize plugin
35
+ *
36
+ * @param none
37
+ * @return void
38
+ */
39
  function __construct() {
40
  if ( is_admin() ) {
41
  add_action('admin_menu', array(&$this, 'menu'));
42
 
43
+ foreach ( $this->options_default as $option => $value ) {
44
+ if ( get_option($option) === FALSE ) {
45
+ add_option($option, $value);
46
+ }
47
+ }
48
  }
49
+
50
  add_action('plugins_loaded', array(&$this, 'buffer_start'));
51
+ //add_action('wp_footer', array(&$this, 'buffer_end'));
52
+
53
+ if ( get_option('wordpress-https_disable_autohttps') == 1 ) {
54
+ add_filter('page_link', array(&$this, 'replace_https'));
55
+ add_filter('post_link', array(&$this, 'replace_https'));
56
+ add_filter('category_link', array(&$this, 'replace_https'));
57
+ }
58
  }
59
 
60
+ /**
61
+ * Add admin panel menu option
62
+ *
63
+ * @param none
64
+ * @return void
65
+ */
66
  function menu() {
67
  add_options_page('WordPress HTTPS Settings', 'WordPress HTTPS', 'manage_options', 'wordpress-https', array(&$this, 'settings'));
68
  }
69
 
70
+ /**
71
+ * Settings page in admin panel
72
+ *
73
+ * @param none
74
+ * @return void
75
+ */
76
  function settings() {
77
  if ( !current_user_can('manage_options') ) {
78
  wp_die( __('You do not have sufficient permissions to access this page.') );
81
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
82
  $errors = array();
83
 
84
+ foreach ($this->options_default as $key => $default) {
85
+ if (!array_key_exists($key, $_POST)) {
86
+ $_POST[$key] = $default;
 
 
 
 
 
 
 
87
  } else {
88
+ if ( $key == 'wordpress-https_bypass' && @ini_get('allow_url_fopen') != 1 ) {
89
+ $errors[] = 'PHP configuration error: allow_url_fopen must be enabled to allow the conversion of external elements to HTTPS.';
90
+ $_POST[$key] = 0;
91
+ } else if ($key == 'wordpress-https_disable_autohttps' && get_bloginfo('version') < 3.0) {
92
+ $_POST[$key] = 0;
93
+ }
94
  }
95
+ update_option($key, $_POST[$key]);
 
96
  }
 
97
  }
98
  ?>
99
  <div class="wrap">
108
  }
109
  echo " </ul>\n";
110
  } else {
111
+ echo " <div class=\"updated below-h2 fade\" id=\"message\"><p><strong>Settings saved.</strong></p></div>\n";
112
  }
113
  }
114
  ?>
 
115
  <form name="form" action="options-general.php?page=wordpress-https" method="post">
116
  <?php settings_fields('wordpress-https'); ?>
117
  <table class="form-table">
131
  <fieldset>
132
  <legend class="screen-reader-text"><span>Disable the option to check if an external element can be loaded over HTTPS.</span></legend>
133
  <label for="wordpress-https_bypass"><input name="wordpress-https_bypass" type="checkbox" id="wordpress-https_bypass" value="1"<?php echo ((get_option('wordpress-https_bypass')) ? ' checked="checked"' : ''); ?> /> Disable the option to check if an external element can be loaded over HTTPS.</label>
134
+ <p class="description">Warning: Bypassing the HTTPS check for external elements may cause elements to not load at all. Only enable this option if you know that all external elements can be loaded over HTTPS.</p>
135
  </fieldset>
136
  </td>
137
  </tr>
138
+ <?php if (get_bloginfo('version') >= 3) { ?>
139
+ <tr valign="top">
140
+ <th scope="row">Disable Automatic HTTPS</th>
141
  <td>
142
+ <fieldset>
143
+ <legend class="screen-reader-text"><span>Disable the feature in WordPress 3.0+ that makes all links HTTPS if the page is being viewed via HTTPS.</span></legend>
144
+ <label for="wordpress-https_disable_autohttps"><input name="wordpress-https_disable_autohttps" type="checkbox" id="wordpress-https_disable_autohttps" value="1"<?php echo ((get_option('wordpress-https_disable_autohttps')) ? ' checked="checked"' : ''); ?> /> Disable the feature in WordPress 3.0+ that makes all links HTTPS if the page is being viewed via HTTPS.</label>
145
+ <p class="description">When a page is viewed via HTTPS in WordPress 3.0+, all internal page, category and post links are changed to HTTPS. This option will disable that.</p>
146
+ </fieldset>
147
  </td>
148
  </tr>
149
+ <?php } ?>
150
  </table>
151
  <p class="submit"><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
152
  <p>This plugin was created by <a href="http://mvied.com/" target="_blank">Mike Ems</a>.</p>
157
  <?php
158
  }
159
 
160
+ /**
161
+ * Process output buffer
162
+ *
163
+ * @param string
164
+ * @return string
165
+ */
166
  function process($buffer) {
167
  if ( !empty($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443 ) {
168
+ if (get_bloginfo('version') > 3) {
169
+ $httpsUrl = $this->replace_http(get_site_url());
170
+ } else {
171
+ $httpsUrl = $this->replace_http(get_bloginfo('home'));
172
+ }
173
+ $httpUrl = $this->replace_https($httpsUrl);
174
+
175
+ preg_match_all('/\<(script|link|img).*(http:\/\/[\/-\w\.]+)/im',$buffer,$matches);
176
+ for ($i = 0; $i<=sizeof($matches[0]); $i++) {
177
+ $html = $matches[0][$i];
178
+ $type = $matches[1][$i];
179
+ $url = $matches[2][$i];
180
+ if ( ( $type == 'link' && strpos($html, 'stylesheet') !== false ) || $type == 'script' || $type == 'img' ) {
181
+ if ( strpos($html,$httpUrl) !== false ) {
182
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
183
+ } else if ( get_option('wordpress-https_externalurls') == 1 ) {
184
+ if ( get_option('wordpress-https_bypass') == 1 ) {
185
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
186
+ } else if (@file_get_contents($this->replace_http($url))) {
187
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
188
  }
189
  }
190
  }
193
  return $buffer;
194
  }
195
 
196
+ /**
197
+ * Start output buffering
198
+ *
199
+ * @param none
200
+ * @return void
201
+ */
202
  function buffer_start() {
203
  if ( get_option('wordpress-https_externalurls') == 1 && get_option('wordpress-https_bypass') != 1 ) {
204
  @ini_set('allow_url_fopen', 1);
206
  ob_start(array(&$this, 'process'));
207
  }
208
 
209
+ /**
210
+ * End output buffering
211
+ *
212
+ * @param none
213
+ * @return void
214
+ */
215
  function buffer_end() {
216
  ob_end_flush();
217
  }
218
 
219
+ /**
220
+ * Replace HTTPS with HTTP
221
+ *
222
+ * @param string
223
+ * @return string
224
+ */
225
+ function replace_https($string) {
226
+ return str_replace('https://', 'http://', $string);
227
+ }
228
+
229
+ /**
230
+ * Replace HTTP with HTTPS
231
+ *
232
+ * @param string
233
+ * @return string
234
+ */
235
+ function replace_http($string) {
236
+ return str_replace('http://', 'https://', $string);
237
+ }
238
+
239
  } // End WordPressHTTPS Class
240
  }
241