ShortPixel Image Optimizer - Version 2.0.3

Version Description

  • added extra check for bad server responses
  • 10 files/post request for file processing
  • updated error codes according to API v2
  • updated description
Download this release

Release Info

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

Code changes from version 2.0.2 to 2.0.3

Files changed (3) hide show
  1. readme.txt +13 -6
  2. shortpixel_api.php +8 -4
  3. wp-shortpixel.php +15 -12
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: AlexSP
4
  Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, tinypng, 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, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, optimise jpg, shrink jpg, gif, animated gif, optimise gif
5
  Requires at least: 3.0.0 or higher
6
  Tested up to: 4.1
7
- Stable tag: 2.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,14 +12,15 @@ The ShortPixel plugin reduces the images' size making your website load faster.
12
 
13
  == Description ==
14
 
15
- ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original.
16
 
17
- ShortPixel uses powerful algorithms that enable your website to load faster, use less bandwidth and rank better in search.
18
 
19
  **The ShortPixel package includes:**
20
 
21
  * **Both lossy and lossless optimisation:** you can choose between the two types of compression. Lossy for photographs. Lossless for technical drawings, clip art and comics.
22
- * **Up to 90% compression rate:** with lossy compression images that were 3MB can crunch to 307Kb, with no before/after differences.
 
23
  * **Supported formats:** JPG, PNG, PDF, both static and animated GIFS. NEW UPDATE: we recently introduced optimisation for PDFs.
24
  * **Backup and restore originals:** if you ever want to return to the original version, images are automatically stored in a backup folder on your hosting servers.
25
  * **Bulk image optimisation:** Crunch your image gallery, and downsize your website. This feature may take up to several hours, depending on the number and size of existing images.
@@ -61,8 +62,7 @@ For more information about the difference read the <a href="http://en.wikipedia.
61
 
62
  = Why do I need an API key? =
63
 
64
- ShortPixel Image Optimiser uses automated processes to crunch images. The ShortPixel API integrates in the dashboard of your Wordpress website and processes both old and new images automatically.
65
- You can also use the API in your own applications, the <a href="https://shortpixel.com/api-docs">Documentation API</a> shows you how.
66
 
67
  = Where do I get my API key? =
68
 
@@ -107,6 +107,13 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
 
110
  = 2.0.2 =
111
 
112
  * added more tags so we better describe newest features
4
  Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, tinypng, 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, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, optimise jpg, shrink jpg, gif, animated gif, optimise gif
5
  Requires at least: 3.0.0 or higher
6
  Tested up to: 4.1
7
+ Stable tag: 2.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original.
16
 
17
+ ShortPixel uses powerful algorithms that enable your website to load faster, use less bandwidth and rank better in search. The unique API key you receive for activating the plugin can be used for multiple websites.
18
 
19
  **The ShortPixel package includes:**
20
 
21
  * **Both lossy and lossless optimisation:** you can choose between the two types of compression. Lossy for photographs. Lossless for technical drawings, clip art and comics.
22
+ * **One API Key for multiple sites:** after registration, you receive an API key that you can further use on several websites or applications.
23
+ * **Up to 90% compression rate:** with lossy compression images that were 3MB can crunch to 307Kb, with no before/after differences..
24
  * **Supported formats:** JPG, PNG, PDF, both static and animated GIFS. NEW UPDATE: we recently introduced optimisation for PDFs.
25
  * **Backup and restore originals:** if you ever want to return to the original version, images are automatically stored in a backup folder on your hosting servers.
26
  * **Bulk image optimisation:** Crunch your image gallery, and downsize your website. This feature may take up to several hours, depending on the number and size of existing images.
62
 
63
  = Why do I need an API key? =
64
 
65
+ ShortPixel Image Optimiser uses automated processes to crunch images. The ShortPixel API integrates in the dashboard of your WordPress website and processes both old and new images automatically. You can also use the same API, multiple times, in your own applications, the <a href="https://shortpixel.com/api-docs">Documentation API</a> shows you how.
 
66
 
67
  = Where do I get my API key? =
68
 
107
 
108
  == Changelog ==
109
 
110
+ = 2.0.3 =
111
+
112
+ * added extra check for bad server responses
113
+ * 10 files/post request for file processing
114
+ * updated error codes according to API v2
115
+ * updated description
116
+
117
  = 2.0.2 =
118
 
119
  * added more tags so we better describe newest features
