ShortPixel Image Optimizer - Version 4.5.5

Version Description

  • max thumbs constant - no more than this number of thumbs will be optimized in one pass
  • fix problem with webp tag when using Fusion Builder
  • really hide the API key everywhere when configured so
Download this release

Release Info

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

Code changes from version 4.5.3 to 4.5.5

class/db/shortpixel-meta-facade.php CHANGED
@@ -58,6 +58,7 @@ class ShortPixelMetaFacade {
58
  ? ($rawMeta["ShortPixel"]["type"] == 'glossy' ? 2 : ($rawMeta["ShortPixel"]["type"] == "lossy" ? 1 : 0) )
59
  : null),
60
  "thumbsOpt" =>(isset($rawMeta["ShortPixel"]["thumbsOpt"]) ? $rawMeta["ShortPixel"]["thumbsOpt"] : null),
 
61
  "thumbsMissing" =>(isset($rawMeta["ShortPixel"]["thumbsMissing"]) ? $rawMeta["ShortPixel"]["thumbsMissing"] : null),
62
  "retinasOpt" =>(isset($rawMeta["ShortPixel"]["retinasOpt"]) ? $rawMeta["ShortPixel"]["retinasOpt"] : null),
63
  "thumbsTodo" =>(isset($rawMeta["ShortPixel"]["thumbsTodo"]) ? $rawMeta["ShortPixel"]["thumbsTodo"] : false),
