ShortPixel Image Optimizer - Version 3.0.8

Version Description

  • fix issue with files in /tmp dir that weren't deleted in certain cases, issue noted by Daniel - germangoogleguy.com
Download this release

Release Info

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

Code changes from version 3.0.7 to 3.0.8

js/short-pixel.js CHANGED
@@ -112,13 +112,14 @@ function checkBulkProcessingCallApi(){
112
  + ShortPixel.API_KEY + ")\">Extend Quota</a>");
113
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
114
  break;
115
- /* case ShortPixel.STATUS_FAIL:
116
  setCellMessage(id, data["Message"]);
117
  if(isBulkPage) {
118
  showToolBarAlert(ShortPixel.STATUS_FAIL, data["Message"]);
119
  }
120
  console.log(data["Message"]);
121
- break;*/
 
122
  case ShortPixel.STATUS_EMPTY_QUEUE:
123
  console.log(data["Message"]);
124
  clearBulkProcessor(); //nothing to process, leave the role. Next page load will check again
@@ -147,10 +148,10 @@ function checkBulkProcessingCallApi(){
147
  }
148
  //fall through
149
  case ShortPixel.STATUS_ERROR: //for error and skip also we retry
150
- case ShortPixel.STATUS_FAIL:
151
  case ShortPixel.STATUS_SKIP:
152
  console.log('Server response: ' + response);
153
  setTimeout(checkBulkProgress, 2000);
 
154
  }
155
  }
156
  });
112
  + ShortPixel.API_KEY + ")\">Extend Quota</a>");
113
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
114
  break;
115
+ case ShortPixel.STATUS_FAIL:
116
  setCellMessage(id, data["Message"]);
117
  if(isBulkPage) {
118
  showToolBarAlert(ShortPixel.STATUS_FAIL, data["Message"]);
119
  }
120
  console.log(data["Message"]);
121
+ setTimeout(checkBulkProgress, 2000);
122
+ break;
123
  case ShortPixel.STATUS_EMPTY_QUEUE:
124
  console.log(data["Message"]);
125
  clearBulkProcessor(); //nothing to process, leave the role. Next page load will check again
148
  }
149
  //fall through
150
  case ShortPixel.STATUS_ERROR: //for error and skip also we retry
 
151
  case ShortPixel.STATUS_SKIP:
152
  console.log('Server response: ' + response);
153
  setTimeout(checkBulkProgress, 2000);
154
+ break;
155
  }
156
  }
157
  });
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === ShortPixel Image Optimizer ===
2
 
3
  Contributors: AlexSP
4
- Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, jpegtran,image, image optimisation, shrink, picture, photo, optimize photos, compress, performance, tinypng, crunch, pngquant, attachment, optimize, pictures,fast, images, image files, image quality, lossy, upload, kraken, resize, seo, smushit, optipng, kraken image optimizer, ewww, photo optimization, gifsicle, image optimizer, images, krakenio, png, gmagick, image optimize, pdf, pdf optimisation, pdf optimization, optimize pdf, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, jpg optimization, optimize jpg, optimise jpg, shrink jpg, gif, animated gif, optimize gif, optimise gif, optimizer, optimiser, compresion, optimization, cruncher, image cruncher, compress png, compress jpg, compress jpeg, faster loading times, image optimiser, improve pagerank, optimise, optimize animated gif, optimise jpeg, optimize jpeg, optimize png, optimise png, tinyjpg, short pixel, shortpixel
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
- Stable tag: 3.0.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -119,6 +119,10 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
119
 
120
  == Changelog ==
121
 
 
 
 
 
122
  = 3.0.7 =
123
 
124
  * Affiliate codes
1
  === ShortPixel Image Optimizer ===
2
 
3
  Contributors: AlexSP
4
+ Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, jpegtran, image, image optimisation, image optimization, shrink, picture, photo, optimize photos, compress, performance, tinypng, crunch, pngquant, attachment, optimize, pictures, fast, images, image files, image quality, lossy, upload, kraken, resize, seo, smushit, optipng, kraken image optimizer, ewww, photo optimization, gifsicle, image optimizer, images, krakenio, png, gmagick, image optimize, pdf, pdf optimisation, pdf optimization, optimize pdf, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, jpg optimization, optimize jpg, optimise jpg, shrink jpg, gif, animated gif, optimize gif, optimise gif, optimizer, optimiser, compresion, optimization, cruncher, image cruncher, compress png, compress jpg, compress jpeg, compress pdf, faster loading times, image optimiser, improve pagerank, optimise, optimize animated gif, optimise jpeg, optimize jpeg, optimize png, optimise png, optimise pdf, optimize pdf, tinyjpg, short pixel, shortpixel
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
+ Stable tag: 3.0.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
119
 
120
  == Changelog ==
121
 