shortpixel_api.php CHANGED
@@ -94,7 +94,6 @@ class shortpixel_api {
94
  if(!$response) return $response;
95
 
96
  if($response['response']['code'] != 200) {
97
- WPShortPixel::log("Response 200 OK");
98
  printf('Web service did not respond. Please try again later.');
99
  return false;
100
  }
@@ -102,6 +101,11 @@ class shortpixel_api {
102
  $data = $this->parseResponse($response);
103
  $data = $data[0];
104
 
 
 
 
 
 
105
  switch($data->Status->Code) {
106
  case 1:
107
  //handle image has been scheduled
@@ -112,9 +116,9 @@ class shortpixel_api {
112
  //handle image has been processed
113
  $this->handleSuccess($data, $url, $filePath, $ID);
114
  break;
115
- case -16:
116
  return 'Quota exceeded</br>';
117
- case -17:
118
  return 'Wrong API Key</br>';
119
  case -302:
120
  return 'Images does not exists</br>';
@@ -226,4 +230,4 @@ class shortpixel_api {
226
  }
227
  return $data;
228
  }
229
- }
94
  if(!$response) return $response;
95
 
96
  if($response['response']['code'] != 200) {
 
97
  printf('Web service did not respond. Please try again later.');
98
  return false;
99
  }
101
  $data = $this->parseResponse($response);
102
  $data = $data[0];
103
 
104
+ if(!is_object($data) || !isset($data->Status->Code)) {
105
+ printf('Web service returned an error. Please try again later.');
106
+ return false;
107
+ }
108
+
109
  switch($data->Status->Code) {
110
  case 1:
111
  //handle image has been scheduled
116
  //handle image has been processed
117
  $this->handleSuccess($data, $url, $filePath, $ID);
118
  break;
119
+ case -403:
120
  return 'Quota exceeded</br>';
121
+ case -401:
122
  return 'Wrong API Key</br>';
123
  case -302:
124
  return 'Images does not exists</br>';
230
  }
231
  return $data;
232
  }
233
+ }
wp-shortpixel.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShortPixel Image Optimiser
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original. To install: 1) Click the "Activate" link to the left of this description. 2) <a href="https://shortpixel.com/wp-apikey" target="_blank">Free Sign up</a> for your unique API Key . 3) Check your email for your API key. 4) Use your API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress. 5) Done!
6
- * Version: 2.0.2
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -386,7 +386,6 @@ class WPShortPixel {
386
 
387
  $meta = wp_get_attachment_metadata($attachment->ID);
388
 
389
-
390
  if($processThumbnails && isset($meta['sizes'])) {
391
  foreach($meta['sizes'] as $thumbnailData) {
392
  $thumbPath = substr($imagePath, 0, strrpos($imagePath, '/')) . '/' . $thumbnailData["file"];
@@ -398,12 +397,12 @@ class WPShortPixel {
398
  wp_update_attachment_metadata($attachment->ID, $meta);
399
  }
400
 
401
- if(count($imageList) > 100) {
402
  $batchList = array();
403
  foreach($imageList as $image) {
404
  $batchList[] = $image;
405
 
406
- if(count($batchList) == 100) {
407
  $this->_apiInterface->doBulkRequest($batchList);
408
  $batchList = array();
409
  }
@@ -492,9 +491,9 @@ class WPShortPixel {
492
  }
493
  echo '<h1>ShortPixel Plugin Settings</h1>';
494
  echo '<p>
495
- <a href="https://shortpixel.com">ShortPixel.com</a> |
496
- <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/">Installation </a> |
497
- <a href="https://wordpress.org/support/plugin/shortpixel-image-optimiser">Support </a>
498
  </p>';
499
  echo '<p>New images uploaded to the Media Library will be optimized automatically.<br/>If you have existing images you would like to optimize, you can use the <a href="' . get_admin_url() . 'upload.php?page=wp-short-pixel-bulk">Bulk Optimisation Tool</a>.</p>';
500
 
@@ -632,11 +631,14 @@ HTML;
632
  echo $formHTML;
633
 
634
  if($this->_verifiedKey) {
635
- $fileCount = get_option('wp-short-pixel-fileCount');
636
  $savedSpace = self::formatBytes(get_option('wp-short-pixel-savedSpace'),2);
637
  $averageCompression = round(get_option('wp-short-pixel-averageCompression'),2);
638
  $savedBandwidth = self::formatBytes(get_option('wp-short-pixel-savedSpace') * 1000,2);
639
  $quotaData = $this->getQuotaInformation();
 
 
 
640
  $backupFolderSize = self::formatBytes(self::folderSize(SP_BACKUP_FOLDER));
641
  $remainingImages = (int)str_replace(',', '', $quotaData['APICallsQuota']) - (int)str_replace(',', '', $quotaData['APICallsMade']);
642
  $remainingImages = number_format($remainingImages);
@@ -647,7 +649,7 @@ HTML;
647
  <table class="form-table">
648
  <tbody><tr>
649
  <th scope="row"><label for="totalFiles">Total number of processed files:</label></th>
650
- <td>$fileCount</td>
651
  </tr>
652
  <tr>
653
  <th scope="row"><label for="savedSpace">Saved disk space by ShortPixel</label></th>
@@ -663,7 +665,7 @@ HTML;
663
  <table class="form-table">
664
  <tbody><tr>
665
  <th scope="row"><label for="apiQuota">Your ShortPixel plan</label></th>
666
- <td>{$quotaData['APICallsQuota']}/month</td>
667
  </tr>
668
  <tr>
669
  <th scope="row"><label for="usedQUota">Number of images processed this month:</label></th>
@@ -855,10 +857,11 @@ HTML;
855
  }
856
  $cleanPath = rtrim($path, '/'). '/';
857
  foreach($files as $t) {
858
- if ($t<>"." && $t<>"..") {
 
859
  $currentFile = $cleanPath . $t;
860
  if (is_dir($currentFile)) {
861
- $size = foldersize($currentFile);
862
  $total_size += $size;
863
  }
864
  else {
3
  * Plugin Name: ShortPixel Image Optimiser
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original. To install: 1) Click the "Activate" link to the left of this description. 2) <a href="https://shortpixel.com/wp-apikey" target="_blank">Free Sign up</a> for your unique API Key . 3) Check your email for your API key. 4) Use your API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress. 5) Done!
6
+ * Version: 2.0.3
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
386
 
387
  $meta = wp_get_attachment_metadata($attachment->ID);
388
 
 
389
  if($processThumbnails && isset($meta['sizes'])) {
390
  foreach($meta['sizes'] as $thumbnailData) {
391
  $thumbPath = substr($imagePath, 0, strrpos($imagePath, '/')) . '/' . $thumbnailData["file"];
397
  wp_update_attachment_metadata($attachment->ID, $meta);
398
  }
399
 
400
+ if(count($imageList) > 10) {
401
  $batchList = array();
402
  foreach($imageList as $image) {
403
  $batchList[] = $image;
404
 
405
+ if(count($batchList) == 10) {
406
  $this->_apiInterface->doBulkRequest($batchList);
407
  $batchList = array();
408
  }
491
  }
492
  echo '<h1>ShortPixel Plugin Settings</h1>';
493
  echo '<p>
494
+ <a href="https://shortpixel.com" target="_blank">ShortPixel.com</a> |
495
+ <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/" target="_blank">Installation </a> |
496
+ <a href="https://shortpixel.com/contact" target="_blank">Support </a>
497
  </p>';
498
  echo '<p>New images uploaded to the Media Library will be optimized automatically.<br/>If you have existing images you would like to optimize, you can use the <a href="' . get_admin_url() . 'upload.php?page=wp-short-pixel-bulk">Bulk Optimisation Tool</a>.</p>';
499
 
631
  echo $formHTML;
632
 
633
  if($this->_verifiedKey) {
634
+ $fileCount = number_format(get_option('wp-short-pixel-fileCount'));
635
  $savedSpace = self::formatBytes(get_option('wp-short-pixel-savedSpace'),2);
636
  $averageCompression = round(get_option('wp-short-pixel-averageCompression'),2);
637
  $savedBandwidth = self::formatBytes(get_option('wp-short-pixel-savedSpace') * 1000,2);
638
  $quotaData = $this->getQuotaInformation();
639
+ if (is_numeric($quotaData['APICallsQuota'])) {
640
+ $quotaData['APICallsQuota'] .= "/month";
641
+ }
642
  $backupFolderSize = self::formatBytes(self::folderSize(SP_BACKUP_FOLDER));
643
  $remainingImages = (int)str_replace(',', '', $quotaData['APICallsQuota']) - (int)str_replace(',', '', $quotaData['APICallsMade']);
644
  $remainingImages = number_format($remainingImages);
649
  <table class="form-table">
650
  <tbody><tr>
651
  <th scope="row"><label for="totalFiles">Total number of processed files:</label></th>
652
+ <td>{$fileCount}</td>
653
  </tr>
654
  <tr>
655
  <th scope="row"><label for="savedSpace">Saved disk space by ShortPixel</label></th>
665
  <table class="form-table">
666
  <tbody><tr>
667
  <th scope="row"><label for="apiQuota">Your ShortPixel plan</label></th>
668
+ <td>{$quotaData['APICallsQuota']}</td>
669
  </tr>
670
  <tr>
671
  <th scope="row"><label for="usedQUota">Number of images processed this month:</label></th>
857
  }
858
  $cleanPath = rtrim($path, '/'). '/';
859
  foreach($files as $t) {
860
+ if ($t<>"." && $t<>"..")
861
+ {
862
  $currentFile = $cleanPath . $t;
863
  if (is_dir($currentFile)) {
864
+ $size = self::folderSize($currentFile);
865
  $total_size += $size;
866
  }
867
  else {