ShortPixel Image Optimizer - Version 4.22.5

Version Description

Release date August 31st, 2021 * Fix: in some cases, the MIME type of other files than images were wrongly set to image/jpg; * Fix: when restoring from backup a PNG that was converted to JPG, the MIME type wasn't set back to image/png; * Fix: in case backup fails for any reason, the image in discussion will be skipped (so the original one won't get overwritten); * Language: 0 new string added, 0 updated, 0 fuzzed, and 0 obsoleted.

Download this release

Release Info

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

Code changes from version 4.22.4 to 4.22.5

class/Model/ImageModel.php CHANGED
@@ -239,7 +239,6 @@ class ImageModel extends \ShortPixel\Model
239
  // Find Thumbs returns *full file path*
240
  $foundThumbs = \WpShortPixelMediaLbraryAdapter::findThumbs($pathFile->getFullPath());
241
 
242
- //Log::addTemp('Found Thumbs', $foundThumbs);
243
  // no thumbs, then done.
244
  if (count($foundThumbs) == 0)
245
  {
239
  // Find Thumbs returns *full file path*
240
  $foundThumbs = \WpShortPixelMediaLbraryAdapter::findThumbs($pathFile->getFullPath());
241
 
 
242
  // no thumbs, then done.
243
  if (count($foundThumbs) == 0)
244
  {
class/shortpixel-png2jpg.php CHANGED
@@ -322,7 +322,7 @@ class ShortPixelPng2Jpg {
322
  $baseRelPath = '';
323
  else
324
  $baseRelPath = trailingslashit($baseRelPath);
325
-
326
  $toReplace[self::removeUrlProtocol($imageUrl)] = $baseUrl . $baseRelPath . wp_basename($ret['file']);
327
  $pngSize = $ret['png_size'];
328
  $jpgSize = $ret['jpg_size'];
@@ -375,6 +375,7 @@ class ShortPixelPng2Jpg {
375
  update_post_meta($ID, '_wp_attachment_metadata', $meta);
376
  $itemHandler->deleteItemCache(); // remove cache since filetype changes.
377
  Log::addDebug("Updated meta: " . json_encode($meta));
 
378
  do_action('shortpixel/image/convertpng2jpg_after', $ID, $meta);
379
  }
380
 
@@ -404,7 +405,6 @@ class ShortPixelPng2Jpg {
404
  */
405
  protected function updateFileAlsoInWPMLDuplicates($parentID, &$parentMeta, $file){
406
  $duplicates = ShortPixelMetaFacade::getWPMLDuplicates($parentID);
407
- Log::addTemp("Update Duplicates on png2jpg", $duplicates);
408
  foreach($duplicates as $ID) {
409
  $meta = $parentID == $ID ? $parentMeta : wp_get_attachment_metadata($ID);
410
  $meta['file'] = $file;
@@ -452,7 +452,7 @@ class ShortPixelPng2Jpg {
452
  'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','shortpixel-image-optimiser') ),
453
  'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','shortpixel-image-optimiser') ),
454
  'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','shortpixel-image-optimiser') ),
455
- 'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s), post_mime_type = 'image/jpeg' ", __('GUIDs','shortpixel-image-optimiser') )
456
  );
457
  if(count($options) == 0) {
458
  $options = array_keys($queries);
@@ -501,7 +501,9 @@ class ShortPixelPng2Jpg {
501
  else {
502
  foreach($map as $oldurl => $newurl) {
503
  if(strlen($newurl)) {
504
- $result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) );
 
 
505
  $results[$option] = array($result, $queries[$option][1]);
506
  }
507
  }
322
  $baseRelPath = '';
323
  else
324
  $baseRelPath = trailingslashit($baseRelPath);
325
+
326
  $toReplace[self::removeUrlProtocol($imageUrl)] = $baseUrl . $baseRelPath . wp_basename($ret['file']);
327
  $pngSize = $ret['png_size'];
328
  $jpgSize = $ret['jpg_size'];
375
  update_post_meta($ID, '_wp_attachment_metadata', $meta);
376
  $itemHandler->deleteItemCache(); // remove cache since filetype changes.
377
  Log::addDebug("Updated meta: " . json_encode($meta));
378
+ wp_update_post(array('ID' => $ID, 'post_mime_type' => 'image/jpeg' ));
379
  do_action('shortpixel/image/convertpng2jpg_after', $ID, $meta);
380
  }
381
 
405
  */
