WordPress HTTPS (SSL) - Version 0.5

Version Description

  • Due to increasing concerns about plugin performance, the option to bypass the HTTPS check on external elements has been added.

=

Download this release

Release Info

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

Code changes from version 0.4 to 0.5

Files changed (2) hide show
  1. readme.txt +3 -1
  2. wordpress-https.php +37 -18
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: encrypted, ssl, http, https
5
  Requires at least: 2.1.0
6
  Tested up to: 3.0.1
7
- Stable tag: 0.4
8
 
9
  This plugin ensures that <em>all</em> elements on a page are accessed through HTTPS if the page is being accessed via HTTPS.
10
 
@@ -48,6 +48,8 @@ My plugin simply replaces HTTP with HTTPS in the source code where it needs to b
48
  = 0.4 =
49
  * Plugin functions converted to OOP class.
50
  * The plugin will now attempt to set the allow_url_fopen option to true with `ini_set` function if possible.
 
 
51
 
52
  == Upgrade Notice ==
53
 
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
8
 
9
  This plugin ensures that <em>all</em> elements on a page are accessed through HTTPS if the page is being accessed via HTTPS.
10
 
48
  = 0.4 =
49
  * Plugin functions converted to OOP class.
50
  * The plugin will now attempt to set the allow_url_fopen option to true with `ini_set` function if possible.
51
+ = 0.5 =
52
+ * Due to increasing concerns about plugin performance, the option to bypass the HTTPS check on external elements has been added.
53
 
54
  == Upgrade Notice ==
55
 
wordpress-https.php CHANGED
@@ -4,7 +4,7 @@ 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.4
8
  Author URI: http://mvied.com/
9
  */
10
 
