WebP Express - Version 0.15.2

Version Description

(released: 17 sep 2019)

  • Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
Download this release

Release Info

Developer rosell.dk
Plugin Icon 128x128 WebP Express
Version 0.15.2
Comparing to
See all releases

Code changes from version 0.15.1 to 0.15.2

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://ko-fi.com/rosell
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
- Stable tag: 0.15.1
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -153,6 +153,26 @@ Easy enough. Browsers looks at the *content type* header rather than the URL to
153
 
154
  I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  = I am on NGINX or OpenResty =
157
 
158
  **The simple way (no redirecting rules)**
@@ -600,6 +620,11 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
600
 
601
  == Changelog ==
602
 
 
 
 
 
 
603
  = 0.15.1 =
604
  *(released: 17 sep 2019)*
605
 
@@ -955,6 +980,9 @@ For older releases, check out changelog.txt
955
 
956
  == Upgrade Notice ==
957
 
 
 
 
958
  = 0.15.1 =
959
  * Multiple bug fixes
960
 
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 0.15.2
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
153
 
154
  I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
155
 
156
+ = Blank images in Safari? =
157
+ WebP Express has three ways of distributing webp to webp-enabled browsers while still sending the originals to webp-disabled browsers.
158
+
159
+ Method 1: Varied image responses
160
+ This method adds rewrites to the .htaccess which redirects jpegs and pngs to the corresponding webps (if they exist). - but only when the browser supports webp images (this is established by examining the "accept" header).
161
+
162
+ Method 2: Altering HTML to use picture tags
163
+ IMG tags are replaced with PICTURE tags which has two sources. One of them points to the webp and has the "content-type" set to "image/webp". The other points to the original. The browser will select the webp source if it supports webp and the other source if it doesn't.
164
+
165
+ Method 3: Altering HTML to point directly to webps in webp enabled browsers, but not altering for browsers not supporting webp. Again, the "accept" header is examined to determine if the browser supports webp.
166
+
167
+ Can some of these go wrong?
168
+ Yes. All!
169
+
170
+ Method 1 can go wrong if you are using a CDN and it hasn't been set up to handle varied image responses. Check out the CDN section in this FAQ (PS: If your CDN has conflated the caches, it is critical that you purge the CDN cache!). I do not believe it can go wrong in other ways. To be certain, please check out [this test page](http://toste.dk/rh.php). When visiting the test-page with Safari, you should see two images with the “JPG” label over them. When visiting the test-page with a browser that supports webp, you should see two images with the “WEBP” label over them. If you do not see one of these things, please report! (no-one has yet experienced that)
171
+
172
+ Method 2 can go wrong on old browser that doesn't support the picture tag syntax. However, simply enable the "Dynamically load picturefill.js on older browsers" option, and it will take care of that issue.
173
+
174
+ Method 3 can go wrong if you are using a page caching plugin if that plugin does not create a separate webp cache for webp-enabled browsers. The *Cache Enabler* plugin handles this. I don't believe there are other page caching plugins that does. There is a FAQ section in this FAQ describing how to set *Cache Enabler* up to work in tandem with WebP Express.
175
+
176
  = I am on NGINX or OpenResty =
177
 
178
  **The simple way (no redirecting rules)**
620
 
621
  == Changelog ==
622
 
623
+ = 0.15.2 =
624
+ *(released: 17 sep 2019)*
625
+
626
+ * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
627
+
628
  = 0.15.1 =
629
  *(released: 17 sep 2019)*
630
 
980
 
981
  == Upgrade Notice ==
982
 
983
+ = 0.15.2 =
984
+ * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
985
+
986
  = 0.15.1 =
987
  * Multiple bug fixes
988
 
changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  = 0.15.1 =
2
  *(released: 17 sep 2019)*
3
 
1
+ = 0.15.2 =
2
+
3
+ * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
4
+
5
  = 0.15.1 =
6
  *(released: 17 sep 2019)*
7
 
lib/classes/ConvertHelperIndependent.php CHANGED
@@ -67,7 +67,7 @@ class ConvertHelperIndependent
67
  public static function appendOrSetExtension($path, $destinationFolder, $destinationExt, $inUploadFolder)
