WordPress HTTPS (SSL) - Version 0.4

Version Description

  • Plugin functions converted to OOP class.
  • The plugin will now attempt to set the allow_url_fopen option to true with ini_set function if possible.

=

Download this release

Release Info

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

Code changes from version 0.3 to 0.4

Files changed (2) hide show
  1. readme.txt +4 -1
  2. wordpress-https.php +114 -75
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.3
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
 
@@ -45,6 +45,9 @@ My plugin simply replaces HTTP with HTTPS in the source code where it needs to b
45
  * Changed the way in which HTTPS was detected to be more reliable.
46
  = 0.3 =
47
  * Added the option to change external elements to HTTPS if the external server allows the elements to be accessed via HTTPS.
 
 
 
48
 
49
  == Upgrade Notice ==
50
 
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
 
45
  * Changed the way in which HTTPS was detected to be more reliable.
46
  = 0.3 =
47
  * Added the option to change external elements to HTTPS if the external server allows the elements to be accessed via HTTPS.
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
 
wordpress-https.php CHANGED
@@ -4,100 +4,139 @@ 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.3
8
  Author URI: http://mvied.com/
9
  */
10
 
11
- add_action('admin_menu', 'wordpress_https_menu');
 
 
 
 
 
12
 
13
- function wordpress_https_menu() {
14
- add_options_page('WordPress HTTPS Settings', 'WordPress HTTPS', 'manage_options', 'wordpress-https', 'wordpress_https_settings');
15
- }
16
-
17
- function wordpress_https_settings() {
18
- if (!current_user_can('manage_options')) {
19
- wp_die( __('You do not have sufficient permissions to access this page.') );
20
- }
21
 
22
- if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
23
- $errors = array();
24
- if ( $_POST['wordpress-https_externalurls'] == '1' ) {
25
- if ( file_get_contents('http://www.google.com') == false ) {
26
- $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/\'.';
27
- update_option('wordpress-https_externalurls', 0);
28
- } else {
29
- update_option('wordpress-https_externalurls', 1);
30
  }
31
- } else {
32
- update_option('wordpress-https_externalurls', 0);
 
 
 
 
33
  }
34
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  ?>
36
- <div class="wrap">
37
- <div id="icon-options-general" class="icon32"><br /></div>
38
- <h2>WordPress HTTPS Settings</h2>
39
  <?php
40
- if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
41
- if ( sizeof( $errors ) > 0 ) {
42
- echo " <ul class=\"errors\">\n";
43
- foreach ( $errors as $error ) {
44
- echo " <li class=\"error\"><p>".$error."</p></li>\n";
 
 
 
 
 
45
  }
46
- echo " </ul>\n";
47
- } else {
48
- echo " <div class=\"updated fade\" id=\"message\"><p><strong>Settings saved.</strong></p></div>\n";
49
- }
50
- }
51
  ?>
52
 
53
- <form name="form" action="options-general.php?page=wordpress-https" method="post">
54
- <?php settings_fields('wordpress-https'); ?>
55
- <table class="form-table">
56
- <tr valign="top">
57
- <th scope="row">External HTTPS Elements</th>
58
- <td>
59
- <fieldset>
60
- <legend class="screen-reader-text"><span>Attempt to automatically convert external elements to HTTPS.</span></legend>
61
- <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.<br /><em>Warning: Depending on the amount of external elements, this could affect the load times of your pages.</em></label>
62
- </fieldset>
63
- </td>
64
- </tr>
65
- </table>
66
- <p class="submit"><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
67
- <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>
68
- </form>
69
- </div>
 
 
 
 
 
70
  <?php