122
+ = 3.0.8 =
123
+
124
+ * fix issue with files in /tmp dir that weren't deleted in certain cases, issue noted by Daniel - germangoogleguy.com
125
+
126
  = 3.0.7 =
127
 
128
  * Affiliate codes
shortpixel_api.php CHANGED
@@ -314,19 +314,18 @@ class ShortPixelAPI {
314
  //overwrite the original files with the optimized ones
315
  foreach ( $tempFiles as $tempFileID => $tempFilePATH )
316
  {
317
- if ( file_exists($tempFilePATH) && file_exists($PATHs[$tempFileID]) && is_writable($PATHs[$tempFileID]) )
318
- {
319
  copy($tempFilePATH, $PATHs[$tempFileID]);
320
- @unlink($tempFilePATH);
321
- }
322
- else
323
  $writeFailed++;
 
 
324
 
325
  if ( $writeFailed > 0 )//there was an error
326
  {
327
  ShortPixelAPI::SaveMessageinMetadata($ID, 'Error: optimized version of ' . $writeFailed . ' file(s) couldn\'t be updated.');
328
  update_option('bulkProcessingStatus', "error");
329
- return array("Status" => self::STATUS_FAIL, "Message" => 'Error: optimized version of ' . $writeFailed . ' file(s) couldn\'t be updated.');
330
  }
331
  else
332
  {//all files were copied, optimization data regarding the savings locally in DB
314
  //overwrite the original files with the optimized ones
315
  foreach ( $tempFiles as $tempFileID => $tempFilePATH )
316
  {
317
+ if ( file_exists($tempFilePATH) && file_exists($PATHs[$tempFileID]) && is_writable($PATHs[$tempFileID]) ) {
 
318
  copy($tempFilePATH, $PATHs[$tempFileID]);
319
+ } else {
 
 
320
  $writeFailed++;
321
+ }
322
+ @unlink($tempFilePATH);
323
 
324
  if ( $writeFailed > 0 )//there was an error
325
  {
326
  ShortPixelAPI::SaveMessageinMetadata($ID, 'Error: optimized version of ' . $writeFailed . ' file(s) couldn\'t be updated.');
327
  update_option('bulkProcessingStatus', "error");
328
+ return array("Status" => self::STATUS_FAIL, "Code" =>"write-fail", "Message" => 'Error: optimized version of ' . $writeFailed . ' file(s) couldn\'t be updated.');
329
  }
330
  else
331
  {//all files were copied, optimization data regarding the savings locally in DB
shortpixel_queue.php CHANGED
@@ -96,6 +96,29 @@ class ShortPixelQueue {
96
  return $found;
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  public function bulkRunning() {
100
  //$bulkProcessingStatus = get_option('bulkProcessingStatus');
101
  return $this->startBulkId > $this->stopBulkId;
96
  return $found;
97
  }
98
 
99
+ public function removeFromFailed($ID) {
100
+ $failed = explode(",", WPShortPixel::getOpt('wp-short-pixel-failed-imgs',''));
101
+ $key = array_search($ID, $failed);
102
+ if($key !== false) {
103
+ unset($failed[$key]);
104
+ $failed = array_values($failed);
105
+ update_option('wp-short-pixel-failed-imgs', implode(",", $failed) );
106
+ }
107
+ }
108
+
109
+ public function addToFailed($ID) {
110
+ $failed = WPShortPixel::getOpt('wp-short-pixel-failed-imgs','');
111
+ if(!in_array($ID, explode(",", $failed))) {
112
+ update_option('wp-short-pixel-failed-imgs', (strlen($failed) ? $failed . "," : "") . $ID );
113
+ }
114
+ }
115
+
116
+ public function getFailed() {
117
+ $failed = WPShortPixel::getOpt('wp-short-pixel-failed-imgs','');
118
+ if(!strlen($failed)) return array();
119
+ return explode(",", $failed);
120
+ }
121
+
122
  public function bulkRunning() {
123
  //$bulkProcessingStatus = get_option('bulkProcessingStatus');
124
  return $this->startBulkId > $this->stopBulkId;
shortpixel_view.php CHANGED
@@ -68,6 +68,13 @@ class ShortPixelView {
68
  <?php if($imgProcessedCount['totalFiles'] < $imageCount['totalFiles']) { ?>
69
  <p><?=number_format($imageCount['mainFiles'] - $imgProcessedCount['mainFiles'])?> images and <?=number_format(($imageCount['totalFiles'] - $imageCount['mainFiles']) - ($imgProcessedCount['totalFiles'] - $imgProcessedCount['mainFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
70
  <?php } ?>
 
 
 
 
 
 
 
71
  <p>Restart the optimization process for new images added to your library by clicking the button below. Already optimized images will not be reprocessed.
72
  <form action='' method='POST' >
73
  <input type='checkbox' name='thumbnails' <?=$this->ctrl->processThumbnails() ? "checked":""?>> Include thumbnails<br><br>
@@ -151,4 +158,20 @@ class ShortPixelView {
151
  <?php
152
  }
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
68
  <?php if($imgProcessedCount['totalFiles'] < $imageCount['totalFiles']) { ?>
69
  <p><?=number_format($imageCount['mainFiles'] - $imgProcessedCount['mainFiles'])?> images and <?=number_format(($imageCount['totalFiles'] - $imageCount['mainFiles']) - ($imgProcessedCount['totalFiles'] - $imgProcessedCount['mainFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
70
  <?php } ?>
71
+ <?php
72
+ $failed = $this->ctrl->getPrioQ()->getFailed();
73
+ //die(print_r($failed));
74
+ if(count($failed)) { ?>
75
+ <p>The following images are not writable so ShortPixel could not update the files. Please check the rights for these and then restart the optimization process.</p>
76
+ <?=$this->displayFailed($failed)?>
77
+ <?php } ?>
78
  <p>Restart the optimization process for new images added to your library by clicking the button below. Already optimized images will not be reprocessed.
79
  <form action='' method='POST' >
80
  <input type='checkbox' name='thumbnails' <?=$this->ctrl->processThumbnails() ? "checked":""?>> Include thumbnails<br><br>
158
  <?php
159
  }
160
 
161
+ public function displayFailed($failed) {
162
+ ?>
163
+ <div class="bulk-progress bulk-stats">
164
+ <?php foreach($failed as $fail) {
165
+ $meta = wp_get_attachment_metadata($fail);
166
+ if(isset($meta["ShortPixelImprovement"]) && is_numeric($meta["ShortPixelImprovement"])){
167
+ $this->ctrl->getPrioQ()->removeFromFailed($fail);
168
+ } else {
169
+ ?> <div class="label"><a href="/wp-admin/post.php?post=<?=$fail?>&action=edit"><?=substr($meta["file"], 0, 80)?> - ID: <?=$fail?></a></div><br/>
170
+ <?php }
171
+ }?>
172
+ </div>
173
+ <?php
174
+ }
175
+
176
+
177
  }
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.0.7
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.0.7");
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);
@@ -437,6 +437,9 @@ class WPShortPixel {
437
  if( $result["Status"] == ShortPixelAPI::STATUS_SUCCESS) {
438
  self::log("HIP: Image ID $ID optimized successfully: ".json_encode($result));
439
  $prio = $this->prioQ->remove($ID);
 
 
 
440
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
441
  $this->prioQ->setStartBulkId($ID - 1);
442
  $this->prioQ->logBulkProgress();
@@ -470,6 +473,10 @@ class WPShortPixel {
470
  elseif ($result["Status"] == ShortPixelAPI::STATUS_SKIP
471
  || $result["Status"] == ShortPixelAPI::STATUS_FAIL) {
472
  $prio = $this->prioQ->remove($ID);
 
 
 
 
473
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
474
  $this->prioQ->setStartBulkId($ID - 1);
475
  }
@@ -1515,6 +1522,10 @@ HTML;
1515
  return $this->_apiKey;
1516
  }
1517
 
 
 
 
 
1518
  public function backupImages() {
1519
  return $this->_backupImages;
1520
  }
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.0.8
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
21
 
22
  define('SP_AFFILIATE_CODE', '');
23
 
24
+ define('PLUGIN_VERSION', "3.0.8");
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);
437
  if( $result["Status"] == ShortPixelAPI::STATUS_SUCCESS) {
438
  self::log("HIP: Image ID $ID optimized successfully: ".json_encode($result));
439
  $prio = $this->prioQ->remove($ID);
440
+ //remove also from the failed list if it failed in the past
441
+ $prio = $this->prioQ->removeFromFailed($ID);
442
+
443
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
444
  $this->prioQ->setStartBulkId($ID - 1);
445
  $this->prioQ->logBulkProgress();
473
  elseif ($result["Status"] == ShortPixelAPI::STATUS_SKIP
474
  || $result["Status"] == ShortPixelAPI::STATUS_FAIL) {
475
  $prio = $this->prioQ->remove($ID);
476
+ if(isset($result["Code"]) && $result["Code"] == "write-fail") {
477
+ //put this one in the failed images list - to show the user at the end
478
+ $prio = $this->prioQ->addToFailed($ID);
479
+ }
480
  if(!$prio && $ID <= $this->prioQ->getStartBulkId()) {
481
  $this->prioQ->setStartBulkId($ID - 1);
482
  }
1522
  return $this->_apiKey;
1523
  }
1524
 
1525
+ public function getPrioQ() {
1526
+ return $this->prioQ;
1527
+ }
1528
+
1529
  public function backupImages() {
1530
  return $this->_backupImages;
1531
  }