@@ -12,14 +12,15 @@ if ( !class_exists('WordPressHTTPS') ) {
12
  class WordPressHTTPS {
13
  // Deafault Options
14
  private $options_default = array(
15
- 'wordpress-https_externalurls' => 0
 
16
  );
17
 
18
  function __construct() {
19
  if ( is_admin() ) {
20
  add_action('admin_menu', array(&$this, 'menu'));
21
 
22
- foreach ( $options_default as $option => $value ) {
23
  if ( get_option($option) === FALSE ) {
24
  add_option($option, $value);
25
  }
@@ -40,13 +41,16 @@ if ( !class_exists('WordPressHTTPS') ) {
40
 
41
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
42
  $errors = array();
43
-
44
- if ( $_POST['wordpress-https_externalurls'] != '' ) {
45
- if ( file_get_contents('http://www.google.com') == false ) {
46
- $errors[] = 'Your current server configuration does not support the \'External HTTPS Elements\' option. This functionality relies on the <a href="http://php.net/file_get_contents" target="_blank">file_get_contents</a> function in PHP and has failed a test call to \'http://www.google.com/\'.';
47
- if ( ini_get('allow_url_fopen') != 1 ) {
48
- $errors[] = 'PHP configuration error: allow_url_fopen must be enabled to allow the conversion of external elements to HTTPS.';
49
- }
 
 
 
50
  update_option('wordpress-https_externalurls', 0);
51
  } else {
52
  update_option('wordpress-https_externalurls', 1);
@@ -54,6 +58,7 @@ if ( !class_exists('WordPressHTTPS') ) {
54
  } else {
55
  update_option('wordpress-https_externalurls', 0);
56
  }
 
57
  }
58
  ?>
59
  <div class="wrap">
@@ -82,7 +87,17 @@ if ( !class_exists('WordPressHTTPS') ) {
82
  <fieldset>
83
  <legend class="screen-reader-text"><span>Attempt to automatically convert external elements to HTTPS.</span></legend>
84
  <label for="wordpress-https_externalurls"><input name="wordpress-https_externalurls" type="checkbox" id="wordpress-https_externalurls" value="1"<?php echo ((get_option('wordpress-https_externalurls')) ? ' checked="checked"' : ''); ?> /> Attempt to automatically convert external elements to HTTPS.</label>
85
- <p class="description">Warning: Depending on the amount of external elements, this could affect the load times of your pages.</p>
 
 
 
 
 
 
 
 
 
 
86
  </fieldset>
87
  </td>
88
  </tr>
@@ -92,7 +107,9 @@ if ( !class_exists('WordPressHTTPS') ) {
92
  </tr>
93
  </table>
94
  <p class="submit"><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
95
- <p>If you found my plugin useful, please <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG" target="_blank">donate</a>. If you need technical assistance, want to provide feedback, or just want to say thanks, <a href="http://wordpress.org/tags/wordpress-https#postform" target="_blank">drop me a line</a>.</p>
 
 
96
  </form>
97
  </div>
98
  <?php
@@ -102,17 +119,19 @@ if ( !class_exists('WordPressHTTPS') ) {
102
  if ( !empty($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443 ) {
103
  $httpsUrl = str_replace('http://', 'https://', get_bloginfo('siteurl'));
104
  $httpUrl = str_replace('https://', 'http://', get_bloginfo('siteurl'));
105
-
106
  preg_match_all('/\<(script|link|img)(.*)http:\/\/[-\w\.]+[^\"\']*/im',$buffer,$matches);
107
  foreach ($matches[0] as $match) {
108
  if ( ( strpos($match, 'link') !== false && strpos($match, 'stylesheet') !== false ) || strpos($match, 'script') !== false || strpos($match, 'img') !== false ) {
109
  if ( strpos($match,$httpUrl) !== false ) {
110
- $buffer = str_replace($match, str_replace('http', 'https', $match), $buffer);
111
  } elseif ( get_option('wordpress-https_externalurls') == '1' ) {
112
  preg_match_all('/http:\/\/[-\w\.]+[^\"\']*/im', $match, $urlMatches);
113
  foreach ( $urlMatches[0] as $urlMatch ) {
114
- if (@file_get_contents(str_replace('http', 'https', $urlMatch))) {
115
- $buffer = str_replace($urlMatch, str_replace('http', 'https', $urlMatch), $buffer);
 
 
116
  }
117
  }
118
  }
@@ -123,7 +142,7 @@ if ( !class_exists('WordPressHTTPS') ) {
123
  }
124
 
125
  function buffer_start() {
126
- if ( get_option('wordpress-https_externalurls') == '1' && ini_get('allow_url_fopen') != 1 ) {
127
  @ini_set('allow_url_fopen', 1);
128
  }
129
  ob_start(array(&$this, 'process'));
@@ -132,7 +151,7 @@ if ( !class_exists('WordPressHTTPS') ) {
132
  function buffer_end() {
133
  ob_end_flush();
134
  }
135
-
136
  } // End WordPressHTTPS Class
137
  }
138
 
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
8
  Author URI: http://mvied.com/
9
  */
10
 
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
  }
41
 
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);
58
  } else {
59
  update_option('wordpress-https_externalurls', 0);
60
  }
61
+
62
  }
63
  ?>
64
  <div class="wrap">
87
  <fieldset>
88
  <legend class="screen-reader-text"><span>Attempt to automatically convert external elements to HTTPS.</span></legend>
89
  <label for="wordpress-https_externalurls"><input name="wordpress-https_externalurls" type="checkbox" id="wordpress-https_externalurls" value="1"<?php echo ((get_option('wordpress-https_externalurls')) ? ' checked="checked"' : ''); ?> /> Attempt to automatically convert external elements to HTTPS.</label>
90
+ <p class="description">Warning: This option checks that the external element can be loaded via HTTPS while the page is loading. Depending on the amount of external elements, this could affect the load times of your pages.</p>
91
+ </fieldset>
92
+ </td>
93
+ </tr>
94
+ <tr valign="top">
95
+ <th scope="row">Bypass External Check</th>
96
+ <td>
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>
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>
111
+ <p>If you found my plugin useful, please <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG" target="_blank">donate</a>.</p>
112
+ <p>If you need technical assistance, want to provide feedback, or just want to say thanks, <a href="http://wordpress.org/tags/wordpress-https#postform" target="_blank">drop me a line</a>.</p>
113
  </form>
114
  </div>
115
  <?php
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
  }
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);
147
  }
148
  ob_start(array(&$this, 'process'));
151
  function buffer_end() {
152
  ob_end_flush();
153
  }
154
+
155
  } // End WordPressHTTPS Class
156
  }
157