71
- }
72
-
73
- function wordpress_https_process($buffer) {
74
- if ( !empty($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443 ) {
75
- $httpsUrl = str_replace('http://', 'https://', get_bloginfo('siteurl'));
76
- $httpUrl = str_replace('https://', 'http://', get_bloginfo('siteurl'));
77
 
78
- preg_match_all('/\<(script|link|img)(.*)http:\/\/[-\w\.]+[^\"\']*/im',$buffer,$matches);
79
- foreach ($matches[0] as $match) {
80
- if ( ( strpos($match, 'link') !== false && strpos($match, 'stylesheet') !== false ) || strpos($match, 'script') !== false || strpos($match, 'img') !== false ) {
81
- if ( strpos($match,$httpUrl) !== false ) {
82
- $buffer = str_replace($match, str_replace('http', 'https', $match), $buffer);
83
- } elseif ( get_option('wordpress-https_externalurls') == '1' ) {
84
- preg_match_all('/http:\/\/[-\w\.]+[^\"\']*/im', $match, $urlMatches);
85
- foreach ( $urlMatches[0] as $urlMatch ) {
86
- if (@file_get_contents(str_replace('http', 'https', $urlMatch))) {
87
- $buffer = str_replace($urlMatch, str_replace('http', 'https', $urlMatch), $buffer);
 
 
 
 
 
 
 
88
  }
89
  }
90
  }
91
  }
 
92
  }
93
- }
94
- return $buffer;
95
- }
96
 
97
- function wordpress_https_buffer_start() { ob_start('wordpress_https_process'); }
98
- function wordpress_https_buffer_end() { ob_end_flush(); }
 
 
 
 
 
 
 
 
 
 
 
99
 
100
- add_action('admin_init', 'wordpress_https_buffer_start');
101
- add_action('send_headers', 'wordpress_https_buffer_start');
102
- add_action('wp_footer', 'wordpress_https_buffer_end');
103
  ?>
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
 
11
+ 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
+ }
26
+ }
 
 
 
27
  }
28
+ add_action('plugins_loaded', array(&$this, 'buffer_start'));
29
+ add_action('wp_footer', array(&$this, 'buffer_end'));
30
+ }
31
+
32
+ function menu() {
33
+ add_options_page('WordPress HTTPS Settings', 'WordPress HTTPS', 'manage_options', 'wordpress-https', array(&$this, 'settings'));
34
  }
35
+
36
+ function settings() {
37
+ if ( !current_user_can('manage_options') ) {
38
+ wp_die( __('You do not have sufficient permissions to access this page.') );
39
+ }
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);
53
+ }
54
+ } else {
55
+ update_option('wordpress-https_externalurls', 0);
56
+ }
57
+ }
58
  ?>
59
+ <div class="wrap">
60
+ <div id="icon-options-general" class="icon32"><br /></div>
61
+ <h2>WordPress HTTPS Settings</h2>
62
  <?php
63
+ if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
64
+ if ( sizeof( $errors ) > 0 ) {
65
+ echo " <ul id=\"message\">\n";
66
+ foreach ( $errors as $error ) {
67
+ echo " <li class=\"error\"><p>".$error."</p></li>\n";
68
+ }
69
+ echo " </ul>\n";
70
+ } else {
71
+ echo " <div class=\"updated fade\" id=\"message\"><p><strong>Settings saved.</strong></p></div>\n";
72
+ }
73
  }
 
 
 
 
 
74
  ?>
75
 
76
+ <form name="form" action="options-general.php?page=wordpress-https" method="post">
77
+ <?php settings_fields('wordpress-https'); ?>
78
+ <table class="form-table">
79
+ <tr valign="top">
80
+ <th scope="row">External HTTPS Elements</th>
81
+ <td>
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>
89
+ <tr>
90
+ <td>
91
+ </td>
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
99
+ }
 
 
 
 
 
100
 
101
+ function process($buffer) {
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
  }
119
  }
120
  }
121
  }
122
+ return $buffer;
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'));
130
+ }
131
+
132
+ function buffer_end() {
133
+ ob_end_flush();
134
+ }
135
+
136
+ } // End WordPressHTTPS Class
137
+ }
138
 
139
+ if ( class_exists('WordPressHTTPS') ) {
140
+ $wordpress_https = new WordPressHTTPS();
141
+ }
142
  ?>