added use SSL on purge requests option
added use SSL on purge requests option

file:a/readme.txt -> file:b/readme.txt
--- a/readme.txt
+++ b/readme.txt
@@ -3,8 +3,8 @@
 Contributors: razvanstanga
 Tags: varnish, purge, cache, caching, optimization, performance, traffic
 Requires at least: 4.0
-Tested up to: 4.8
-Stable tag: 1.6.1
+Tested up to: 4.9
+Stable tag: 1.6.6
 License: GPLv2 or later
 
 Wordpress Varnish Cache 3.x/4.x/5.x integration
@@ -116,6 +116,22 @@
 
 == Changelog ==
 
+= 1.6.6 =
+* no more SSl auto detection. If you use SSL with Varnish use the option 'Use SSL (https://) for purge requests.'
+* there are cases where the website uses SSL, but the Varnish servers do not
+
+= 1.6.5 =
+* added sslverify set default to false to wp_remote_request. thanks @Jules81
+
+= 1.6.4 =
+* fixed php notice
+
+= 1.6.3 =
+* added SSL to schema filter. thanks @Jules81
+
+= 1.6.2 =
+* fixed purge_post empty 2nd param
+
 = 1.6.1 =
 * Do/do not purge when saving menus option
 * fixed bug showing multiple `Truncate message activated ...`

--- a/vcaching.php
+++ b/vcaching.php
@@ -3,7 +3,7 @@
 Plugin Name: Varnish Caching
 Plugin URI: http://wordpress.org/extend/plugins/vcaching/
 Description: WordPress Varnish Cache integration.
-Version: 1.6.1
+Version: 1.6.6
 Author: Razvan Stanga
 Author URI: http://git.razvi.ro/
 License: http://www.apache.org/licenses/LICENSE-2.0
@@ -35,6 +35,8 @@
     protected $debug = 0;
     protected $vclGeneratorTab = true;
     protected $purgeOnMenuSave = false;
+    protected $currentTab;
+    protected $useSsl = false;
 
     public function __construct()
     {
@@ -134,6 +136,8 @@
             $this->purge_url(home_url() . $_POST['varnish_caching_purge_url']);
             add_action('admin_notices' , array($this, 'purge_message'));
         }
+        $this->currentTab = isset($_GET['tab']) ? $_GET['tab'] : 'options';
+        $this->useSsl = get_option($this->prefix . 'ssl');
     }
 
     public function override_ttl($post)
@@ -388,7 +392,7 @@
             $path = '';
         }
 
