ShortPixel Image Optimizer - Version 2.1.5

Version Description

  • visiting Settings/ShortPixel now resets the Queue flag
  • when plgin's API Key cannot be validated the JS script that calls admin-ajas.php is stopped
  • return meaningful message on Media Library listing when API Key is not valid
  • extra check for API Key validation
Download this release

Release Info

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

Code changes from version 2.1.4 to 2.1.5

Files changed (2) hide show
  1. readme.txt +9 -2
  2. wp-shortpixel.php +27 -8
readme.txt CHANGED
@@ -3,8 +3,8 @@
3
  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, 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
5
  Requires at least: 3.0.0 or higher
6
- Tested up to: 4.1.2
7
- Stable tag: 2.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -112,6 +112,13 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
112
 
113
  == Changelog ==
114
 
 
 
 
 
 
 
 
115
  = 2.1.4 =
116
 
117
  * fixed global variable issue for some variables
3
  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, 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
5
  Requires at least: 3.0.0 or higher
6
+ Tested up to: 4.2
7
+ Stable tag: 2.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
112
 
113
  == Changelog ==
114
 
115
+ = 2.1.5 =
116
+
117
+ * visiting Settings/ShortPixel now resets the Queue flag
118
+ * when plgin's API Key cannot be validated the JS script that calls admin-ajas.php is stopped
119
+ * return meaningful message on Media Library listing when API Key is not valid
120
+ * extra check for API Key validation
121
+
122
  = 2.1.4 =
123
 
124
  * fixed global variable issue for some variables
wp-shortpixel.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimizes 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.1.4
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -15,7 +15,7 @@ if ( !is_plugin_active( 'wpmandrill/wpmandrill.php' ) ) {
15
  require_once( ABSPATH . 'wp-includes/pluggable.php' );//to avoid conflict with wpmandrill plugin
16
  }
17
 
18
- define('PLUGIN_VERSION', "2.1.4");
19
  define('SP_DEBUG', false);
20
  define('SP_LOG', false);
21
  define('SP_MAX_TIMEOUT', 10);
@@ -178,14 +178,14 @@ class WPShortPixel {
178
  }
179
  }
180
 
