Version Description
- fixed small upload glitch
- added succes message upon bulk processing completion
- improved image backup
- lossy option by default upon plugin installation
Download this release
Release Info
Developer | ShortPixel |
Plugin | ShortPixel Image Optimizer |
Version | 1.6.1 |
Comparing to | |
See all releases |
Code changes from version 1.6.0 to 1.6.1
- readme.txt +8 -1
- shortpixel_api.php +2 -3
- wp-shortpixel.php +24 -35
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.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -107,6 +107,13 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
|
|
107 |
|
108 |
== Changelog ==
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
= 1.6.0 =
|
111 |
|
112 |
* images' requests for optimization are sent for all sizes upon image upload in media gallery
|
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 |
|
108 |
== Changelog ==
|
109 |
|
110 |
+
= 1.6.1 =
|
111 |
+
|
112 |
+
* fixed small upload glitch
|
113 |
+
* added succes message upon bulk processing completion
|
114 |
+
* improved image backup
|
115 |
+
* lossy option by default upon plugin installation
|
116 |
+
|
117 |
= 1.6.0 =
|
118 |
|
119 |
* images' requests for optimization are sent for all sizes upon image upload in media gallery
|
shortpixel_api.php
CHANGED
@@ -64,7 +64,6 @@ class shortpixel_api {
|
|
64 |
|
65 |
//handles the processing of the image using the ShortPixel API
|
66 |
public function processImage($url, $filePath, $ID = null, $startTime = 0) {
|
67 |
-
|
68 |
if($startTime == 0) { $startTime = time(); }
|
69 |
if(time() - $startTime > MAX_EXECUTION_TIME) {
|
70 |
$meta = wp_get_attachment_metadata($ID);
|
@@ -102,7 +101,7 @@ class shortpixel_api {
|
|
102 |
return 'Wrong API Key</br>';
|
103 |
default:
|
104 |
//handle error
|
105 |
-
return 'An error occurred while processing this image. Please try uploading it again.</br>'
|
106 |
}
|
107 |
|
108 |
return $data;
|
@@ -202,4 +201,4 @@ class shortpixel_api {
|
|
202 |
}
|
203 |
return $data;
|
204 |
}
|
205 |
-
}
|
64 |
|
65 |
//handles the processing of the image using the ShortPixel API
|
66 |
public function processImage($url, $filePath, $ID = null, $startTime = 0) {
|
|
|
67 |
if($startTime == 0) { $startTime = time(); }
|
68 |
if(time() - $startTime > MAX_EXECUTION_TIME) {
|
69 |
$meta = wp_get_attachment_metadata($ID);
|
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;
|
201 |
}
|
202 |
return $data;
|
203 |
}
|
204 |
+
}
|
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.
|
7 |
* Author: ShortPixel
|
8 |
* Author URI: https://shortpixel.com
|
9 |
*/
|
@@ -11,7 +11,7 @@
|
|
11 |
require_once('shortpixel_api.php');
|
12 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
13 |
|
14 |
-
define('SP_DEBUG',
|
15 |
define('SP_LOG', false);
|
16 |
define('SP_MAX_TIMEOUT', 10);
|
17 |
define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
|
@@ -23,7 +23,7 @@ class WPShortPixel {
|
|
23 |
|
24 |
private $_apiInterface = null;
|
25 |
private $_apiKey = '';
|
26 |
-
private $_compressionType =
|
27 |
private $_processThumbnails = 1;
|
28 |
private $_backupImages = 1;
|
29 |
private $_verifiedKey = false;
|
@@ -75,6 +75,8 @@ class WPShortPixel {
|
|
75 |
|
76 |
if(get_option('wp-short-pixel-compression') != false) {
|
77 |
$this->_compressionType = get_option('wp-short-pixel-compression');
|
|
|
|
|
78 |
}
|
79 |
|
80 |
if(get_option('wp-short-process_thumbnails') != false) {
|
@@ -115,7 +117,7 @@ class WPShortPixel {
|
|
115 |
var data = { 'action': 'my_action' };
|
116 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
117 |
jQuery.post(ajaxurl, data, function(response) {
|
118 |
-
if(response
|
119 |
console.log('Queue is empty');
|
120 |
} else {
|
121 |
console.log('Server response: ' + response);
|
@@ -177,8 +179,6 @@ class WPShortPixel {
|
|
177 |
die();
|
178 |
}
|
179 |
|
180 |
-
$bulkLog = get_option('bulkProcessingLog');
|
181 |
-
|
182 |
//query database for first found entry that needs processing
|
183 |
global $wpdb;
|
184 |
$qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
|
@@ -195,20 +195,10 @@ class WPShortPixel {
|
|
195 |
$imagePath = get_attached_file($ID);
|
196 |
$meta = wp_get_attachment_metadata($ID);
|
197 |
|
198 |
-
//check bulk processing
|
199 |
-
if(isset($bulkLog) && is_array($bulkLog)) {
|
200 |
-
if(array_key_exists($ID, $bulkLog)) {
|
201 |
-
unset($bulkLog[$ID]);
|
202 |
-
update_option('bulkProcessingLog', $bulkLog);
|
203 |
-
}
|
204 |
-
}
|
205 |
-
|
206 |
$result = $this->_apiInterface->processImage($imageURL, $imagePath, $ID);
|
207 |
|
208 |
if(is_string($result)) {
|
209 |
$meta['ShortPixelImprovement'] = $result;
|
210 |
-
$bulkLog[$ID] = false;
|
211 |
-
update_option('bulkProcessingLog', $bulkLog);
|
212 |
echo "error processing image";
|
213 |
die();
|
214 |
}
|
@@ -236,9 +226,6 @@ class WPShortPixel {
|
|
236 |
echo "Processing done succesfully for image #{$ID}";
|
237 |
}
|
238 |
|
239 |
-
if(empty($bulkLog)) { $bulkLog = time(); }
|
240 |
-
update_option('bulkProcessingLog', $bulkLog);
|
241 |
-
|
242 |
die();
|
243 |
}
|
244 |
|
@@ -367,7 +354,6 @@ class WPShortPixel {
|
|
367 |
));
|
368 |
|
369 |
if($_GET['cancel']) {
|
370 |
-
delete_option('bulkProcessingLog');
|
371 |
foreach($attachments as $attachment) {
|
372 |
$meta = wp_get_attachment_metadata($attachment->ID);
|
373 |
if(isset($meta['ShortPixel']['BulkProcessing'])) unset($meta['ShortPixel']['BulkProcessing']);
|
@@ -379,19 +365,21 @@ class WPShortPixel {
|
|
379 |
$imageLog = array();
|
380 |
//remove all ShortPixel data from metadata
|
381 |
foreach($attachments as $attachment) {
|
|
|
382 |
$meta = wp_get_attachment_metadata($attachment->ID);
|
383 |
$meta['ShortPixel']['BulkProcessing'] = true;
|
384 |
wp_update_attachment_metadata($attachment->ID, $meta);
|
385 |
-
$imageLog[$attachment->ID] = false;
|
386 |
}
|
387 |
-
|
388 |
-
update_option('bulkProcessingLog', $imageLog);
|
389 |
}
|
390 |
|
391 |
-
$
|
|
|
|
|
|
|
392 |
|
393 |
-
if(!empty($
|
394 |
-
if(is_array($
|
395 |
echo "<p>
|
396 |
Bulk optimisation has started. It may take a while until we process all your images. <BR>The latest status of the processing will be displayed here every 30 seconds.
|
397 |
In the meantime, you can continue using the admin as usual.<BR> However, <b>you musn’t close the WordPress admin</b>, or the bulk processing will stop.
|
@@ -402,7 +390,7 @@ class WPShortPixel {
|
|
402 |
</script>
|
403 |
';
|
404 |
|
405 |
-
$imagesLeft = count($
|
406 |
$totalImages = count($attachments);
|
407 |
|
408 |
echo "<p>{$imagesLeft} out of {$totalImages} images left to process.</p>";
|
@@ -411,13 +399,14 @@ class WPShortPixel {
|
|
411 |
<a class="button button-secondary" href="' . get_admin_url() . 'upload.php">Media Library</a>
|
412 |
<a class="button button-secondary" href="' . get_admin_url() . 'upload.php?page=wp-short-pixel-bulk&cancel=1">Cancel Processing</a>
|
413 |
';
|
414 |
-
}
|
|
|
|
|
|
|
415 |
echo "<p>Bulk optimisation was successful. ShortPixel has finished optimising all your images.</p>
|
416 |
<p>Go to the ShortPixel <a href='" . get_admin_url() . "options-general.php?page=wp-shortpixel#facts'>Facts & Figures</a> and see your website's optimised stats (in Settings > ShortPixel). </p>";
|
417 |
-
|
418 |
-
//delete_option('bulkProcessingLog');
|
419 |
}
|
420 |
-
} else {
|
421 |
echo $this->getBulkProcessingForm(count($attachments));
|
422 |
echo '
|
423 |
<script type="text/javascript" >
|
@@ -526,12 +515,12 @@ Lossless compression: the shrunk image will be identical with the original and s
|
|
526 |
</th><td>
|
527 |
HTML;
|
528 |
|
529 |
-
if($this->_compressionType ==
|
530 |
-
$formHTML .= '<input type="radio" name="compressionType" value="1" >Lossy</br></br>';
|
531 |
-
$formHTML .= '<input type="radio" name="compressionType" value="0" checked>Lossless';
|
532 |
-
} else {
|
533 |
$formHTML .= '<input type="radio" name="compressionType" value="1" checked>Lossy</br></br>';
|
534 |
$formHTML .= '<input type="radio" name="compressionType" value="0" >Lossless';
|
|
|
|
|
|
|
535 |
}
|
536 |
|
537 |
$formHTML .= <<<HTML
|
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 |
*/
|
11 |
require_once('shortpixel_api.php');
|
12 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
13 |
|
14 |
+
define('SP_DEBUG', false);
|
15 |
define('SP_LOG', false);
|
16 |
define('SP_MAX_TIMEOUT', 10);
|
17 |
define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
|
23 |
|
24 |
private $_apiInterface = null;
|
25 |
private $_apiKey = '';
|
26 |
+
private $_compressionType = 1;
|
27 |
private $_processThumbnails = 1;
|
28 |
private $_backupImages = 1;
|
29 |
private $_verifiedKey = false;
|
75 |
|
76 |
if(get_option('wp-short-pixel-compression') != false) {
|
77 |
$this->_compressionType = get_option('wp-short-pixel-compression');
|
78 |
+
} else {
|
79 |
+
add_option('wp-short-pixel-compression', $this->_compressionType, '', 'yes');
|
80 |
}
|
81 |
|
82 |
if(get_option('wp-short-process_thumbnails') != false) {
|
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);
|
179 |
die();
|
180 |
}
|
181 |
|
|
|
|
|
182 |
//query database for first found entry that needs processing
|
183 |
global $wpdb;
|
184 |
$qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
|
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 |
}
|
226 |
echo "Processing done succesfully for image #{$ID}";
|
227 |
}
|
228 |
|
|
|
|
|
|
|
229 |
die();
|
230 |
}
|
231 |
|
354 |
));
|
355 |
|
356 |
if($_GET['cancel']) {
|
|
|
357 |
foreach($attachments as $attachment) {
|
358 |
$meta = wp_get_attachment_metadata($attachment->ID);
|
359 |
if(isset($meta['ShortPixel']['BulkProcessing'])) unset($meta['ShortPixel']['BulkProcessing']);
|
365 |
$imageLog = array();
|
366 |
//remove all ShortPixel data from metadata
|
367 |
foreach($attachments as $attachment) {
|
368 |
+
if(exif_imagetype(get_attached_file($attachment->ID)) == false) continue;
|
369 |
$meta = wp_get_attachment_metadata($attachment->ID);
|
370 |
$meta['ShortPixel']['BulkProcessing'] = true;
|
371 |
wp_update_attachment_metadata($attachment->ID, $meta);
|
|
|
372 |
}
|
373 |
+
update_option('bulkProcessingStatus', 'running');
|
|
|
374 |
}
|
375 |
|
376 |
+
global $wpdb;
|
377 |
+
$qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
|
378 |
+
WHERE meta_value LIKE '%\"BulkProcessing\";b:1;%'";
|
379 |
+
$idList = $wpdb->get_results($qry);
|
380 |
|
381 |
+
if(!empty($idList)) {
|
382 |
+
if(is_array($idList)) {
|
383 |
echo "<p>
|
384 |
Bulk optimisation has started. It may take a while until we process all your images. <BR>The latest status of the processing will be displayed here every 30 seconds.
|
385 |
In the meantime, you can continue using the admin as usual.<BR> However, <b>you musn’t close the WordPress admin</b>, or the bulk processing will stop.
|
390 |
</script>
|
391 |
';
|
392 |
|
393 |
+
$imagesLeft = count($idList);
|
394 |
$totalImages = count($attachments);
|
395 |
|
396 |
echo "<p>{$imagesLeft} out of {$totalImages} images left to process.</p>";
|
399 |
<a class="button button-secondary" href="' . get_admin_url() . 'upload.php">Media Library</a>
|
400 |
<a class="button button-secondary" href="' . get_admin_url() . 'upload.php?page=wp-short-pixel-bulk&cancel=1">Cancel Processing</a>
|
401 |
';
|
402 |
+
}
|
403 |
+
} else {
|
404 |
+
$bulkProcessingStatus = get_option('bulkProcessingStatus');
|
405 |
+
if(isset($bulkProcessingStatus) && $bulkProcessingStatus == 'running') {
|
406 |
echo "<p>Bulk optimisation was successful. ShortPixel has finished optimising all your images.</p>
|
407 |
<p>Go to the ShortPixel <a href='" . get_admin_url() . "options-general.php?page=wp-shortpixel#facts'>Facts & Figures</a> and see your website's optimised stats (in Settings > ShortPixel). </p>";
|
408 |
+
delete_option('bulkProcessingStatus');
|
|
|
409 |
}
|
|
|
410 |
echo $this->getBulkProcessingForm(count($attachments));
|
411 |
echo '
|
412 |
<script type="text/javascript" >
|
515 |
</th><td>
|
516 |
HTML;
|
517 |
|
518 |
+
if($this->_compressionType == 1) {
|
|
|
|
|
|
|
519 |
$formHTML .= '<input type="radio" name="compressionType" value="1" checked>Lossy</br></br>';
|
520 |
$formHTML .= '<input type="radio" name="compressionType" value="0" >Lossless';
|
521 |
+
} else {
|
522 |
+
$formHTML .= '<input type="radio" name="compressionType" value="1">Lossy</br></br>';
|
523 |
+
$formHTML .= '<input type="radio" name="compressionType" value="0" checked>Lossless';
|
524 |
}
|
525 |
|
526 |
$formHTML .= <<<HTML
|