ShortPixel Image Optimizer - Version 4.22.4

Version Description

Release date August 25th, 2021 * Compat: Added a notification system for the cases when AVIF files cannot be delivered with the current server/host settings; * Compat: bumped the minimum supported PHP version to 5.6; * Language: 5 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.4
Comparing to
See all releases

Code changes from version 4.22.3 to 4.22.4

class/Controller/AdminNoticesController.php CHANGED
@@ -17,12 +17,14 @@ class AdminNoticesController extends \ShortPixel\Controller
17
  const MSG_COMPAT = 'Error100'; // Plugin Compatility, warn for the ones that disturb functions.
18
  const MSG_FILEPERMS = 'Error101'; // File Permission check, if Queue is file-based.
19
  const MSG_UNLISTED_FOUND = 'Error102'; // SPIO found unlisted images, but this setting is not on
 
20
 
21
  //const MSG_NO_
22
  const MSG_QUOTA_REACHED = 'QuotaReached100';
23
  const MSG_UPGRADE_MONTH = 'UpgradeNotice200'; // When processing more than the subscription allows on average..
24
  const MSG_UPGRADE_BULK = 'UpgradeNotice201'; // when there is no enough for a bulk run.
25
 
 
26
  const MSG_NO_APIKEY = 'ApiNotice300'; // API Key not found
27
  const MSG_NO_APIKEY_REPEAT = 'ApiNotice301'; // First Repeat.
28
  const MSG_NO_APIKEY_REPEAT_LONG = 'ApiNotice302'; // Last Repeat.
@@ -356,6 +358,7 @@ class AdminNoticesController extends \ShortPixel\Controller
356
  }
357
 
358
 
 
359
  protected function doHelpOptInNotices()
360
  {
361
  return; // this is disabled pending review.
17
  const MSG_COMPAT = 'Error100'; // Plugin Compatility, warn for the ones that disturb functions.
18
  const MSG_FILEPERMS = 'Error101'; // File Permission check, if Queue is file-based.
19
  const MSG_UNLISTED_FOUND = 'Error102'; // SPIO found unlisted images, but this setting is not on
20
+ const MSG_AVIF_ERROR = 'Error103'; // Detected unexpected or wrong AVIF headers when avif is on.
21
 
22
  //const MSG_NO_
23
  const MSG_QUOTA_REACHED = 'QuotaReached100';
24
  const MSG_UPGRADE_MONTH = 'UpgradeNotice200'; // When processing more than the subscription allows on average..
25
  const MSG_UPGRADE_BULK = 'UpgradeNotice201'; // when there is no enough for a bulk run.
26
 
27
+
28
  const MSG_NO_APIKEY = 'ApiNotice300'; // API Key not found
29
  const MSG_NO_APIKEY_REPEAT = 'ApiNotice301'; // First Repeat.
30
  const MSG_NO_APIKEY_REPEAT_LONG = 'ApiNotice302'; // Last Repeat.
358
  }
359
 
360
 
361
+
362
  protected function doHelpOptInNotices()
363
  {
364
  return; // this is disabled pending review.
class/Controller/OtherMediaController.php CHANGED
@@ -136,8 +136,13 @@ class OtherMediaController extends \ShortPixel\Controller
136
  }
137
 
138
  /** Check directory structure for new files */
139
- public function refreshFolders($force = false, $expires = 5 * MINUTE_IN_SECONDS)
140
  {
 
 
 
 
 
141
  $customFolders = $this->getActiveFolders();
142
 
143
  $cache = new CacheController();
136
  }
137
 
138
  /** Check directory structure for new files */
139
+ public function refreshFolders($force = false, $expires = null)
140
  {
141
+ // a little PHP 5.5. compat.
142
+ if (is_null($expires))
143
+ {
144
+ $expires = 5 * MINUTE_IN_SECONDS;
145
+ }
146
  $customFolders = $this->getActiveFolders();
147
 
148
  $cache = new CacheController();
class/Controller/SettingsController.php CHANGED
@@ -162,6 +162,11 @@ class SettingsController extends \ShortPixel\Controller
162
  $this->keyModel->checkKey($check_key);
163
  }
164
 
 
 
 
 
 
165
  // end
166
  if ($this->do_redirect)
167
  $this->doRedirect('bulk');
@@ -196,6 +201,9 @@ class SettingsController extends \ShortPixel\Controller
196
  $settings = \wpSPIO()->settings();
197
  $this->view->dismissedNotices = $settings->dismissedNotices;
198
 
 
 
 
199
  $this->loadView('view-settings');
200
  }
201
 
@@ -237,6 +245,79 @@ class SettingsController extends \ShortPixel\Controller
237
  return false;
238
  }
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  protected function getMaxIntermediateImageSize() {
241
  global $_wp_additional_image_sizes;
242
 
@@ -442,8 +523,6 @@ class SettingsController extends \ShortPixel\Controller
442
  unset($post['deliverWebpAlteringType']);
443
  unset($post['deliverWebpType']);
444
 
445
- //echo "<PRE>"; var_dump($deliverwebp); print_r($post); echo "</PRE>"; exit();
446
-
447
  return $post;
448
  }
449
 
162
  $this->keyModel->checkKey($check_key);
163
  }
164
 
165
+ // Reset Avif Check Cache.
166
+ // $cache = new CacheController();
167
+ // $cache->deleteItem('avif_server_check');
168
+ // Notice::removeNoticeByID(AdminNoticesController::MSG_AVIF_ERROR);
169
+
170
  // end
171
  if ($this->do_redirect)
