ShortPixel Image Optimizer - Version 2.1.3

Version Description

  • when backup wasn't activated the processed files weren't put in the right place
  • removed forgotten debug message
  • changed "optimised" to "optimized". Welcome USA :)
  • improved bulk handling and also "cancel" and "resume" options
  • fixed confilct with wpmandrill on wp_mail function
Download this release

Release Info

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

Code changes from version 2.1.2 to 2.1.3

Files changed (3) hide show
  1. readme.txt +34 -21
  2. shortpixel_api.php +13 -12
  3. wp-shortpixel.php +36 -30
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === ShortPixel Image Optimiser ===
2
 
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, 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
 
@@ -12,20 +12,20 @@ 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. 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.
27
 
28
- On the https://ShortPixel.com website, we offer free access to the ShrtPixel API which you can use for further image optimisation purposes.
29
 
30
  == Installation ==
31
 
@@ -36,7 +36,7 @@ Let's get ShortPixel plugin running on your WordPress website:
36
  2. You will receive your personal API key in a confirmation email, to the address you provided.
37
  3. Upload the ShortPixel plugin to the /wp-content/plugins/ directory
38
  4. Use your unique API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress.
39
- 5. Uploaded images can be automatically optimised in the Media Library.
40
  6. Done!
41
 
42
 
@@ -44,15 +44,15 @@ Let's get ShortPixel plugin running on your WordPress website:
44
 
45
  = What happens to the existing images, when installing the ShortPixel plugin? =
46
 
47
- Just installing the plugin won’t start the optimisation process on existing images. To begin optimising the images previously loaded on your website, you should:
48
 
49
- * Go to **Media Library**, and select which of the existing images you want to optimise.
50
 
51
  OR
52
 
53
- * Use the **Bulk ShortPixel** option, to automatically optimise all your previous library.
54
 
55
- = Should I pick lossy or lossless optimisation? =
56
 
57
  This depends on your compression needs. **Lossy** has a better compression rate than lossless compression. The resulting image is not 100% identical with the original. Works well for photos taken with your camera.
58
 
@@ -62,7 +62,7 @@ For more information about the difference read the <a href="http://en.wikipedia.
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
 
@@ -72,11 +72,16 @@ To get your API key, you must <a href="https://shortpixel.com/wp-apikey">Sign up
72
 
73
  You use the API key in the ShortPixel plugin Settings (don’t forget to click Save Settings). The same API key can be used on multiple websites/blogs.
74
 
75
- = How does Bulk Optimisation work? =
76
 
77
- The Bulk option makes ShortPixel optimise all your images at once (not one by one). You can do this in the Media > Bulk ShortPixel section by clicking on the **Compress all your images** button.
 
78
 
79
- The batch optimisation may work slower, depending on your existing image gallery. Please be patient and do not close the Wordpress admin while you are rolling the Bulk Processing on your media gallery.
 
 
 
 
80
 
81
  = Are my images safe? =
82
 
@@ -84,11 +89,11 @@ Yes, privacy is guaranteed. The ShortPixel encryption process doesn't allow anyo
84
 
85
  = What happens with my original images after they have been processed with ShortPixel? =
86
 
87
- Your images are automatically stored in a backup folder, on your hosting server. After optimisation, if you want to switch back to a certain original image, hit **Restore backup** in the Media Library. If you are happy with the ShortPixel optimised images, you can deactivate saving the backups in the plugin Settings.
88
 
89
- = What types of formats can be optimised? =
90
 
91
- For now, ShortPixel supports JPEG, PNG, PDF and GIF formats. Animated GIFs and thumbnails are also optimised. Additional formats are scheduled for optimisation in the future.
92
 
93
  = I’m stuck. What do I do? =
94
 
@@ -107,6 +112,14 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
 
 
110
  = 2.1.2 =
111
 
112
  * fixed condition that hanged bulk processing sometimes
1
+ === ShortPixel Image Optimizer ===
2
 
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.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 optimizes 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 optimization:** 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 optimization 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 optimization:** 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.
27
 
28
+ On the https://ShortPixel.com website, we offer free access to the ShrtPixel API which you can use for further image optimization purposes.
29
 
30
  == Installation ==
31
 
36
  2. You will receive your personal API key in a confirmation email, to the address you provided.
37
  3. Upload the ShortPixel plugin to the /wp-content/plugins/ directory
38
  4. Use your unique API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress.
39
+ 5. Uploaded images can be automatically optimized in the Media Library.
40
  6. Done!
41
 
42
 
44
 
45
  = What happens to the existing images, when installing the ShortPixel plugin? =
46
 
47
+ Just installing the plugin won’t start the optimization process on existing images. To begin optimizing the images previously loaded on your website, you should:
48
 
49
+ * Go to **Media Library**, and select which of the existing images you want to optimize.
50
 
