ShortPixel Image Optimizer - Version 2.1.2

Version Description

  • fixed condition that hanged bulk processing sometimes
  • added "Reduced by" text
  • more useful wrong/missing API Key message
  • test if a backup dir can be created upon plugin validation
  • added alert when a file couldn't have been overwritten
  • added alert when a file cannot be saved in backup dir
  • added Quota on API Calls functionality
  • added resume bulk processing feature
Download this release

Release Info

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

Code changes from version 2.1.1 to 2.1.2

Files changed (3) hide show
  1. readme.txt +12 -1
  2. shortpixel_api.php +22 -10
  3. wp-shortpixel.php +228 -126
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.1
7
- Stable tag: 2.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,6 +107,17 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
 
 
 
 
 
110
  = 2.1.1 =
111
 
112
  * fixed condition in function that validates content by extension
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.1
7
+ Stable tag: 2.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = 2.1.2 =
111
+
112
+ * fixed condition that hanged bulk processing sometimes
113
+ * added "Reduced by" text
114
+ * more useful wrong/missing API Key message
115
+ * test if a backup dir can be created upon plugin validation
116
+ * added alert when a file couldn't have been overwritten
117
+ * added alert when a file cannot be saved in backup dir
118
+ * added Quota on API Calls functionality
119
+ * added resume bulk processing feature
120
+
121
  = 2.1.1 =
122
 
123
  * fixed condition in function that validates content by extension
