ShortPixel Image Optimizer - Version 5.1.5

Version Description

Release date November 29, 2022 * Fix: WebP/AVIF delivery now works correctly, without affecting SVG files or other images or requests (e.g. in WooCommerce). Sorry about this!; * Fix: a PHP warning was displayed if no valid API key was added; * Fix: error in Custom Media if the folder is not in the root directory; * Language: 0 new strings added, 0 updated, 0 fuzzed, and 0 deprecated.

Download this release

Release Info

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

Code changes from version 5.1.4 to 5.1.5

class/Model/ApiKeyModel.php CHANGED
@@ -108,6 +108,8 @@ class ApiKeyModel extends \ShortPixel\Model
108
  public function checkKey($key)
109
  {
110
 
 
 
111
  if (strlen($key) == 0)
112
  {
113
  // first-timers, redirect to nokey screen
108
  public function checkKey($key)
109
  {
110
 
111
+ $valid = false;
112
+
113
  if (strlen($key) == 0)
114
  {
115
  // first-timers, redirect to nokey screen
class/Model/File/DirectoryOtherMediaModel.php CHANGED
@@ -280,7 +280,7 @@ class DirectoryOtherMediaModel extends DirectoryModel
280
  {
281
  if ($silent === false)
282
  {
283
- Notice::addError( sprintf(__('The %s folder cannot be processed as it\'s not inside the root path of your website (%s).','shortpixel-image-optimiser'),$directory->getPath(), $rootDir->getPath()));
284
  }
285
  return false;
286
  }
280
  {
281
  if ($silent === false)
282
  {
283
+ Notice::addError( sprintf(__('The %s folder cannot be processed as it\'s not inside the root path of your website (%s).','shortpixel-image-optimiser'),$this->getPath(), $rootDir->getPath()));
284
  }
285
  return false;
286
  }
class/front/img-to-picture-webp.php CHANGED
@@ -191,6 +191,9 @@ class ShortPixelImgToPictureWebp
191
 
192
  $srcsetWebP = array();
193
  $srcsetAvif = array();
 
 
 
194
 
195
  $imagePaths = array();
196
 
@@ -206,13 +209,17 @@ class ShortPixelImgToPictureWebp
206
  $mime = ''; // is_infinite
207
 
208
  foreach ($definitions as $item) {
 
209
  $parts = preg_split('/\s+/', trim($item));
210
 
211
  $fileurl = $parts[0];
212
  // A source that starts with data:, will not need processing.
213
  if (strpos($fileurl, 'data:') === 0)
214
  continue;
215
- $condition = isset($parts[1]) ? ' ' . $parts[1] : '';
 
 
 
216
 
217
  // Log::addDebug('Running item - ' . $item, $fileurl);
218
 
@@ -235,6 +242,9 @@ class ShortPixelImgToPictureWebp
235
 
236
  $fileAvif = $fs->getFile($imageBase . $fsFile->getFileBase() . '.avif');
237
 
 
 
 
238
  foreach($files as $thisfile)
239
  {
240
  if (! $thisfile->exists())
@@ -247,6 +257,8 @@ class ShortPixelImgToPictureWebp
247
  {
248
  // base url + found filename + optional condition ( in case of sourceset, as in 1400w or similar)
249
  Log::addDebug('Adding new URL', $fileurl_base . $thisfile->getFileName() . $condition);
 
 
250
  $srcsetWebP[] = $fileurl_base . $thisfile->getFileName() . $condition;
251
  break;
252
  }
@@ -260,12 +272,11 @@ class ShortPixelImgToPictureWebp
260
  {
261
  $fileurl_base = str_replace($fsFile->getFileName(), '', $fileurl);
262
  $srcsetAvif[] = $fileurl_base . $fileAvif->getFileName() . $condition;
 
263
  }
264
  }
265
 
266
-
267
-
268
- if (count($srcsetWebP) == 0 && count($srcsetAvif) == 0) {
269
 
270
  return $match[0]; //. (isset($_GET['SHORTPIXEL_DEBUG']) ? '<!-- SPDBG no srcsetWebP found (' . $srcsetWebP . ') -->' : '');
271
  }
@@ -292,14 +303,14 @@ class ShortPixelImgToPictureWebp
292
 
293
  $output = '<picture ' . $this->create_attributes($imgpicture) . '>';
294
 
295
- if (is_array($srcsetAvif) && count($srcsetAvif) > 0)
296
  {
297
- $srcsetAvif = implode(',', $srcsetAvif);
298
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcsetAvif . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="image/avif">';
299
  }
300
- if (is_array($srcsetWebP) && count($srcsetWebP) > 0)
301
  {
302
- $srcsetWebP = implode(',', $srcsetWebP);
303
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcsetWebP . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="image/webp">';
304
  }
305
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcset . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="' . $mime . '">'
191
 
192
  $srcsetWebP = array();
193
  $srcsetAvif = array();
194
+ // Count real instances of either of them, without fillers.
195
+ $webpCount = $avifCount = 0;
196
+
197
 
198
  $imagePaths = array();
199
 
209
  $mime = ''; // is_infinite
210
 
211
  foreach ($definitions as $item) {
212
+
213
  $parts = preg_split('/\s+/', trim($item));
214
 
215
  $fileurl = $parts[0];
216
  // A source that starts with data:, will not need processing.
217
  if (strpos($fileurl, 'data:') === 0)
218
  continue;
219
+
220
+ // The space if not set is required, otherwise it will not work.
221
+ $condition = isset($parts[1]) ? ' ' . $parts[1] : ' ';
222
+ // $condition = '';
223
 
224
  // Log::addDebug('Running item - ' . $item, $fileurl);
225
 
242
 
243
  $fileAvif = $fs->getFile($imageBase . $fsFile->getFileBase() . '.avif');
244
 
245
+
246
+
247
+
248
  foreach($files as $thisfile)
249
  {
250
  if (! $thisfile->exists())
257
  {
258
  // base url + found filename + optional condition ( in case of sourceset, as in 1400w or similar)
259
  Log::addDebug('Adding new URL', $fileurl_base . $thisfile->getFileName() . $condition);
260
+ $webpCount++;
261
+
262
  $srcsetWebP[] = $fileurl_base . $thisfile->getFileName() . $condition;
263
  break;
264
  }
272
  {
273
  $fileurl_base = str_replace($fsFile->getFileName(), '', $fileurl);
274
  $srcsetAvif[] = $fileurl_base . $fileAvif->getFileName() . $condition;
275
+ $avifCount++;
276
  }
277
  }
278
 
279
+ if ($webpCount == 0 && $avifCount == 0) {
 
 
280
 
281
  return $match[0]; //. (isset($_GET['SHORTPIXEL_DEBUG']) ? '<!-- SPDBG no srcsetWebP found (' . $srcsetWebP . ') -->' : '');
282
  }
303
 
304
  $output = '<picture ' . $this->create_attributes($imgpicture) . '>';
305
 
306
+ if (is_array($srcsetAvif) && $avifCount > 0)
307
  {
308
+ $srcsetAvif = implode(',', array_unique($srcsetAvif));
309
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcsetAvif . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="image/avif">';
310
  }
311
+ if (is_array($srcsetWebP) && $webpCount > 0)
312
  {
313
+ $srcsetWebP = implode(',', array_unique($srcsetWebP));
314
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcsetWebP . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="image/webp">';
315
  }
316
  $output .= '<source ' . $srcsetPrefix . 'srcset="' . $srcset . '"' . ($sizes ? ' ' . $sizesPrefix . 'sizes="' . $sizes . '"' : '') . ' type="' . $mime . '">'
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: convert webp, optimize images, image optimization, resize, compressor, ima
4
  Requires at least: 4.8.0
5
  Tested up to: 6.1
6
  Requires PHP: 5.6
7
- Stable tag: 5.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -292,9 +292,10 @@ filters the array of paths of the images sent for backup and can be used to excl
292
  For version 5.0.0 and later:
293
 
294
  `apply_filters('shortpixel/image/skip_backup', false, $this->getFullPath(), $this->is_main_file)`
295
- filters the images that are skipped or not from the backup. Return true for the type of images to be skipped in the backup. If you check if `is_main_file` is true and return false (do not skip backup), while while otherwise returning true, the backup will be kept only for the main image. We suggest using it in conjuction with this action that fires right after the restore from backup is done (to cleanup the meta data from the database, regenerate thumbnails after restoring the main file, etc.):
296
 
297
  `do_action('shortpixel/image/after_restore', $this, $this->id, $cleanRestore);`
 
298
 
299
  `apply_filters('shortpixel/settings/image_sizes', $sizes);`
300
  filters the array (`$sizes`) of image sizes that can be excluded from processing (displayed in the plugin Advanced settings);
@@ -366,6 +367,13 @@ Add HTTP basic authentication credentials by defining these constants in wp-conf
366
 
367
  == Changelog ==
368
 
 
 
 
 
 
 
 
369
  = 5.1.4 =
370
  Release date November 28, 2022
371
  * New: added a filter to force a file check for WebP/AVIF if they were manually deleted from disk;
4
  Requires at least: 4.8.0
5
  Tested up to: 6.1
6
  Requires PHP: 5.6
7
+ Stable tag: 5.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
292
  For version 5.0.0 and later:
293
 
294
  `apply_filters('shortpixel/image/skip_backup', false, $this->getFullPath(), $this->is_main_file)`
295
+ filters the images that are skipped or not from the backup. Return true for the type of images to be skipped in the backup. If you check if `is_main_file` is true and return false (do not skip backup), while while otherwise returning true, the backup will be kept only for the main image. We suggest using it in conjuction with this action that fires right after the restore from backup is done:
296
 
297
  `do_action('shortpixel/image/after_restore', $this, $this->id, $cleanRestore);`
298
+ This action can be used to cleanup the meta data from the database, regenerate thumbnails after restoring the main file, writing the updated meta data, etc.
299
 
300
  `apply_filters('shortpixel/settings/image_sizes', $sizes);`
301
  filters the array (`$sizes`) of image sizes that can be excluded from processing (displayed in the plugin Advanced settings);
367
 
368
  == Changelog ==
369
 
370
+ = 5.1.5 =
371
+ Release date November 29, 2022
372
+ * Fix: WebP/AVIF delivery now works correctly, without affecting SVG files or other images or requests (e.g. in WooCommerce). Sorry about this!;
373
+ * Fix: a PHP warning was displayed if no valid API key was added;
374
+ * Fix: error in Custom Media if the folder is not in the root directory;
375
+ * Language: 0 new strings added, 0 updated, 0 fuzzed, and 0 deprecated.
376
+
377
  = 5.1.4 =
378
  Release date November 28, 2022
379
  * New: added a filter to force a file check for WebP/AVIF if they were manually deleted from disk;
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="/wp-admin/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: 5.1.4
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
@@ -31,7 +31,7 @@ if (! defined('SHORTPIXEL_RESET_ON_ACTIVATE'))
31
  define('SHORTPIXEL_PLUGIN_FILE', __FILE__);
32
  define('SHORTPIXEL_PLUGIN_DIR', __DIR__);
33
 
34
- define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "5.1.4");
35
 
36
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
37
  define('SHORTPIXEL_MAX_FAIL_RETRIES', 3);
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="/wp-admin/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: 5.1.5
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
31
  define('SHORTPIXEL_PLUGIN_FILE', __FILE__);
32
  define('SHORTPIXEL_PLUGIN_DIR', __DIR__);
33
 
34
+ define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "5.1.5");
35
 
36
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
37
  define('SHORTPIXEL_MAX_FAIL_RETRIES', 3);