172
  $this->doRedirect('bulk');
201
  $settings = \wpSPIO()->settings();
202
  $this->view->dismissedNotices = $settings->dismissedNotices;
203
 
204
+ if ($this->view->data->createAvif == 1)
205
+ $this->avifServerCheck();
206
+
207
  $this->loadView('view-settings');
208
  }
209
 
245
  return false;
246
  }
247
 
248
+ protected function avifServerCheck()
249
+ {
250
+ $cache = new CacheController();
251
+ if (apply_filters('shortpixel/avifcheck/override', false) === true)
252
+ { return; }
253
+
254
+ if ($cache->getItem('avif_server_check')->exists() === false)
255
+ {
256
+ $url = \WPSPIO()->plugin_url('res/img/test.avif');
257
+ $headers = get_headers($url);
258
+ $is_error = true;
259
+
260
+ // Defaults.
261
+ $error_message = __('Avif server test failed. Your server might not be configured to display AVIF files properly. Serving Avif might cause your images to not load. Check your images, disable the AVIF option or update your web server configuration.', 'shortpixel-image-optimiser');
262
+ $error_detail = __('The request did not return valid HTTP Headers. Check if the plugin is allowed to get ' . $url, 'shortpixel-image-optimiser');
263
+
264
+ $contentType = null;
265
+ $response = $headers[0];
266
+
267
+ if (is_array($headers) )
268
+ {
269
+ foreach($headers as $index => $header)
270
+ {
271
+ if ( strpos(strtolower($header), 'content-type') !== false )
272
+ {
273
+ // This is another header that can interrupt.
274
+ if (strpos(strtolower($header), 'x-content-type-options') === false)
275
+ {
276
+ $contentType = $header;
277
+ }
278
+ }
279
+ }
280
+
281
+ // http not ok, redirect etc. Shouldn't happen.
282
+ if (is_null($response) || strpos($response, '200') === false)
283
+ {
284
+ $error_detail = sprintf(__('The AVIF check could not be completed, because the plugin couldn\'t fetch %s %s %s. %s Please check the security/firewall settings and try again', 'shortpixel-image-optimiser'), '<a href="' . $url . '">', $url, '</a>', '<br>');
285
+ }
286
+ elseif(is_null($contentType) || strpos($contentType, 'avif') === false)
287
+ {
288
+ $error_detail = sprintf(__('The necessary Content-type header for AVIF files wasn\'t found, please check this with your Hosting and/or CDN provider. For more details about how to fix this, %s check this article %s', 'shortpixel_image_optimiser'), '<a href="https://blog.shortpixel.com/avif-mime-type-delivery-apache-nginx/"> ', '</a>');
289
+ }
290
+ else
291
+ {
292
+ $is_error = false;
293
+ }
294
+ }
295
+
296
+ if ($is_error)
297
+ {
298
+ $noticeController = Notice::getInstance();
299
+ $notice = $noticeController->getNoticeByID(AdminNoticesController::MSG_AVIF_ERROR);
300
+ if ($notice && $notice->isDismissed() === true)
301
+ {
302
+ // Do Nothing
303
+ }
304
+ else
305
+ {
306
+ $notice = Notice::addError('<h4>' . $error_message . '</h4><p>' . $error_detail . '</p><p class="small">' . __('Returned Headers:<br>', 'shortpixel-image-optimiser') . print_r($headers, true) . '</p>');
307
+ Notice::makePersistent($notice, AdminNoticesController::MSG_AVIF_ERROR, MONTH_IN_SECONDS);
308
+ }
309
+
310
+ }
311
+ else
312
+ {
313
+ $item = $cache->getItem('avif_server_check');
314
+ $item->setValue(time());
315
+ $item->setExpires(WEEK_IN_SECONDS);
316
+ $cache->storeItemObject($item );
317
+ }
318
+ }
319
+ }
320
+
321
  protected function getMaxIntermediateImageSize() {
322
  global $_wp_additional_image_sizes;
323
 
523
  unset($post['deliverWebpAlteringType']);
524
  unset($post['deliverWebpType']);
525
 
 
 
526
  return $post;
527
  }
528
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: ShortPixel
3
  Tags: convert webp, optimize images, image optimization, resize, compressor, image, avif, compression, optimize, image optimiser, image compression, compress pdf, compress jpg, compress png, performance, photography, smush, scale, pictures
4
  Requires at least: 4.2.0
5
  Tested up to: 5.8
6
- Requires PHP: 5.3
7
- Stable tag: 4.22.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -314,6 +314,12 @@ Alternatively, you can use this filter in your theme's functions.php file:
314
 
315
  == Changelog ==
316
 
 
 
 
 
 
 
317
  = 4.22.3 =
318
  Release date July 28th, 2021
319
  * Fix: Error when using WordPress 5.8 Widget editor;
3
  Tags: convert webp, optimize images, image optimization, resize, compressor, image, avif, compression, optimize, image optimiser, image compression, compress pdf, compress jpg, compress png, performance, photography, smush, scale, pictures
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
 
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;
320
+ * Compat: bumped the minimum supported PHP version to 5.6;
321
+ * Language: 5 new string added, 0 updated, 0 fuzzed, and 0 obsoleted.
322
+
323
  = 4.22.3 =
324
  Release date July 28th, 2021
325
  * Fix: Error when using WordPress 5.8 Widget editor;
res/img/test.avif ADDED
Binary file
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.3
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.3");
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.4
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.4");
37
  define('SHORTPIXEL_MAX_TIMEOUT', 10);
38
  define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
39
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');