181
- function my_action_javascript() { ?>
182
  <script type="text/javascript" >
183
  jQuery(document).ready(sendRequest());
184
  function sendRequest() {
185
  var data = { 'action': 'my_action' };
186
  // since WP 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
187
  jQuery.post(ajaxurl, data, function(response) {
188
- if(response.search('Empty queue') >= 0 || response.search('Error processing image') >= 0) {
189
  console.log('Queue is empty');
190
  } else {
191
  console.log('Server response: ' + response);
@@ -300,6 +300,7 @@ class WPShortPixel {
300
  )
301
  ORDER BY post_id DESC
302
  LIMIT " . SP_MAX_RESULTS_QUERY;
 
303
  $resultsPostMeta = $wpdb->get_results($queryPostMeta);
304
 
305
  if ( empty($resultsPostMeta) )
@@ -436,7 +437,7 @@ class WPShortPixel {
436
  $meta['ShortPixelImprovement'] = round($result[0]->PercentImprovement,2);
437
  wp_update_attachment_metadata($ID, $meta);
438
  echo "\nProcessing done succesfully for image #{$ID}";
439
-
440
  //set the next ID to be processed (skip to the next valid value)
441
  if ( isset($isList[1]) )
442
  {
@@ -1063,13 +1064,21 @@ Currently, you have {$imageCount} images in your library. </br>
1063
  $response = wp_remote_get(str_replace('https://', 'http://', $requestURL), $args);
1064
  }
1065
 
 
 
1066
  $defaultData = array(
1067
  "APIKeyValid" => false,
1068
- "Message" => 'API Key could not be validated. Could not connect Shortpixel service.',
1069
  "APICallsMade" => 'Information unavailable. Please check your API key.',
1070
  "APICallsQuota" => 'Information unavailable. Please check your API key.');
1071
 
1072
  if(is_object($response) && get_class($response) == 'WP_Error') {
 
 
 
 
 
 
1073
  return $defaultData;
1074
  }
1075
 
@@ -1087,6 +1096,11 @@ Currently, you have {$imageCount} images in your library. </br>
1087
  return $defaultData;
1088
  }
1089
 
 
 
 
 
 
1090
  return array(
1091
  "APIKeyValid" => true,
1092
  "APICallsMade" => number_format($data->APICallsMade) . ' images',
@@ -1106,8 +1120,13 @@ Currently, you have {$imageCount} images in your library. </br>
1106
 
1107
  if ( empty($data) )
1108
  {
1109
- if ( $fileExtension <> "pdf" )
1110
- print 'Optimisation N/A';
 
 
 
 
 
1111
  else
1112
  {
1113
  if ( get_option('wp-short-pixel-quota-exceeded') )
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimizes 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.1.5
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
15
  require_once( ABSPATH . 'wp-includes/pluggable.php' );//to avoid conflict with wpmandrill plugin
16
  }
17
 
18
+ define('PLUGIN_VERSION', "2.1.5");
19
  define('SP_DEBUG', false);
20
  define('SP_LOG', false);
21
  define('SP_MAX_TIMEOUT', 10);
178
  }
179
  }
180
 
181
+ function my_action_javascript() { ?>
182
  <script type="text/javascript" >
183
  jQuery(document).ready(sendRequest());
184
  function sendRequest() {
185
  var data = { 'action': 'my_action' };
186
  // since WP 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
187
  jQuery.post(ajaxurl, data, function(response) {
188
+ if(response.search('Empty queue') >= 0 || response.search('Error processing image') >= 0 || response.search('Missing API Key') >= 0) {
189
  console.log('Queue is empty');
190
  } else {
191
  console.log('Server response: ' + response);
300
  )
301
  ORDER BY post_id DESC
302
  LIMIT " . SP_MAX_RESULTS_QUERY;
303
+
304
  $resultsPostMeta = $wpdb->get_results($queryPostMeta);
305
 
306
  if ( empty($resultsPostMeta) )
437
  $meta['ShortPixelImprovement'] = round($result[0]->PercentImprovement,2);
438
  wp_update_attachment_metadata($ID, $meta);
439
  echo "\nProcessing done succesfully for image #{$ID}";
440
+
441
  //set the next ID to be processed (skip to the next valid value)
442
  if ( isset($isList[1]) )
443
  {
1064
  $response = wp_remote_get(str_replace('https://', 'http://', $requestURL), $args);
1065
  }
1066
 
1067
+
1068
+
1069
  $defaultData = array(
1070
  "APIKeyValid" => false,
1071
+ "Message" => 'API Key could not be validated. Could not connect to Shortpixel service.',
1072
  "APICallsMade" => 'Information unavailable. Please check your API key.',
1073
  "APICallsQuota" => 'Information unavailable. Please check your API key.');
1074
 
1075
  if(is_object($response) && get_class($response) == 'WP_Error') {
1076
+
1077
+ $urlElements = parse_url($requestURL);
1078
+ $portConnect = @fsockopen($urlElements['host'],81,$errno,$errstr,15);
1079
+ if(!$portConnect)
1080
+ $defaultData['Message'] .= "<BR>Debug info: <i>$errstr</i>";
1081
+
1082
  return $defaultData;
1083
  }
1084
 
1096
  return $defaultData;
1097
  }
1098
 
1099
+ if ( $data->APICallsMade < $data->APICallsQuota ) //reset quota exceeded flag -> user is allowed to process more images.
1100
+ update_option('wp-short-pixel-quota-exceeded',0);
1101
+ else
1102
+ update_option('wp-short-pixel-quota-exceeded',1);//activate quota limiting
1103
+
1104
  return array(
1105
  "APIKeyValid" => true,
1106
  "APICallsMade" => number_format($data->APICallsMade) . ' images',
1120
 
1121
  if ( empty($data) )
1122
  {
1123
+ if ( $fileExtension <> "pdf" )
1124
+ {
1125
+ if(!$this->_verifiedKey)
1126
+ print 'Invalid API Key. <a href="options-general.php?page=wp-shortpixel">Check your Settings</a>';
1127
+ else
1128
+ print 'Optimisation N/A';
1129
+ }
1130
  else
1131
  {
1132
  if ( get_option('wp-short-pixel-quota-exceeded') )