68
  {
69
  if (($destinationFolder == 'mingled') && ($destinationExt == 'set') && $inUploadFolder) {
70
- return preg_replace('/\\.(jpe?g|png)$/', '', $path) . '.webp';
71
  } else {
72
  return $path . '.webp';
73
  }
@@ -405,12 +405,23 @@ class ConvertHelperIndependent
405
  $source = preg_replace('/\\.(webp)$/', '', $destination);
406
  } else {
407
  $source = preg_replace('#\\.webp$#', '.jpg', $destination);
 
 
408
  if (!@file_exists($source)) {
409
  $source = preg_replace('/\\.webp$/', '.jpeg', $destination);
410
  }
 
 
 
 
 
 
411
  if (!@file_exists($source)) {
412
  $source = preg_replace('/\\.webp$/', '.png', $destination);
413
  }
 
 
 
414
  }
415
  if ($destinationStructure == 'doc-root') {
416
  $source = SanityCheck::absPathExistsAndIsFileInDocRoot($source);
@@ -558,7 +569,7 @@ APACHE
558
 
559
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
560
 
561
- $text = 'WebP Express 0.15.1. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
562
 
563
  $logFile = self::getLogFilename($source, $logDir);
564
 
67
  public static function appendOrSetExtension($path, $destinationFolder, $destinationExt, $inUploadFolder)
68
  {
69
  if (($destinationFolder == 'mingled') && ($destinationExt == 'set') && $inUploadFolder) {
70
+ return preg_replace('/\\.(jpe?g|png)$/i', '', $path) . '.webp';
71
  } else {
72
  return $path . '.webp';
73
  }
405
  $source = preg_replace('/\\.(webp)$/', '', $destination);
406
  } else {
407
  $source = preg_replace('#\\.webp$#', '.jpg', $destination);
408
+ // TODO!
409
+ // Also check for "Jpeg", "JpEg" etc.
410
  if (!@file_exists($source)) {
411
  $source = preg_replace('/\\.webp$/', '.jpeg', $destination);
412
  }
413
+ if (!@file_exists($source)) {
414
+ $source = preg_replace('/\\.webp$/', '.JPG', $destination);
415
+ }
416
+ if (!@file_exists($source)) {
417
+ $source = preg_replace('/\\.webp$/', '.JPEG', $destination);
418
+ }
419
  if (!@file_exists($source)) {
420
  $source = preg_replace('/\\.webp$/', '.png', $destination);
421
  }
422
+ if (!@file_exists($source)) {
423
+ $source = preg_replace('/\\.webp$/', '.PNG', $destination);
424
+ }
425
  }
426
  if ($destinationStructure == 'doc-root') {
427
  $source = SanityCheck::absPathExistsAndIsFileInDocRoot($source);
569
 
570
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
571
 
572
+ $text = 'WebP Express 0.15.2. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
573
 
574
  $logFile = self::getLogFilename($source, $logDir);
575
 
lib/classes/SelfTestHelper.php CHANGED
@@ -95,6 +95,7 @@ class SelfTestHelper
95
  }
96
  $testSource = Paths::getPluginDirAbs() . '/webp-express/test/' . $fileNameToCopy;
97
  $filenameOfDestination = self::randomDigitsAndLetters(6) . '.' . strtoupper($imageType);
 
98
  $result[] = 'Copying ' . strtoupper($imageType) . ' to ' . $rootId . ' folder (*webp-express-test-images/' . $filenameOfDestination . '*)';
99
 
100
  $destDir = Paths::getAbsDirById($rootId) . '/webp-express-test-images';
@@ -180,7 +181,7 @@ class SelfTestHelper
180
  $return = wp_remote_get($requestUrl, $args);
181
  if (is_wp_error($return)) {
182
  $result[] = 'Request URL: ' . $requestUrl;
183
- $result[] = 'The remote request errored!';
184
  return [false, $result, [], $return];
185
  }
186
  if ($return['response']['code'] != '200') {
@@ -193,6 +194,14 @@ class SelfTestHelper
193
  } else {
194
  $return['headers'] = [];
195
  }
 
 
 
 
 
 
 
 
196
  return [false, $result, $return['headers'], $return];
197
  }
