ShortPixel Image Optimizer - Version 3.1.1

Version Description

  • fix calculation of displayed images to be processed counters on bulk start
  • restore option appeared wrongly sometimes - thanks to Bogdan Gnther @ http://medianotions.de
Download this release

Release Info

Developer ShortPixel
Plugin Icon 128x128 ShortPixel Image Optimizer
Version 3.1.1
Comparing to
See all releases

Code changes from version 3.1.0 to 3.1.1

js/short-pixel.js CHANGED
@@ -39,12 +39,20 @@ function showToolBarAlert($status, $message) {
39
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert");
40
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-quota-exceeded");
41
  jQuery("li.shortpixel-toolbar-processing a").attr("href", "http://shortpixel.com/login/" + ShortPixel.API_KEY);
 
42
  jQuery("li.shortpixel-toolbar-processing a div").attr("title", "ShortPixel quota exceeded. Click to top-up");
43
  break;
44
  case ShortPixel.STATUS_FAIL:
45
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert shortpixel-processing");
46
  jQuery("li.shortpixel-toolbar-processing a div").attr("title", $message);
47
  break;
 
 
 
 
 
 
 
48
  }
49
  jQuery("li.shortpixel-toolbar-processing").removeClass("shortpixel-hide");
50
  }
@@ -105,11 +113,15 @@ function checkBulkProcessingCallApi(){
105
  var id = data["ImageID"];
106
 
107
  var isBulkPage = (jQuery("div.short-pixel-bulk-page").length > 0);
108
-
109
  switch (data["Status"]) {
 
 
 
 
110
  case ShortPixel.STATUS_QUOTA_EXCEEDED:
111
  setCellMessage(id, data["Message"] + " | <a href=\"https://shortpixel.com/login/"
112
- + ShortPixel.API_KEY + ")\">Extend Quota</a>");
113
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
114
  break;
115
  case ShortPixel.STATUS_FAIL:
@@ -137,9 +149,8 @@ function checkBulkProcessingCallApi(){
137
  break;
138
  case ShortPixel.STATUS_SUCCESS:
139
  var percent = data["PercentImprovement"];
140
- var cellMsg = "Reduced by <span class='percent'>" + percent
141
- + "%</span> | <a href=\"admin.php?action=shortpixel_restore_backup&attachment_ID="
142
- + id + ")\">Restore backup</a>";
143
  if(0 + data['ThumbsCount'] > 0) {
144
  cellMsg += "<br>+" + data['ThumbsCount'] + " thumbnails optimized";
145
  }
39
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert");
40
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-quota-exceeded");
41
  jQuery("li.shortpixel-toolbar-processing a").attr("href", "http://shortpixel.com/login/" + ShortPixel.API_KEY);
42
+ jQuery("li.shortpixel-toolbar-processing a").attr("target", "_blank");
43
  jQuery("li.shortpixel-toolbar-processing a div").attr("title", "ShortPixel quota exceeded. Click to top-up");
44
  break;
45
  case ShortPixel.STATUS_FAIL:
46
  jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert shortpixel-processing");
47
  jQuery("li.shortpixel-toolbar-processing a div").attr("title", $message);
48
  break;
49
+ case ShortPixel.STATUS_NO_KEY:
50
+ jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert");
51
+ jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-quota-exceeded");
52
+ jQuery("li.shortpixel-toolbar-processing a").attr("href", "http://shortpixel.com/wp-apikey");
53
+ jQuery("li.shortpixel-toolbar-processing a").attr("target", "_blank");
54
+ jQuery("li.shortpixel-toolbar-processing a div").attr("title", "Get API Key");
55
+ break;
56
  }
57
  jQuery("li.shortpixel-toolbar-processing").removeClass("shortpixel-hide");
58
  }
113
  var id = data["ImageID"];
114
 
115
  var isBulkPage = (jQuery("div.short-pixel-bulk-page").length > 0);
116
+
117
  switch (data["Status"]) {
118
+ case ShortPixel.STATUS_NO_KEY:
119
+ setCellMessage(id, data["Message"] + " | <a href=\"https://shortpixel.com/wp-apikey\" target=\"_blank\">Get API Key</a>");
120
+ showToolBarAlert(ShortPixel.STATUS_NO_KEY);
121
+ break;
122
  case ShortPixel.STATUS_QUOTA_EXCEEDED:
123
  setCellMessage(id, data["Message"] + " | <a href=\"https://shortpixel.com/login/"
124
+ + ShortPixel.API_KEY + "\" target=\"_blank\">Extend Quota</a>");
125
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
126
  break;
127
  case ShortPixel.STATUS_FAIL:
149
  break;
150
  case ShortPixel.STATUS_SUCCESS:
151
  var percent = data["PercentImprovement"];
152
+ var cellMsg = "Reduced by <span class='percent'>" + percent + "%</span> "
153
+ + (data["BackupEnabled"] == 1 ? "| <a href=\"admin.php?action=shortpixel_restore_backup&attachment_ID=" + id + ")\">Restore backup</a>" : "");
 
154
  if(0 + data['ThumbsCount'] > 0) {
155
  cellMsg += "<br>+" + data['ThumbsCount'] + " thumbnails optimized";
156
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, co
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
- Stable tag: 3.1.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -160,16 +160,21 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
160
 
161
  == Changelog ==
162
 
 
 
 
 
 
163
  = 3.1.0 =
164
 
165
- * rescale images option
166
  * referral system
167
  * show how many thumbs are optimized for each image
168
  * fix the Visual Composer conflict - thanks to Andy Adams - www.certainlysoftware.com
169
 
170
  = 3.0.8 =
171
 
172
- * fix issue with files in /tmp dir that weren't deleted in certain cases, issue noted by Daniel - germangoogleguy.com
173
 
174
  = 3.0.7 =
175
 
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
+ Stable tag: 3.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
160
 
161
  == Changelog ==
162
 
163
+ = 3.1.1 =
164
+
165
+ * fix calculation of displayed images to be processed counters on bulk start
166
+ * restore option appeared wrongly sometimes - thanks to Bogdan Günther @ http://medianotions.de
167
+
168
  = 3.1.0 =
169
 
170
+ * rescale big images option - thanks to Bogdan Günther @ http://medianotions.de
171
  * referral system
172
  * show how many thumbs are optimized for each image
173
  * fix the Visual Composer conflict - thanks to Andy Adams - www.certainlysoftware.com
174
 
175
  = 3.0.8 =
176
 
177
+ * fix issue with files in /tmp dir that weren't deleted in certain cases, issue noted by Daniel - http://germangoogleguy.com
178
 
179
  = 3.0.7 =
180
 
shortpixel_api.php CHANGED
@@ -12,6 +12,7 @@ class ShortPixelAPI {
12
  const STATUS_QUOTA_EXCEEDED = -3;
13
  const STATUS_SKIP = -4;
14
  const STATUS_NOT_FOUND = -5;
 
15
 
16
  private $_apiKey = '';
17
  private $_compressionType = '';
12
  const STATUS_QUOTA_EXCEEDED = -3;
13
  const STATUS_SKIP = -4;
14
  const STATUS_NOT_FOUND = -5;
15
+ const STATUS_NO_KEY = -6;
16
 
17
  private $_apiKey = '';
18
  private $_compressionType = '';
shortpixel_queue.php CHANGED
@@ -147,7 +147,7 @@ class ShortPixelQueue {
147
  }
148
 
149
  public function resetStartBulkId() {
150
- $this->setStartBulkId($this->ctrl->getMaxMediaId());
151
  }
152
 
153
  public function setStartBulkId($start){
@@ -204,7 +204,7 @@ class ShortPixelQueue {
204
  }
205
 
206
  public function stopBulk() {
207
- $this->startBulkId = $this->ctrl->getMaxMediaId();
208
  $this->stopBulkId = $this->startBulkId;
209
  update_option("wp-short-pixel-query-id-start", $this->startBulkId);
210
  update_option("wp-short-pixel-query-id-stop", $this->stopBulkId);
@@ -238,12 +238,12 @@ class ShortPixelQueue {
238
  delete_option( 'wp-short-pixel-cancel-pointer');
239
  }
240
 
241
- public function resetBulk() {
242
  delete_option('bulkProcessingStatus');
243
  delete_option( 'wp-short-pixel-cancel-pointer');
244
- $this->startBulkId = $this->stopBulkId = $this->ctrl->getMaxMediaId();
245
- update_option( 'wp-short-pixel-query-id-stop', $this->startBulkId );
246
- update_option( 'wp-short-pixel-query-id-start', $this->startBulkId );
247
  update_option('wp-short-pixel-bulk-running-time', 0);
248
  update_option('wp-short-pixel-last-bulk-start-time', 0);
249
  update_option('wp-short-pixel-last-bulk-success-time', 0);
147
  }
148
 
149
  public function resetStartBulkId() {
150
+ $this->setStartBulkId(WPShortPixel::getMaxMediaId());
151
  }
152
 
153
  public function setStartBulkId($start){
204
  }
205
 
206
  public function stopBulk() {
207
+ $this->startBulkId = WPShortPixel::getMaxMediaId();
208
  $this->stopBulkId = $this->startBulkId;
209
  update_option("wp-short-pixel-query-id-start", $this->startBulkId);
210
  update_option("wp-short-pixel-query-id-stop", $this->stopBulkId);
238
  delete_option( 'wp-short-pixel-cancel-pointer');
239
  }
240
 
241
+ public static function resetBulk() {
242
  delete_option('bulkProcessingStatus');
243
  delete_option( 'wp-short-pixel-cancel-pointer');
244
+ $startBulkId = $stopBulkId = WPShortPixel::getMaxMediaId();
245
+ update_option( 'wp-short-pixel-query-id-stop', $startBulkId );
246
+ update_option( 'wp-short-pixel-query-id-start', $startBulkId );
247
  update_option('wp-short-pixel-bulk-running-time', 0);
248
  update_option('wp-short-pixel-last-bulk-start-time', 0);
249
  update_option('wp-short-pixel-last-bulk-success-time', 0);
shortpixel_view.php CHANGED
@@ -30,7 +30,7 @@ class ShortPixelView {
30
  </div> <?php
31
  }
32
 
33
- public function displayApiKeyAlert()
34
  { ?>
35
  <p>In order to start the optimization process, you need to validate your API key in the <a href="options-general.php?page=wp-shortpixel">ShortPixel Settings</a> page in your WordPress Admin.</p>
36
  <p>If you don’t have an API Key, you can get one delivered to your inbox, for free.</p>
@@ -38,7 +38,7 @@ class ShortPixelView {
38
  <?php
39
  }
40
 
41
- public function displayActivationNotice($when = 'activate') { ?>
42
  <div class='notice notice-warning' id='short-pixel-notice-<?=$when?>'>
43
  <?php if($when != 'activate') { ?>
44
  <div style="float:right;"><a href="javascript:dismissShortPixelNotice('<?=$when?>')" class="button" style="margin-top:10px;">Dismiss</a></div>
@@ -52,7 +52,7 @@ class ShortPixelView {
52
  echo "Your image gallery is not optimized. It takes 2 minutes to <a href='https://shortpixel.com/wp-apikey' target='_blank'>get your API key</a> and activate your ShortPixel plugin.<BR><BR>";
53
  break;
54
  case 'activate':
55
- $this->displayApiKeyAlert();
56
  break;
57
  }
58
  ?>
@@ -66,11 +66,11 @@ class ShortPixelView {
66
  <h1>Bulk Image Optimization by ShortPixel</h1>
67
  <?php
68
  if ( !$bulkRan ) { ?>
69
- <p>You have <?=number_format($imageCount['mainFiles'])?> images in your Media Library and <?=number_format($imageCount['totalFiles'] - $imageCount['mainFiles'])?> smaller thumbnails, associated to these images.</p>
70
  <?php if($quotaData["totalProcessedFiles"] > 0) { ?>
71
  <p>From these, <?=number_format($quotaData['mainProcessedFiles'])?> images and <?=number_format($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])?> thumbnails were already processed by ShorPixel</p>
72
  <?php } ?>
73
- <p>If the box below is checked, <b>ShortPixel will process a total of <?=number_format($imageCount['totalFiles'] - $imgProcessedCount['totalFiles'])?> images.</b> However, images with less than 5% optimization will not be counted out of your quota, so the final number of counted images could be smaller.</p>
74
  <p>Thumbnails are important because they are displayed on most of your website's pages and they may generate more traffic than the originals. Optimizing thumbnails will improve your overall website speed. However, if you don't want to optimize thumbnails, please uncheck the box below.</p>
75
 
76
  <form action='' method='POST' >
@@ -85,7 +85,7 @@ class ShortPixelView {
85
  <p>Bulk processing is paused until you resume the optimization process.</p>
86
  <?=$this->displayBulkProgressBar(false, $percent, "")?>
87
  <p>Please see below the optimization status so far:</p>
88
- <?=$this->displayBulkStats($filesOptimized, $thumbsProcessedCount, $under5PercentCount, $averageCompression, $savedSpace)?>
89
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
90
  <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
91
  <?=number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
@@ -94,7 +94,7 @@ class ShortPixelView {
94
  <?php
95
  } else { ?>
96
  <p>Congratulations, your media library has been successfully optimized!</p>
97
- <?=$this->displayBulkStats($filesOptimized, $thumbsProcessedCount, $under5PercentCount, $averageCompression, $savedSpace)?>
98
  <p>Go to the ShortPixel <a href='<?=get_admin_url()?>options-general.php?page=wp-shortpixel#facts'>Stats</a> and see all your websites' optimized stats. Download your detailed <a href="https://api.shortpixel.com/v2/report.php?key=<?=$this->ctrl->getApiKey()?>">Optimization Report</a> to check your image optimization statistics for the last 40 days</p>
99
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
100
  <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
@@ -173,14 +173,14 @@ class ShortPixelView {
173
  <?php
174
  }
175
 
176
- public function displayBulkStats($filesOptimized, $thumbsProcessedCount, $under5PercentCount, $averageCompression, $savedSpace) {
177
  ?>
178
  <div class="bulk-progress bulk-stats">
179
- <div class="label">Processed Images and PDFs:</div><div class="stat-value"><?=number_format($filesOptimized - $thumbsProcessedCount)?></div><br>
180
- <div class="label">Processed Thumbnails:</div><div class="stat-value"><?=number_format($thumbsProcessedCount)?></div><br>
181
- <div class="label totals">Total files processed:</div><div class="stat-value"><?=number_format($filesOptimized)?></div><br>
182
- <div class="label totals">Files with <5% optimization (free):</div><div class="stat-value">-<?=number_format($under5PercentCount)?></div><br><br>
183
- <div class="label totals">Used quota:</div><div class="stat-value"><?=number_format($filesOptimized - $under5PercentCount)?></div><br>
184
  <br>
185
  <div class="label">Average optimization:</div><div class="stat-value"><?=$averageCompression?>%</div><br>
186
  <div class="label">Saved space:</div><div class="stat-value"><?=$savedSpace?></div>
@@ -274,10 +274,10 @@ class ShortPixelView {
274
  <th scope="row"><label for="resize">Resize larger images</label></th>
275
  <td>
276
  <input name="resize" type="checkbox" id="resize" <?= $resize ?>> to maximum
277
- <input type="text" name="width" id="width" style="width:70px" value="<?= max($this->ctrl->getResizeWidth(), $minSizes['width']) ?>" <?= $resizeDisabled ?>/> pixels wide &times;
278
- <input type="text" name="height" id="height" style="width:70px" value="<?= max($this->ctrl->getResizeHeight(), $minSizes['height']) ?>" <?= $resizeDisabled ?>/> pixels high
279
  <p class="settings-info"> Recommended for large photos, like the ones taken with your phone. Saved space can go up to 80% after resizing.<br/>
280
- The new resolution cannot be less than your largest thumbnail size, which is <?=$minSizes['width']?> &times; <?=$minSizes['height']?> pixels.</p>
281
  </td>
282
  </tr>
283
  </tbody>
@@ -290,8 +290,8 @@ class ShortPixelView {
290
  <script>
291
  var rad = document.wp_shortpixel_options.compressionType;
292
  var prev = null;
293
- var minWidth = <?=$minSizes['width']?>,
294
- minHeight = <?=$minSizes['height']?>;
295
  for(var i = 0; i < rad.length; i++) {
296
  rad[i].onclick = function() {
297
 
@@ -311,10 +311,10 @@ class ShortPixelView {
311
  enableResize("#resize");
312
  jQuery("#resize").change(function(){ enableResize(this) });
313
  jQuery("#width").blur(function(){
314
- jQuery(this).val(jQuery(this).val() < minWidth ? minWidth : parseInt(jQuery(this).val()));
315
  });
316
  jQuery("#height").blur(function(){
317
- jQuery(this).val(jQuery(this).val() < minHeight ? minHeight : parseInt(jQuery(this).val()));
318
  });
319
  </script>
320
  <?php } ?>
30
  </div> <?php
31
  }
32
 
33
+ public static function displayApiKeyAlert()
34
  { ?>
35
  <p>In order to start the optimization process, you need to validate your API key in the <a href="options-general.php?page=wp-shortpixel">ShortPixel Settings</a> page in your WordPress Admin.</p>
36
  <p>If you don’t have an API Key, you can get one delivered to your inbox, for free.</p>
38
  <?php
39
  }
40
 
41
+ public static function displayActivationNotice($when = 'activate') { ?>
42
  <div class='notice notice-warning' id='short-pixel-notice-<?=$when?>'>
43
  <?php if($when != 'activate') { ?>
44
  <div style="float:right;"><a href="javascript:dismissShortPixelNotice('<?=$when?>')" class="button" style="margin-top:10px;">Dismiss</a></div>
52
  echo "Your image gallery is not optimized. It takes 2 minutes to <a href='https://shortpixel.com/wp-apikey' target='_blank'>get your API key</a> and activate your ShortPixel plugin.<BR><BR>";
53
  break;
54
  case 'activate':
55
+ self::displayApiKeyAlert();
56
  break;
57
  }
58
  ?>
66
  <h1>Bulk Image Optimization by ShortPixel</h1>
67
  <?php
68
  if ( !$bulkRan ) { ?>
69
+ <p>You have <?=number_format($quotaData['mainFiles'])?> images in your Media Library and <?=number_format($quotaData['totalFiles'] - $quotaData['mainFiles'])?> smaller thumbnails, associated to these images.</p>
70
  <?php if($quotaData["totalProcessedFiles"] > 0) { ?>
71
  <p>From these, <?=number_format($quotaData['mainProcessedFiles'])?> images and <?=number_format($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])?> thumbnails were already processed by ShorPixel</p>
72
  <?php } ?>
73
+ <p>If the box below is checked, <b>ShortPixel will process a total of <?=number_format($quotaData['totalFiles'] - $quotaData['totalProcessedFiles'])?> images.</b> However, images with less than 5% optimization will not be counted out of your quota, so the final number of counted images could be smaller.</p>
74
  <p>Thumbnails are important because they are displayed on most of your website's pages and they may generate more traffic than the originals. Optimizing thumbnails will improve your overall website speed. However, if you don't want to optimize thumbnails, please uncheck the box below.</p>
75
 
76
  <form action='' method='POST' >
85
  <p>Bulk processing is paused until you resume the optimization process.</p>
86
  <?=$this->displayBulkProgressBar(false, $percent, "")?>
87
  <p>Please see below the optimization status so far:</p>
88
+ <?=$this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace)?>
89
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
90
  <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
91
  <?=number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
94
  <?php
95
  } else { ?>
96
  <p>Congratulations, your media library has been successfully optimized!</p>
97
+ <?=$this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace)?>
98
  <p>Go to the ShortPixel <a href='<?=get_admin_url()?>options-general.php?page=wp-shortpixel#facts'>Stats</a> and see all your websites' optimized stats. Download your detailed <a href="https://api.shortpixel.com/v2/report.php?key=<?=$this->ctrl->getApiKey()?>">Optimization Report</a> to check your image optimization statistics for the last 40 days</p>
99
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
100
  <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
173
  <?php
174
  }
175
 
176
+ public function displayBulkStats($totalOptimized, $mainOptimized, $under5PercentCount, $averageCompression, $savedSpace) {
177
  ?>
178
  <div class="bulk-progress bulk-stats">
179
+ <div class="label">Processed Images and PDFs:</div><div class="stat-value"><?=number_format($mainOptimized)?></div><br>
180
+ <div class="label">Processed Thumbnails:</div><div class="stat-value"><?=number_format($totalOptimized - $mainOptimized)?></div><br>
181
+ <div class="label totals">Total files processed:</div><div class="stat-value"><?=number_format($totalOptimized)?></div><br>
182
+ <div class="label totals">Minus files with <5% optimization (free):</div><div class="stat-value"><?=number_format($under5PercentCount)?></div><br><br>
183
+ <div class="label totals">Used quota:</div><div class="stat-value"><?=number_format($totalOptimized - $under5PercentCount)?></div><br>
184
  <br>
185
  <div class="label">Average optimization:</div><div class="stat-value"><?=$averageCompression?>%</div><br>
186
  <div class="label">Saved space:</div><div class="stat-value"><?=$savedSpace?></div>
274
  <th scope="row"><label for="resize">Resize larger images</label></th>
275
  <td>
276
  <input name="resize" type="checkbox" id="resize" <?= $resize ?>> to maximum
277
+ <input type="text" name="width" id="width" style="width:70px" value="<?= max($this->ctrl->getResizeWidth(), min(1024, $minSizes['width'])) ?>" <?= $resizeDisabled ?>/> pixels wide &times;
278
+ <input type="text" name="height" id="height" style="width:70px" value="<?= max($this->ctrl->getResizeHeight(), min(1024, $minSizes['height'])) ?>" <?= $resizeDisabled ?>/> pixels high
279
  <p class="settings-info"> Recommended for large photos, like the ones taken with your phone. Saved space can go up to 80% after resizing.<br/>
280
+ The new resolution should not be less than your largest thumbnail size, which is <?=$minSizes['width']?> &times; <?=$minSizes['height']?> pixels.</p>
281
  </td>
282
  </tr>
283
  </tbody>
290
  <script>
291
  var rad = document.wp_shortpixel_options.compressionType;
292
  var prev = null;
293
+ var minWidth = Math.min(1024, <?=$minSizes['width']?>),
294
+ minHeight = Math.min(1024, <?=$minSizes['height']?>);
295
  for(var i = 0; i < rad.length; i++) {
296
  rad[i].onclick = function() {
297
 
311
  enableResize("#resize");
312
  jQuery("#resize").change(function(){ enableResize(this) });
313
  jQuery("#width").blur(function(){
314
+ jQuery(this).val(Math.max(minWidth, parseInt(jQuery(this).val())));
315
  });
316
  jQuery("#height").blur(function(){
317
+ jQuery(this).val(Math.max(minHeight, parseInt(jQuery(this).val())));
318
  });
319
  </script>
320
  <?php } ?>
wp-shortpixel.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
- * Version: 3.1.0
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -21,7 +21,7 @@ define('SP_RESET_ON_ACTIVATE', false);
21
 
22
  define('SP_AFFILIATE_CODE', '');
23
 
24
- define('PLUGIN_VERSION', "3.1.0");
25
  define('SP_MAX_TIMEOUT', 10);
26
  define('SP_BACKUP', 'ShortpixelBackups');
27
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
@@ -93,10 +93,6 @@ class WPShortPixel {
93
  add_action( 'delete_attachment', array( &$this, 'handleDeleteAttachmentInBackup' ) );
94
  add_action( 'load-upload.php', array( &$this, 'handleCustomBulk'));
95
 
96
- //when plugin is activated run this
97
- register_activation_hook( __FILE__, array( &$this, 'shortPixelActivatePlugin' ) );
98
- register_deactivation_hook( __FILE__, array( &$this, 'shortPixelDeactivatePlugin' ) );
99
-
100
  //automatic optimization
101
  add_action( 'wp_ajax_shortpixel_image_processing', array( &$this, 'handleImageProcessing') );
102
  //manual optimization
@@ -140,9 +136,9 @@ class WPShortPixel {
140
  $this->_resizeHeight = self::getOpt( 'wp-short-pixel-resize-height', 0);
141
  }
142
 
143
- public function shortPixelActivatePlugin()//reset some params to avoid trouble for plugins that were activated/deactivated/activated
144
  {
145
- $this->prioQ->resetBulk();
146
  if(SP_RESET_ON_ACTIVATE === true && WP_DEBUG === true) { //force reset plugin counters, only on specific occasions and on test environments
147
  update_option( 'wp-short-pixel-fileCount', 0);
148
  update_option( 'wp-short-pixel-thumbnail-count', 0);
@@ -154,25 +150,37 @@ class WPShortPixel {
154
  update_option( 'wp-short-pixel-total-optimized', 0);//amount of optimized
155
  update_option( 'wp-short-pixel-bulk-ever-ran', 0);
156
  delete_option('wp-short-pixel-priorityQueue');
157
- unset($_SESSION["wp-short-pixel-priorityQueue"]);
 
 
158
  delete_option("wp-short-pixel-bulk-previous-percent");
159
  }
160
- if(!$this->_verifiedKey) {
161
- $this->view->displayActivationNotice();
162
  }
163
  update_option( 'wp-short-pixel-activation-date', time());
164
  }
165
 
 
 
 
 
 
 
 
166
  public function displayAdminNotices() {
167
- update_option( 'wp-short-pixel-activation-date', time());
168
  if(!$this->_verifiedKey) {
169
  $dismissed = self::getOpt( 'wp-short-pixel-dismissed-notices', array());
170
  $now = time();
171
  $act = self::getOpt( 'wp-short-pixel-activation-date', $now);
 
 
 
 
172
  if( ($now > $act + 7200) && !isset($dismissed['2h'])) {
173
- $this->view->displayActivationNotice('2h');
174
  } else if( ($now > $act + 72 * 3600) && !isset($dismissed['3d'])) {
175
- $this->view->displayActivationNotice('3d');
176
  }
177
  }
178
  }
@@ -185,12 +193,6 @@ class WPShortPixel {
185
  die(json_encode(array("Status" => 'success', "Message" => 'Notice ID: ' . $noticeId . ' dismissed')));
186
  }
187
 
188
-
189
- public function shortPixelDeactivatePlugin()//reset some params to avoid trouble for plugins that were activated/deactivated/activated
190
- {
191
- $this->prioQ->resetBulk();
192
- }
193
-
194
  //set default move as "list". only set once, it won't try to set the default mode again.
195
  public function setDefaultViewModeList()
196
  {
@@ -226,8 +228,9 @@ class WPShortPixel {
226
  STATUS_EMPTY_QUEUE: <?= self::BULK_EMPTY_QUEUE ?>,
227
  STATUS_ERROR: <?= ShortPixelAPI::STATUS_ERROR ?>,
228
  STATUS_FAIL: <?= ShortPixelAPI::STATUS_FAIL ?>,
229
- STATUS_SKIP: <?= ShortPixelAPI::STATUS_SKIP ?>,
230
  STATUS_QUOTA_EXCEEDED: <?= ShortPixelAPI::STATUS_QUOTA_EXCEEDED ?>,
 
 
231
  WP_PLUGIN_URL: '<?= plugins_url( '', __FILE__ ) ?>',
232
  API_KEY: "<?= $this->_apiKey ?>"
233
  });
@@ -425,8 +428,11 @@ class WPShortPixel {
425
  //die("bau");
426
  //0: check key
427
  if( $this->_verifiedKey == false) {
428
- echo "Missing API Key";
429
- die("Missing API Key");
 
 
 
430
  }
431
 
432
  self::log("HIP: 0 Priority Queue: ".json_encode($this->prioQ->get()));
@@ -484,6 +490,7 @@ class WPShortPixel {
484
  $prio = $this->prioQ->removeFromFailed($ID);
485
  $meta = wp_get_attachment_metadata($ID);
486
  $result["ThumbsCount"] = isset($meta['sizes']) && is_array($meta['sizes']) ? count($meta['sizes']): 0;
 
487
 
488
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
489
  $this->prioQ->setStartBulkId($ID - 1);
@@ -696,7 +703,7 @@ class WPShortPixel {
696
  global $wpdb;
697
 
698
  if( $this->_verifiedKey == false ) {//invalid API Key
699
- $this->view->displayApiKeyAlert();
700
  return;
701
  }
702
 
@@ -861,8 +868,11 @@ class WPShortPixel {
861
  if($validityData['APIKeyValid']) {
862
  if(isset($_POST['validate']) && $_POST['validate'] == "validate") {
863
  //display notification
864
- if(in_array($_SERVER["SERVER_ADDR"], array("127.0.0.1","::1"))) {
865
- printf($noticeHTML, '#FFC800', "API Key is valid but your server seems to have a local address.
 
 
 
866
  Please make sure that your server is accessible from the Internet before using the API or otherwise we won't be able to optimize them.");
867
  } else {
868
 
@@ -904,7 +914,7 @@ class WPShortPixel {
904
  $this->_resizeImages = (isset($_POST['resize']) ? 1: 0);
905
  $this->_resizeWidth = (isset($_POST['width']) ? $_POST['width']: $this->_resizeWidth);
906
  $this->_resizeHeight = (isset($_POST['height']) ? $_POST['height']: $this->_resizeHeight);
907
- update_option( 'wp-short-pixel-resize-images', $this->_resizeImages);
908
  update_option( 'wp-short-pixel-resize-width', 0 + $this->_resizeWidth);
909
  update_option( 'wp-short-pixel-resize-height', 0 + $this->_resizeHeight);
910
 
@@ -1044,7 +1054,9 @@ class WPShortPixel {
1044
  else
1045
  {
1046
  print 'PDF not processed';
1047
- print " | <a href=\"javascript:manualOptimization({$id})\">Optimize now</a>";
 
 
1048
  return;
1049
  }
1050
  }
@@ -1065,15 +1077,17 @@ class WPShortPixel {
1065
  }
1066
  elseif( is_numeric($data['ShortPixelImprovement']) ) {
1067
  if ( $data['ShortPixelImprovement'] < 5 ) {
1068
- print $data['ShortPixelImprovement'] . '%';
1069
- print " optimized<BR> Bonus processing";
 
 
1070
  } else {
1071
  print 'Reduced by ';
1072
  print $data['ShortPixelImprovement'] . '%';
1073
  }
1074
  if ( get_option('wp-short-backup_images') && !isset($data['ShortPixel']['NoBackup'])) //display restore backup option only when backup is active
1075
  print " | <a href=\"admin.php?action=shortpixel_restore_backup&amp;attachment_ID={$id}\">Restore backup</a>";
1076
- if ($this->_backupImages && count($data['sizes'])) {
1077
  print "<br>+" . count($data['sizes']) . " thumbnails optimized";
1078
  }
1079
  }
@@ -1128,7 +1142,7 @@ class WPShortPixel {
1128
  print 'Image not processed';
1129
  print " | <a href=\"javascript:manualOptimization({$id})\">Optimize now</a>";
1130
  }
1131
- if ($this->_backupImages && count($data['sizes'])) {
1132
  print "<br>+" . count($data['sizes']) . " thumbnails";
1133
  }
1134
  }
@@ -1271,7 +1285,7 @@ class WPShortPixel {
1271
  return $total_size;
1272
  }
1273
 
1274
- public function getMaxMediaId() {
1275
  global $wpdb;
1276
  $queryMax = "SELECT max(post_id) as QueryID FROM " . $wpdb->prefix . "postmeta";
1277
  $resultQuery = $wpdb->get_results($queryMax);
@@ -1470,6 +1484,10 @@ function onInit() {
1470
 
1471
  if ( !function_exists( 'vc_action' ) || vc_action() !== 'vc_inline' ) { //handle incompatibility with Visual Composer
1472
  add_action( 'init', 'onInit');
 
 
 
 
1473
  }
1474
 
1475
  //$pluginInstance = new WPShortPixel();
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
+ * Version: 3.1.1
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
21
 
22
  define('SP_AFFILIATE_CODE', '');
23
 
24
+ define('PLUGIN_VERSION', "3.1.1");
25
  define('SP_MAX_TIMEOUT', 10);
26
  define('SP_BACKUP', 'ShortpixelBackups');
27
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
93
  add_action( 'delete_attachment', array( &$this, 'handleDeleteAttachmentInBackup' ) );
94
  add_action( 'load-upload.php', array( &$this, 'handleCustomBulk'));
95
 
 
 
 
 
96
  //automatic optimization
97
  add_action( 'wp_ajax_shortpixel_image_processing', array( &$this, 'handleImageProcessing') );
98
  //manual optimization
136
  $this->_resizeHeight = self::getOpt( 'wp-short-pixel-resize-height', 0);
137
  }
138
 
139
+ public static function shortPixelActivatePlugin()//reset some params to avoid trouble for plugins that were activated/deactivated/activated
140
  {
141
+ self::shortPixelDeactivatePlugin();
142
  if(SP_RESET_ON_ACTIVATE === true && WP_DEBUG === true) { //force reset plugin counters, only on specific occasions and on test environments
143
  update_option( 'wp-short-pixel-fileCount', 0);
144
  update_option( 'wp-short-pixel-thumbnail-count', 0);
150
  update_option( 'wp-short-pixel-total-optimized', 0);//amount of optimized
151
  update_option( 'wp-short-pixel-bulk-ever-ran', 0);
152
  delete_option('wp-short-pixel-priorityQueue');
153
+ if(isset($_SESSION["wp-short-pixel-priorityQueue"])) {
154
+ unset($_SESSION["wp-short-pixel-priorityQueue"]);
155
+ }
156
  delete_option("wp-short-pixel-bulk-previous-percent");
157
  }
158
+ if(!self::getOpt('wp-short-pixel-verifiedKey', false)) {
159
+ update_option('wp-short-pixel-activation-notice', true);
160
  }
161
  update_option( 'wp-short-pixel-activation-date', time());
162
  }
163
 
164
+ public static function shortPixelDeactivatePlugin()//reset some params to avoid trouble for plugins that were activated/deactivated/activated
165
+ {
166
+ include_once dirname( __FILE__ ) . '/shortpixel_queue.php';
167
+ ShortPixelQueue::resetBulk();
168
+ delete_option('wp-short-pixel-activation-notice');
169
+ }
170
+
171
  public function displayAdminNotices() {
 
172
  if(!$this->_verifiedKey) {
173
  $dismissed = self::getOpt( 'wp-short-pixel-dismissed-notices', array());
174
  $now = time();
175
  $act = self::getOpt( 'wp-short-pixel-activation-date', $now);
176
+ if(self::getOpt( 'wp-short-pixel-activation-notice', false)) {
177
+ ShortPixelView::displayActivationNotice();
178
+ delete_option('wp-short-pixel-activation-notice');
179
+ }
180
  if( ($now > $act + 7200) && !isset($dismissed['2h'])) {
181
+ ShortPixelView::displayActivationNotice('2h');
182
  } else if( ($now > $act + 72 * 3600) && !isset($dismissed['3d'])) {
183
+ ShortPixelView::displayActivationNotice('3d');
184
  }
185
  }
186
  }
193
  die(json_encode(array("Status" => 'success', "Message" => 'Notice ID: ' . $noticeId . ' dismissed')));
194
  }
195
 
 
 
 
 
 
 
196
  //set default move as "list". only set once, it won't try to set the default mode again.
197
  public function setDefaultViewModeList()
198
  {
228
  STATUS_EMPTY_QUEUE: <?= self::BULK_EMPTY_QUEUE ?>,
229
  STATUS_ERROR: <?= ShortPixelAPI::STATUS_ERROR ?>,
230
  STATUS_FAIL: <?= ShortPixelAPI::STATUS_FAIL ?>,
 
231
  STATUS_QUOTA_EXCEEDED: <?= ShortPixelAPI::STATUS_QUOTA_EXCEEDED ?>,
232
+ STATUS_SKIP: <?= ShortPixelAPI::STATUS_SKIP ?>,
233
+ STATUS_NO_KEY: <?= ShortPixelAPI::STATUS_NO_KEY ?>,
234
  WP_PLUGIN_URL: '<?= plugins_url( '', __FILE__ ) ?>',
235
  API_KEY: "<?= $this->_apiKey ?>"
236
  });
428
  //die("bau");
429
  //0: check key
430
  if( $this->_verifiedKey == false) {
431
+ if($ID == null){
432
+ $ids = $this->getFromPrioAndCheck();
433
+ $ID = (count($ids) > 0 ? $ids[0] : null);
434
+ }
435
+ die(json_encode(array("Status" => ShortPixelAPI::STATUS_NO_KEY, "ImageID" => $ID, "Message" => "Missing API Key")));
436
  }
437
 
438
  self::log("HIP: 0 Priority Queue: ".json_encode($this->prioQ->get()));
490
  $prio = $this->prioQ->removeFromFailed($ID);
491
  $meta = wp_get_attachment_metadata($ID);
492
  $result["ThumbsCount"] = isset($meta['sizes']) && is_array($meta['sizes']) ? count($meta['sizes']): 0;
493
+ $result["BackupEnabled"] = $this->_backupImages;
494
 
495
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
496
  $this->prioQ->setStartBulkId($ID - 1);
703
  global $wpdb;
704
 
705
  if( $this->_verifiedKey == false ) {//invalid API Key
706
+ ShortPixelView::displayApiKeyAlert();
707
  return;
708
  }
709
 
868
  if($validityData['APIKeyValid']) {
869
  if(isset($_POST['validate']) && $_POST['validate'] == "validate") {
870
  //display notification
871
+ $urlParts = explode("/", get_site_url());
872
+ if( false
873
+ && (((count($urlParts) >= 3) && ($urlParts[2] == 'wpshortpixel.com'))
874
+ || in_array($_SERVER["SERVER_ADDR"], array("127.0.0.1","::1")))){
875
+ printf($noticeHTML, '#FFC800', "API Key is valid but your server seems to have a local address (" . $_SERVER['SERVER_ADDR'] . ").
876
  Please make sure that your server is accessible from the Internet before using the API or otherwise we won't be able to optimize them.");
877
  } else {
878
 
914
  $this->_resizeImages = (isset($_POST['resize']) ? 1: 0);
915
  $this->_resizeWidth = (isset($_POST['width']) ? $_POST['width']: $this->_resizeWidth);
916
  $this->_resizeHeight = (isset($_POST['height']) ? $_POST['height']: $this->_resizeHeight);
917
+ update_option( 'wp-short-pixel-resize-images', $this->_resizeImages);
918
  update_option( 'wp-short-pixel-resize-width', 0 + $this->_resizeWidth);
919
  update_option( 'wp-short-pixel-resize-height', 0 + $this->_resizeHeight);
920
 
1054
  else
1055
  {
1056
  print 'PDF not processed';
1057
+ //if($this->_verifiedKey) {
1058
+ print " | <a href=\"javascript:manualOptimization({$id})\">Optimize now</a>";
1059
+ //}
1060
  return;
1061
  }
1062
  }
1077
  }
1078
  elseif( is_numeric($data['ShortPixelImprovement']) ) {
1079
  if ( $data['ShortPixelImprovement'] < 5 ) {
1080
+ if($data['ShortPixelImprovement'] > 0 ) {
1081
+ print $data['ShortPixelImprovement'] . '% optimized<br>';
1082
+ }
1083
+ print "Bonus processing";
1084
  } else {
1085
  print 'Reduced by ';
1086
  print $data['ShortPixelImprovement'] . '%';
1087
  }
1088
  if ( get_option('wp-short-backup_images') && !isset($data['ShortPixel']['NoBackup'])) //display restore backup option only when backup is active
1089
  print " | <a href=\"admin.php?action=shortpixel_restore_backup&amp;attachment_ID={$id}\">Restore backup</a>";
1090
+ if (count($data['sizes'])) {
1091
  print "<br>+" . count($data['sizes']) . " thumbnails optimized";
1092
  }
1093
  }
1142
  print 'Image not processed';
1143
  print " | <a href=\"javascript:manualOptimization({$id})\">Optimize now</a>";
1144
  }
1145
+ if (count($data['sizes'])) {
1146
  print "<br>+" . count($data['sizes']) . " thumbnails";
1147
  }
1148
  }
1285
  return $total_size;
1286
  }
1287
 
1288
+ public static function getMaxMediaId() {
1289
  global $wpdb;
1290
  $queryMax = "SELECT max(post_id) as QueryID FROM " . $wpdb->prefix . "postmeta";
1291
  $resultQuery = $wpdb->get_results($queryMax);
1484
 
1485
  if ( !function_exists( 'vc_action' ) || vc_action() !== 'vc_inline' ) { //handle incompatibility with Visual Composer
1486
  add_action( 'init', 'onInit');
1487
+
1488
+ register_activation_hook( __FILE__, array( 'WPShortPixel', 'shortPixelActivatePlugin' ) );
1489
+ register_deactivation_hook( __FILE__, array( 'WPShortPixel', 'shortPixelDeactivatePlugin' ) );
1490
+
1491
  }
1492
 
1493
  //$pluginInstance = new WPShortPixel();