406
  protected function updateFileAlsoInWPMLDuplicates($parentID, &$parentMeta, $file){
407
  $duplicates = ShortPixelMetaFacade::getWPMLDuplicates($parentID);
 
408
  foreach($duplicates as $ID) {
409
  $meta = $parentID == $ID ? $parentMeta : wp_get_attachment_metadata($ID);
410
  $meta['file'] = $file;
452
  'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','shortpixel-image-optimiser') ),
453
  'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','shortpixel-image-optimiser') ),
454
  'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','shortpixel-image-optimiser') ),
455
+ 'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) ", __('GUIDs','shortpixel-image-optimiser') )
456
  );
457
  if(count($options) == 0) {
458
  $options = array_keys($queries);
501
  else {
502
  foreach($map as $oldurl => $newurl) {
503
  if(strlen($newurl)) {
504
+ $prepared = $wpdb->prepare( $queries[$option][0], $oldurl, $newurl);
505
+ Log::addDebug("Prepared Query", $prepared);
506
+ $result = $wpdb->query( $prepared );
507
  $results[$option] = array($result, $queries[$option][1]);
508
  }
509
  }
class/wp-short-pixel.php CHANGED
@@ -1422,7 +1422,7 @@ class WPShortPixel {
1422
  //$prio = $this->prioQ->remove($ID);
1423
  $prio = $this->prioQ->remove($itemId);
1424
  if(isset($result["Code"])
1425
- && ( $result["Code"] == "write-fail" //could not write
1426
  || (in_array(0+$result["Code"], array(-201)) && $meta->getRetries() >= 3))) { //for -201 (invalid image format) we retry only 3 times.
1427
  //put this one in the failed images list - to show the user at the end
1428
  $prio = $this->prioQ->addToFailed($itemHandler->getQueuedId());
@@ -2032,6 +2032,10 @@ class WPShortPixel {
2032
  $fsFile = $fs->getFile($png2jpgMain); // original is non-existing at this time. :: Target
2033
  $bkFile = $fs->getFile($bkFolder->getPath() . $fsFile->getFileName()); // Update this, because of filename (extension)
2034
 
 
 
 
 
2035
  }
2036
 
2037
  //first check if the file is readable by the current user - otherwise it will be unaccessible for the web browser
1422
  //$prio = $this->prioQ->remove($ID);
1423
  $prio = $this->prioQ->remove($itemId);
1424
  if(isset($result["Code"])
1425
+ && ( in_array($result["Code"], array("write-fail", "backup-fail")) //could not write
1426
  || (in_array(0+$result["Code"], array(-201)) && $meta->getRetries() >= 3))) { //for -201 (invalid image format) we retry only 3 times.
1427
  //put this one in the failed images list - to show the user at the end
1428
  $prio = $this->prioQ->addToFailed($itemHandler->getQueuedId());
2032
  $fsFile = $fs->getFile($png2jpgMain); // original is non-existing at this time. :: Target
2033
  $bkFile = $fs->getFile($bkFolder->getPath() . $fsFile->getFileName()); // Update this, because of filename (extension)
2034
 
2035
+ // Do the mime type
2036
+ wp_update_post(array('ID' => $attachmentID, 'post_mime_type' => 'image/png' ));
2037
+
2038
+
2039
  }
2040
 
2041
  //first check if the file is readable by the current user - otherwise it will be unaccessible for the web browser
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: convert webp, optimize images, image optimization, resize, compressor, ima
4
  Requires at least: 4.2.0
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 4.22.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -314,6 +314,13 @@ Alternatively, you can use this filter in your theme's functions.php file:
314
 
315
  == Changelog ==
316
 
 
 
 
 
 
 
 
317
  = 4.22.4 =
318
  Release date August 25th, 2021
319
  * Compat: Added a notification system for the cases when AVIF files cannot be delivered with the current server/host settings;
4
  Requires at least: 4.2.0
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 4.22.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
314
 
315
  == Changelog ==
316
 
317
+ = 4.22.5 =
318
+ Release date August 31st, 2021
319
+ * Fix: in some cases, the MIME type of other files than images were wrongly set to `image/jpg`;
320
+ * Fix: when restoring from backup a PNG that was converted to JPG, the MIME type wasn't set back to `image/png`;
321
+ * Fix: in case backup fails for any reason, the image in discussion will be skipped (so the original one won't get overwritten);
322
+ * Language: 0 new string added, 0 updated, 0 fuzzed, and 0 obsoleted.
323
+
324
  = 4.22.4 =
325
  Release date August 25th, 2021
326
  * Compat: Added a notification system for the cases when AVIF files cannot be delivered with the current server/host settings;
shortpixel_api.php CHANGED
@@ -434,7 +434,6 @@ class ShortPixelAPI {
434
  if($avifUrl !== "NA") {
435
  $avifUrl = $this->setPreferredProtocol(urldecode($avifUrl));
436
  $avifTempFile = download_url($avifUrl, $downloadTimeout);
437
- Log::addTemp("Download Avif " . $avifUrl);
438
  $avifTempFile = is_wp_error( $avifTempFile ) ? "NA" : $avifTempFile;
439
  }
440
 
@@ -672,9 +671,6 @@ class ShortPixelAPI {
672
  $webpUrl = isset($fileData->$webpType) ? $fileData->$webpType : 'NA';
673
  $avifUrl = isset($fileData->$avifType) ? $fileData->$avifType : 'NA';
674
 
675
- Log::addTemp('Searching for types : ' . $webpType . ' - ' . $avifType);
676
- Log::addtemp("HandleSuccess, FileData ", $fileData);
677
-
678
  //TODO la sfarsit sa faca fallback la handleDownload
679
  if($archive) {
680
  $downloadResult = $this->fromArchive($archive['Path'], $fileData->$fileType, $fileData->$fileSize, $fileData->OriginalSize, $webpUrl, $avifUrl );
@@ -711,8 +707,7 @@ class ShortPixelAPI {
711
  if( $this->_settings->backupImages )
712
  {
713
  $backupStatus = self::backupImage($mainPath, $PATHs);
714
- Log::addTemp('Status backup - ', $backupStatus);
715
- if($backupStatus == self::STATUS_FAIL) {
716
  $itemHandler->incrementRetries(1, self::ERR_SAVE_BKP, $backupStatus["Message"]);
717
  self::cleanupTemporaryFiles($archive, empty($tempFiles) ? array() : $tempFiles);
718
  Log::addError('Failed to create image backup!', array('status' => $backupStatus));
@@ -812,7 +807,6 @@ class ShortPixelAPI {
812
  /*$targetAvifFileCompat = $fs->getFile($targetFile->getFileDir() . $targetFile->getFileName() . '.avif');*/
813
 
814
  $targetWebPFile = $fs->getFile($targetFile->getFileDir() . $targetFile->getFileBase() . '.avif');
815
- Log::addTemp("Moving Avif file ");
816
  $tempAvifFilePATH->move($targetWebPFile);
817
 
818
  }
434
  if($avifUrl !== "NA") {
435
  $avifUrl = $this->setPreferredProtocol(urldecode($avifUrl));
436
  $avifTempFile = download_url($avifUrl, $downloadTimeout);
 
437
  $avifTempFile = is_wp_error( $avifTempFile ) ? "NA" : $avifTempFile;
438
  }
439
 
671
  $webpUrl = isset($fileData->$webpType) ? $fileData->$webpType : 'NA';
672
  $avifUrl = isset($fileData->$avifType) ? $fileData->$avifType : 'NA';
673
 
 
 
 
674
  //TODO la sfarsit sa faca fallback la handleDownload
675
  if($archive) {
676
  $downloadResult = $this->fromArchive($archive['Path'], $fileData->$fileType, $fileData->$fileSize, $fileData->OriginalSize, $webpUrl, $avifUrl );
707
  if( $this->_settings->backupImages )
708
  {
709
  $backupStatus = self::backupImage($mainPath, $PATHs);
710
+ if($backupStatus['Status'] == self::STATUS_FAIL) {
 
711
  $itemHandler->incrementRetries(1, self::ERR_SAVE_BKP, $backupStatus["Message"]);
712
  self::cleanupTemporaryFiles($archive, empty($tempFiles) ? array() : $tempFiles);
713
  Log::addError('Failed to create image backup!', array('status' => $backupStatus));
807
  /*$targetAvifFileCompat = $fs->getFile($targetFile->getFileDir() . $targetFile->getFileName() . '.avif');*/
808
 
809
  $targetWebPFile = $fs->getFile($targetFile->getFileDir() . $targetFile->getFileBase() . '.avif');
 
810
  $tempAvifFilePATH->move($targetWebPFile);
811
 
812
  }
wp-shortpixel.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel-settings" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
- * Version: 4.22.4
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
@@ -33,7 +33,7 @@ define('SHORTPIXEL_PLUGIN_DIR', __DIR__);
33
 
34
  //define('SHORTPIXEL_AFFILIATE_CODE', '');
35
 
36
- define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.22.4");
37
  define('SHORTPIXEL_MAX_TIMEOUT', 10);
38
  define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
39
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel-settings" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
+ * Version: 4.22.5
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
33
 
34
  //define('SHORTPIXEL_AFFILIATE_CODE', '');
35
 
36
+ define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.22.5");
37
  define('SHORTPIXEL_MAX_TIMEOUT', 10);
38
  define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
39
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');