51
  OR
52
 
53
+ * Use the **Bulk ShortPixel** option, to automatically optimize all your previous library.
54
 
55
+ = Should I pick lossy or lossless optimization? =
56
 
57
  This depends on your compression needs. **Lossy** has a better compression rate than lossless compression. The resulting image is not 100% identical with the original. Works well for photos taken with your camera.
58
 
62
 
63
  = Why do I need an API key? =
64
 
65
+ ShortPixel Image Optimizer 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
 
72
 
73
  You use the API key in the ShortPixel plugin Settings (don’t forget to click Save Settings). The same API key can be used on multiple websites/blogs.
74
 
75
+ = How do I activate the API key on a multisite? =
76
 
77
+ You have to activate the plugin in the network admin and then activate it manually via the plugins page on each individual site in the multisite.
78
+ Once you have done that, the Settings menu appears and you can add the API key for each individual site.
79
 
80
+ = How does Bulk Optimization work? =
81
+
82
+ The Bulk option makes ShortPixel optimize all your images at once (not one by one). You can do this in the Media > Bulk ShortPixel section by clicking on the **Compress all your images** button.
83
+
84
+ The batch optimization may work slower, depending on your existing image gallery. Please be patient and do not close the Wordpress admin while you are rolling the Bulk Processing on your media gallery.
85
 
86
  = Are my images safe? =
87
 
89
 
90
  = What happens with my original images after they have been processed with ShortPixel? =
91
 
92
+ Your images are automatically stored in a backup folder, on your hosting server. After optimization, if you want to switch back to a certain original image, hit **Restore backup** in the Media Library. If you are happy with the ShortPixel optimized images, you can deactivate saving the backups in the plugin Settings.
93
 
94
+ = What types of formats can be optimized? =
95
 
96
+ For now, ShortPixel supports JPEG, PNG, PDF and GIF formats. Animated GIFs and thumbnails are also optimized. Additional formats are scheduled for optimization in the future.
97
 
98
  = I’m stuck. What do I do? =
99
 
112
 
113
  == Changelog ==
114
 
115
+ = 2.1.3 =
116
+
117
+ * when backup wasn't activated the processed files weren't put in the right place
118
+ * removed forgotten debug message
119
+ * changed "optimised" to "optimized". Welcome USA :)
120
+ * improved bulk handling and also "cancel" and "resume" options
121
+ * fixed confilct with wpmandrill on wp_mail function
122
+
123
  = 2.1.2 =
124
 
125
  * fixed condition that hanged bulk processing sometimes
shortpixel_api.php CHANGED
@@ -223,6 +223,19 @@ class shortpixel_api {
223
  $tempFiles[$counter] = "";
224
  $counter++;
225
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  //if backup is enabled
228
  if( get_option('wp-short-backup_images') )
@@ -235,18 +248,6 @@ class shortpixel_api {
235
  return sprintf("Backup folder does not exist and it could not be created");
236
  }
237
 
238
- $meta = wp_get_attachment_metadata($ID);
239
- if ( empty($meta['file']) )//file has no metadata attached (like PDF files uploaded before SP plugin)
240
- {
241
- $attachedFilePath = get_attached_file($ID);
242
- $SubDir = $this->returnSubDir($attachedFilePath);
243
- }
244
- else
245
- {
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);
252
  $destination[$imageIndex] = SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir . basename($source[$imageIndex]);//for main file
223
  $tempFiles[$counter] = "";
224
  $counter++;
225
  }
226
+
227
+ //generate SubDir for this file
228
+ $meta = wp_get_attachment_metadata($ID);
229
+ if ( empty($meta['file']) )//file has no metadata attached (like PDF files uploaded before SP plugin)
230
+ {
231
+ $attachedFilePath = get_attached_file($ID);
232
+ $SubDir = $this->returnSubDir($attachedFilePath);
233
+ }
234
+ else
235
+ {
236
+ $SubDir = $this->returnSubDir($meta['file']);
237
+ $source = $filePath;
238
+ }
239
 
240
  //if backup is enabled
241
  if( get_option('wp-short-backup_images') )
248
  return sprintf("Backup folder does not exist and it could not be created");
249
  }
250
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  //create backup dir if needed
252
  @mkdir( SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir, 0777, true);
253
  $destination[$imageIndex] = SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir . basename($source[$imageIndex]);//for main file
wp-shortpixel.php CHANGED
@@ -1,18 +1,21 @@
1
  <?php
2
  /**
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
  */
10
 
11
  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.2");
16
  define('SP_DEBUG', false);
17
  define('SP_LOG', false);
18
  define('SP_MAX_TIMEOUT', 10);
