WordPress HTTPS (SSL) - Version 1.6

Version Description

  • Multiple enhancements to core functionality of plugin. Mostly just changing code to integrate more smoothely with WordPress.
  • Enhancements have been made to the plugin's settings page.
Download this release

Release Info

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

Code changes from version 1.5.2 to 1.6

css/admin.css ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ div#message-wrap {
2
+ height: 35px;
3
+ overflow: hidden;
4
+ }
5
+
6
+ form#wordpress-https {
7
+ float: left;
8
+ margin-right: 320px;
9
+ margin-top: 15px;
10
+ }
11
+ form#wordpress-https h3 {
12
+ margin-bottom: .5em;
13
+ }
14
+ form#wordpress-https fieldset {
15
+ margin-bottom: 20px;
16
+ }
17
+ form#wordpress-https fieldset p {
18
+ margin: 2px 0 5px 0;
19
+ }
20
+
21
+ div#wphttps-sidebar {
22
+ margin: 20px 0 0 -300px;
23
+ clear: right;
24
+ float: right;
25
+ width: 300px;
26
+ }
27
+ div#wphttps-sidebar div.wphttps-widget {
28
+ margin: 0 auto 20px auto;
29
+ width: 285px;
30
+ }
31
+ div.wphttps-widget-content {
32
+ background: #F1F1F1;
33
+ padding: 5px 20px;
34
+ -moz-border-radius-bottomleft:8px;
35
+ -moz-border-radius-bottomright:8px;
36
+ border: 1px solid #DDD;
37
+ border-top: 0;
38
+ }
39
+ div.wphttps-widget h3 {
40
+ font-size: 13px;
41
+ height: 19px;
42
+ margin: 0;
43
+ overflow: hidden;
44
+ padding: 5px 12px;
45
+ white-space: nowrap;
46
+ background: url(images/widget-title.png) repeat-x;
47
+ border: 1px solid #636363;
48
+ border-bottom: 0;
49
+ -moz-border-radius-topleft:8px;
50
+ -moz-border-radius-topright:8px;
51
+ color: #FFF;
52
+ text-shadow:0 -1px 0 #3F3F3F;
53
+ }
54
+
55
+ div.wphttps-widget#wphttps-donate input[type="text"] {
56
+ width: 95px;
57
+ }
58
+
59
+ img.waiting {
60
+ display: none;
61
+ }
62
+ img#submit-waiting {
63
+ vertical-align: middle;
64
+ margin-left: 5px;
65
+ }
66
+
67
+ p.description {
68
+ color: #666;
69
+ font-size: 12px;
70
+ font-style: italic;
71
+ }
css/images/widget-title.png ADDED
Binary file
css/images/wpspin_light.gif ADDED
Binary file
js/admin.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery('#message-body').fadeOut();
3
+
4
+ jQuery('#wordpress-https').submit(function() {
5
+ jQuery('#submit-waiting').show();
6
+ });
7
+ //
8
+ var options = {
9
+ data: { ajax: '1'},
10
+ success: function() {
11
+ jQuery('#message-body').html('<div class=\"updated below-h2 fade\" id=\"message\"><p>Settings saved.</p></div>');
12
+ // .animate is used to delay the fadeOut by 2 seconds
13
+ jQuery('#message-body').fadeIn().animate({opacity: 1.0}, 2000).fadeOut();
14
+ jQuery('#submit-waiting').hide();
15
+ }
16
+ };
17
+
18
+ jQuery('#wordpress-https').ajaxForm(options);
19
+ });
js/jquery.form.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ jQuery Form Plugin
3
+ version: 2.47 (04-SEP-2010)
4
+ @requires jQuery v1.3.2 or later
5
+
6
+ Examples and documentation at: http://malsup.com/jquery/form/
7
+ Dual licensed under the MIT and GPL licenses:
8
+ http://www.opensource.org/licenses/mit-license.php
9
+ http://www.gnu.org/licenses/gpl.html
10
+ */;(function($){$.fn.ajaxSubmit=function(options){if(!this.length){log('ajaxSubmit: skipping submit process - no element selected');return this;}if(typeof options=='function'){options={success:options};}var url=$.trim(this.attr('action'));if(url){url=(url.match(/^([^#]+)/)||[])[1];}url=url||window.location.href||'';options=$.extend(true,{url:url,type:this.attr('method')||'GET',iframeSrc:/^https/i.test(window.location.href||'')?'javascript:false':'about:blank'},options);var veto={};this.trigger('form-pre-serialize',[this,options,veto]);if(veto.veto){log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');return this;}if(options.beforeSerialize&&options.beforeSerialize(this,options)===false){log('ajaxSubmit: submit aborted via beforeSerialize callback');return this;}var n,v,a=this.formToArray(options.semantic);if(options.data){options.extraData=options.data;for(n in options.data){if(options.data[n]instanceof Array){for(var k in options.data[n]){a.push({name:n,value:options.data[n][k]});}}else{v=options.data[n];v=$.isFunction(v)?v():v;a.push({name:n,value:v});}}}if(options.beforeSubmit&&options.beforeSubmit(a,this,options)===false){log('ajaxSubmit: submit aborted via beforeSubmit callback');return this;}this.trigger('form-submit-validate',[a,this,options,veto]);if(veto.veto){log('ajaxSubmit: submit vetoed via form-submit-validate trigger');return this;}var q=$.param(a);if(options.type.toUpperCase()=='GET'){options.url+=(options.url.indexOf('?')>=0?'&':'?')+q;options.data=null;}else{options.data=q;}var $form=this,callbacks=[];if(options.resetForm){callbacks.push(function(){$form.resetForm();});}if(options.clearForm){callbacks.push(function(){$form.clearForm();});}if(!options.dataType&&options.target){var oldSuccess=options.success||function(){};callbacks.push(function(data){var fn=options.replaceTarget?'replaceWith':'html';$(options.target)[fn](data).each(oldSuccess,arguments);});}else if(options.success){callbacks.push(options.success);}options.success=function(data,status,xhr){var context=options.context||options;for(var i=0,max=callbacks.length;i<max;i++){callbacks[i].apply(context,[data,status,xhr||$form,$form]);}};var fileInputs=$('input:file',this).length>0;var mp='multipart/form-data';var multipart=($form.attr('enctype')==mp||$form.attr('encoding')==mp);if(options.iframe!==false&&(fileInputs||options.iframe||multipart)){if(options.closeKeepAlive){$.get(options.closeKeepAlive,fileUpload);}else{fileUpload();}}else{$.ajax(options);}this.trigger('form-submit-notify',[this,options]);return this;function fileUpload(){var form=$form[0];if($(':input[name=submit],:input[id=submit]',form).length){alert('Error: Form elements must not have name or id of "submit".');return;}var s=$.extend(true,{},$.ajaxSettings,options);s.context=s.context||s;var id='jqFormIO'+(new Date().getTime()),fn='_'+id;window[fn]=function(){var f=$io.data('form-plugin-onload');if(f){f();window[fn]=undefined;try{delete window[fn];}catch(e){}}}var $io=$('<iframe id="'+id+'" name="'+id+'" src="'+s.iframeSrc+'" onload="window[\'_\'+this.id]()" />');var io=$io[0];$io.css({position:'absolute',top:'-1000px',left:'-1000px'});var xhr={aborted:0,responseText:null,responseXML:null,status:0,statusText:'n/a',getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){this.aborted=1;$io.attr('src',s.iframeSrc);}};var g=s.global;if(g&&!$.active++){$.event.trigger("ajaxStart");}if(g){$.event.trigger("ajaxSend",[xhr,s]);}if(s.beforeSend&&s.beforeSend.call(s.context,xhr,s)===false){if(s.global){$.active--;}return;}if(xhr.aborted){return;}var cbInvoked=false;var timedOut=0;var sub=form.clk;if(sub){var n=sub.name;if(n&&!sub.disabled){s.extraData=s.extraData||{};s.extraData[n]=sub.value;if(sub.type=="image"){s.extraData[n+'.x']=form.clk_x;s.extraData[n+'.y']=form.clk_y;}}}function doSubmit(){var t=$form.attr('target'),a=$form.attr('action');form.setAttribute('target',id);if(form.getAttribute('method')!='POST'){form.setAttribute('method','POST');}if(form.getAttribute('action')!=s.url){form.setAttribute('action',s.url);}if(!s.skipEncodingOverride){$form.attr({encoding:'multipart/form-data',enctype:'multipart/form-data'});}if(s.timeout){setTimeout(function(){timedOut=true;cb();},s.timeout);}var extraInputs=[];try{if(s.extraData){for(var n in s.extraData){extraInputs.push($('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />').appendTo(form)[0]);}}$io.appendTo('body');$io.data('form-plugin-onload',cb);form.submit();}finally{form.setAttribute('action',a);if(t){form.setAttribute('target',t);}else{$form.removeAttr('target');}$(extraInputs).remove();}}if(s.forceSync){doSubmit();}else{setTimeout(doSubmit,10);}var data,doc,domCheckCount=50;function cb(){if(cbInvoked){return;}$io.removeData('form-plugin-onload');var ok=true;try{if(timedOut){throw'timeout';}doc=io.contentWindow?io.contentWindow.document:io.contentDocument?io.contentDocument:io.document;var isXml=s.dataType=='xml'||doc.XMLDocument||$.isXMLDoc(doc);log('isXml='+isXml);if(!isXml&&window.opera&&(doc.body==null||doc.body.innerHTML=='')){if(--domCheckCount){log('requeing onLoad callback, DOM not available');setTimeout(cb,250);return;}}cbInvoked=true;xhr.responseText=doc.documentElement?doc.documentElement.innerHTML:null;xhr.responseXML=doc.XMLDocument?doc.XMLDocument:doc;xhr.getResponseHeader=function(header){var headers={'content-type':s.dataType};return headers[header];};var scr=/(json|script)/.test(s.dataType);if(scr||s.textarea){var ta=doc.getElementsByTagName('textarea')[0];if(ta){xhr.responseText=ta.value;}else if(scr){var pre=doc.getElementsByTagName('pre')[0];if(pre){xhr.responseText=pre.innerHTML;}}}else if(s.dataType=='xml'&&!xhr.responseXML&&xhr.responseText!=null){xhr.responseXML=toXml(xhr.responseText);}data=$.httpData(xhr,s.dataType);}catch(e){log('error caught:',e);ok=false;xhr.error=e;$.handleError(s,xhr,'error',e);}if(ok){s.success.call(s.context,data,'success',xhr);if(g){$.event.trigger("ajaxSuccess",[xhr,s]);}}if(g){$.event.trigger("ajaxComplete",[xhr,s]);}if(g&&!--$.active){$.event.trigger("ajaxStop");}if(s.complete){s.complete.call(s.context,xhr,ok?'success':'error');}setTimeout(function(){$io.removeData('form-plugin-onload');$io.remove();xhr.responseXML=null;},100);}function toXml(s,doc){if(window.ActiveXObject){doc=new ActiveXObject('Microsoft.XMLDOM');doc.async='false';doc.loadXML(s);}else{doc=(new DOMParser()).parseFromString(s,'text/xml');}return(doc&&doc.documentElement&&doc.documentElement.tagName!='parsererror')?doc:null;}}};$.fn.ajaxForm=function(options){if(this.length===0){var o={s:this.selector,c:this.context};if(!$.isReady&&o.s){log('DOM not ready, queuing ajaxForm');$(function(){$(o.s,o.c).ajaxForm(options);});return this;}log('terminating; zero elements found by selector'+($.isReady?'':' (DOM not ready)'));return this;}return this.ajaxFormUnbind().bind('submit.form-plugin',function(e){if(!e.isDefaultPrevented()){e.preventDefault();$(this).ajaxSubmit(options);}}).bind('click.form-plugin',function(e){var target=e.target;var $el=$(target);if(!($el.is(":submit,input:image"))){var t=$el.closest(':submit');if(t.length==0){return;}target=t[0];}var form=this;form.clk=target;if(target.type=='image'){if(e.offsetX!=undefined){form.clk_x=e.offsetX;form.clk_y=e.offsetY;}else if(typeof $.fn.offset=='function'){var offset=$el.offset();form.clk_x=e.pageX-offset.left;form.clk_y=e.pageY-offset.top;}else{form.clk_x=e.pageX-target.offsetLeft;form.clk_y=e.pageY-target.offsetTop;}}setTimeout(function(){form.clk=form.clk_x=form.clk_y=null;},100);});};$.fn.ajaxFormUnbind=function(){return this.unbind('submit.form-plugin click.form-plugin');};$.fn.formToArray=function(semantic){var a=[];if(this.length===0){return a;}var form=this[0];var els=semantic?form.getElementsByTagName('*'):form.elements;if(!els){return a;}var i,j,n,v,el;for(i=0,max=els.length;i<max;i++){el=els[i];n=el.name;if(!n){continue;}if(semantic&&form.clk&&el.type=="image"){if(!el.disabled&&form.clk==el){a.push({name:n,value:$(el).val()});a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});}continue;}v=$.fieldValue(el,true);if(v&&v.constructor==Array){for(j=0,jmax=v.length;j<jmax;j++){a.push({name:n,value:v[j]});}}else if(v!==null&&typeof v!='undefined'){a.push({name:n,value:v});}}if(!semantic&&form.clk){var $input=$(form.clk),input=$input[0];n=input.name;if(n&&!input.disabled&&input.type=='image'){a.push({name:n,value:$input.val()});a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});}}return a;};$.fn.formSerialize=function(semantic){return $.param(this.formToArray(semantic));};$.fn.fieldSerialize=function(successful){var a=[];this.each(function(){var n=this.name;if(!n){return;}var v=$.fieldValue(this,successful);if(v&&v.constructor==Array){for(var i=0,max=v.length;i<max;i++){a.push({name:n,value:v[i]});}}else if(v!==null&&typeof v!='undefined'){a.push({name:this.name,value:v});}});return $.param(a);};$.fn.fieldValue=function(successful){for(var val=[],i=0,max=this.length;i<max;i++){var el=this[i];var v=$.fieldValue(el,successful);if(v===null||typeof v=='undefined'||(v.constructor==Array&&!v.length)){continue;}v.constructor==Array?$.merge(val,v):val.push(v);}return val;};$.fieldValue=function(el,successful){var n=el.name,t=el.type,tag=el.tagName.toLowerCase();if(successful===undefined){successful=true;}if(successful&&(!n||el.disabled||t=='reset'||t=='button'||(t=='checkbox'||t=='radio')&&!el.checked||(t=='submit'||t=='image')&&el.form&&el.form.clk!=el||tag=='select'&&el.selectedIndex==-1)){return null;}if(tag=='select'){var index=el.selectedIndex;if(index<0){return null;}var a=[],ops=el.options;var one=(t=='select-one');var max=(one?index+1:ops.length);for(var i=(one?index:0);i<max;i++){var op=ops[i];if(op.selected){var v=op.value;if(!v){v=(op.attributes&&op.attributes['value']&&!(op.attributes['value'].specified))?op.text:op.value;}if(one){return v;}a.push(v);}}return a;}return $(el).val();};$.fn.clearForm=function(){return this.each(function(){$('input,select,textarea',this).clearFields();});};$.fn.clearFields=$.fn.clearInputs=function(){return this.each(function(){var t=this.type,tag=this.tagName.toLowerCase();if(t=='text'||t=='password'||tag=='textarea'){this.value='';}else if(t=='checkbox'||t=='radio'){this.checked=false;}else if(tag=='select'){this.selectedIndex=-1;}});};$.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=='function'||(typeof this.reset=='object'&&!this.reset.nodeType)){this.reset();}});};$.fn.enable=function(b){if(b===undefined){b=true;}return this.each(function(){this.disabled=!b;});};$.fn.selected=function(select){if(select===undefined){select=true;}return this.each(function(){var t=this.type;if(t=='checkbox'||t=='radio'){this.checked=select;}else if(this.tagName.toLowerCase()=='option'){var $sel=$(this).parent('select');if(select&&$sel[0]&&$sel[0].type=='select-one'){$sel.find('option').selected(false);}this.selected=select;}});};function log(){if($.fn.ajaxSubmit.debug){var msg='[jquery.form] '+Array.prototype.join.call(arguments,'');if(window.console&&window.console.log){window.console.log(msg);}else if(window.opera&&window.opera.postError){window.opera.postError(msg);}}};})(jQuery);
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.7.0
6
  Tested up to: 3.0.1
7
- Stable tag: 1.5.2
8
 
9
  Features: Force HTTPS on only certain pages. Fix partially encrypted errors. Disable WordPress from changing links to HTTPS. And more!
10
 
@@ -64,6 +64,9 @@ In most cases, yes. There are limitations to what this plugin can fix. Here are
64
 
65
  == Changelog ==
66
 
 
 
 
67
  = 1.5.2 =
68
  * Fixed a bug that would prevent stylesheets from being fixed if the rel attribute came after the href attribute. Bug could have also caused errors with other tags.
69
  = 1.5.1 =
4
  Tags: encrypted, ssl, http, https
5
  Requires at least: 2.7.0
6
  Tested up to: 3.0.1
7
+ Stable tag: 1.6
8
 
9
  Features: Force HTTPS on only certain pages. Fix partially encrypted errors. Disable WordPress from changing links to HTTPS. And more!
10
 
64
 
65
  == Changelog ==
66
 
67
+ = 1.6 =
68
+ * Multiple enhancements to core functionality of plugin. Mostly just changing code to integrate more smoothely with WordPress.
69
+ * Enhancements have been made to the plugin's settings page.
70
  = 1.5.2 =
71
  * Fixed a bug that would prevent stylesheets from being fixed if the rel attribute came after the href attribute. Bug could have also caused errors with other tags.
72
  = 1.5.1 =
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
wordpress-https.php CHANGED
@@ -2,9 +2,9 @@
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.5.2
8
  Author URI: http://mvied.com/
9
  */
10
 
@@ -20,18 +20,25 @@ if ( !class_exists('WordPressHTTPS') ) {
20
  class WordPressHTTPS {
21
 
22
  /**
23
- * Default options
24
  *
25
- * @private array
26
  */
27
- private $options_default;
28
 
29
  /**
30
- * WordPress version
31
  *
32
- * @var int
33
  */
34
- var $wp_version;
 
 
 
 
 
 
 
35
 
36
  /**
37
  * Initialize plugin
@@ -40,40 +47,52 @@ if ( !class_exists('WordPressHTTPS') ) {
40
  * @return void
41
  */
42
  function __construct() {
43
- // Format WordPress version for comparison. 2.9 => 29, 3.0 => 30, etc.
44
- $this->wp_version = (int)substr(str_replace('.','',get_bloginfo('version')), 0, 2);
 
 
 
 
45
 
46
  // Define default options
47
  $this->options_default = array(
48
- 'wordpress-https_externalurls' => 0, // Option to change external URL's to HTTPS
 
49
  'wordpress-https_bypass' => 0, // Bypass option to check if external elements can be loaded via HTTPS
50
  '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.
51
- 'wordpress-https_exclusive_https' => 0
 
52
  );
53
 
54
  if ( is_admin() ) {
55
  // Add admin menus
56
  add_action('admin_menu', array(&$this, 'menu'));
57
 
58
- // Set default options
59
- foreach ( $this->options_default as $option => $value ) {
60
- if ( get_option($option) === false ) {
61
- add_option($option, $value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
  }
64
  } else {
65
- // If not admin, enable front-end redirection
66
- add_action('wp_head', array(&$this, 'redirect'));
67
  }
68
 
69
- // Add 'Force SSL' checkbox to add/edit post pages
70
- add_action('post_submitbox_misc_actions', array(&$this, 'post_checkbox'));
71
- add_action('save_post', array(&$this, 'post_save'));
72
-
73
- // Output buffering
74
- add_action('plugins_loaded', array(&$this, 'buffer_start'));
75
- //add_action('wp_footer', array(&$this, 'buffer_end'));
76
-
77
  // Filter HTTPS from links in WP 3.0+
78
  if ( get_option('wordpress-https_disable_autohttps') == 1 ) {
79
  add_filter('page_link', array(&$this, 'replace_https'));
@@ -85,6 +104,92 @@ if ( !class_exists('WordPressHTTPS') ) {
85
  add_filter('bloginfo', array(&$this, 'bloginfo'), 10, 2);
86
  add_filter('bloginfo_url', array(&$this, 'bloginfo'), 10, 2);
87
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
 
90
  /**
@@ -102,7 +207,7 @@ if ( !class_exists('WordPressHTTPS') ) {
102
  if ($post->ID) {
103
  $checked = get_post_meta($post->ID, 'force_ssl', true);
104
  }
105
- echo '<div class="misc-pub-section misc-pub-section-last" style="border-top: 1px solid #EEE;"><label>Force HTTPS: <input type="checkbox" value="1" name="force_ssl" id="force_ssl"'.(($checked) ? ' checked="checked"' : '').' /></label></div>';
106
  }
107
 
108
  /**
@@ -183,22 +288,28 @@ if ( !class_exists('WordPressHTTPS') ) {
183
 
184
  foreach ($this->options_default as $key => $default) {
185
  if (!array_key_exists($key, $_POST)) {
186
- $_POST[$key] = $default;
187
  } else {
188
  if ( $key == 'wordpress-https_bypass' && @ini_get('allow_url_fopen') != 1 ) {
189
  $errors[] = 'PHP configuration error: allow_url_fopen must be enabled to allow the conversion of external elements to HTTPS.';
190
  $_POST[$key] = 0;
191
- } else if ($key == 'wordpress-https_disable_autohttps' && $this->wp_version < 30) {
192
  $_POST[$key] = 0;
193
  }
194
  }
195
  update_option($key, $_POST[$key]);
196
  }
 
 
 
 
 
197
  }
198
  ?>
199
  <div class="wrap">
200
  <div id="icon-options-general" class="icon32"><br /></div>
201
  <h2>WordPress HTTPS Settings</h2>
 
202
  <?php
203
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
204
  if ( sizeof( $errors ) > 0 ) {
@@ -208,122 +319,109 @@ if ( !class_exists('WordPressHTTPS') ) {
208
  }
209
  echo " </ul>\n";
210
  } else {
211
- echo " <div class=\"updated below-h2 fade\" id=\"message\"><p>Items saved.</p></div>\n";
212
  }
 
 
213
  }
214
  ?>
215
- <form name="form" action="options-general.php?page=wordpress-https" method="post">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  <?php settings_fields('wordpress-https'); ?>
217
- <table class="form-table">
218
- <tr valign="top">
219
- <th scope="row">External HTTPS Elements</th>
220
- <td>
221
- <fieldset>
222
- <legend class="screen-reader-text"><span>Attempt to automatically convert external elements to HTTPS.</span></legend>
223
- <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>
224
- <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>
225
- </fieldset>
226
- </td>
227
- </tr>
228
- <tr valign="top">
229
- <th scope="row">Bypass External Check</th>
230
- <td>
231
- <fieldset>
232
- <legend class="screen-reader-text"><span>Disable the option to check if an external element can be loaded over HTTPS.</span></legend>
233
- <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>
234
- <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>
235
- </fieldset>
236
- </td>
237
- </tr>
238
- <?php if ($this->wp_version >= 30) { ?>
239
- <tr valign="top">
240
- <th scope="row">Disable Automatic HTTPS</th>
241
- <td>
242
- <fieldset>
243
- <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>
244
- <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>
245
- <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>
246
- </fieldset>
247
- </td>
248
- </tr>
249
  <?php } ?>
250
- <tr valign="top">
251
- <th scope="row">Force SSL Exclusively</th>
252
- <td>
253
- <fieldset>
254
- <legend class="screen-reader-text"><span>Exclusively force SSL on posts and pages with the 'Force SSL' option checked. All others are redirected to HTTP.</span></legend>
255
- <label for="wordpress-https_exclusive_https"><input name="wordpress-https_exclusive_https" type="checkbox" id="wordpress-https_exclusive_https" value="1"<?php echo ((get_option('wordpress-https_exclusive_https')) ? ' checked="checked"' : ''); ?> /> Exclusively force SSL on posts and pages with the `Force SSL` option checked. All others are redirected to HTTP.</label>
256
- <p class="description">WordPress HTTPS adds a 'Force SSL' checkbox to each post and page right above the publish button (<a href="http://s.wordpress.org/extend/plugins/wordpress-https/screenshot-2.png" target="_blank">screenshot</a>). When selected, the post or page will be forced to HTTPS. With this option enabled, all posts and pages without 'Force SSL' checked will be redirected to HTTP.</p>
257
- </fieldset>
258
- </td>
259
- </tr>
260
- </table>
261
- <p class="submit"><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
262
- <p>This plugin was created by <a href="http://mvied.com/" target="_blank">Mike Ems</a>. If you found my plugin useful, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG" target="_blank">donating</a> and/or <a href="http://wordpress.org/extend/plugins/wordpress-https/">rating</a>. If you're having any trouble, please <a href="http://wordpress.org/tags/wordpress-https#postform" target="_blank">start a support topic</a>. Thanks for downloading!</p>
 
 
 
 
 
 
263
  </form>
 
 
 
264
  </div>
265
  <?php
266
  }
267
 
268
- /**
269
- * Redirect posts and pages accordingly
270
- *
271
- * @param none
272
- * @return void
273
- */
274
- function redirect() {
275
- global $post;
276
- if ( is_single() || is_page() ) {
277
- if ( $_SERVER['SERVER_PORT'] != 443 ) {
278
- $forceSSL = get_post_meta($post->ID, 'force_ssl');
279
- if ($forceSSL) {
280
- header("Location: https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
281
- exit;
282
- }
283
- } else if ( get_option('wordpress-https_exclusive_https') == 1 ) {
284
- $forceSSL = get_post_meta($post->ID, 'force_ssl');
285
- if (!$forceSSL) {
286
- header("Location: http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
287
- exit;
288
- }
289
- }
290
  }
291
- }
292
-
293
- /**
294
- * Process output buffer
295
- *
296
- * @param string
297
- * @return string
298
- */
299
- function process($buffer) {
300
- if ( $_SERVER['SERVER_PORT'] == 443 ) {
301
- if ($this->wp_version >= 30) {
302
- $httpsUrl = $this->replace_http(get_site_url());
303
- } else {
304
- $httpsUrl = $this->replace_http(get_bloginfo('home'));
305
- }
306
- $httpUrl = $this->replace_https($httpsUrl);
307
 
308
- preg_match_all('/\<(script|link|img|input)[^>]+(http:\/\/[\/-\w\.]+)[^>]+>/im',$buffer,$matches);
309
- for ($i = 0; $i<=sizeof($matches[0]); $i++) {
310
- $html = $matches[0][$i];
311
- $type = $matches[1][$i];
312
- $url = $matches[2][$i];
313
- if ( ( $type == 'link' && strpos($html, 'stylesheet') !== false ) || ( $type == 'input' && strpos($html, 'image') !== false ) || $type == 'script' || $type == 'img' ) {
314
- if ( strpos($html,$httpUrl) !== false ) {
315
- $buffer = str_replace($html, $this->replace_http($html), $buffer);
316
- } else if ( get_option('wordpress-https_externalurls') == 1 ) {
317
- if ( get_option('wordpress-https_bypass') == 1 ) {
318
- $buffer = str_replace($html, $this->replace_http($html), $buffer);
319
- } else if (@file_get_contents($this->replace_http($url))) {
320
- $buffer = str_replace($html, $this->replace_http($html), $buffer);
321
- }
322
- }
323
- }
324
- }
325
- }
326
- return $buffer;
327
  }
328
 
329
  /**
2
  /*
3
  Plugin Name: WordPress HTTPS
4
  Plugin URI: http://mvied.com/projects/wordpress-https/
5
+ Description: Force HTTPS on only certain pages. Fix partially encrypted errors. Disable WordPress from changing links to HTTPS. And more!
6
  Author: Mike Ems
7
+ Version: 1.6
8
  Author URI: http://mvied.com/
9
  */
10
 
20
  class WordPressHTTPS {
21
 
22
  /**
23
+ * Plugin version
24
  *
25
+ * @var int
26
  */
27
+ var $plugin_version = '1.6';
28
 
29
  /**
30
+ * Plugin URL
31
  *
32
+ * @var string
33
  */
34
+ var $plugin_url;
35
+
36
+ /**
37
+ * Default options
38
+ *
39
+ * @private array
40
+ */
41
+ private $options_default;
42
 
43
  /**
44
  * Initialize plugin
47
  * @return void
48
  */
49
  function __construct() {
50
+ // Assign plugin_url
51
+ if ( version_compare( get_bloginfo('version'), '2.8', '>=' ) ) {
52
+ $this->plugin_url = plugins_url('', __FILE__);
53
+ } else {
54
+ $this->plugin_url = WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__));
55
+ }
56
 
57
  // Define default options
58
  $this->options_default = array(
59
+ 'wordpress-https_internalurls' => 1, // Force internal URL's to HTTPS
60
+ 'wordpress-https_externalurls' => 0, // Force external URL's to HTTPS
61
  'wordpress-https_bypass' => 0, // Bypass option to check if external elements can be loaded via HTTPS
62
  '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.
63
+ 'wordpress-https_exclusive_https' => 0, // Exclusively force SSL on posts and pages with the `Force SSL` option checked.
64
+ 'wordpress-https_frontpage' => 0 // Force SSL on front page
65
  );
66
 
67
  if ( is_admin() ) {
68
  // Add admin menus
69
  add_action('admin_menu', array(&$this, 'menu'));
70
 
71
+ // Load on plugins page
72
+ if ( 'plugins.php' == $GLOBALS['pagenow'] ) {
73
+ add_filter( 'plugin_row_meta', array( &$this, 'plugin_links' ), 10, 2);
74
+ }
75
+
76
+ // Load on Settings page
77
+ if (@$_GET['page'] == 'wordpress-https') {
78
+ wp_enqueue_style('widgets');
79
+
80
+ wp_enqueue_script('jquery-form', $this->plugin_url . '/js/jquery.form.js', array('jquery'), '2.47', true);
81
+ wp_enqueue_script('wordpress-https', $this->plugin_url . '/js/admin.js', array('jquery'), $this->plugin_version, true);
82
+ wp_enqueue_style('wordpress-https', $this->plugin_url . '/css/admin.css', $this->plugin_version, true);
83
+
84
+ // Set default options
85
+ foreach ( $this->options_default as $option => $value ) {
86
+ if ( get_option($option) === false ) {
87
+ add_option($option, $value);
88
+ }
89
  }
90
  }
91
  } else {
92
+ // If not admin, check to see if the page needs to be redirected
93
+ add_action('get_header', array(&$this, 'check_https'));
94
  }
95
 
 
 
 
 
 
 
 
 
96
  // Filter HTTPS from links in WP 3.0+
97
  if ( get_option('wordpress-https_disable_autohttps') == 1 ) {
98
  add_filter('page_link', array(&$this, 'replace_https'));
104
  add_filter('bloginfo', array(&$this, 'bloginfo'), 10, 2);
105
  add_filter('bloginfo_url', array(&$this, 'bloginfo'), 10, 2);
106
  }
107
+
108
+ // Add 'Force SSL' checkbox to add/edit post pages
109
+ add_action('post_submitbox_misc_actions', array(&$this, 'post_checkbox'));
110
+ add_action('save_post', array(&$this, 'post_save'));
111
+
112
+ // Start output buffering
113
+ add_action('plugins_loaded', array(&$this, 'buffer_start'));
114
+ // End output buffering
115
+ //add_action('shutdown', array(&$this, 'buffer_end'));
116
+ }
117
+
118
+ /**
119
+ * Process output buffer
120
+ *
121
+ * @param string
122
+ * @return string
123
+ */
124
+ function process($buffer) {
125
+ if ( is_ssl() ) {
126
+ $httpsUrl = $this->replace_http(get_option('siteurl'));
127
+ $httpUrl = $this->replace_https($httpsUrl);
128
+
129
+ preg_match_all('/\<(script|link|img|input)[^>]+(http:\/\/[\/-\w\.]+)[^>]+>/im',$buffer,$matches);
130
+ for ($i = 0; $i<=sizeof($matches[0]); $i++) {
131
+ $html = $matches[0][$i];
132
+ $type = $matches[1][$i];
133
+ $url = $matches[2][$i];
134
+ if ( ( $type == 'link' && strpos($html, 'stylesheet') !== false ) || ( $type == 'input' && strpos($html, 'image') !== false ) || $type == 'script' || $type == 'img' ) {
135
+ if ( strpos($html,$httpUrl) !== false && get_option('wordpress-https_internalurls') == 1 ) {
136
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
137
+ } else if ( get_option('wordpress-https_externalurls') == 1 ) {
138
+ if ( get_option('wordpress-https_bypass') == 1 ) {
139
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
140
+ } else if (@file_get_contents($this->replace_http($url))) {
141
+ $buffer = str_replace($html, $this->replace_http($html), $buffer);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ return $buffer;
148
+ }
149
+
150
+ /**
151
+ * Checks to see if the current page needs to be redirected
152
+ *
153
+ * @param none
154
+ * @return void
155
+ */
156
+ function check_https() {
157
+ global $post;
158
+ if ( is_single() || is_page() ) {
159
+ if ( !is_ssl() ) {
160
+ $forceSSL = get_post_meta($post->ID, 'force_ssl');
161
+ if ($forceSSL) {
162
+ $this->redirect(true);
163
+ }
164
+ } else if ( get_option('wordpress-https_exclusive_https') == 1 ) {
165
+ $forceSSL = get_post_meta($post->ID, 'force_ssl');
166
+ if (!$forceSSL) {
167
+ $this->redirect(false);
168
+ }
169
+ }
170
+ } else if (is_front_page()) {
171
+ if (get_option('wordpress-https_frontpage') == 1 && !is_ssl() ) {
172
+ $this->redirect(true);
173
+ } else if (get_option('wordpress-https_frontpage') != 1 && is_ssl()) {
174
+ $this->redirect(false);
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Redirects page to HTTP or HTTPS accordingly
181
+ *
182
+ * @param none
183
+ * @return void
184
+ */
185
+ function redirect($ssl = true) {
186
+ if ( !is_ssl() && $ssl == true ) {
187
+ wp_redirect('https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
188
+ exit();
189
+ } else if (is_ssl() && $ssl == false) {
190
+ wp_redirect('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
191
+ exit();
192
+ }
193
  }
194
 
195
  /**
207
  if ($post->ID) {
208
  $checked = get_post_meta($post->ID, 'force_ssl', true);
209
  }
210
+ echo '<div class="misc-pub-section misc-pub-section-last" style="border-top: 1px solid #EEE;"><label>Force SSL: <input type="checkbox" value="1" name="force_ssl" id="force_ssl"'.(($checked) ? ' checked="checked"' : '').' /></label></div>';
211
  }
212
 
213
  /**
288
 
289
  foreach ($this->options_default as $key => $default) {
290
  if (!array_key_exists($key, $_POST)) {
291
+ $_POST[$key] = 0;
292
  } else {
293
  if ( $key == 'wordpress-https_bypass' && @ini_get('allow_url_fopen') != 1 ) {
294
  $errors[] = 'PHP configuration error: allow_url_fopen must be enabled to allow the conversion of external elements to HTTPS.';
295
  $_POST[$key] = 0;
296
+ } else if ($key == 'wordpress-https_disable_autohttps' && version_compare(get_bloginfo('version'),'3.0','<')) {
297
  $_POST[$key] = 0;
298
  }
299
  }
300
  update_option($key, $_POST[$key]);
301
  }
302
+ if ( @$_POST['ajax'] == 1 ) {
303
+ ob_clean();
304
+ echo "1";
305
+ exit();
306
+ }
307
  }
308
  ?>
309
  <div class="wrap">
310
  <div id="icon-options-general" class="icon32"><br /></div>
311
  <h2>WordPress HTTPS Settings</h2>
312
+
313
  <?php
314
  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
315
  if ( sizeof( $errors ) > 0 ) {
319
  }
320
  echo " </ul>\n";
321
  } else {
322
+ echo " <div class=\"updated below-h2 fade\" id=\"message\"><p>Settings saved.</p></div>\n";
323
  }
324
+ } else {
325
+ echo " <div id=\"message-wrap\"><div id=\"message-body\"></div></div>\n";
326
  }
327
  ?>
328
+
329
+ <div id="wphttps-sidebar">
330
+
331
+ <div class="wphttps-widget" id="wphttps-support">
332
+ <h3 class="wphttps-widget-title">Support</h3>
333
+ <div class="wphttps-widget-content">
334
+ <p>Have you tried everything and your website is still giving you partially encrypted errors?</p>
335
+ <p>If you haven't already, check out the <a href="http://wordpress.org/extend/plugins/wordpress-https/faq/" target="_blank">Frequently Asked Questions</a>.</p>
336
+ <p>Still not fixed? Having other problems? Please <a href="http://wordpress.org/tags/wordpress-https#postform" target="_blank">start a support topic</a> and I'll do my best to assist you.</p>
337
+ </div>
338
+ </div>
339
+
340
+ <div class="wphttps-widget" id="wphttps-donate">
341
+ <h3 class="wphttps-widget-title">Donate</h3>
342
+ <div class="wphttps-widget-content">
343
+ <p>If you found this plugin useful, or I've already helped you with your website, please considering buying me a <a href="http://en.wikipedia.org/wiki/Newcastle_Brown_Ale" target="_blank">beer</a> or two.</p>
344
+ <p>Donations help alleviate the time spent developing and supporting this plugin and are greatly appreciated.</p>
345
+
346
+ <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
347
+ <input type="hidden" name="cmd" value="_xclick">
348
+ <input type="hidden" name="business" value="mike@mvied.com">
349
+ <input type="hidden" name="item_name" value="WordPress HTTPS Donation">
350
+ <input type="hidden" name="currency_code" value="USD">
351
+ <label for="amount">Amount: $ <input type="text" name="amount" value="0.00" /></label>
352
+ <input type="submit" class="button-secondary" value="Donate" />
353
+ </form>
354
+ </div>
355
+ </div>
356
+
357
+ </div>
358
+
359
+ <form name="form" id="wordpress-https" action="options-general.php?page=wordpress-https" method="post">
360
  <?php settings_fields('wordpress-https'); ?>
361
+
362
+ <fieldset>
363
+ <label for="wordpress-https_internalurls"><input name="wordpress-https_internalurls" type="checkbox" id="wordpress-https_internalurls" value="1"<?php echo ((get_option('wordpress-https_internalurls')) ? ' checked="checked"' : ''); ?> /> <strong>Internal HTTPS Elements</strong></label>
364
+ <p>Force internal elements to HTTPS.</p>
365
+ <p class="description">Disabling this will basically disable the plugin.</p>
366
+ </fieldset>
367
+
368
+ <fieldset>
369
+ <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"' : ''); ?> /> <strong>External HTTPS Elements</strong></label>
370
+ <p>Attempt to automatically force external elements to HTTPS.</p>
371
+ <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>
372
+ </fieldset>
373
+
374
+ <fieldset>
375
+ <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"' : ''); ?> /> <strong>Bypass External Check</strong></label>
376
+ <p>Disable the option to check if an external element can be loaded over HTTPS.</p>
377
+ <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>
378
+ </fieldset>
379
+
380
+ <?php if (version_compare(get_bloginfo('version'),'3.0','>=')) { ?>
381
+ <fieldset>
382
+ <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"' : ''); ?> /> <strong>Disable Automatic HTTPS</strong></label>
383
+ <p>Disable the feature in WordPress 3.0+ that makes all links HTTPS if the page is being viewed via HTTPS.</p>
384
+ <p class="description">When a page is viewed via HTTPS in WordPress 3.0+, all internal page, category and post links are forced to HTTPS. This option will disable that.</p>
385
+ </fieldset>
386
+
 
 
 
 
 
 
387
  <?php } ?>
388
+
389
+ <fieldset>
390
+ <label for="wordpress-https_exclusive_https"><input name="wordpress-https_exclusive_https" type="checkbox" id="wordpress-https_exclusive_https" value="1"<?php echo ((get_option('wordpress-https_exclusive_https')) ? ' checked="checked"' : ''); ?> /> <strong>Force SSL Exclusively</strong></label>
391
+ <p>Exclusively force SSL on posts and pages with the `Force SSL` option checked. All others are redirected to HTTP.</p>
392
+ <p class="description">WordPress HTTPS adds a 'Force SSL' checkbox to each post and page right above the publish button (<a href="<?php echo $this->plugin_url; ?>screenshot-2.png" target="_blank">screenshot</a>). When selected, the post or page will be forced to HTTPS. With this option enabled, all posts and pages without 'Force SSL' checked will be redirected to HTTP.</p>
393
+ </fieldset>
394
+
395
+ <?php if (get_option('show_on_front') == 'posts') { ?>
396
+ <fieldset>
397
+ <label for="wordpress-https_frontpage"><input name="wordpress-https_frontpage" type="checkbox" id="wordpress-https_frontpage" value="1"<?php echo ((get_option('wordpress-https_frontpage')) ? ' checked="checked"' : ''); ?> /> <strong>HTTPS Front Page</strong></label>
398
+ <p>It appears you are using your latest posts for your home page. If you would like that page to have SSL enforced, enable this option.</p>
399
+ </fieldset>
400
+
401
+ <?php } ?>
402
+
403
+ <p class="button-controls">
404
+ <input type="submit" name="Submit" value="Save Changes" class="button-primary" />
405
+ <img alt="Waiting..." src="<?php echo $this->plugin_url; ?>/css/images/wpspin_light.gif" class="waiting" id="submit-waiting" />
406
+ </p>
407
  </form>
408
+
409
+ <br style="clear: both" />
410
+
411
  </div>
412
  <?php
413
  }
414
 
415
+ function plugin_links($links,$file) {
416
+ if ( strpos($file,basename( __FILE__)) === false ) {
417
+ return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
 
420
+ $links[] = '<a href="'.site_url().'/wp-admin/options-general.php?page=wordpress-https" title="WordPress HTTPS Settings">Settings</a>';
421
+ $links[] = '<a href="http://wordpress.org/extend/plugins/wordpress-https/faq/" title="Frequently Asked Questions">FAQ</a>';
422
+ $links[] = '<a href="http://wordpress.org/tags/wordpress-https#postform" title="Support">Support</a>';
423
+ $links[] = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZL95VTJ388HG" title="Support WordPress HTTPS development with a donation!">Donate</a>';
424
+ return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  }
426
 
427
  /**