-        $schema = apply_filters('vcaching_schema', 'http://');
+        $schema = apply_filters('vcaching_schema', $this->useSsl ? 'https://' : 'http://');
 
         foreach ($this->ipsToHosts as $key => $ipToHost) {
             $purgeme = $schema . $ipToHost['ip'] . $path . $pregex;
@@ -396,7 +400,7 @@
             if (!is_null($this->purgeKey)) {
                 $headers['X-VC-Purge-Key'] = $this->purgeKey;
             }
-            $response = wp_remote_request($purgeme, array('method' => 'PURGE', 'headers' => $headers));
+            $response = wp_remote_request($purgeme, array('method' => 'PURGE', 'headers' => $headers, "sslverify" => false));
             if ($response instanceof WP_Error) {
                 foreach ($response->errors as $error => $errors) {
                     $this->noticeMessage .= '<br />Error ' . $error . '<br />';
@@ -406,7 +410,7 @@
                 }
             } else {
                 if ($this->truncateNotice && $this->truncateCount <= 2 || $this->truncateNotice == false) {
-                    $this->noticeMessage .= '' . __('Trying to purge URL :', $this->plugin) . $purgeme;
+                    $this->noticeMessage .= '' . __('Trying to purge URL : ', $this->plugin) . $purgeme;
                     preg_match("/<title>(.*)<\/title>/i", $response['body'], $matches);
                     $this->noticeMessage .= ' => <br /> ' . isset($matches[1]) ? " => " . $matches[1] : $response['body'];
                     $this->noticeMessage .= '<br />';
@@ -421,10 +425,10 @@
         do_action('vcaching_after_purge_url', $url, $purgeme);
     }
 
-    public function purge_post($postId, $post)
+    public function purge_post($postId, $post=null)
     {
         // Do not purge menu items
-        if ($post->post_type == 'nav_menu_item' && $this->purgeOnMenuSave == false) {
+        if (get_post_type($post) == 'nav_menu_item' && $this->purgeOnMenuSave == false) {
             return;
         }
 
@@ -562,17 +566,17 @@
         <h1><?=__('Varnish Caching', $this->plugin)?></h1>
 
         <h2 class="nav-tab-wrapper">
-            <a class="nav-tab <?php if(!isset($_GET['tab']) || $_GET['tab'] == 'options'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=options"><?=__('Settings', $this->plugin)?></a>
+            <a class="nav-tab <?php if($this->currentTab == 'options'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=options"><?=__('Settings', $this->plugin)?></a>
             <?php if ($this->check_if_purgeable()): ?>
-                <a class="nav-tab <?php if($_GET['tab'] == 'console'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=console"><?=__('Console', $this->plugin)?></a>
+                <a class="nav-tab <?php if($this->currentTab == 'console'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=console"><?=__('Console', $this->plugin)?></a>
             <?php endif; ?>
-            <a class="nav-tab <?php if($_GET['tab'] == 'stats'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=stats"><?=__('Statistics', $this->plugin)?></a>
+            <a class="nav-tab <?php if($this->currentTab == 'stats'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=stats"><?=__('Statistics', $this->plugin)?></a>
             <?php if ($this->vclGeneratorTab): ?>
-                <a class="nav-tab <?php if($_GET['tab'] == 'conf'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=conf"><?=__('VCLs Generator', $this->plugin)?></a>
+                <a class="nav-tab <?php if($this->currentTab == 'conf'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=conf"><?=__('VCLs Generator', $this->plugin)?></a>
             <?php endif; ?>
         </h2>
 
-        <?php if(!isset($_GET['tab']) || $_GET['tab'] == 'options'): ?>
+        <?php if($this->currentTab == 'options'): ?>
             <form method="post" action="options.php">
                 <?php
                     settings_fields($this->prefix . 'options');
@@ -592,7 +596,7 @@
                     jQuery('#' + id).val(outStr);
                 }
             </script>
-        <?php elseif($_GET['tab'] == 'console'): ?>
+        <?php elseif($this->currentTab == 'console'): ?>
             <form method="post" action="index.php?page=<?=$this->plugin?>-plugin&amp;tab=console">
                 <?php
                     settings_fields($this->prefix . 'console');
@@ -600,7 +604,7 @@
                     submit_button(__('Purge', $this->plugin));
                 ?>
             </form>
-        <?php elseif($_GET['tab'] == 'stats'): ?>
+        <?php elseif($this->currentTab == 'stats'): ?>
             <h2><?= __('Statistics', $this->plugin) ?></h2>
 
             <div class="wrap">
@@ -672,7 +676,7 @@
                     </script>
                 <?php endif; ?>
             </div>
-        <?php elseif($_GET['tab'] == 'conf'): ?>
+        <?php elseif($this->currentTab == 'conf'): ?>
             <form method="post" action="options.php">
                 <?php
                     settings_fields($this->prefix . 'conf');
@@ -719,6 +723,7 @@
         add_settings_field($this->prefix . "stats_json_file", __("Statistics JSONs", $this->plugin), array($this, $this->prefix . "stats_json_file"), $this->prefix . 'options', $this->prefix . 'options');
         add_settings_field($this->prefix . "truncate_notice", __("Truncate notice message", $this->plugin), array($this, $this->prefix . "truncate_notice"), $this->prefix . 'options', $this->prefix . 'options');
         add_settings_field($this->prefix . "purge_menu_save", __("Purge on save menu", $this->plugin), array($this, $this->prefix . "purge_menu_save"), $this->prefix . 'options', $this->prefix . 'options');
+        add_settings_field($this->prefix . "ssl", __("Use SSL on purge requests", $this->plugin), array($this, $this->prefix . "ssl"), $this->prefix . 'options', $this->prefix . 'options');
         add_settings_field($this->prefix . "debug", __("Enable debug", $this->plugin), array($this, $this->prefix . "debug"), $this->prefix . 'options', $this->prefix . 'options');
 
         if(isset($_POST['option_page']) && $_POST['option_page'] == $this->prefix . 'options') {
@@ -734,6 +739,7 @@
             register_setting($this->prefix . 'options', $this->prefix . "stats_json_file");
             register_setting($this->prefix . 'options', $this->prefix . "truncate_notice");
             register_setting($this->prefix . 'options', $this->prefix . "purge_menu_save");
+            register_setting($this->prefix . 'options', $this->prefix . "ssl");
             register_setting($this->prefix . 'options', $this->prefix . "debug");
         }
     }
@@ -846,6 +852,16 @@
             <input type="checkbox" name="varnish_caching_purge_menu_save" value="1" <?php checked(1, get_option($this->prefix . 'purge_menu_save'), true); ?> />
             <p class="description">
                 <?=__('Purge menu related pages when a menu is saved.', $this->plugin)?>
+            </p>
+        <?php
+    }
+
+    public function varnish_caching_ssl()
+    {
+        ?>
+            <input type="checkbox" name="varnish_caching_ssl" value="1" <?php checked(1, get_option($this->prefix . 'ssl'), true); ?> />
+            <p class="description">
+                <?=__('Use SSL (https://) for purge requests.', $this->plugin)?>
             </p>
         <?php
     }

comments