@@ -37,6 +40,7 @@ class WPShortPixel {
37
  private $_verifiedKey = false;
38
 
39
  public function __construct() {
 
40
  $this->populateOptions();
41
  $this->setDefaultViewModeList();//set default mode as list. only @ first run
42
 
@@ -134,10 +138,11 @@ class WPShortPixel {
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
  }
142
 
143
  public function shortPixelDeactivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
@@ -298,10 +303,7 @@ class WPShortPixel {
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;
@@ -376,16 +378,12 @@ class WPShortPixel {
376
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
377
  die();
378
  }
379
- else
380
- echo "GGGG-->";
381
 
382
 
383
  //////////////////////
384
 
385
  if( empty($idList) && $startQueryID <= $endQueryID ) { //die but before set the $endQueryID so only new files will be processed
386
- $queryMax = "SELECT max(post_id) as startQueryID FROM " . $wpdb->prefix . "postmeta";
387
- $resultQuery = $wpdb->get_results($queryMax);
388
- $endQueryID = $resultQuery[0]->startQueryID;
389
  update_option('wp-short-pixel-query-id-stop', $endQueryID);
390
  delete_option('bulkProcessingStatus');
391
  echo 'Empty queue - '.$endQueryID; die;
@@ -612,7 +610,7 @@ class WPShortPixel {
612
 
613
  public function bulkProcess() {
614
  global $wpdb;
615
- echo '<h1>Bulk Image Optimisation by ShortPixel</h1>';
616
 
617
  if(MUST_HAVE_KEY && $this->_verifiedKey == false) {//invalid API Key
618
  echo "<p>In order to start processing your images, you need to validate your API key in the ShortPixel Settings. If you don’t have an API Key, you can get one delivered to your inbox.</p>";
@@ -627,9 +625,7 @@ class WPShortPixel {
627
 
628
  if(isset($_POST["bulkProcess"]))
629
  {
630
- $queryMax = "SELECT max(post_id) as startQueryID FROM " . $wpdb->prefix . "postmeta";
631
- $resultQuery = $wpdb->get_results($queryMax);
632
- $startQueryID = $resultQuery[0]->startQueryID;
633
  update_option("wp-short-pixel-query-id-start", $startQueryID);//start downwards from the biggest item ID
634
  update_option("wp-short-pixel-query-id-stop", 0);
635
  update_option("wp-short-pixel-flag-id", $startQueryID);//we use to detect new added files while bulk is running
@@ -682,7 +678,7 @@ class WPShortPixel {
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>
687
  1 to 100 images < 20 min <BR>
688
  100 to 500 images < 2 hour<BR>
@@ -714,12 +710,10 @@ class WPShortPixel {
714
  $bulkProcessingStatus = get_option('bulkProcessingStatus');
715
  if(isset($bulkProcessingStatus) && $bulkProcessingStatus == 'running')
716
  {
717
- echo "<p>Bulk optimisation was successful. ShortPixel has finished optimising all your images.</p>
718
- <p>Go to the ShortPixel <a href='" . get_admin_url() . "options-general.php?page=wp-shortpixel#facts'>Stats</a> and see your website's optimised stats (in Settings > ShortPixel). </p>";
719
-
720
- $queryMax = "SELECT max(post_id) as startQueryID FROM " . $wpdb->prefix . "postmeta";
721
- $resultQuery = $wpdb->get_results($queryMax);
722
- $startQueryID = $resultQuery[0]->startQueryID;
723
  $maxIDbeforeBulk = get_option("wp-short-pixel-flag-id");//what was the max id before bulk was started?
724
 
725
  if ( $startQueryID > $maxIDbeforeBulk )//basically we resume the processing for the files uploaded while bulk was running
@@ -765,10 +759,13 @@ class WPShortPixel {
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
  }
@@ -783,7 +780,7 @@ class WPShortPixel {
783
  <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/" target="_blank">Installation </a> |
784
  <a href="https://shortpixel.com/contact" target="_blank">Support </a>
785
  </p>';
786
- 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>';
787
 
788
  $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>";
789
 
@@ -1310,6 +1307,15 @@ Currently, you have {$imageCount} images in your library. </br>
1310
  }
1311
  return $total_size;
1312
  }
 
 
 
 
 
 
 
 
 
1313
 
1314
  public function migrateBackupFolder() {
1315
  $oldBackupFolder = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'ShortpixelBackups';
1
  <?php
2
  /**
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.3
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
10
 
11
  require_once('shortpixel_api.php');
12
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
13
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
14
+ 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.3");
19
  define('SP_DEBUG', false);
20
  define('SP_LOG', false);
21
  define('SP_MAX_TIMEOUT', 10);
40
  private $_verifiedKey = false;
41
 
42
  public function __construct() {
43
+
44
  $this->populateOptions();
45
  $this->setDefaultViewModeList();//set default mode as list. only @ first run
46
 
138
 
139
  public function shortPixelActivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
140
  {
141
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
142
  delete_option('bulkProcessingStatus');
143
  delete_option( 'wp-short-pixel-cancel-pointer');
144
+ update_option( 'wp-short-pixel-query-id-stop', $endQueryID );
145
+ update_option( 'wp-short-pixel-query-id-start', $startQueryID );
146
  }
147
 
148
  public function shortPixelDeactivatePlugin()//reset some params to avoid troubles for plugins that were activated/deactivated/activated
303
 
304
  if ( empty($resultsPostMeta) )
305
  {
306
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
 
 
 
307
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max and min ID
308
  update_option("wp-short-pixel-query-id-stop", $endQueryID);
309
  echo 'Empty results ' . $startQueryID . '->' . $endQueryID;
378
  update_option("wp-short-pixel-query-id-start", $startQueryID);//update max ID
379
  die();
380
  }
 
 
381
 
382
 
383
  //////////////////////
384
 
385
  if( empty($idList) && $startQueryID <= $endQueryID ) { //die but before set the $endQueryID so only new files will be processed
386
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
 
 
387
  update_option('wp-short-pixel-query-id-stop', $endQueryID);
388
  delete_option('bulkProcessingStatus');
389
  echo 'Empty queue - '.$endQueryID; die;
610
 
611
  public function bulkProcess() {
612
  global $wpdb;
613
+ echo '<h1>Bulk Image Optimization by ShortPixel</h1>';
614
 
615
  if(MUST_HAVE_KEY && $this->_verifiedKey == false) {//invalid API Key
616
  echo "<p>In order to start processing your images, you need to validate your API key in the ShortPixel Settings. If you don’t have an API Key, you can get one delivered to your inbox.</p>";
625
 
626
  if(isset($_POST["bulkProcess"]))
627
  {
628
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
 
 
629
  update_option("wp-short-pixel-query-id-start", $startQueryID);//start downwards from the biggest item ID
630
  update_option("wp-short-pixel-query-id-stop", 0);
631
  update_option("wp-short-pixel-flag-id", $startQueryID);//we use to detect new added files while bulk is running
678
  {
679
 
680
  echo "<p>
681
+ Bulk optimization 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>
682
  This is a brief estimation of the bulk processing times:<BR>
683
  1 to 100 images < 20 min <BR>
684
  100 to 500 images < 2 hour<BR>
710
  $bulkProcessingStatus = get_option('bulkProcessingStatus');
711
  if(isset($bulkProcessingStatus) && $bulkProcessingStatus == 'running')
712
  {
713
+ echo "<p>Bulk optimization was successful. ShortPixel has finished optimizing all your images.</p>
714
+ <p>Go to the ShortPixel <a href='" . get_admin_url() . "options-general.php?page=wp-shortpixel#facts'>Stats</a> and see your website's optimized stats (in Settings > ShortPixel). </p>";
715
+
716
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
 
 
717
  $maxIDbeforeBulk = get_option("wp-short-pixel-flag-id");//what was the max id before bulk was started?
718
 
719
  if ( $startQueryID > $maxIDbeforeBulk )//basically we resume the processing for the files uploaded while bulk was running
759
 
760
  public function cancelProcessing(){
761
  //cancel an ongoing bulk processing, it might be needed sometimes
762
+ global $wpdb;
763
  $startQueryID = get_option('wp-short-pixel-query-id-start');
764
  add_option( 'wp-short-pixel-cancel-pointer', $startQueryID);//we save this so we can resume bulk processing
765
+
766
+ $this->getMaxShortPixelId();//fetch data for endQueryID and startQueryID
767
+ update_option("wp-short-pixel-query-id-start", $startQueryID);
768
+ update_option("wp-short-pixel-query-id-stop", $endQueryID);
769
  delete_option('bulkProcessingStatus');
770
  echo "Empty queue";
771
  }
780
  <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/installation/" target="_blank">Installation </a> |
781
  <a href="https://shortpixel.com/contact" target="_blank">Support </a>
782
  </p>';
783
+ 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 Optimization Tool</a>.</p>';
784
 
785
  $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>";
786
 
1307
  }
1308
  return $total_size;
1309
  }
1310
+
1311
+ public function getMaxShortPixelId() {
1312
+ global $wpdb,$startQueryID,$endQueryID;
1313
+ $queryMax = "SELECT max(post_id) as startQueryID FROM " . $wpdb->prefix . "postmeta";
1314
+ $resultQuery = $wpdb->get_results($queryMax);
1315
+ $startQueryID = $resultQuery[0]->startQueryID;
1316
+ $endQueryID = $startQueryID;
1317
+
1318
+ }
1319
 
1320
  public function migrateBackupFolder() {
1321
  $oldBackupFolder = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'ShortpixelBackups';