ShortPixel Image Optimizer - Version 1.6.2

Version Description

  • extra check for images that return 3xx/4xx codes to be ignored
  • API Key validation (error) message is returned to user
  • error messages for images are displayed in the "ShortPixel Compression" column
Download this release

Release Info

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

Code changes from version 1.6.1 to 1.6.2

Files changed (3) hide show
  1. readme.txt +7 -1
  2. shortpixel_api.php +9 -3
  3. wp-shortpixel.php +39 -43
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
5
  Requires at least: 3.0.0 or higher
6
  Tested up to: 4.0
7
- Stable tag: 1.6.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,6 +107,12 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
110
  = 1.6.1 =
111
 
112
  * fixed small upload glitch
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
5
  Requires at least: 3.0.0 or higher
6
  Tested up to: 4.0
7
+ Stable tag: 1.6.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = 1.6.2 =
111
+
112
+ * extra check for images that return 3xx/4xx codes to be ignored
113
+ * API Key validation (error) message is returned to user
114
+ * error messages for images are displayed in the "ShortPixel Compression" column
115
+
116
  = 1.6.1 =
117
 
118
  * fixed small upload glitch
shortpixel_api.php CHANGED
@@ -101,7 +101,7 @@ class shortpixel_api {
101
  return 'Wrong API Key</br>';
102
  default:
103
  //handle error
104
- return 'An error occurred while processing this image. Please try uploading it again.</br> ' . print_r(array($data, $url, $filePath, $ID), true);
105
  }
106
 
107
  return $data;