@@ -139,8 +140,10 @@ class ShortPixelMetaFacade {
139
  //thumbs were processed if settings or if they were explicitely requested
140
  if(null === $this->meta->getThumbsOpt()) {
141
  unset($rawMeta['ShortPixel']['thumbsOpt']);
 
142
  } else {
143
  $rawMeta['ShortPixel']['thumbsOpt'] = $this->meta->getThumbsOpt();
 
144
  }
145
 
146
  $thumbsMissing = $this->meta->getThumbsMissing();
@@ -310,11 +313,21 @@ class ShortPixelMetaFacade {
310
  $Tmp = explode("/", $uploadDir['basedir']);
311
  $TmpCount = count($Tmp);
312
  $StichString = $Tmp[$TmpCount-2] . "/" . $Tmp[$TmpCount-1];
313
-
 
314
  foreach( $sizes as $thumbnailName => $thumbnailInfo ) {
 
315
  if(strpos($thumbnailName, ShortPixelMeta::WEBP_THUMB_PREFIX) === 0) {
316
  continue;
317
  }
 
 
 
 
 
 
 
 
318
  $origPath = $tPath = str_replace(ShortPixelAPI::MB_basename($path), $thumbnailInfo['file'], $path);
319
  if ( !file_exists($tPath) ) {
320
  $tPath = $uploadDir['basedir'] . substr($tPath, strpos($tPath, $StichString) + strlen($StichString));
@@ -377,6 +390,8 @@ class ShortPixelMetaFacade {
377
 
378
  $parentId = get_post_meta ($id, '_icl_lang_duplicate_of', true );
379
  if($parentId) $id = $parentId;
 
 
380
 
381
  $duplicates = $wpdb->get_col( $wpdb->prepare( "
382
  SELECT pm.post_id FROM {$wpdb->postmeta} pm
@@ -391,7 +406,9 @@ class ShortPixelMetaFacade {
391
  if(count($transGroupId)) {
392
  $transGroup = $wpdb->get_results("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid = " . $transGroupId[0]->trid);
393
  foreach($transGroup as $trans) {
394
- $duplicates[] = $trans->element_id;
 
 
395
  }
396
  }
397
  }
58
  ? ($rawMeta["ShortPixel"]["type"] == 'glossy' ? 2 : ($rawMeta["ShortPixel"]["type"] == "lossy" ? 1 : 0) )
59
  : null),
60
  "thumbsOpt" =>(isset($rawMeta["ShortPixel"]["thumbsOpt"]) ? $rawMeta["ShortPixel"]["thumbsOpt"] : null),
61
+ "thumbsOptList" =>(isset($rawMeta["ShortPixel"]["thumbsOptList"]) ? $rawMeta["ShortPixel"]["thumbsOptList"] : array()),
62
  "thumbsMissing" =>(isset($rawMeta["ShortPixel"]["thumbsMissing"]) ? $rawMeta["ShortPixel"]["thumbsMissing"] : null),
63
  "retinasOpt" =>(isset($rawMeta["ShortPixel"]["retinasOpt"]) ? $rawMeta["ShortPixel"]["retinasOpt"] : null),
64
  "thumbsTodo" =>(isset($rawMeta["ShortPixel"]["thumbsTodo"]) ? $rawMeta["ShortPixel"]["thumbsTodo"] : false),
140
  //thumbs were processed if settings or if they were explicitely requested
141
  if(null === $this->meta->getThumbsOpt()) {
142
  unset($rawMeta['ShortPixel']['thumbsOpt']);
143
+ unset($rawMeta['ShortPixel']['thumbsOptList']);
144
  } else {
145
  $rawMeta['ShortPixel']['thumbsOpt'] = $this->meta->getThumbsOpt();
146
+ $rawMeta['ShortPixel']['thumbsOptList'] = $this->meta->getThumbsOptList();
147
  }
148
 
149
  $thumbsMissing = $this->meta->getThumbsMissing();
313
  $Tmp = explode("/", $uploadDir['basedir']);
314
  $TmpCount = count($Tmp);
315
  $StichString = $Tmp[$TmpCount-2] . "/" . $Tmp[$TmpCount-1];
316
+
317
+ $count = 0;
318
  foreach( $sizes as $thumbnailName => $thumbnailInfo ) {
319
+
320
  if(strpos($thumbnailName, ShortPixelMeta::WEBP_THUMB_PREFIX) === 0) {
321
  continue;
322
  }
323
+
324
+ if(in_array($thumbnailInfo['file'], $meta->getThumbsOptList())) {
325
+ continue;
326
+ }
327
+
328
+ if($count >= SHORTPIXEL_MAX_THUMBS) break;
329
+ $count++;
330
+
331
  $origPath = $tPath = str_replace(ShortPixelAPI::MB_basename($path), $thumbnailInfo['file'], $path);
332
  if ( !file_exists($tPath) ) {
333
  $tPath = $uploadDir['basedir'] . substr($tPath, strpos($tPath, $StichString) + strlen($StichString));
390
 
391
  $parentId = get_post_meta ($id, '_icl_lang_duplicate_of', true );
392
  if($parentId) $id = $parentId;
393
+
394
+ $mainFile = get_attached_file($id);
395
 
396
  $duplicates = $wpdb->get_col( $wpdb->prepare( "
397
  SELECT pm.post_id FROM {$wpdb->postmeta} pm
406
  if(count($transGroupId)) {
407
  $transGroup = $wpdb->get_results("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid = " . $transGroupId[0]->trid);
408
  foreach($transGroup as $trans) {
409
+ if($mainFile == get_attached_file($trans->element_id)){
410
+ $duplicates[] = $trans->element_id;
411
+ }
412
  }
413
  }
414
  }
class/db/wp-shortpixel-media-library-adapter.php CHANGED
@@ -156,12 +156,12 @@ class WpShortPixelMediaLbraryAdapter {
156
  }
157
 
158
  public static function countNonWebpSizes($sizes) {
159
- $count = 0;
160
  foreach($sizes as $key => $val) {
161
  if (strpos($key, ShortPixelMeta::WEBP_THUMB_PREFIX) === 0) continue;
162
- $count++;
163
  }
164
- return $count;
165
  }
166
 
167
  public static function cleanupFoundThumbs($itemHandler) {
156
  }
157
 
158
  public static function countNonWebpSizes($sizes) {
159
+ $uniq = array();
160
  foreach($sizes as $key => $val) {
161
  if (strpos($key, ShortPixelMeta::WEBP_THUMB_PREFIX) === 0) continue;
162
+ $uniq[$val['file']] = $key;
163
  }
164
+ return count($uniq);
165
  }
166
 
167
  public static function cleanupFoundThumbs($itemHandler) {
class/front/img-to-picture-webp.php CHANGED
@@ -13,7 +13,7 @@ class ImgToPictureWebp {
13
  return preg_replace_callback('/<img[^>]*>/', function ($match) {
14
  // Do nothing with images that has the 'rwp-not-responsive' class.
15
  if ( strpos($match[0], 'sp-no-webp') ) { return $match[0]; }
16
-
17
  $img = self::get_attributes($match[0]);
18
 
19
  $src = (isset($img['src'])) ? $img['src'] : false;
@@ -22,7 +22,9 @@ class ImgToPictureWebp {
22
 
23
  //check if there are webps
24
  $id = self::url_to_attachment_id( $src );
25
- if(!$id) { return $match[0]; }
 
 
26
 
27
  $imageBase = dirname(get_attached_file($id)) . '/';
28
 
13
  return preg_replace_callback('/<img[^>]*>/', function ($match) {
14
  // Do nothing with images that has the 'rwp-not-responsive' class.
15
  if ( strpos($match[0], 'sp-no-webp') ) { return $match[0]; }
16
+
17
  $img = self::get_attributes($match[0]);
18
 
19
  $src = (isset($img['src'])) ? $img['src'] : false;
22
 
23
  //check if there are webps
24
  $id = self::url_to_attachment_id( $src );
25
+ if(!$id) {
26
+ return $match[0];
27
+ }
28
 
29
  $imageBase = dirname(get_attached_file($id)) . '/';
30
 
class/model/shortpixel-meta.php CHANGED
@@ -12,6 +12,7 @@ class ShortPixelMeta extends ShortPixelEntity{
12
  protected $compressionType;
13
  protected $compressedSize;
14
  protected $thumbsOpt;
 
15
  protected $thumbsMissing;
16
  protected $retinasOpt;
17
  protected $thumbsTodo;
@@ -140,6 +141,14 @@ class ShortPixelMeta extends ShortPixelEntity{
140
  $this->thumbsOpt = $thumbsOpt;
141
  }
142
 
 
 
 
 
 
 
 
 
143
  function getThumbsMissing() {
144
  return $this->thumbsMissing;
145
  }
12
  protected $compressionType;
13
  protected $compressedSize;
14
  protected $thumbsOpt;
15
+ protected $thumbsOptList;
16
  protected $thumbsMissing;
17
  protected $retinasOpt;
18
  protected $thumbsTodo;
141
  $this->thumbsOpt = $thumbsOpt;
142
  }
143
 
144
+ function getThumbsOptList() {
145
+ return $this->thumbsOptList;
146
+ }
147
+
148
+ function setThumbsOptList($thumbsOptList) {
149
+ $this->thumbsOptList = $thumbsOptList;
150
+ }
151
+
152
  function getThumbsMissing() {
153
  return $this->thumbsMissing;
154
  }
class/view/shortpixel_view.php CHANGED
@@ -585,7 +585,7 @@ class ShortPixelView {
585
  echo($this->ctrl->getVerifiedKey() ? "login/".(defined("SHORTPIXEL_HIDE_API_KEY") ? '' : $this->ctrl->getApiKey()) : "pricing");
586
  ?>" target="_blank" style="font-size:18px">
587
  <?php _e('Upgrade now','shortpixel-image-optimiser');?>
588
- </a> |
589
  <a href="https://shortpixel.com/contact/<?php //echo($this->ctrl->getEncryptedData());?>" target="_blank" style="font-size:18px"><?php _e('Support','shortpixel-image-optimiser');?> </a>
590
  </p>
591
  <?php if($notice !== null) { ?>
@@ -975,13 +975,13 @@ class ShortPixelView {
975
  <th scope="row"><label for="excludePatterns"><?php _e('Exclude patterns','shortpixel-image-optimiser');?></label></th>
976
  <td>
977
  <input name="excludePatterns" type="text" id="excludePatterns" value="<?php echo( $excludePatterns );?>" class="regular-text" placeholder="<?php
978
- _e('file:keepbig, path:/ignore_regex/i, size:1000x2000','shortpixel-image-optimiser');?>">
979
  <?php _e('Exclude certain images from being optimized, based on patterns.','shortpixel-image-optimiser');?>
980
  <p class="settings-info">
981
  <?php _e('Add patterns separated by comma. A pattern consist of a <strong>type:value</strong> pair; the accepted types are '
982
- . '<strong>"file"</strong>, <strong>"path"</strong> and <strong>"size"</strong>. '
983
  . 'A file will be excluded if it matches any of the patterns. '
984
- . '<br>For a <strong>"file"</strong> pattern only the filename will be matched but for a <strong>"path"</strong>, '
985
  . 'all the path will be matched (useful for excluding certain subdirectories altoghether).'
986
  . 'For these you can also use regular expressions accepted by preg_match, but without "," or ":". '
987
  . 'A pattern will be considered a regex if it starts with a "/" and is valid. '
@@ -1124,7 +1124,7 @@ class ShortPixelView {
1124
 
1125
  public function renderCustomColumn($id, $data, $extended = false){ ?>
1126
  <div id='sp-msg-<?php echo($id);?>' class='column-wp-shortPixel'>
1127
-
1128
  <?php switch($data['status']) {
1129
  case 'n/a': ?>
1130
  <?php _e('Optimization N/A','shortpixel-image-optimiser');?> <?php
@@ -1183,7 +1183,9 @@ class ShortPixelView {
1183
  . $missingThumbs;
1184
  }
1185
  $this->renderListCell($id, $data['status'], $data['showActions'],
1186
- !$data['thumbsOpt'] && $data['thumbsTotal'], $data['thumbsTotal'], $data['backup'], $data['type'], $data['invType'], $successText);
 
 
1187
 
1188
  break;
1189
  }
@@ -1205,7 +1207,7 @@ class ShortPixelView {
1205
  .($retinasOpt ? '<br>' . sprintf(__('+%s Retina images optimized','shortpixel-image-optimiser') , $retinasOpt) : '' ) ;
1206
  }
1207
 
1208
- public function renderListCell($id, $status, $showActions, $optimizeThumbs, $thumbsTotal, $backup, $type, $invType, $message, $extraClass = '') {
1209
  if($showActions) { ?>
1210
  <div class='sp-column-actions <?php echo($extraClass);?>'>
1211
  <div class="sp-dropdown">
@@ -1216,7 +1218,7 @@ class ShortPixelView {
1216
  <?php } ?>
1217
  <?php if($optimizeThumbs) { ?>
1218
  <a class="sp-action-optimize-thumbs" href="javascript:optimizeThumbs(<?php echo($id)?>);" style="background-color:#0085ba;color:white;">
1219
- <?php printf(__('Optimize %s thumbnails','shortpixel-image-optimiser'),$thumbsTotal);?>
1220
  </a>
1221
  <?php }
1222
  if($backup) {
585
  echo($this->ctrl->getVerifiedKey() ? "login/".(defined("SHORTPIXEL_HIDE_API_KEY") ? '' : $this->ctrl->getApiKey()) : "pricing");
586
  ?>" target="_blank" style="font-size:18px">
587
  <?php _e('Upgrade now','shortpixel-image-optimiser');?>
588
+ </a> | <a href="https://shortpixel.com/pricing#faq" target="_blank" style="font-size:18px"><?php _e('FAQ','shortpixel-image-optimiser');?> </a> |
589
  <a href="https://shortpixel.com/contact/<?php //echo($this->ctrl->getEncryptedData());?>" target="_blank" style="font-size:18px"><?php _e('Support','shortpixel-image-optimiser');?> </a>
590
  </p>
591
  <?php if($notice !== null) { ?>
975
  <th scope="row"><label for="excludePatterns"><?php _e('Exclude patterns','shortpixel-image-optimiser');?></label></th>
976
  <td>
977
  <input name="excludePatterns" type="text" id="excludePatterns" value="<?php echo( $excludePatterns );?>" class="regular-text" placeholder="<?php
978
+ _e('name:keepbig, path:/ignore_regex/i, size:1000x2000','shortpixel-image-optimiser');?>">
979
  <?php _e('Exclude certain images from being optimized, based on patterns.','shortpixel-image-optimiser');?>
980
  <p class="settings-info">
981
  <?php _e('Add patterns separated by comma. A pattern consist of a <strong>type:value</strong> pair; the accepted types are '
982
+ . '<strong>"name"</strong>, <strong>"path"</strong> and <strong>"size"</strong>. '
983
  . 'A file will be excluded if it matches any of the patterns. '
984
+ . '<br>For a <strong>"name"</strong> pattern only the filename will be matched but for a <strong>"path"</strong>, '
985
  . 'all the path will be matched (useful for excluding certain subdirectories altoghether).'
986
  . 'For these you can also use regular expressions accepted by preg_match, but without "," or ":". '
987
  . 'A pattern will be considered a regex if it starts with a "/" and is valid. '
1124
 
1125
  public function renderCustomColumn($id, $data, $extended = false){ ?>
1126
  <div id='sp-msg-<?php echo($id);?>' class='column-wp-shortPixel'>
1127
+
1128
  <?php switch($data['status']) {
1129
  case 'n/a': ?>
1130
  <?php _e('Optimization N/A','shortpixel-image-optimiser');?> <?php
1183
  . $missingThumbs;
1184
  }
1185
  $this->renderListCell($id, $data['status'], $data['showActions'],
1186
+ (!$data['thumbsOpt'] && $data['thumbsTotal']) //no thumb was optimized
1187
+ || (count($data['thumbsOptList']) && ($data['thumbsTotal'] - $data['thumbsOpt'] > 0)), $data['thumbsTotal'] - $data['thumbsOpt'],
1188
+ $data['backup'], $data['type'], $data['invType'], $successText);
1189
 
1190
  break;
1191
  }
1207
  .($retinasOpt ? '<br>' . sprintf(__('+%s Retina images optimized','shortpixel-image-optimiser') , $retinasOpt) : '' ) ;
1208
  }
1209
 
1210
+ public function renderListCell($id, $status, $showActions, $optimizeThumbs, $thumbsRemain, $backup, $type, $invType, $message, $extraClass = '') {
1211
  if($showActions) { ?>
1212
  <div class='sp-column-actions <?php echo($extraClass);?>'>
1213
  <div class="sp-dropdown">
1218
  <?php } ?>
1219
  <?php if($optimizeThumbs) { ?>
1220
  <a class="sp-action-optimize-thumbs" href="javascript:optimizeThumbs(<?php echo($id)?>);" style="background-color:#0085ba;color:white;">
1221
+ <?php printf(__('Optimize %s thumbnails','shortpixel-image-optimiser'),$thumbsRemain);?>
1222
  </a>
1223
  <?php }
1224
  if($backup) {
class/wp-short-pixel.php CHANGED
@@ -609,7 +609,8 @@ class WPShortPixel {
609
  }
610
  }
611
  elseif( $this->_settings->processThumbnails && $meta->getThumbsOpt() !== null
612
- && $meta->getThumbsOpt() == 0 && count($meta->getThumbs()) > 0) { //thumbs were chosen in settings
 
613
  //if($crtStartQueryID == 44 || $crtStartQueryID == 49) {echo("No THuMBS?");die(var_dump($meta));}
614
  $meta->setThumbsTodo(true);
615
  $item->updateMeta($meta);//wp_update_attachment_metadata($crtStartQueryID, $meta);
@@ -1326,12 +1327,13 @@ class WPShortPixel {
1326
  //die(var_dump($meta));
1327
  if( isset($meta['ShortPixelImprovement'])
1328
  && isset($meta['sizes']) && WpShortPixelMediaLbraryAdapter::countNonWebpSizes($meta['sizes'])
1329
- && ( !isset($meta['ShortPixel']['thumbsOpt']) || $meta['ShortPixel']['thumbsOpt'] == 0)) { //optimized without thumbs, thumbs exist
 
1330
  $meta['ShortPixel']['thumbsTodo'] = true;
1331
  wp_update_attachment_metadata($ID, $meta);
1332
  $this->prioQ->push($ID);
1333
  try {
1334
- $this->sendToProcessing(new ShortPixelMetaFacade($ID));
1335
  $ret = array("Status" => ShortPixelAPI::STATUS_SUCCESS, "message" => "");
1336
  } catch(Exception $e) { // Exception("Post metadata is corrupt (No attachment URL)") or Exception("Image files are missing.")
1337
  $meta['ShortPixelImprovement'] = $e->getMessage();
@@ -2219,6 +2221,7 @@ class WPShortPixel {
2219
  $renderData['invType'] = ShortPixelAPI::getCompressionTypeName($this->getOtherCompressionTypes(ShortPixelAPI::getCompressionTypeCode($renderData['type'])));
2220
  $renderData['thumbsTotal'] = $sizesCount;
2221
  $renderData['thumbsOpt'] = isset($data['ShortPixel']['thumbsOpt']) ? $data['ShortPixel']['thumbsOpt'] : $sizesCount;
 
2222
  $renderData['thumbsMissing'] = isset($data['ShortPixel']['thumbsMissing']) ? $data['ShortPixel']['thumbsMissing'] : array();
2223
  $renderData['retinasOpt'] = isset($data['ShortPixel']['retinasOpt']) ? $data['ShortPixel']['retinasOpt'] : null;
2224
  $renderData['exifKept'] = isset($data['ShortPixel']['exifKept']) ? $data['ShortPixel']['exifKept'] : null;
@@ -2275,7 +2278,10 @@ class WPShortPixel {
2275
  $renderData['status'] = $quotaExceeded ? 'quotaExceeded' : 'optimizeNow';
2276
  $sizes = isset($data['sizes']) ? WpShortPixelMediaLbraryAdapter::countNonWebpSizes($data['sizes']) : 0;
2277
  $renderData['thumbsTotal'] = $sizes;
2278
- $renderData['message'] = ($fileExtension == "pdf" ? 'PDF' : 'Image') . ' not processed.';
 
 
 
2279
  }
2280
 
2281
  $this->view->renderCustomColumn($id, $renderData, $extended);
@@ -2354,6 +2360,7 @@ class WPShortPixel {
2354
  'percent' => $meta->getImprovementPercent(),
2355
  'bonus' => $meta->getImprovementPercent() < 5,
2356
  'thumbsOpt' => 0,
 
2357
  'thumbsTotal' => 0,
2358
  'retinasOpt' => 0,
2359
  'backup' => true
@@ -2365,6 +2372,7 @@ class WPShortPixel {
2365
  'showActions' => false && current_user_can( 'manage_options' ),
2366
  'status' => 'optimizeNow',
2367
  'thumbsOpt' => 0,
 
2368
  'thumbsTotal' => 0,
2369
  'retinasOpt' => 0,
2370
  'message' => "Not optimized"
609
  }
610
  }
611
  elseif( $this->_settings->processThumbnails && $meta->getThumbsOpt() !== null
612
+ && ($meta->getThumbsOpt() == 0 && count($meta->getThumbs()) > 0
613
+ || $meta->getThumbsOpt() < WpShortPixelMediaLbraryAdapter::countNonWebpSizes($meta->getThumbs()) && is_array($meta->getThumbsOptList()))) { //thumbs were chosen in settings
614
  //if($crtStartQueryID == 44 || $crtStartQueryID == 49) {echo("No THuMBS?");die(var_dump($meta));}
615
  $meta->setThumbsTodo(true);
616
  $item->updateMeta($meta);//wp_update_attachment_metadata($crtStartQueryID, $meta);
1327
  //die(var_dump($meta));
1328
  if( isset($meta['ShortPixelImprovement'])
1329
  && isset($meta['sizes']) && WpShortPixelMediaLbraryAdapter::countNonWebpSizes($meta['sizes'])
1330
+ && ( !isset($meta['ShortPixel']['thumbsOpt']) || $meta['ShortPixel']['thumbsOpt'] == 0
1331
+ || (isset($meta['sizes']) && isset($meta['ShortPixel']['thumbsOptList']) && $meta['ShortPixel']['thumbsOpt'] < WpShortPixelMediaLbraryAdapter::countNonWebpSizes($meta['sizes'])))) { //optimized without thumbs, thumbs exist
1332
  $meta['ShortPixel']['thumbsTodo'] = true;
1333
  wp_update_attachment_metadata($ID, $meta);
1334
  $this->prioQ->push($ID);
1335
  try {
1336
+ $this->sendToProcessing(new ShortPixelMetaFacade($ID), false, true);
1337
  $ret = array("Status" => ShortPixelAPI::STATUS_SUCCESS, "message" => "");
1338
  } catch(Exception $e) { // Exception("Post metadata is corrupt (No attachment URL)") or Exception("Image files are missing.")
1339
  $meta['ShortPixelImprovement'] = $e->getMessage();
2221
  $renderData['invType'] = ShortPixelAPI::getCompressionTypeName($this->getOtherCompressionTypes(ShortPixelAPI::getCompressionTypeCode($renderData['type'])));
2222
  $renderData['thumbsTotal'] = $sizesCount;
2223
  $renderData['thumbsOpt'] = isset($data['ShortPixel']['thumbsOpt']) ? $data['ShortPixel']['thumbsOpt'] : $sizesCount;
2224
+ $renderData['thumbsOptList'] = isset($data['ShortPixel']['thumbsOptList']) ? $data['ShortPixel']['thumbsOptList'] : array();
2225
  $renderData['thumbsMissing'] = isset($data['ShortPixel']['thumbsMissing']) ? $data['ShortPixel']['thumbsMissing'] : array();
2226
  $renderData['retinasOpt'] = isset($data['ShortPixel']['retinasOpt']) ? $data['ShortPixel']['retinasOpt'] : null;
2227
  $renderData['exifKept'] = isset($data['ShortPixel']['exifKept']) ? $data['ShortPixel']['exifKept'] : null;
2278
  $renderData['status'] = $quotaExceeded ? 'quotaExceeded' : 'optimizeNow';
2279
  $sizes = isset($data['sizes']) ? WpShortPixelMediaLbraryAdapter::countNonWebpSizes($data['sizes']) : 0;
2280
  $renderData['thumbsTotal'] = $sizes;
2281
+ $renderData['message'] = ($fileExtension == "pdf" ? 'PDF' : __('Image','shortpixel-image-optimiser'))
2282
+ . __(' not processed.','shortpixel-image-optimiser')
2283
+ . ' (<a href="https://shortpixel.com/image-compression-test?site-url=' . urlencode(ShortPixelMetaFacade::safeGetAttachmentUrl($id)) . '" target="_blank">'
2284
+ . __('Test for free','shortpixel-image-optimiser') . '</a>)';
2285
  }
2286
 
2287
  $this->view->renderCustomColumn($id, $renderData, $extended);
2360
  'percent' => $meta->getImprovementPercent(),
2361
  'bonus' => $meta->getImprovementPercent() < 5,
2362
  'thumbsOpt' => 0,
2363
+ 'thumbsOptList' => array(),
2364
  'thumbsTotal' => 0,
2365
  'retinasOpt' => 0,
2366
  'backup' => true
2372
  'showActions' => false && current_user_can( 'manage_options' ),
2373
  'status' => 'optimizeNow',
2374
  'thumbsOpt' => 0,
2375
+ 'thumbsOptList' => array(),
2376
  'thumbsTotal' => 0,
2377
  'retinasOpt' => 0,
2378
  'message' => "Not optimized"
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: ShortPixel
3
  Tags: compress, image, compression, optimize, image optimizer, image compression, resize, compress pdf, compress jpg, compress png, image compression
4
  Requires at least: 3.2.0
5
  Tested up to: 4.8
6
- Stable tag: 4.5.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -81,8 +81,6 @@ Help us spread a the word by recommending ShortPixel to your friends and collect
81
  * Facebook <a href="https://www.facebook.com/ShortPixel" target="_blank">https://www.facebook.com/ShortPixel</a>
82
  * LinkedIn <a href="https://www.linkedin.com/company/shortpixel" target="_blank">https://www.linkedin.com/company/shortpixel</a>
83
 
84
- **Keywords:** picture, optimization, image editor, pngout, upload speed, shortpixel, compression, nextgen, nextgen gallery optimizer, jpegmini, webp, lossless, cwebp, media, jpegtran, image, image optimisation, image optimization, 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, 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, optimizer, optimiser, compresion, cruncher, image cruncher, compress png, compress jpg, compress jpeg, compress pdf, faster loading times, image optimiser, improve pagerank, optimise, optimize animated gif, optimise jpeg, optimize jpeg, optimize png, optimise png, tinyjpg, short pixel, woocommerce compatible, wpml compatible, smush, imsanity, scale, wp smush, compress images, pdf compression, optimize images, shrink jpeg, compressor, faster website, google pagerank, imagify, prizm, optimus, zara, improve page speed, PageSpeed Insights, sitespeed, smaller images, tinyjpeg, wordpress compression, wordPress image tool, reduce image size, bandwidth, pics, keep exif, remove exif, speed up site, speed up website, compress thumbnails, optimize thumbnails
85
-
86
  == Installation ==
87
 
88
  Let's get ShortPixel plugin running on your WordPress website:
@@ -149,6 +147,11 @@ Let's get ShortPixel plugin running on your WordPress website:
149
  where ‘APIKEY’ is the API Key received upon sign up.
150
  If configured that way, the API key will be used for all the sites of the multisite but will only be visible on the main site’s Settings page, being hidden for the rest of the sites.
151
 
 
 
 
 
 
152
  = How much is a credit? =
153
  A credit is used each time ShortPixel optimizes an image or thumbnail by at least 5%. If we're not able to optimize an image or thumbnail by at least 5% then no credit will be used :-)
154
  Please also note that usually images in your Media Library have 3-5 thumbs associated and a credit will be used for each featured image or associated thumbnail that is optimized.
@@ -219,6 +222,11 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
219
 
220
  == Changelog ==
221
 
 
 
 
 
 
222
  = 4.5.3 =
223
 
224
  * fix Javascript error in bulk in some cases
3
  Tags: compress, image, compression, optimize, image optimizer, image compression, resize, compress pdf, compress jpg, compress png, image compression
4
  Requires at least: 3.2.0
5
  Tested up to: 4.8
6
+ Stable tag: 4.5.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
81
  * Facebook <a href="https://www.facebook.com/ShortPixel" target="_blank">https://www.facebook.com/ShortPixel</a>
82
  * LinkedIn <a href="https://www.linkedin.com/company/shortpixel" target="_blank">https://www.linkedin.com/company/shortpixel</a>
83
 
 
 
84
  == Installation ==
85
 
86
  Let's get ShortPixel plugin running on your WordPress website:
147
  where ‘APIKEY’ is the API Key received upon sign up.
148
  If configured that way, the API key will be used for all the sites of the multisite but will only be visible on the main site’s Settings page, being hidden for the rest of the sites.
149
 
150
+ = I am not the only one working in the WordPress Dashboard. How can I hide my API key? =
151
+ There is a simple way to hide the API key, all you need to do is to add these two lines in your wp-config.php:
152
+ define('SHORTPIXEL_API_KEY', '<<your api key here>>');
153
+ define('SHORTPIXEL_HIDE_API_KEY', true);
154
+
155
  = How much is a credit? =
156
  A credit is used each time ShortPixel optimizes an image or thumbnail by at least 5%. If we're not able to optimize an image or thumbnail by at least 5% then no credit will be used :-)
157
  Please also note that usually images in your Media Library have 3-5 thumbs associated and a credit will be used for each featured image or associated thumbnail that is optimized.
222
 
223
  == Changelog ==
224
 
225
+ = 4.5.5 =
226
+ * max thumbs constant - no more than this number of thumbs will be optimized in one pass
227
+ * fix problem with webp <picture> tag when using Fusion Builder
228
+ * really hide the API key everywhere when configured so
229
+
230
  = 4.5.3 =
231
 
232
  * fix Javascript error in bulk in some cases
shortpixel_api.php CHANGED
@@ -467,6 +467,7 @@ class ShortPixelAPI {
467
  $resize = $this->_settings->resizeImages;
468
  $retinas = 0;
469
  $thumbsOpt = 0;
 
470
  $webpSizes = array();
471
 
472
  if ( !empty($tempFiles) )
@@ -482,6 +483,7 @@ class ShortPixelAPI {
482
  if( ($tempFile['Status'] == self::STATUS_UNCHANGED || $tempFile['Status'] == self::STATUS_SUCCESS) && !$isRetina
483
  && $targetFile !== $mainPath) {
484
  $thumbsOpt++;
 
485
  }
486
 
487
  if($tempFile['Status'] == self::STATUS_SUCCESS) { //if it's unchanged it will still be in the array but only for WebP (handled below)
@@ -517,7 +519,7 @@ class ShortPixelAPI {
517
 
518
  $tempWebpFilePATH = $tempFile["WebP"];
519
  if(file_exists($tempWebpFilePATH)) {
520
- $targetWebPFile = dirname($targetFile) . '/' . basename($targetFile, '.' . pathinfo($targetFile, PATHINFO_EXTENSION)) . ".webp";
521
  copy($tempWebpFilePATH, $targetWebPFile);
522
 
523
  /* the webp thumbnails in metadata sizes is not working so deactivate for now
@@ -564,7 +566,8 @@ class ShortPixelAPI {
564
  $meta->setCompressedSize(@filesize($meta->getPath()));
565
  $meta->setKeepExif($this->_settings->keepExif);
566
  $meta->setTsOptimized(date("Y-m-d H:i:s"));
567
- $meta->setThumbsOpt(($meta->getThumbsTodo() || $this->_settings->processThumbnails) ? $thumbsOpt : 0);
 
568
  $meta->setRetinasOpt($retinas);
569
  $meta->setThumbsTodo(false);
570
  //* Not yet as it doesn't seem to work... */$meta->addThumbs($webpSizes);
467
  $resize = $this->_settings->resizeImages;
468
  $retinas = 0;
469
  $thumbsOpt = 0;
470
+ $thumbsOptList = array();
471
  $webpSizes = array();
472
 
473
  if ( !empty($tempFiles) )
483
  if( ($tempFile['Status'] == self::STATUS_UNCHANGED || $tempFile['Status'] == self::STATUS_SUCCESS) && !$isRetina
484
  && $targetFile !== $mainPath) {
485
  $thumbsOpt++;
486
+ $thumbsOptList[] = self::MB_basename($targetFile);
487
  }
488
 
489
  if($tempFile['Status'] == self::STATUS_SUCCESS) { //if it's unchanged it will still be in the array but only for WebP (handled below)
519
 
520
  $tempWebpFilePATH = $tempFile["WebP"];
521
  if(file_exists($tempWebpFilePATH)) {
522
+ $targetWebPFile = dirname($targetFile) . '/' . self::MB_basename($targetFile, '.' . pathinfo($targetFile, PATHINFO_EXTENSION)) . ".webp";
523
  copy($tempWebpFilePATH, $targetWebPFile);
524
 
525
  /* the webp thumbnails in metadata sizes is not working so deactivate for now
566
  $meta->setCompressedSize(@filesize($meta->getPath()));
567
  $meta->setKeepExif($this->_settings->keepExif);
568
  $meta->setTsOptimized(date("Y-m-d H:i:s"));
569
+ $meta->setThumbsOptList(array_unique(array_merge($meta->getThumbsOptList(), $thumbsOptList)));
570
+ $meta->setThumbsOpt(($meta->getThumbsTodo() || $this->_settings->processThumbnails) ? count($meta->getThumbsOptList()) : 0);
571
  $meta->setRetinasOpt($retinas);
572
  $meta->setThumbsTodo(false);
573
  //* Not yet as it doesn't seem to work... */$meta->addThumbs($webpSizes);
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" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
- * Version: 4.5.3
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * Text Domain: shortpixel-image-optimiser
@@ -17,13 +17,15 @@ define('SHORTPIXEL_PLUGIN_FILE', __FILE__);
17
 
18
  define('SP_AFFILIATE_CODE', '');
19
 
20
- define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.5.3");
21
  define('SP_MAX_TIMEOUT', 10);
22
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
23
  define('SP_BACKUP', 'ShortpixelBackups');
24
  define('MAX_API_RETRIES', 50);
25
  define('MAX_ERR_RETRIES', 5);
26
  define('MAX_FAIL_RETRIES', 3);
 
 
27
  $MAX_EXECUTION_TIME = ini_get('max_execution_time');
28
 
29
  require_once(ABSPATH . 'wp-admin/includes/file.php');
@@ -93,75 +95,11 @@ function shortPixelDeactivatePlugin () {
93
  WPShortPixel::shortPixelDeactivatePlugin();
94
  }
95
 
96
-
97
- /**
98
- * filter function to force wordpress to add our custom srcset values
99
- * @param array $sources {
100
- * One or more arrays of source data to include in the 'srcset'.
101
- *
102
- * @type type array $width {
103
- * @type type string $url The URL of an image source.
104
- * @type type string $descriptor The descriptor type used in the image candidate string,
105
- * either 'w' or 'x'.
106
- * @type type int $value The source width, if paired with a 'w' descriptor or a
107
- * pixel density value if paired with an 'x' descriptor.
108
- * }
109
- * }
110
- * @param array $size_array Array of width and height values in pixels (in that order).
111
- * @param string $image_src The 'src' of the image.
112
- * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
113
- * @param int $attachment_id Image attachment ID.
114
- */
115
- function sp_add_webp_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ){
116
-
117
- // image base name
118
- $image_basename = wp_basename( $image_meta['file'] );
119
- // upload directory info array
120
- $upload_dir_info_arr = wp_upload_dir();
121
- // base url of upload directory
122
- $image_baseurl = $baseurl = $upload_dir_info_arr['baseurl'];
123
- $image_basedir = $basedir = $upload_dir_info_arr['basedir'];
124
-
125
- // Uploads are (or have been) in year/month sub-directories.
126
- if ( $image_basename !== $image_meta['file'] ) {
127
- $dirname = dirname( $image_meta['file'] );
128
-
129
- if ( $dirname !== '.' ) {
130
- $image_baseurl = trailingslashit( $baseurl ) . $dirname;
131
- $image_basedir = trailingslashit( $basedir ) . $dirname;
132
- }
133
- }
134
-
135
- $image_baseurl = trailingslashit( $image_baseurl );
136
- $image_basedir = trailingslashit( $image_basedir );
137
- // check whether our custom image size exists in image meta
138
- foreach($image_meta['sizes'] as $key => $size) {
139
- $fn = $size['file'];
140
- $ext = pathinfo($fn, PATHINFO_EXTENSION);
141
- $webp = substr($fn, 0, strlen($fn) - strlen($ext)) . 'webp';
142
- if( file_exists($image_basedir . $webp) ){
143
- // add source value to create srcset
144
- $sources[ 'webp-' . $size['width'] ] = array(
145
- 'url' => $image_baseurl . $webp,
146
- 'descriptor' => 'w',
147
- 'value' => $size['width'],
148
- );
149
- }
150
- }
151
- //return sources with new srcset value
152
- return $sources;
153
- }
154
- //not really working, the srcset does not accept webp AND other type of image together. Below trying with <picture> ...
155
- //add_filter( 'wp_calculate_image_srcset', 'sp_add_webp_image_srcset', 10, 5 );
156
-
157
-
158
-
159
-
160
  //Picture generation, hooked on the_content filter
161
  function spConvertImgToPictureAddWebp($content) {
162
  require_once('class/front/img-to-picture-webp.php');
163
  //require_once('class/responsive-image.php');
164
- return ImgToPictureWebp::convert($content);
165
  }
166
  function spAddPictureJs() {
167
  // Don't do anything with the RSS feed.
@@ -182,7 +120,7 @@ function spAddPictureJs() {
182
  // wp_enqueue_script( 'picturefill', plugins_url('/res/js/picturefill.min.js', __FILE__), null, null, true);
183
  //}
184
  if ( get_option('wp-short-pixel-create-webp-markup')) {
185
- add_filter( 'the_content', 'spConvertImgToPictureAddWebp' );
186
  add_action( 'wp_head', 'spAddPictureJs');
187
  // add_action( 'wp_enqueue_scripts', 'spAddPicturefillJs' );
188
  }
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" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
+ * Version: 4.5.5
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * Text Domain: shortpixel-image-optimiser
17
 
18
  define('SP_AFFILIATE_CODE', '');
19
 
20
+ define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.5.5");
21
  define('SP_MAX_TIMEOUT', 10);
22
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
23
  define('SP_BACKUP', 'ShortpixelBackups');
24
  define('MAX_API_RETRIES', 50);
25
  define('MAX_ERR_RETRIES', 5);
26
  define('MAX_FAIL_RETRIES', 3);
27
+ define('SHORTPIXEL_MAX_THUMBS', 100);
28
+
29
  $MAX_EXECUTION_TIME = ini_get('max_execution_time');
30
 
31
  require_once(ABSPATH . 'wp-admin/includes/file.php');
95
  WPShortPixel::shortPixelDeactivatePlugin();
96
  }
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  //Picture generation, hooked on the_content filter
99
  function spConvertImgToPictureAddWebp($content) {
100
  require_once('class/front/img-to-picture-webp.php');
101
  //require_once('class/responsive-image.php');
102
+ return ImgToPictureWebp::convert($content) . "<!-- PICTURE TAGS BY SHORTPIXEL -->";
103
  }
104
  function spAddPictureJs() {
105
  // Don't do anything with the RSS feed.
120
  // wp_enqueue_script( 'picturefill', plugins_url('/res/js/picturefill.min.js', __FILE__), null, null, true);
121
  //}
122
  if ( get_option('wp-short-pixel-create-webp-markup')) {
123
+ add_filter( 'the_content', 'spConvertImgToPictureAddWebp', 10000 ); // priority big, so it will be executed last
124
  add_action( 'wp_head', 'spAddPictureJs');
125
  // add_action( 'wp_enqueue_scripts', 'spAddPicturefillJs' );
126
  }