198
  return [true, $result, $return['headers'], $return];
95
  }
96
  $testSource = Paths::getPluginDirAbs() . '/webp-express/test/' . $fileNameToCopy;
97
  $filenameOfDestination = self::randomDigitsAndLetters(6) . '.' . strtoupper($imageType);
98
+ //$filenameOfDestination = self::randomDigitsAndLetters(6) . '.' . $imageType;
99
  $result[] = 'Copying ' . strtoupper($imageType) . ' to ' . $rootId . ' folder (*webp-express-test-images/' . $filenameOfDestination . '*)';
100
 
101
  $destDir = Paths::getAbsDirById($rootId) . '/webp-express-test-images';
181
  $return = wp_remote_get($requestUrl, $args);
182
  if (is_wp_error($return)) {
183
  $result[] = 'Request URL: ' . $requestUrl;
184
+ $result[] = 'The remote request errored';
185
  return [false, $result, [], $return];
186
  }
187
  if ($return['response']['code'] != '200') {
194
  } else {
195
  $return['headers'] = [];
196
  }
197
+ if (isset($return['headers']['content-type'])) {
198
+ if (strpos($return['headers']['content-type'], 'text/html') !== false) {
199
+ $result[] = 'Body:';
200
+ $result[] = print_r($return['body'], true);
201
+ }
202
+
203
+ }
204
+
205
  return [false, $result, $return['headers'], $return];
206
  }
207
  return [true, $result, $return['headers'], $return];
lib/dismissable-messages/0.15.1/problems-with-mingled-set.php CHANGED
@@ -2,6 +2,7 @@
2
 
3
  namespace WebPExpress;
4
 
 
5
  DismissableMessages::printDismissableMessage(
6
  'error',
7
  'Sorry, due to a bug, the combination of having destination folder set to "mingled" and ' .
@@ -11,3 +12,4 @@ DismissableMessages::printDismissableMessage(
11
  '0.15.1/problems-with-mingled-set',
12
  'Got it!'
13
  );
 
2
 
3
  namespace WebPExpress;
4
 
5
+ /*
6
  DismissableMessages::printDismissableMessage(
7
  'error',
8
  'Sorry, due to a bug, the combination of having destination folder set to "mingled" and ' .
12
  '0.15.1/problems-with-mingled-set',
13
  'Got it!'
14
  );
15
+ */
lib/migrate/migrate12.php CHANGED
@@ -6,6 +6,7 @@ function webpexpress_migrate12() {
6
 
7
  $config = Config::loadConfigAndFix(false); // false, because we do not need to test if quality detection is working
8
 
 
9
  if (($config['destination-extension'] == 'set') && ($config['destination-folder'] == 'mingled')) {
10
  DismissableMessages::addDismissableMessage('0.15.1/problems-with-mingled-set');
11
 
@@ -15,7 +16,7 @@ function webpexpress_migrate12() {
15
  'Please <a href="' . Paths::getSettingsUrl() . '">go to the settings page</a> to fix.'
16
  );
17
 
18
- }
19
 
20
  $forceHtaccessRegeneration = true;
21
  $result = Config::saveConfigurationAndHTAccess($config, $forceHtaccessRegeneration);
6
 
7
  $config = Config::loadConfigAndFix(false); // false, because we do not need to test if quality detection is working
8
 
9
+ /*
10
  if (($config['destination-extension'] == 'set') && ($config['destination-folder'] == 'mingled')) {
11
  DismissableMessages::addDismissableMessage('0.15.1/problems-with-mingled-set');
12
 
16
  'Please <a href="' . Paths::getSettingsUrl() . '">go to the settings page</a> to fix.'
17
  );
18
 
19
+ }*/
20
 
21
  $forceHtaccessRegeneration = true;
22
  $result = Config::saveConfigurationAndHTAccess($config, $forceHtaccessRegeneration);
webp-express.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
- * Version: 0.15.1
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
+ * Version: 0.15.2
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2