@@ -113,11 +113,17 @@ class shortpixel_api {
113
  if($this->_compressionType) {
114
  //lossy
115
  $correctFileSize = $callData->LossySize;
116
- $tempFile = download_url(str_replace('https://','http://',urldecode($callData->LossyURL)));
 
 
 
117
  } else {
118
  //lossless
119
  $correctFileSize = $callData->LoselessSize;
120
- $tempFile = download_url(str_replace('https://','http://',urldecode($callData->LosslessURL)));
 
 
 
121
  }
122
 
123
  if ( is_wp_error( $tempFile ) ) {
101
  return 'Wrong API Key</br>';
102
  default:
103
  //handle error
104
+ return $data->Status->Message;
105
  }
106
 
107
  return $data;
113
  if($this->_compressionType) {
114
  //lossy
115
  $correctFileSize = $callData->LossySize;
116
+ $tempFile = download_url(urldecode($callData->LossyURL));
117
+ if(is_wp_error( $tempFile )) {
118
+ $tempFile = download_url(str_replace('https://', 'http://', urldecode($callData->LossyURL)));
119
+ }
120
  } else {
121
  //lossless
122
  $correctFileSize = $callData->LoselessSize;
123
+ $tempFile = download_url(urldecode($callData->LosslessURL));
124
+ if(is_wp_error( $tempFile )) {
125
+ $tempFile = download_url(str_replace('https://', 'http://', urldecode($callData->LosslessURL)));
126
+ }
127
  }
128
 
129
  if ( is_wp_error( $tempFile ) ) {
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: 1.6.1
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -117,7 +117,7 @@ class WPShortPixel {
117
  var data = { 'action': 'my_action' };
118
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
119
  jQuery.post(ajaxurl, data, function(response) {
120
- if(response.search('empty queue') >= 0 || response.search('error processing image') >= 0) {
121
  console.log('Queue is empty');
122
  } else {
123
  console.log('Server response: ' + response);
@@ -187,7 +187,7 @@ class WPShortPixel {
187
  LIMIT " . BATCH_SIZE;
188
  $idList = $wpdb->get_results($qry);
189
 
190
- if(empty($idList)) { echo 'empty queue'; die; }
191
 
192
  foreach($idList as $post) {
193
  $ID = $post->post_id;
@@ -195,12 +195,23 @@ class WPShortPixel {
195
  $imagePath = get_attached_file($ID);
196
  $meta = wp_get_attachment_metadata($ID);
197
 
 
 
 
 
 
 
 
 
198
  $result = $this->_apiInterface->processImage($imageURL, $imagePath, $ID);
199
 
200
  if(is_string($result)) {
 
 
201
  $meta['ShortPixelImprovement'] = $result;
202
- echo "error processing image";
203
- die();
 
204
  }
205
 
206
  $processThumbnails = get_option('wp-short-process_thumbnails');
@@ -435,18 +446,36 @@ class WPShortPixel {
435
  if ( !current_user_can( 'manage_options' ) ) {
436
  wp_die('You do not have sufficient permissions to access this page.');
437
  }
 
 
 
 
 
 
 
 
 
438
 
439
  if(isset($_POST['submit']) || isset($_POST['validate'])) {
440
  //handle API Key - common for submit and validate
441
  $_POST['key'] = trim($_POST['key']);
442
  $validityData = $this->getQuotaInformation($_POST['key'], true);
 
443
  $this->_apiKey = $_POST['key'];
444
  $this->_apiInterface->setApiKey($this->_apiKey);
445
  update_option('wp-short-pixel-apiKey', $_POST['key']);
446
  if($validityData['APIKeyValid']) {
 
 
 
 
447
  update_option('wp-short-pixel-verifiedKey', true);
448
  $this->_verifiedKey = true;
449
  } else {
 
 
 
 
450
  update_option('wp-short-pixel-verifiedKey', false);
451
  $this->_verifiedKey = false;
452
  }
@@ -481,14 +510,6 @@ class WPShortPixel {
481
  $checkedBackupImages = '';
482
  if($this->_backupImages) { $checkedBackupImages = 'checked'; }
483
 
484
- echo '<h1>ShortPixel Image Optimiser Settings</h1>';
485
- echo '<p>
486
- <a href="https://shortpixel.com">ShortPixel.com</a> |
487
- <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/">Installation </a> |
488
- <a href="https://wordpress.org/support/plugin/shortpixel-image-optimiser">Support </a>
489
- </p>';
490
- 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>';
491
-
492
  $formHTML = <<< HTML
493
  <form name='wp_shortpixel_options' action='' method='post' id='wp_shortpixel_options'>
494
  <table class="form-table">
@@ -633,35 +654,6 @@ HTML;
633
  }
634
 
635
  public function displayNotice() {
636
- global $hook_suffix;
637
-
638
- $divHeader = '<br/><div class="updated">';
639
- $divWarningHeader = '<br/><div class="update-nag">';
640
- $divFooter = '</div>';
641
-
642
- $noticeInvalidKeyContent = '
643
- <div style="background-color: #FFFFFF; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); padding: 1px 12px; margin: 15px 0; ">
644
- <p>
645
- <a href="options-general.php?page=wp-shortpixel">Activate your ShortPixel plugin.</a>
646
- Get an API key <a href="https://shortpixel.com/wp-apikey" target="_blank">here</a>. Sign up, it’s free.
647
- </p>
648
- </div>
649
- ';
650
- $noticeWrongAPIKeyContent = '<p>API Key invalid!</p>';
651
- $noticeCorrectAPIKeyContent = '<p>API Key valid!</p>';
652
-
653
- if($hook_suffix == 'settings_page_wp-shortpixel' && !empty($_POST)) {
654
- $keyCheckData = $this->getQuotaInformation($_POST['key']);
655
-
656
- if(!isset($_POST['validate'])) return;
657
-
658
- if($keyCheckData['APIKeyValid']) {
659
- echo $divHeader . $noticeCorrectAPIKeyContent . $divFooter;
660
- } else {
661
- echo $divWarningHeader . $noticeWrongAPIKeyContent . $divFooter;
662
- }
663
- }
664
- if($hook_suffix == 'plugins.php' && !$this->_verifiedKey) { echo $noticeInvalidKeyContent; }
665
  }
666
 
667
  public function getQuotaInformation($apiKey = null, $appendUserAgent = false) {
@@ -679,6 +671,7 @@ HTML;
679
 
680
  $defaultData = array(
681
  "APIKeyValid" => false,
 
682
  "APICallsMade" => 'Information unavailable. Please check your API key.',
683
  "APICallsQuota" => 'Information unavailable. Please check your API key.');
684
 
@@ -695,7 +688,10 @@ HTML;
695
 
696
  if(empty($data)) { return $defaultData; }
697
 
698
- if($data->Status->Code == '-401') { return $defaultData; }
 
 
 
699
 
700
  return array(
701
  "APIKeyValid" => true,
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: 1.6.2
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
117
  var data = { 'action': 'my_action' };
118
  // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
119
  jQuery.post(ajaxurl, data, function(response) {
120
+ if(response.search('Empty queue') >= 0 || response.search('Error processing image') >= 0) {
121
  console.log('Queue is empty');
122
  } else {
123
  console.log('Server response: ' + response);
187
  LIMIT " . BATCH_SIZE;
188
  $idList = $wpdb->get_results($qry);
189
 
190
+ if(empty($idList)) { echo 'Empty queue'; die; }
191
 
192
  foreach($idList as $post) {
193
  $ID = $post->post_id;
195
  $imagePath = get_attached_file($ID);
196
  $meta = wp_get_attachment_metadata($ID);
197
 
198
+ //check if image is public
199
+ if(wp_remote_retrieve_response_code($imageURL) > 400) {
200
+ if(isset($meta['ShortPixel']['BulkProcessing'])) { unset($meta['ShortPixel']['BulkProcessing']); }
201
+ if(isset($met['ShortPixel']['WaitingProcessing'])) { unset($meta['ShortPixel']['WaitingProcessing']); }
202
+ wp_update_attachment_metadata($ID, $meta);
203
+ die;
204
+ }
205
+
206
  $result = $this->_apiInterface->processImage($imageURL, $imagePath, $ID);
207
 
208
  if(is_string($result)) {
209
+ if(isset($meta['ShortPixel']['BulkProcessing'])) { unset($meta['ShortPixel']['BulkProcessing']); }
210
+ if(isset($meta['ShortPixel']['WaitingProcessing'])) { unset($meta['ShortPixel']['WaitingProcessing']); }
211
  $meta['ShortPixelImprovement'] = $result;
212
+ wp_update_attachment_metadata($ID, $meta);
213
+ echo "Error processing image: " . $result;
214
+ die;
215
  }
216
 
217
  $processThumbnails = get_option('wp-short-process_thumbnails');
446
  if ( !current_user_can( 'manage_options' ) ) {
447
  wp_die('You do not have sufficient permissions to access this page.');
448
  }
449
+ echo '<h1>ShortPixel Image Optimiser Settings</h1>';
450
+ echo '<p>
451
+ <a href="https://shortpixel.com">ShortPixel.com</a> |
452
+ <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/">Installation </a> |
453
+ <a href="https://wordpress.org/support/plugin/shortpixel-image-optimiser">Support </a>
454
+ </p>';
455
+ 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>';
456
+
457
+ $noticeHTML = "<br/><div style=\"background-color: #fff; border-left: 4px solid %s; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); padding: 1px 12px;\"><p>%s</p></div>";
458
 
459
  if(isset($_POST['submit']) || isset($_POST['validate'])) {
460
  //handle API Key - common for submit and validate
461
  $_POST['key'] = trim($_POST['key']);
462
  $validityData = $this->getQuotaInformation($_POST['key'], true);
463
+
464
  $this->_apiKey = $_POST['key'];
465
  $this->_apiInterface->setApiKey($this->_apiKey);
466
  update_option('wp-short-pixel-apiKey', $_POST['key']);
467
  if($validityData['APIKeyValid']) {
468
+ if(isset($_POST['validate'])) {
469
+ //display notification
470
+ printf($noticeHTML, '#7ad03a', 'API Key valid!');
471
+ }
472
  update_option('wp-short-pixel-verifiedKey', true);
473
  $this->_verifiedKey = true;
474
  } else {
475
+ if(isset($_POST['validate'])) {
476
+ //display notification
477
+ printf($noticeHTML, '#dd3d36', $validityData["Message"]);
478
+ }
479
  update_option('wp-short-pixel-verifiedKey', false);
480
  $this->_verifiedKey = false;
481
  }
510
  $checkedBackupImages = '';
511
  if($this->_backupImages) { $checkedBackupImages = 'checked'; }
512
 
 
 
 
 
 
 
 
 
513
  $formHTML = <<< HTML
514
  <form name='wp_shortpixel_options' action='' method='post' id='wp_shortpixel_options'>
515
  <table class="form-table">
654
  }
655
 
656
  public function displayNotice() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
  }
658
 
659
  public function getQuotaInformation($apiKey = null, $appendUserAgent = false) {
671
 
672
  $defaultData = array(
673
  "APIKeyValid" => false,
674
+ "Message" => '',
675
  "APICallsMade" => 'Information unavailable. Please check your API key.',
676
  "APICallsQuota" => 'Information unavailable. Please check your API key.');
677
 
688
 
689
  if(empty($data)) { return $defaultData; }
690
 
691
+ if($data->Status->Code != 2) {
692
+ $defaultData['Message'] = $data->Status->Message;
693
+ return $defaultData;
694
+ }
695
 
696
  return array(
697
  "APIKeyValid" => true,