shortpixel_api.php CHANGED
@@ -135,6 +135,7 @@ class shortpixel_api {
135
  break;
136
  case 2:
137
  //handle image has been processed
 
138
  $this->handleSuccess($data, $url, $filePaths, $ID);
139
  break;
140
  default:
@@ -147,7 +148,11 @@ class shortpixel_api {
147
  {
148
  switch($data['Status']->Code) {
149
  case -403:
150
- return 'Quota exceeded</br>';
 
 
 
 
151
  break;
152
  case -401:
153
  return 'Wrong API Key</br>';
@@ -219,9 +224,8 @@ class shortpixel_api {
219
  $counter++;
220
  }
221
 
222
-
223
  //if backup is enabled
224
- if( get_option('wp-short-backup_images') )
225
  {
226
  $imageIndex = 0;
227
  $uploadDir = wp_upload_dir();
@@ -242,7 +246,6 @@ class shortpixel_api {
242
  $SubDir = $this->returnSubDir($meta['file']);
243
  $source = $filePath;
244
  }
245
-
246
 
247
  //create backup dir if needed
248
  @mkdir( SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir, 0777, true);
@@ -268,6 +271,9 @@ class shortpixel_api {
268
  }
269
  }
270
  } else {
 
 
 
271
  return sprintf("Backup folder exists but is not writable");
272
  }
273
 
@@ -275,18 +281,19 @@ class shortpixel_api {
275
 
276
 
277
  $counter = 0;
 
278
  foreach ( $tempFiles as $tempFile )//overwrite the original files with the optimized ones
279
  {
280
  $sourceFile = $tempFile;
281
  $destinationFile = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $SubDir . basename($url[$counter]);
282
 
283
- if ( $sourceFile <> "" && file_exists($sourceFile) )//possibly there was an error and the file couldn't have been processed
284
  {
285
  @unlink( $destinationFile );
286
  $success = @rename( $sourceFile, $destinationFile );
287
 
288
  if (!$success) {
289
- $copySuccess = copy($sourceFile, $destinationFile);
290
  unlink($sourceFile);
291
  }
292
  }
@@ -297,7 +304,8 @@ class shortpixel_api {
297
  }
298
 
299
  //save data to counters
300
- if( $success || $copySuccess) {
 
301
  //update statistics
302
  $fileData = $callData[$counter];
303
  $savedSpace = $fileData->OriginalSize - $fileData->LossySize;
@@ -311,15 +319,19 @@ class shortpixel_api {
311
  $averageCompression = $averageCompression / (get_option('wp-short-pixel-fileCount') + 1);
312
  update_option('wp-short-pixel-averageCompression', $averageCompression);
313
  update_option('wp-short-pixel-fileCount', get_option('wp-short-pixel-fileCount')+1);
314
-
315
  }
 
 
316
  $counter++;
317
  }
318
 
319
  //update metadata
320
- if(isset($ID)) {
321
  $meta = wp_get_attachment_metadata($ID);
322
- $meta['ShortPixelImprovement'] = round($percentImprovement,2);
 
 
 
323
  wp_update_attachment_metadata($ID, $meta);
324
  }
325
 
135
  break;
136
  case 2:
137
  //handle image has been processed
138
+ update_option( 'wp-short-pixel-quota-exceeded', 0);//reset the quota exceeded flag
139
  $this->handleSuccess($data, $url, $filePaths, $ID);
140
  break;
141
  default:
148
  {
149
  switch($data['Status']->Code) {
150
  case -403:
151
+ update_option("wp-short-pixel-query-id-start", 0);//update max and min ID
152
+ update_option("wp-short-pixel-query-id-stop", 0);
153
+ @delete_option('bulkProcessingStatus');
154
+ update_option( 'wp-short-pixel-quota-exceeded', 1);
155
+ return 'Quota exceeded';
156
  break;
157
  case -401:
158
  return 'Wrong API Key</br>';
224
  $counter++;
225
  }
226
 
 
227
  //if backup is enabled
228
+ if( get_option('wp-short-backup_images') )
229
  {
230
  $imageIndex = 0;
231
  $uploadDir = wp_upload_dir();
246
  $SubDir = $this->returnSubDir($meta['file']);
247
  $source = $filePath;
248
  }
 
249
 
250
  //create backup dir if needed
251
  @mkdir( SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir, 0777, true);
271
  }
272
  }
273
  } else {
274
+ $meta = wp_get_attachment_metadata($ID);
275
+ $meta['ShortPixelImprovement'] = 'Cannot save file in backup directory';
276
+ wp_update_attachment_metadata($ID, $meta);
277
  return sprintf("Backup folder exists but is not writable");
278
  }
279
 
281
 
282
 
283
  $counter = 0;
284
+ $writeFailed = 0;
285
  foreach ( $tempFiles as $tempFile )//overwrite the original files with the optimized ones
286
  {
287
  $sourceFile = $tempFile;
288
  $destinationFile = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $SubDir . basename($url[$counter]);
289
 
290
+ if ( $sourceFile <> "" && file_exists($sourceFile) )
291
  {
292
  @unlink( $destinationFile );
293
  $success = @rename( $sourceFile, $destinationFile );
294
 
295
  if (!$success) {
296
+ $copySuccess = @copy($sourceFile, $destinationFile);
297
  unlink($sourceFile);
298
  }
299
  }
304
  }
305
 
306
  //save data to counters
307
+ if( $success || $copySuccess)
308
+ {
309
  //update statistics
310
  $fileData = $callData[$counter];
311
  $savedSpace = $fileData->OriginalSize - $fileData->LossySize;
319
  $averageCompression = $averageCompression / (get_option('wp-short-pixel-fileCount') + 1);
320
  update_option('wp-short-pixel-averageCompression', $averageCompression);
321
  update_option('wp-short-pixel-fileCount', get_option('wp-short-pixel-fileCount')+1);
 
322
  }
323
+ else
324
+ $writeFailed++;//the file couldn't have been overwritten, we'll let the user know about this
325
  $counter++;
326
  }
327
 
328
  //update metadata
329
+ if(isset($ID)) {
330
  $meta = wp_get_attachment_metadata($ID);
331
+ if ( $writeFailed == 0 )
332
+ $meta['ShortPixelImprovement'] = round($percentImprovement,2);
333
+ else
334
+ $meta['ShortPixelImprovement'] = 'Cannot write optimized file';
335
  wp_update_attachment_metadata($ID, $meta);
336
  }
337
 
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.1.1
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -12,16 +12,19 @@ require_once('shortpixel_api.php');
12
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
13
  require_once( ABSPATH . 'wp-includes/pluggable.php' );
14
 
15
- define('PLUGIN_VERSION', "2.1.1");
16
  define('SP_DEBUG', false);
17
  define('SP_LOG', false);
18
  define('SP_MAX_TIMEOUT', 10);
19
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
20
  define('MUST_HAVE_KEY', true);
21
  define('MAX_API_RETRIES', 5);
 
22
  $MAX_EXECUTION_TIME = ini_get('max_execution_time');
23
  if ( is_numeric($MAX_EXECUTION_TIME) )
24
  define('MAX_EXECUTION_TIME', $MAX_EXECUTION_TIME - 3 ); //in seconds
 
 
25
  define("SP_MAX_RESULTS_QUERY", 6);
26
 
27
  class WPShortPixel {
@@ -122,12 +125,17 @@ class WPShortPixel {
122
  if(get_option('wp-short-pixel-query-id-stop') === false) {//min ID used for postmeta queries
123
  add_option( 'wp-short-pixel-query-id-stop', 0, '', 'yes' );
124
  }
 
 
 
 
125
 
126
  }
127
 
128
  public function shortPixelActivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
129
  {
130
- delete_option('bulkProcessingStatus');
 
131
  update_option( 'wp-short-pixel-query-id-stop', 0 );
132
  update_option( 'wp-short-pixel-query-id-start', 0 );
133
  }
@@ -135,6 +143,7 @@ class WPShortPixel {
135
  public function shortPixelDeactivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
136
  {
137
  delete_option('bulkProcessingStatus');
 
138
  update_option( 'wp-short-pixel-query-id-stop', 0 );
139
  update_option( 'wp-short-pixel-query-id-start', 0 );
140
  }
@@ -168,7 +177,7 @@ class WPShortPixel {
168
  jQuery(document).ready(sendRequest());
169
  function sendRequest() {
170
  var data = { 'action': 'my_action' };
171
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
172
  jQuery.post(ajaxurl, data, function(response) {
173
  if(response.search('Empty queue') >= 0 || response.search('Error processing image') >= 0) {
174
  console.log('Queue is empty');
@@ -270,12 +279,13 @@ class WPShortPixel {
270
 
271
  $startQueryID = get_option('wp-short-pixel-query-id-start');
272
  $endQueryID = get_option('wp-short-pixel-query-id-stop');
273
-
274
  if ( $startQueryID <= $endQueryID )
275
  {
276
  echo 'Empty queue ' . $startQueryID . '->' . $endQueryID;
277
  die;
278
  }
 
279
  sleep(1);
280
  $queryPostMeta = "SELECT * FROM " . $wpdb->prefix . "postmeta
281
  WHERE ( post_id <= $startQueryID AND post_id > $endQueryID ) AND (
@@ -288,8 +298,12 @@ class WPShortPixel {
288
 
289
  if ( empty($resultsPostMeta) )
290
  {
291
- $startQueryID = 0;
292
- update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
 
 
 
 
293
  echo 'Empty results ' . $startQueryID . '->' . $endQueryID;
294
  die;
295
  }
@@ -316,6 +330,7 @@ class WPShortPixel {
316
 
317
  $countMeta++;
318
  }
 
319
 
320
  if ( isset($idList[0]) )
321
  {
@@ -332,7 +347,11 @@ class WPShortPixel {
332
  }
333
  elseif( !empty($meta) && !isset($meta['ShortPixel']['WaitingProcessing']) ) //possibly the file wasn't processed in the first pass so we'll wait for it to be completed
334
  {
335
- $startQueryID = ( $idList[0]->post_id );
 
 
 
 
336
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
337
  }
338
  elseif ( empty($meta) && $fileExtension <> "pdf" )//file is not an image or PDF so we just skip to the next batch
@@ -341,8 +360,9 @@ class WPShortPixel {
341
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
342
  die();
343
  }
344
- else //file was processed in the first pass
345
  {
 
346
  $startQueryID = $idList[0]->post_id;
347
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
348
  }
@@ -356,7 +376,8 @@ class WPShortPixel {
356
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
357
  die();
358
  }
359
-
 
360
 
361
 
362
  //////////////////////
@@ -404,11 +425,14 @@ class WPShortPixel {
404
  }
405
 
406
  //$processThumbnails = get_option('wp-short-process_thumbnails');
407
- if ( isset($meta['ShortPixel']['WaitingProcessing']) )
408
- unset($meta['ShortPixel']['WaitingProcessing']);
409
-
410
- if( isset($meta['ShortPixel']['BulkProcessing']) )
411
- unset($meta['ShortPixel']['BulkProcessing']);
 
 
 
412
 
413
  $meta['ShortPixelImprovement'] = round($result[0]->PercentImprovement,2);
414
  wp_update_attachment_metadata($ID, $meta);
@@ -435,72 +459,35 @@ class WPShortPixel {
435
  $imageURL = wp_get_attachment_url($ID);
436
  $imagePath = get_attached_file($ID);
437
  $meta = wp_get_attachment_metadata($ID);
438
-
439
- if ( !isset($meta['file']) )//this could be a PDF file
440
- {
441
- $qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
442
- WHERE (
443
- post_id = $ID AND
444
- meta_key = '_wp_attached_file'
445
- )";
446
- $idList = $wpdb->get_results($qry);
447
- if ( isset($idList[0]) )
448
- {
449
- $idList = $idList[0];
450
- $uploadDir = wp_upload_dir();
451
- $filePath = $uploadDir['path'] . DIRECTORY_SEPARATOR . basename($idList->meta_value);
452
-
453
- //check if the image file exists on disk, if not set the right params
454
- if(!file_exists($filePath)) {
455
- if(isset($meta['ShortPixel']['BulkProcessing'])) { unset($meta['ShortPixel']['BulkProcessing']); }
456
- if(isset($meta['ShortPixel']['WaitingProcessing'])) { unset($meta['ShortPixel']['WaitingProcessing']); }
457
- $meta['ShortPixel']['NoFileOnDisk'] = true;
458
- wp_update_attachment_metadata($ID, $meta);
459
- die;
460
- }
461
 
462
- $imageURLs[] = $uploadDir['url'] . DIRECTORY_SEPARATOR . basename($idList->meta_value);//URL to PDF file
463
- $imagePaths[] = $filePath;
464
- }
465
- }
466
- else
467
- {//process images
468
- //check if the image file exists on disk, if not set the right params
469
- if(!file_exists($imagePath)) {
470
- if(isset($meta['ShortPixel']['BulkProcessing'])) { unset($meta['ShortPixel']['BulkProcessing']); }
471
- if(isset($meta['ShortPixel']['WaitingProcessing'])) { unset($meta['ShortPixel']['WaitingProcessing']); }
472
- $meta['ShortPixel']['NoFileOnDisk'] = true;
473
- wp_update_attachment_metadata($ID, $meta);
474
- die;
475
- }
476
-
477
- //figure out the base URL
478
- $SubDir = substr($meta['file'],0,strrpos($meta['file'],"/")+1);
479
- $uploadDir = wp_upload_dir();
480
- $filesPath = $uploadDir['basedir'] . DIRECTORY_SEPARATOR . $SubDir;//base upload path
481
- $filesURL = $uploadDir['baseurl'] . DIRECTORY_SEPARATOR . $SubDir;//base upload url
482
-
483
- //create the images' URL list
484
- $imageURLs[$imageIndex] = $filesURL . basename($meta['file']);//main image first
485
- $imagePaths[$imageIndex] = $filesPath . basename($meta['file']);
486
- $processThumbnails = get_option('wp-short-process_thumbnails');
487
- //handle the rest of the thumbnails generated by WP
488
- if ( $processThumbnails )
489
  {
490
- foreach ( $meta['sizes'] as $pictureDetails )
491
- {
492
- $imageIndex++;
493
- $imageURLs[$imageIndex] = $filesURL . $pictureDetails['file'];
494
- $imagePaths[$imageIndex] = $filesPath . $pictureDetails['file'];
495
- }
496
- }
497
  }
498
 
499
  if ( isset($imageURLs) )
500
  return array("imageURLs" => $imageURLs, "imagePaths" => $imagePaths, "meta" => $meta, "ID" => $ID);
501
  else
502
  return false;
503
- }
 
504
 
505
 
506
  public function handleManualOptimization() {
@@ -515,7 +502,7 @@ class WPShortPixel {
515
  //process all files (including thumbs)
516
  if($processThumbnails && !empty($meta['sizes'])) {
517
  //we generate an array with the URLs that need to be handled
518
- $SubDirs = substr($meta['file'],0,strrpos($meta['file'],"/")+1);
519
  foreach($meta['sizes'] as $thumbnailInfo)
520
  {
521
  $urlList[]= str_replace(basename($filePath[0]), $thumbnailInfo['file'], $urlList[0]);
@@ -632,7 +619,7 @@ class WPShortPixel {
632
  echo "<p>Don’t have an API Key yet? Get it now at <a href=\"https://shortpixel.com/wp-apikey\" target=\"_blank\">www.ShortPixel.com</a>, for free.</p>";
633
  return;
634
  }
635
-
636
  if(isset($_GET['cancel']))
637
  {//cancel an ongoing bulk processing, it might be needed sometimes
638
  $this->cancelProcessing();
@@ -648,9 +635,20 @@ class WPShortPixel {
648
  update_option("wp-short-pixel-flag-id", $startQueryID);//we use to detect new added files while bulk is running
649
  add_option('bulkProcessingStatus', 'running');//set bulk flag
650
  }//end bulk process was clicked
 
 
 
 
 
 
 
 
 
 
651
 
652
  $bulkProcessingStatus = get_option('bulkProcessingStatus');
653
  $startQueryID = get_option('wp-short-pixel-query-id-start');
 
654
 
655
  //figure out all the files that could be processed
656
  $qry = "SELECT count(*) FilesToBeProcessed FROM " . $wpdb->prefix . "postmeta
@@ -661,8 +659,28 @@ class WPShortPixel {
661
  WHERE meta_key = '_wp_attached_file' AND post_id <= $startQueryID";
662
  $filesLeft = $wpdb->get_results($qry_left);
663
 
664
- if( $filesLeft[0]->FilesLeftToBeProcessed > 0 && $bulkProcessingStatus == "running" )//bulk processing was started and wasn't yet ended
665
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
  echo "<p>
667
  Bulk optimisation has started. This process will take some time, depending on the number of images in your library. <BR>Do not worry about the slow speed, it is a necessary measure in order not to interfere with the normal functioning of your site.<BR><BR>
668
  This is a brief estimation of the bulk processing times:<BR>
@@ -712,12 +730,13 @@ class WPShortPixel {
712
  }
713
  else
714
  {
715
- update_option("wp-short-pixel-query-id-start", 0);
716
- update_option("wp-short-pixel-query-id-stop", 0);
717
  delete_option('bulkProcessingStatus');
718
  }
719
  }
720
-
 
721
  echo $this->getBulkProcessingForm($allFiles[0]->FilesToBeProcessed);
722
  echo '
723
  <script type="text/javascript" >
@@ -746,9 +765,12 @@ class WPShortPixel {
746
 
747
  public function cancelProcessing(){
748
  //cancel an ongoing bulk processing, it might be needed sometimes
 
 
749
  update_option("wp-short-pixel-query-id-start", 0);
750
  update_option("wp-short-pixel-query-id-stop", 0);
751
  delete_option('bulkProcessingStatus');
 
752
  }
753
 
754
  public function renderSettingsMenu() {
@@ -768,27 +790,42 @@ class WPShortPixel {
768
  if(isset($_POST['submit']) || isset($_POST['validate'])) {
769
 
770
  //handle API Key - common for submit and validate
771
- $_POST['key'] = trim($_POST['key']);
772
 
773
- $validityData = $this->getQuotaInformation($_POST['key'], true);
774
-
775
- $this->_apiKey = $_POST['key'];
776
- $this->_apiInterface->setApiKey($this->_apiKey);
777
- update_option('wp-short-pixel-apiKey', $_POST['key']);
778
- if($validityData['APIKeyValid']) {
779
- if(isset($_POST['validate'])) {
780
- //display notification
781
- printf($noticeHTML, '#7ad03a', 'API Key valid!');
782
- }
783
- update_option('wp-short-pixel-verifiedKey', true);
784
- $this->_verifiedKey = true;
785
- } else {
786
- if(isset($_POST['validate'])) {
787
- //display notification
788
- printf($noticeHTML, '#ff0000', $validityData["Message"]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
789
  }
790
- update_option('wp-short-pixel-verifiedKey', false);
791
- $this->_verifiedKey = false;
792
  }
793
 
794
 
@@ -907,7 +944,7 @@ for(var i = 0; i < rad.length; i++) {
907
  if(this !== prev) {
908
  prev = this;
909
  }
910
- alert('Select Media/Bulk ShortPixel to reprocess all the images');
911
  };
912
  }
913
  </script>
@@ -988,14 +1025,20 @@ HTML;
988
  }
989
 
990
  public function getBulkProcessingForm($imageCount) {
991
- return <<< HTML
992
- </br>
993
  Currently, you have {$imageCount} images in your library. </br>
994
  </br>
995
- <form action='' method="POST" >
996
- <input type="submit" name="bulkProcess" id="bulkProcess" class="button button-primary" value="Compress all your images">
997
- </form>
998
- HTML;
 
 
 
 
 
 
999
  }
1000
 
1001
 
@@ -1046,7 +1089,9 @@ HTML;
1046
  return array(
1047
  "APIKeyValid" => true,
1048
  "APICallsMade" => number_format($data->APICallsMade) . ' images',
1049
- "APICallsQuota" => number_format($data->APICallsQuota) . ' images'
 
 
1050
  );
1051
 
1052
 
@@ -1064,35 +1109,65 @@ HTML;
1064
  print 'Optimisation N/A';
1065
  else
1066
  {
1067
- print 'PDF not processed';
1068
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
 
 
 
 
 
 
 
 
 
1069
  }
1070
  return;
1071
  }
1072
  elseif ( isset( $data['ShortPixelImprovement'] ) )
1073
  {
1074
- if(isset($meta['ShortPixel']['BulkProcessing'])) {
1075
- print 'Waiting for bulk processing';
1076
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1077
- return;
 
 
 
 
 
 
 
 
 
1078
  }
1079
 
1080
  if( is_numeric($data['ShortPixelImprovement']) && !isset($data['ShortPixel']['NoBackup']) ) {
 
1081
  print $data['ShortPixelImprovement'] . '%';
1082
  print " | <a href=\"admin.php?action=shortpixel_restore_backup&amp;attachment_ID={$id}\">Restore backup</a>";
1083
  return;
1084
  }
1085
  elseif ( is_numeric($data['ShortPixelImprovement']) )
1086
  {
 
1087
  print $data['ShortPixelImprovement'];
1088
  print '%';
1089
  return;
1090
  }
1091
  elseif ( $data['ShortPixelImprovement'] <> "Optimisation N/A" )
1092
  {
1093
- print $data['ShortPixelImprovement'];
1094
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Try again</a>";
1095
- return;
 
 
 
 
 
 
 
 
 
 
1096
  }
1097
  else
1098
  {
@@ -1102,23 +1177,50 @@ HTML;
1102
 
1103
 
1104
  } elseif(isset($data['ShortPixel']['WaitingProcessing'])) {
1105
- print 'Image waiting to be processed';
1106
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1107
- return;
 
 
 
 
 
 
 
 
 
1108
  } elseif(isset($data['ShortPixel']['NoFileOnDisk'])) {
1109
  print 'Image does not exist';
1110
  return;
1111
  } else {
1112
 
1113
- if ( wp_attachment_is_image( $id ) ) {
1114
- print 'Image not processed';
1115
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1116
- return;
 
 
 
 
 
 
 
 
 
1117
  }
1118
- elseif ( $fileExtension == "pdf" ){
1119
- print 'PDF not processed';
1120
- print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1121
- return;
 
 
 
 
 
 
 
 
 
1122
  }
1123
 
1124
  }
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.1.2
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
12
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
13
  require_once( ABSPATH . 'wp-includes/pluggable.php' );
14
 
15
+ define('PLUGIN_VERSION', "2.1.2");
16
  define('SP_DEBUG', false);
17
  define('SP_LOG', false);
18
  define('SP_MAX_TIMEOUT', 10);
19
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
20
  define('MUST_HAVE_KEY', true);
21
  define('MAX_API_RETRIES', 5);
22
+ define('QUOTA_EXCEEDED', "Quota Exceeded. <a href='https://shortpixel.com/pricing' target='_blank'>Learn more</a>");
23
  $MAX_EXECUTION_TIME = ini_get('max_execution_time');
24
  if ( is_numeric($MAX_EXECUTION_TIME) )
25
  define('MAX_EXECUTION_TIME', $MAX_EXECUTION_TIME - 3 ); //in seconds
26
+ else
27
+ define('MAX_EXECUTION_TIME', 25 );
28
  define("SP_MAX_RESULTS_QUERY", 6);
29
 
30
  class WPShortPixel {
125
  if(get_option('wp-short-pixel-query-id-stop') === false) {//min ID used for postmeta queries
126
  add_option( 'wp-short-pixel-query-id-stop', 0, '', 'yes' );
127
  }
128
+
129
+ if(get_option('wp-short-pixel-quota-exceeded') === false) {//min ID used for postmeta queries
130
+ add_option( 'wp-short-pixel-quota-exceeded', 0, '', 'yes' );
131
+ }
132
 
133
  }
134
 
135
  public function shortPixelActivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
136
  {
137
+ delete_option('bulkProcessingStatus');
138
+ delete_option( 'wp-short-pixel-cancel-pointer');
139
  update_option( 'wp-short-pixel-query-id-stop', 0 );
140
  update_option( 'wp-short-pixel-query-id-start', 0 );
141
  }
143
  public function shortPixelDeactivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
144
  {
145
  delete_option('bulkProcessingStatus');
146
+ delete_option( 'wp-short-pixel-cancel-pointer');
147
  update_option( 'wp-short-pixel-query-id-stop', 0 );
148
  update_option( 'wp-short-pixel-query-id-start', 0 );
149
  }
177
  jQuery(document).ready(sendRequest());
178
  function sendRequest() {
179
  var data = { 'action': 'my_action' };
180
+ // since WP 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
181
  jQuery.post(ajaxurl, data, function(response) {
182
  if(response.search('Empty queue') >= 0 || response.search('Error processing image') >= 0) {
183
  console.log('Queue is empty');
279
 
280
  $startQueryID = get_option('wp-short-pixel-query-id-start');
281
  $endQueryID = get_option('wp-short-pixel-query-id-stop');
282
+
283
  if ( $startQueryID <= $endQueryID )
284
  {
285
  echo 'Empty queue ' . $startQueryID . '->' . $endQueryID;
286
  die;
287
  }
288
+
289
  sleep(1);
290
  $queryPostMeta = "SELECT * FROM " . $wpdb->prefix . "postmeta
291
  WHERE ( post_id <= $startQueryID AND post_id > $endQueryID ) AND (
298
 
299
  if ( empty($resultsPostMeta) )
300
  {
301
+ $queryMax = "SELECT max(post_id) as startQueryID FROM " . $wpdb->prefix . "postmeta";
302
+ $resultQuery = $wpdb->get_results($queryMax);
303
+ $startQueryID = $resultQuery[0]->startQueryID;
304
+ $endQueryID = $startQueryID;
305
+ update_option("wp-short-pixel-query-id-start", $startQueryID);//update max and min ID
306
+ update_option("wp-short-pixel-query-id-stop", $endQueryID);
307
  echo 'Empty results ' . $startQueryID . '->' . $endQueryID;
308
  die;
309
  }
330
 
331
  $countMeta++;
332
  }
333
+
334
 
335
  if ( isset($idList[0]) )
336
  {
347
  }
348
  elseif( !empty($meta) && !isset($meta['ShortPixel']['WaitingProcessing']) ) //possibly the file wasn't processed in the first pass so we'll wait for it to be completed
349
  {
350
+ //if ( isset($idList[1]) )
351
+ $startQueryID = ( $idList[0]->post_id );
352
+ //else
353
+ // $startQueryID = ( $idList[0]->post_id - 1 );
354
+
355
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
356
  }
357
  elseif ( empty($meta) && $fileExtension <> "pdf" )//file is not an image or PDF so we just skip to the next batch
360
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
361
  die();
362
  }
363
+ else //file was NOT processed in the first pass
364
  {
365
+
366
  $startQueryID = $idList[0]->post_id;
367
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
368
  }
376
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
377
  die();
378
  }
379
+ else
380
+ echo "GGGG-->";
381
 
382
 
383
  //////////////////////
425
  }
426
 
427
  //$processThumbnails = get_option('wp-short-process_thumbnails');
428
+ if ( isset($meta['ShortPixel']) )
429
+ {
430
+ if ( isset($meta['ShortPixel']['WaitingProcessing']) )
431
+ unset($meta['ShortPixel']['WaitingProcessing']);
432
+
433
+ if( isset($meta['ShortPixel']['BulkProcessing']) )
434
+ unset($meta['ShortPixel']['BulkProcessing']);
435
+ }
436
 
437
  $meta['ShortPixelImprovement'] = round($result[0]->PercentImprovement,2);
438
  wp_update_attachment_metadata($ID, $meta);
459
  $imageURL = wp_get_attachment_url($ID);
460
  $imagePath = get_attached_file($ID);
461
  $meta = wp_get_attachment_metadata($ID);
462
+ $uploadDir = wp_upload_dir();
463
+
464
+ if ( empty($meta['file']) )//file has no metadata attached (like PDF files uploaded before SP plugin)
465
+ $SubDir = $this->_apiInterface->returnSubDir($imagePath);
466
+ else
467
+ $SubDir = $this->_apiInterface->returnSubDir($meta['file']);
468
+
469
+ $imageURLs[] = $uploadDir['baseurl'] . DIRECTORY_SEPARATOR . $SubDir . basename($imagePath);//URL to PDF file
470
+ $imagePaths[] = $uploadDir['basedir'] . DIRECTORY_SEPARATOR . $SubDir . basename($imagePath);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
+ $processThumbnails = get_option('wp-short-process_thumbnails');
473
+
474
+ if ( isset($meta['file']) && $processThumbnails )//handle the rest of the thumbnails generated by WP
475
+ {
476
+ $imageIndex = 0;
477
+ foreach ( $meta['sizes'] as $pictureDetails )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  {
479
+ $imageIndex++;
480
+ $imageURLs[$imageIndex] = $uploadDir['baseurl'] . DIRECTORY_SEPARATOR . $SubDir . basename($pictureDetails['file']);
481
+ $imagePaths[$imageIndex] = $uploadDir['basedir'] . DIRECTORY_SEPARATOR . $SubDir . basename($pictureDetails['file']);
482
+ }
 
 
 
483
  }
484
 
485
  if ( isset($imageURLs) )
486
  return array("imageURLs" => $imageURLs, "imagePaths" => $imagePaths, "meta" => $meta, "ID" => $ID);
487
  else
488
  return false;
489
+
490
+ }//end returnURLsAndPaths
491
 
492
 
493
  public function handleManualOptimization() {
502
  //process all files (including thumbs)
503
  if($processThumbnails && !empty($meta['sizes'])) {
504
  //we generate an array with the URLs that need to be handled
505
+ $SubDir = $this->_apiInterface->returnSubDir($meta['file']);
506
  foreach($meta['sizes'] as $thumbnailInfo)
507
  {
508
  $urlList[]= str_replace(basename($filePath[0]), $thumbnailInfo['file'], $urlList[0]);
619
  echo "<p>Don’t have an API Key yet? Get it now at <a href=\"https://shortpixel.com/wp-apikey\" target=\"_blank\">www.ShortPixel.com</a>, for free.</p>";
620
  return;
621
  }
622
+
623
  if(isset($_GET['cancel']))
624
  {//cancel an ongoing bulk processing, it might be needed sometimes
625
  $this->cancelProcessing();
635
  update_option("wp-short-pixel-flag-id", $startQueryID);//we use to detect new added files while bulk is running
636
  add_option('bulkProcessingStatus', 'running');//set bulk flag
637
  }//end bulk process was clicked
638
+
639
+ if(isset($_POST["bulkProcessResume"]))
640
+ {
641
+ $startQueryID = get_option( 'wp-short-pixel-cancel-pointer');
642
+ update_option("wp-short-pixel-query-id-start", $startQueryID);//start downwards from the biggest item ID
643
+ update_option("wp-short-pixel-query-id-stop", 0);
644
+ update_option("wp-short-pixel-flag-id", $startQueryID);//we use to detect new added files while bulk is running
645
+ add_option('bulkProcessingStatus', 'running');//set bulk flag
646
+ delete_option( 'wp-short-pixel-cancel-pointer');
647
+ }//resume was clicked
648
 
649
  $bulkProcessingStatus = get_option('bulkProcessingStatus');
650
  $startQueryID = get_option('wp-short-pixel-query-id-start');
651
+ $endQueryID = get_option('wp-short-pixel-query-id-stop');
652
 
653
  //figure out all the files that could be processed
654
  $qry = "SELECT count(*) FilesToBeProcessed FROM " . $wpdb->prefix . "postmeta
659
  WHERE meta_key = '_wp_attached_file' AND post_id <= $startQueryID";
660
  $filesLeft = $wpdb->get_results($qry_left);
661
 
662
+ if ( get_option('wp-short-pixel-quota-exceeded') )//quota exceeded, let the user know
663
  {
664
+ $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>";
665
+ $quotaData = $this->getQuotaInformation();
666
+
667
+ //maybe in the meantime the user added credits to their account?
668
+
669
+ if ( $quotaData['APICallsQuotaNumeric'] > $quotaData['APICallsMadeNumeric'] )
670
+ {
671
+ update_option('wp-short-pixel-quota-exceeded','0');
672
+ }
673
+ else
674
+ {
675
+ printf($noticeHTML, '#ff0000', "The plugin has optimized " . number_format($quotaData['APICallsMadeNumeric']) . " images and stopped because it reached the monthly limit which is " . number_format($quotaData['APICallsQuotaNumeric']) . ".<BR> See the other <a href='https://shortpixel.com/pricing' target='_blank'>options availbe</a> and <a href='https://shortpixel.com/login' target='_blank'>log into your account</a> to change your type of subscription.");
676
+ return;
677
+ }
678
+ }
679
+
680
+
681
+ if( $filesLeft[0]->FilesLeftToBeProcessed > 0 && ( $startQueryID <> $endQueryID ) && $bulkProcessingStatus == "running" )//bulk processing was started and is still running
682
+ {
683
+
684
  echo "<p>
685
  Bulk optimisation has started. This process will take some time, depending on the number of images in your library. <BR>Do not worry about the slow speed, it is a necessary measure in order not to interfere with the normal functioning of your site.<BR><BR>
686
  This is a brief estimation of the bulk processing times:<BR>
730
  }
731
  else
732
  {
733
+ update_option("wp-short-pixel-query-id-start", $startQueryID);
734
+ update_option("wp-short-pixel-query-id-stop", $endQueryID);
735
  delete_option('bulkProcessingStatus');
736
  }
737
  }
738
+
739
+ delete_option('bulkProcessingStatus');
740
  echo $this->getBulkProcessingForm($allFiles[0]->FilesToBeProcessed);
741
  echo '
742
  <script type="text/javascript" >
765
 
766
  public function cancelProcessing(){
767
  //cancel an ongoing bulk processing, it might be needed sometimes
768
+ $startQueryID = get_option('wp-short-pixel-query-id-start');
769
+ add_option( 'wp-short-pixel-cancel-pointer', $startQueryID);//we save this so we can resume bulk processing
770
  update_option("wp-short-pixel-query-id-start", 0);
771
  update_option("wp-short-pixel-query-id-stop", 0);
772
  delete_option('bulkProcessingStatus');
773
+ echo "Empty queue";
774
  }
775
 
776
  public function renderSettingsMenu() {
790
  if(isset($_POST['submit']) || isset($_POST['validate'])) {
791
 
792
  //handle API Key - common for submit and validate
793
+ $_POST['key'] = trim(str_replace("*","",$_POST['key']));
794
 
795
+ if ( strlen($_POST['key']) <> 20 )
796
+ {
797
+ $KeyLength = strlen($_POST['key']);
798
+
799
+ printf($noticeHTML, '#ff0000', "The key you provided has " . $KeyLength . " characters. The API key should have 20 characters, letters and numbers only.<BR> <b>Please check that the API key is the same as the one you received in your confirmation email.</b><BR>
800
+ If this problem persists, please contact us at <a href='mailto:support@shortpixel.com?Subject=API Key issues' target='_top'>support@shortpixel.com</a> or <a href='https://shortpixel.com/contact' target='_blank'>here</a>.");
801
+ }
802
+ else
803
+ {
804
+ $validityData = $this->getQuotaInformation($_POST['key'], true);
805
+
806
+ $this->_apiKey = $_POST['key'];
807
+ $this->_apiInterface->setApiKey($this->_apiKey);
808
+ update_option('wp-short-pixel-apiKey', $_POST['key']);
809
+ if($validityData['APIKeyValid']) {
810
+ if(isset($_POST['validate'])) {
811
+ //display notification
812
+ printf($noticeHTML, '#7ad03a', 'API Key valid!');
813
+ }
814
+ update_option('wp-short-pixel-verifiedKey', true);
815
+ $this->_verifiedKey = true;
816
+ //test that the "uploads" have the right rights and also we can create the backup dir for ShortPixel
817
+ if ( !file_exists(SP_BACKUP_FOLDER) && !@mkdir(SP_BACKUP_FOLDER, 0777, true) )
818
+ printf($noticeHTML, '#ff0000', "There is something preventing us to create a new folder for backing up your original files.<BR>
819
+ Please make sure that folder <b>" .
820
+ WP_CONTENT_DIR . DIRECTORY_SEPARATOR . "uploads</b> has the necessary write and read rights." );
821
+ } else {
822
+ if(isset($_POST['validate'])) {
823
+ //display notification
824
+ printf($noticeHTML, '#ff0000', $validityData["Message"]);
825
+ }
826
+ update_option('wp-short-pixel-verifiedKey', false);
827
+ $this->_verifiedKey = false;
828
  }
 
 
829
  }
830
 
831
 
944
  if(this !== prev) {
945
  prev = this;
946
  }
947
+ alert('This type of optimization will apply to new uploaded images. <BR>Images that were already processed will not be re-optimized.');
948
  };
949
  }
950
  </script>
1025
  }
1026
 
1027
  public function getBulkProcessingForm($imageCount) {
1028
+
1029
+ $message = "</br>
1030
  Currently, you have {$imageCount} images in your library. </br>
1031
  </br>
1032
+ <form action='' method='POST' >
1033
+ <input type='submit' name='bulkProcess' id='bulkProcess' class='button button-primary' value='Compress all your images'>";
1034
+
1035
+ if ( get_option( 'wp-short-pixel-cancel-pointer') )//add also the resume bulk processing option
1036
+ $message .= "&nbsp;&nbsp;&nbsp;<input type='submit' name='bulkProcessResume' id='bulkProcessResume' class='button button-primary' value='Resume cancelled process'>";
1037
+
1038
+ $message .= "
1039
+ </form>";
1040
+ return $message;
1041
+
1042
  }
1043
 
1044
 
1089
  return array(
1090
  "APIKeyValid" => true,
1091
  "APICallsMade" => number_format($data->APICallsMade) . ' images',
1092
+ "APICallsQuota" => number_format($data->APICallsQuota) . ' images',
1093
+ "APICallsMadeNumeric" => $data->APICallsMade,
1094
+ "APICallsQuotaNumeric" => $data->APICallsQuota
1095
  );
1096
 
1097
 
1109
  print 'Optimisation N/A';
1110
  else
1111
  {
1112
+ if ( get_option('wp-short-pixel-quota-exceeded') )
1113
+ {
1114
+ print QUOTA_EXCEEDED;
1115
+ return;
1116
+ }
1117
+ else
1118
+ {
1119
+ print 'PDF not processed';
1120
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1121
+ return;
1122
+ }
1123
  }
1124
  return;
1125
  }
1126
  elseif ( isset( $data['ShortPixelImprovement'] ) )
1127
  {
1128
+ if(isset($meta['ShortPixel']['BulkProcessing']))
1129
+ {
1130
+ if ( get_option('wp-short-pixel-quota-exceeded') )
1131
+ {
1132
+ print QUOTA_EXCEEDED;
1133
+ return;
1134
+ }
1135
+ else
1136
+ {
1137
+ print 'Waiting for bulk processing';
1138
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1139
+ return;
1140
+ }
1141
  }
1142
 
1143
  if( is_numeric($data['ShortPixelImprovement']) && !isset($data['ShortPixel']['NoBackup']) ) {
1144
+ print 'Reduced by ';
1145
  print $data['ShortPixelImprovement'] . '%';
1146
  print " | <a href=\"admin.php?action=shortpixel_restore_backup&amp;attachment_ID={$id}\">Restore backup</a>";
1147
  return;
1148
  }
1149
  elseif ( is_numeric($data['ShortPixelImprovement']) )
1150
  {
1151
+ print 'Reduced by ';
1152
  print $data['ShortPixelImprovement'];
1153
  print '%';
1154
  return;
1155
  }
1156
  elseif ( $data['ShortPixelImprovement'] <> "Optimisation N/A" )
1157
  {
1158
+ if ( trim(strip_tags($data['ShortPixelImprovement'])) == "Quota exceeded" )
1159
+ {
1160
+ print $data['ShortPixelImprovement'];
1161
+ if ( !get_option('wp-short-pixel-quota-exceeded') )
1162
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Try again</a>";
1163
+ return;
1164
+ }
1165
+ else
1166
+ {
1167
+ print $data['ShortPixelImprovement'];
1168
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Try again</a>";
1169
+ return;
1170
+ }
1171
  }
1172
  else
1173
  {
1177
 
1178
 
1179
  } elseif(isset($data['ShortPixel']['WaitingProcessing'])) {
1180
+ if ( get_option('wp-short-pixel-quota-exceeded') )
1181
+ {
1182
+ print QUOTA_EXCEEDED;
1183
+ return;
1184
+ }
1185
+ else
1186
+ {
1187
+ print 'Image waiting to be processed';
1188
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1189
+ return;
1190
+ }
1191
+
1192
  } elseif(isset($data['ShortPixel']['NoFileOnDisk'])) {
1193
  print 'Image does not exist';
1194
  return;
1195
  } else {
1196
 
1197
+ if ( wp_attachment_is_image( $id ) )
1198
+ {
1199
+ if ( get_option('wp-short-pixel-quota-exceeded') )
1200
+ {
1201
+ print QUOTA_EXCEEDED;
1202
+ return;
1203
+ }
1204
+ else
1205
+ {
1206
+ print 'Image not processed';
1207
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1208
+ return;
1209
+ }
1210
  }
1211
+ elseif ( $fileExtension == "pdf" )
1212
+ {
1213
+ if ( get_option('wp-short-pixel-quota-exceeded') )
1214
+ {
1215
+ print QUOTA_EXCEEDED;
1216
+ return;
1217
+ }
1218
+ else
1219
+ {
1220
+ print 'PDF not processed';
1221
+ print " | <a href=\"admin.php?action=shortpixel_manual_optimize&amp;attachment_ID={$id}\">Optimize now</a>";
1222
+ return;
1223
+ }
1224
  }
1225
 
1226
  }