WebP Express - Version 0.13.1

Version Description

(released: 10 may 2019) * Fixed critical bug which could result in update failures in the Gutenberg editor. Thanks to Andrei Glingeanu from Moldova for his part in solving this. * Fixed bug that caused the Bulk convert to start over. Thanks to Bas van Dijk, presumably from the Netherlands, for finding the root cause. * On Nginx (in some configurations), the script that triggered conversion were exiting prematurely. Thanks to Sam Benson from the UK for fixing this. * Improved Bulk conversion client, which was slowing down when many images where converted. * A class had existential problems on HHVM. Thanks to @jaumerrr for posting the PHP error message. * When selecting "custom" in the Cache-Control dropdown, the default text was invalid syntax. Thanks to Kevin Batdorf from Thailand for discovering this. * When an image was deleted, the corresponding webp image was not automatically deleted. Thanks to Tobias Keller from Germany for pointing out that this could potentially lead to old webp images being shown.

For more info, see the closed issues on the 0.13.1 milestone on the github repository: https://github.com/rosell-dk/webp-express/milestone/17?closed=1

Download this release

Release Info

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

Code changes from version 0.13.0 to 0.13.1

README.md CHANGED
@@ -165,7 +165,7 @@ location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
165
}
166
try_files
167
/nonexisting-because-try-files-needs-fallback
168
- /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content
169
;
170
}
171
```
@@ -207,7 +207,7 @@ location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
207
}
208
try_files
209
$uri.webp
210
- /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content
211
;
212
}
213
# ------------------- (WebP Express rules ends here)
@@ -229,7 +229,7 @@ Simply add the following rules below the ones you added in step 2:
229
location ~* ^/?wp-content/.*\.(png|jpe?g)\.webp$ {
230
try_files
231
$uri
232
- /wp-content/plugins/webp-express/wod/webp-realizer.php?wp-content=wp-content
233
;
234
}
235
```
@@ -597,6 +597,9 @@ Here are my current plans ahead: 0.13 might be bulk conversion and addition of a
597
598
If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
599
600
## Changes in 0.13.0
601
- Bulk Conversion
602
- Fixed problems with Gd converter and PNG
165
}
166
try_files
167
/nonexisting-because-try-files-needs-fallback
168
+ /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content&$args
169
;
170
}
171
```
207
}
208
try_files
209
$uri.webp
210
+ /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content&$args
211
;
212
}
213
# ------------------- (WebP Express rules ends here)
229
location ~* ^/?wp-content/.*\.(png|jpe?g)\.webp$ {
230
try_files
231
$uri
232
+ /wp-content/plugins/webp-express/wod/webp-realizer.php?wp-content=wp-content&$args
233
;
234
}
235
```
597
598
If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
599
600
+ ## Changes in 0.13.1
601
+ - Fixed several bugs.
602
+
603
## Changes in 0.13.0
604
- Bulk Conversion
605
- Fixed problems with Gd converter and PNG
README.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: rosell.dk
3
Donate link: https://ko-fi.com/rosell
4
Tags: webp, images, performance
5
Requires at least: 4.0
6
- Tested up to: 5.1
7
- Stable tag: 0.13.0
8
Requires PHP: 5.6
9
License: GPLv3
10
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -604,6 +604,18 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
604
605
== Changelog ==
606
607
= 0.13.0 =
608
*(released: 21 mar 2019)*
609
* Bulk Conversion
@@ -751,6 +763,9 @@ For older releases, check out changelog.txt
751
752
== Upgrade Notice ==
753
754
= 0.13.0 =
755
* Bulk Conversion, fixed problem with Gd converter and PNGs and more...
756
3
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.13.1
8
Requires PHP: 5.6
9
License: GPLv3
10
License URI: https://www.gnu.org/licenses/gpl-3.0.html
604
605
== Changelog ==
606
607
+ = 0.13.1 =
608
+ *(released: 10 may 2019)*
609
+ * Fixed critical bug which could result in update failures in the Gutenberg editor. Thanks to Andrei Glingeanu from Moldova for his part in solving this.
610
+ * Fixed bug that caused the Bulk convert to start over. Thanks to Bas van Dijk, presumably from the Netherlands, for finding the root cause.
611
+ * On Nginx (in some configurations), the script that triggered conversion were exiting prematurely. Thanks to Sam Benson from the UK for fixing this.
612
+ * Improved Bulk conversion client, which was slowing down when many images where converted.
613
+ * A class had existential problems on HHVM. Thanks to @jaumerrr for posting the PHP error message.
614
+ * When selecting "custom" in the Cache-Control dropdown, the default text was invalid syntax. Thanks to Kevin Batdorf from Thailand for discovering this.
615
+ * When an image was deleted, the corresponding webp image was not automatically deleted. Thanks to Tobias Keller from Germany for pointing out that this could potentially lead to old webp images being shown.
616
+
617
+ For more info, see the closed issues on the 0.13.1 milestone on the github repository: https://github.com/rosell-dk/webp-express/milestone/17?closed=1
618
+
619
= 0.13.0 =
620
*(released: 21 mar 2019)*
621
* Bulk Conversion
763
764
== Upgrade Notice ==
765
766
+ = 0.13.1 =
767
+ * Fixed several bugs. You should update...
768
+
769
= 0.13.0 =
770
* Bulk Conversion, fixed problem with Gd converter and PNGs and more...
771
lib/classes/AdminInit.php CHANGED
@@ -82,9 +82,9 @@ class AdminInit
82
add_action('wp_ajax_convert_file', array('\WebPExpress\BulkConvert', 'processAjaxConvertFile'));
83
add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
84
85
- // Filters for processing upload hooks (in order to convert images upon upload)
86
- //add_filter('wp_handle_upload', array('\WebPExpress\HandleUploadHooks', 'handleUpload'), 10, 2);
87
- //add_filter('image_make_intermediate_size', array('\WebPExpress\HandleUploadHooks', 'handleMakeIntermediateSize'), 10, 1);
88
89
}
90
}
82
add_action('wp_ajax_convert_file', array('\WebPExpress\BulkConvert', 'processAjaxConvertFile'));
83
add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
84
85
+ // PS:
86
+ // Filters for processing upload hooks in order to convert images upon upload (wp_handle_upload / image_make_intermediate_size)
87
+ // are located in webp-express.php
88
89
}
90
}
lib/classes/AlterHtmlInit.php CHANGED
@@ -13,7 +13,8 @@ class AlterHtmlInit
13
public static function startOutputBuffer()
14
{
15
if (!is_admin() || (function_exists("wp_doing_ajax") && wp_doing_ajax()) || (defined( 'DOING_AJAX' ) && DOING_AJAX)) {
16
- ob_start('self::alterHtml');
17
}
18
}
19
@@ -24,7 +25,12 @@ class AlterHtmlInit
24
return $content;
25
}
26
27
- if (is_admin() ) {
28
return $content;
29
}
30
@@ -53,6 +59,7 @@ class AlterHtmlInit
53
require_once __DIR__ . "/../../vendor/autoload.php";
54
require_once __DIR__ . '/AlterHtmlHelper.php';
55
require_once __DIR__ . '/AlterHtmlImageUrls.php';
56
return \WebPExpress\AlterHtmlImageUrls::replace($content);
57
}
58
}
13
public static function startOutputBuffer()
14
{
15
if (!is_admin() || (function_exists("wp_doing_ajax") && wp_doing_ajax()) || (defined( 'DOING_AJAX' ) && DOING_AJAX)) {
16
+ // note: "self::alterHtml" does for some reason not work on hhvm (#226)
17
+ ob_start('\\WebPExpress\\AlterHtmlInit::alterHtml');
18
}
19
}
20
25
return $content;
26
}
27
28
+ if (is_admin()) {
29
+ return $content;
30
+ }
31
+
32
+ // Exit if it doesn't look like HTML (see #228)
33
+ if (!preg_match("#^\\s*<#", $content)) {
34
return $content;
35
}
36
59
require_once __DIR__ . "/../../vendor/autoload.php";
60
require_once __DIR__ . '/AlterHtmlHelper.php';
61
require_once __DIR__ . '/AlterHtmlImageUrls.php';
62
+
63
return \WebPExpress\AlterHtmlImageUrls::replace($content);
64
}
65
}
lib/classes/BulkConvert.php CHANGED
@@ -4,6 +4,7 @@ namespace WebPExpress;
4
5
use \WebPExpress\ConvertHelperIndependent;
6
use \WebPExpress\Paths;
7
8
class BulkConvert
9
{
@@ -94,6 +95,9 @@ class BulkConvert
94
{
95
$dir = $listOptions['root'] . '/' . $relDir;
96
97
if (!@file_exists($dir) || !@is_dir($dir)) {
98
return [];
99
}
4
5
use \WebPExpress\ConvertHelperIndependent;
6
use \WebPExpress\Paths;
7
+ use \WebPExpress\PathHelper;
8
9
class BulkConvert
10
{
95
{
96
$dir = $listOptions['root'] . '/' . $relDir;
97
98
+ // Canonicalize because dir might contain "/./", which causes file_exists to fail (#222)
99
+ $dir = PathHelper::canonicalize($dir);
100
+
101
if (!@file_exists($dir) || !@is_dir($dir)) {
102
return [];
103
}
lib/classes/Config.php CHANGED
@@ -62,7 +62,7 @@ class Config
62
'destination-folder' => 'separate',
63
'destination-extension' => 'append',
64
'cache-control' => 'no-header', /* can be "no-header", "set" or "custom" */
65
- 'cache-control-custom' => 'public, max-age:86400, stale-while-revalidate=604800, stale-if-error=604800',
66
'cache-control-max-age' => 'one-week',
67
'cache-control-public' => false,
68
62
'destination-folder' => 'separate',
63
'destination-extension' => 'append',
64
'cache-control' => 'no-header', /* can be "no-header", "set" or "custom" */
65
+ 'cache-control-custom' => 'public, max-age=31536000, stale-while-revalidate=604800, stale-if-error=604800',
66
'cache-control-max-age' => 'one-week',
67
'cache-control-public' => false,
68
lib/classes/Convert.php CHANGED
@@ -7,6 +7,7 @@ It is used by webp-on-demand.php, which does not register an auto loader. It is
7
namespace WebPExpress;
8
9
use \WebPExpress\ConvertHelperIndependent;
10
11
class Convert
12
{
7
namespace WebPExpress;
8
9
use \WebPExpress\ConvertHelperIndependent;
10
+ use \WebPExpress\Config;
11
12
class Convert
13
{
lib/classes/HandleDeleteFileHook.php ADDED
@@ -0,0 +1,30 @@
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+ use \WebPExpress\Convert;
5
+ use \WebPExpress\Mime;
6
+
7
+ class HandleDeleteFileHook
8
+ {
9
+
10
+ /**
11
+ * hook: wp_delete_file
12
+ */
13
+ public static function deleteAssociatedWebP($filename)
14
+ {
15
+ $mimeTypes = [
16
+ 'image/jpeg',
17
+ 'image/png',
18
+ ];
19
+ if (!Mime::isOneOfTheseImageMimeTypes($filename, $mimeTypes)) {
20
+ return;
21
+ }
22
+
23
+ $destination = Convert::getDestination($filename);
24
+ error_log('deleting webp:' . $destination);
25
+ if (!unlink($destination)) {
26
+ error_log('failed deleting webp:' . $destination);
27
+ }
28
+
29
+ }
30
+ }
lib/classes/HandleUploadHooks.php CHANGED
@@ -4,39 +4,13 @@ namespace WebPExpress;
4
5
use \WebPExpress\Config;
6
use \WebPExpress\Convert;
7
8
class HandleUploadHooks
9
{
10
11
private static $config;
12
13
-
14
- private static function getMimeTypeOfMedia($filename)
15
- {
16
- // Try the Wordpress function. It tries exif_imagetype and getimagesize and returns false if no methods are available
17
- $mimeType = wp_get_image_mime($filename);
18
- if ($mimeType !== false) {
19
- return $mimeType;
20
- }
21
-
22
- // Try mime_content_type
23
- if (function_exists('mime_content_type')) {
24
- $mimeType = mime_content_type($filename);
25
- if ($mimeType !== false) {
26
- return $mimeType;
27
- }
28
- }
29
-
30
- // Try wordpress method, which simply uses the file extension and a map
31
- $mimeType = wp_check_filetype($filePath)['type'];
32
- if ($mimeType !== false) {
33
- return $mimeType;
34
- }
35
-
36
- // Don't say we didn't try!
37
- return 'unknown';
38
- }
39
-
40
/**
41
* Convert if:
42
* - Option has been enabled
@@ -70,7 +44,7 @@ class HandleUploadHooks
70
$allowedMimeTypes[] = 'image/png';
71
}
72
73
- if (!in_array(self::getMimeTypeOfMedia($filename), $allowedMimeTypes)) {
74
return;
75
}
76
4
5
use \WebPExpress\Config;
6
use \WebPExpress\Convert;
7
+ use \WebPExpress\Mime;
8
9
class HandleUploadHooks
10
{
11
12
private static $config;
13
14
/**
15
* Convert if:
16
* - Option has been enabled
44
$allowedMimeTypes[] = 'image/png';
45
}
46
47
+ if (!in_array(Mime::getMimeTypeOfMedia($filename), $allowedMimeTypes)) {
48
return;
49
}
50
lib/classes/Mime.php ADDED
@@ -0,0 +1,43 @@
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+
5
+ use \WebPExpress\Config;
6
+ use \WebPExpress\Convert;
7
+
8
+ class Mime
9
+ {
10
+
11
+ public static function getMimeTypeOfMedia($filename)
12
+ {
13
+ // Try the Wordpress function. It tries exif_imagetype and getimagesize and returns false if no methods are available
14
+ $mimeType = wp_get_image_mime($filename);
15
+ if ($mimeType !== false) {
16
+ return $mimeType;
17
+ }
18
+
19
+ // Try mime_content_type
20
+ if (function_exists('mime_content_type')) {
21
+ $mimeType = mime_content_type($filename);
22
+ if ($mimeType !== false) {
23
+ return $mimeType;
24
+ }
25
+ }
26
+
27
+ // Try wordpress method, which simply uses the file extension and a map
28
+ $mimeType = wp_check_filetype($filePath)['type'];
29
+ if ($mimeType !== false) {
30
+ return $mimeType;
31
+ }
32
+
33
+ // Don't say we didn't try!
34
+ return 'unknown';
35
+ }
36
+
37
+ public static function isOneOfTheseImageMimeTypes($filename, $imageMimeTypes)
38
+ {
39
+ $detectedMimeType = self::getMimeTypeOfMedia($filename);
40
+ return in_array($detectedMimeType, $imageMimeTypes);
41
+ }
42
+
43
+ }
lib/options/enqueue_scripts.php CHANGED
@@ -6,7 +6,7 @@ use \WebPExpress\Paths;
6
include_once __DIR__ . '/../classes/Config.php';
7
use \WebPExpress\Config;
8
9
- $version = '0.13.0';
10
11
12
if (!function_exists('webp_express_add_inline_script')) {
6
include_once __DIR__ . '/../classes/Config.php';
7
use \WebPExpress\Config;
8
9
+ $version = '0.13.1';
10
11
12
if (!function_exists('webp_express_add_inline_script')) {
lib/options/js/bulk-convert.js CHANGED
@@ -30,10 +30,15 @@ function openBulkConvertPopup() {
30
html += '<p>There are no unconverted files</p>';
31
} else {
32
html += '<div>'
33
- html += '<p>There are ' + numFiles + ' unconverted files.</p><br>';
34
html += '<button onclick="startBulkConversion()" class="button button-primary" type="button">Start conversion</button>';
35
html += '</div>';
36
-
37
}
38
document.getElementById('bulkconvertcontent').innerHTML = html;
39
});
@@ -102,6 +107,19 @@ function getReductionHtml(orgSize, webpSize, sizeOfOriginalText, sizeOfWebpText)
102
'</span><br>';
103
}
104
105
function convertNextInBulkQueue() {
106
var html;
107
var bulkInfo = window.webpexpress_bulkconvert;
@@ -109,9 +127,10 @@ function convertNextInBulkQueue() {
109
110
// Current group might contain 0, - skip if that is the case
111
while ((bulkInfo.groupPointer < bulkInfo.groups.length) && (bulkInfo.filePointer >= bulkInfo.groups[bulkInfo.groupPointer].files.length)) {
112
- html = '<h3>' + bulkInfo.groups[bulkInfo.groupPointer].groupName + '</h3>';
113
- html += '<p>Nothing to convert</p>';
114
- document.getElementById('bulkconvertlog').innerHTML += html;
115
116
bulkInfo.groupPointer++;
117
bulkInfo.filePointer = 0;
@@ -126,13 +145,10 @@ function convertNextInBulkQueue() {
126
var filename = group.files[bulkInfo.filePointer];
127
128
if (bulkInfo.filePointer == 0) {
129
- html = '<h3>' + group.groupName + '</h3>';
130
- //html += '<p>root: ' + group.root + '</p><br>';
131
- document.getElementById('bulkconvertlog').innerHTML += html;
132
}
133
134
- html = 'Converting <i>' + filename + '</i>';
135
- document.getElementById('bulkconvertlog').innerHTML += html;
136
137
var data = {
138
'action': 'convert_file',
@@ -164,8 +180,11 @@ function convertNextInBulkQueue() {
164
bulkInfo['orgTotalFilesize'] += orgSize;
165
bulkInfo['webpTotalFilesize'] += webpSize;
166
167
- html += ' <span style="color:green" class="has-tip">ok<span class="tip">' + result['log'] + '</span></span>' +
168
getReductionHtml(orgSize, webpSize, 'Size of original', 'Size of webp')
169
} else {
170
html += ' <span style="color:red">failed</span><br>';
171
if (result['msg'] != '') {
@@ -175,7 +194,7 @@ function convertNextInBulkQueue() {
175
html += ' <span style="font-size:10px">' + result['log'] + '</span>';
176
}
177
}
178
- document.getElementById('bulkconvertlog').innerHTML += html;
179
180
181
// Get next
30
html += '<p>There are no unconverted files</p>';
31
} else {
32
html += '<div>'
33
+ html += '<p>There are ' + numFiles + ' unconverted files.</p>';
34
+ html += '<p><i>Note that in a typical setup, you will have redirect rules which triggers conversion when needed, ' +
35
+ 'and thus you have no need for bulk conversion. In fact, in that case, you should probably not bulk convert ' +
36
+ 'because bulk conversion will also convert images and thumbnails which are not in use, and thus take up ' +
37
+ 'more disk space than neccessary. The bulk conversion feature was only added in order to make the plugin usable even when ' +
38
+ 'there is problems with redirects (ie on Nginx in case you do not have access to the config or on Microsoft IIS). ' +
39
+ '</i></p><br>';
40
html += '<button onclick="startBulkConversion()" class="button button-primary" type="button">Start conversion</button>';
41
html += '</div>';
42
}
43
document.getElementById('bulkconvertcontent').innerHTML = html;
44
});
107
'</span><br>';
108
}
109
110
+ function logLn() {
111
+ var html = '';
112
+ for (i = 0; i < arguments.length; i++) {
113
+ html += arguments[i];
114
+ }
115
+ var spanEl = document.createElement('span');
116
+ spanEl.innerHTML = html;
117
+
118
+ document.getElementById('bulkconvertlog').appendChild(spanEl);
119
+
120
+ //document.getElementById('bulkconvertlog').innerHTML += html;
121
+ }
122
+
123
function convertNextInBulkQueue() {
124
var html;
125
var bulkInfo = window.webpexpress_bulkconvert;
127
128
// Current group might contain 0, - skip if that is the case
129
while ((bulkInfo.groupPointer < bulkInfo.groups.length) && (bulkInfo.filePointer >= bulkInfo.groups[bulkInfo.groupPointer].files.length)) {
130
+ logLn(
131
+ '<h3>' + bulkInfo.groups[bulkInfo.groupPointer].groupName + '</h3>',
132
+ '<p>Nothing to convert</p>'
133
+ );
134
135
bulkInfo.groupPointer++;
136
bulkInfo.filePointer = 0;
145
var filename = group.files[bulkInfo.filePointer];
146
147
if (bulkInfo.filePointer == 0) {
148
+ logLn('<h3>' + group.groupName + '</h3>');
149
}
150
151
+ logLn('Converting <i>' + filename + '</i>');
152
153
var data = {
154
'action': 'convert_file',
180
bulkInfo['orgTotalFilesize'] += orgSize;
181
bulkInfo['webpTotalFilesize'] += webpSize;
182
183
+ html += ' <span style="color:green">ok</span></span>' +
184
getReductionHtml(orgSize, webpSize, 'Size of original', 'Size of webp')
185
+
186
+ //html += ' <span style="color:green" class="has-tip">ok<span class="tip">' + result['log'] + '</span></span>' +
187
+ // getReductionHtml(orgSize, webpSize, 'Size of original', 'Size of webp')
188
} else {
189
html += ' <span style="color:red">failed</span><br>';
190
if (result['msg'] != '') {
194
html += ' <span style="font-size:10px">' + result['log'] + '</span>';
195
}
196
}
197
+ logLn(html);
198
199
200
// Get next
lib/options/options/alter-html/alter-html-options.inc CHANGED
@@ -59,22 +59,26 @@
59
<td>Works great with page caching, because all browsers are served the same HTML</td>
60
<td>
61
<p>
62
- As the HTML varies with the webp-capability of the browser, page caching is tricky.
63
- However, it can be achieved with the wonderful <i>Cache Enabler</i> plugin, which maintains two cached versions of each page.<br><br>
64
<span style="font-size:10px">
65
Note: <i>Cache Enabler</i> also has HTML altering, but their implementation has <a target="_blank" href="https://github.com/keycdn/cache-enabler/issues/51">limitations</a>.
66
It for example doesn't replace background images in inline styles and it does not look for all common lazy load attributes. It also has some problems in edge cases.
67
For this reason, I recommend activating HTML altering in WebP Express, even when <i>Cache Enabler</i> is used.
68
By doing that, both plugins will have a go at it (WebP Express comes first).
69
At least it will take care of the limitations in <i>Cache Enabler</i>.
70
- It does however not cure the edge cases where Cache Enabler replaces things it should not.
71
</span>
72
</p>
73
</td>
74
</tr>
75
<tr>
76
<th><nobr>Styling and javascript</nobr></th>
77
- <td>May break because of changed HTML structure</td>
78
<td>No problems</td>
79
</tr>
80
<tr>
@@ -100,7 +104,10 @@
100
'<p>"Picture tag" replaces &lt;img&gt tags with &lt;picture&gt; tags and adds the webp as an extra source. ' .
101
'This effectively points webp-enabled browsers to the webp variant and other browsers to ' .
102
'the original image.</p>' .
103
- '<p><em>Beware that this structural change may affect styling!</em></p>' .
104
'<p>PS: This functionality is handled by ' .
105
'<a target="_blank" href="https://github.com/rosell-dk/dom-util-for-webp">this external library</a>' .
106
' (I have pushed the code to an external library so it can be used by other projects besides this plugin)</p>'
@@ -130,6 +137,7 @@
130
'<p>"Image URLs" replaces the image URLs to point to ' .
131
'the webp <i>rather than</i> the original. Handles src, srcset, common lazy-load attributes and even ' .
132
'inline styles</p>' .
133
'<p>Note that you will have to do something for the browsers that does not support webp. ' .
134
'And that something is in most cases to enable the <i>Only do the replacements in webp enabled browsers</i> option, which ' .
135
'will show up when you enable this option. ' .
59
<td>Works great with page caching, because all browsers are served the same HTML</td>
60
<td>
61
<p>
62
+ <b>Does not work with page caching</b> &ndash; <i>unless</i> you are using the <i>Cache Enabler</i> plugin,
63
+ which is able to maintain two cached versions of each page.<br><br>
64
<span style="font-size:10px">
65
Note: <i>Cache Enabler</i> also has HTML altering, but their implementation has <a target="_blank" href="https://github.com/keycdn/cache-enabler/issues/51">limitations</a>.
66
It for example doesn't replace background images in inline styles and it does not look for all common lazy load attributes. It also has some problems in edge cases.
67
For this reason, I recommend activating HTML altering in WebP Express, even when <i>Cache Enabler</i> is used.
68
By doing that, both plugins will have a go at it (WebP Express comes first).
69
At least it will take care of the limitations in <i>Cache Enabler</i>.
70
+ It does however not cure the edge cases where Cache Enabler replaces things it should not, or <a href="https://wordpress.org/support/topic/why-optimus-with-cache-enabler/">crashes</a>
71
</span>
72
</p>
73
</td>
74
</tr>
75
<tr>
76
<th><nobr>Styling and javascript</nobr></th>
77
+ <td>May break because of changed HTML structure.
78
+ A selector such as "div > img" will no longer match the image because the immidiate parent is now "picture".
79
+ However, a selector such as "div img" will still work.
80
+ Luckily, the picture element is not meant to be styled - one still has to target the contained img element.
81
+ </td>
82
<td>No problems</td>
83
</tr>
84
<tr>
104
'<p>"Picture tag" replaces &lt;img&gt tags with &lt;picture&gt; tags and adds the webp as an extra source. ' .
105
'This effectively points webp-enabled browsers to the webp variant and other browsers to ' .
106
'the original image.</p>' .
107
+ '<p><em>Beware that this structural change may break styling!</em><br>' .
108
+ '(a selector such as "div > img" will no longer match the image because the immidiate parent is now "picture". However, ' .
109
+ 'a selector such as "div img" will still work)' .
110
+ '</p>' .
111
'<p>PS: This functionality is handled by ' .
112
'<a target="_blank" href="https://github.com/rosell-dk/dom-util-for-webp">this external library</a>' .
113
' (I have pushed the code to an external library so it can be used by other projects besides this plugin)</p>'
137
'<p>"Image URLs" replaces the image URLs to point to ' .
138
'the webp <i>rather than</i> the original. Handles src, srcset, common lazy-load attributes and even ' .
139
'inline styles</p>' .
140
+ '<p><b>Does not work with page caching</b> &ndash; <i>unless</i> you are using the <i>Cache Enabler</i> plugin</p>' .
141
'<p>Note that you will have to do something for the browsers that does not support webp. ' .
142
'And that something is in most cases to enable the <i>Only do the replacements in webp enabled browsers</i> option, which ' .
143
'will show up when you enable this option. ' .
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.13.0
7
* Author: Bjørn Rosell
8
* Author URI: https://www.bitwise-it.dk
9
* License: GPL2
@@ -64,6 +64,7 @@ add_action('all', function() {
64
// When images are uploaded with Gutenberg, is_admin() returns false, so, hook needs to be added here
65
add_filter('wp_handle_upload', array('\WebPExpress\HandleUploadHooks', 'handleUpload'), 10, 2);
66
add_filter('image_make_intermediate_size', array('\WebPExpress\HandleUploadHooks', 'handleMakeIntermediateSize'), 10, 1);
67
68
/*
69
add_action('wp_handle_upload', function($a) {
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.13.1
7
* Author: Bjørn Rosell
8
* Author URI: https://www.bitwise-it.dk
9
* License: GPL2
64
// When images are uploaded with Gutenberg, is_admin() returns false, so, hook needs to be added here
65
add_filter('wp_handle_upload', array('\WebPExpress\HandleUploadHooks', 'handleUpload'), 10, 2);
66
add_filter('image_make_intermediate_size', array('\WebPExpress\HandleUploadHooks', 'handleMakeIntermediateSize'), 10, 1);
67
+ add_filter('wp_delete_file', array('\WebPExpress\HandleDeleteFileHook', 'deleteAssociatedWebP'), 10, 2);
68
69
/*
70
add_action('wp_handle_upload', function($a) {
wod/webp-on-demand.php CHANGED
@@ -29,7 +29,7 @@ function exitWithError($msg) {
29
30
// Protect against directly accessing webp-on-demand.php
31
// Only protect on Apache. We know for sure that the method is not reliable on nginx. We have not tested on litespeed yet, so we dare not.
32
- if (stripos($_SERVER["SERVER_SOFTWARE"], 'apache') !== false) {
33
if (strpos($_SERVER['REQUEST_URI'], 'webp-on-demand.php') !== false) {
34
exitWithError('It seems you are visiting this file (plugins/webp-express/wod/webp-on-demand.php) directly. We do not allow this.');
35
exit;
29
30
// Protect against directly accessing webp-on-demand.php
31
// Only protect on Apache. We know for sure that the method is not reliable on nginx. We have not tested on litespeed yet, so we dare not.
32
+ if (stripos($_SERVER["SERVER_SOFTWARE"], 'apache') !== false && stripos($_SERVER["SERVER_SOFTWARE"], 'nginx') === false) {
33
if (strpos($_SERVER['REQUEST_URI'], 'webp-on-demand.php') !== false) {
34
exitWithError('It seems you are visiting this file (plugins/webp-express/wod/webp-on-demand.php) directly. We do not allow this.');
35
exit;
wod/webp-realizer.php CHANGED
@@ -24,7 +24,7 @@ function exitWithError($msg) {
24
25
// Protect against directly accessing webp-on-demand.php
26
// Only protect on Apache. We know for sure that the method is not reliable on nginx. We have not tested on litespeed yet, so we dare not.
27
- if (stripos($_SERVER["SERVER_SOFTWARE"], 'apache') !== false) {
28
if (strpos($_SERVER['REQUEST_URI'], 'webp-realizer.php') !== false) {
29
exitWithError('It seems you are visiting this file (plugins/webp-express/wod/webp-realizer.php) directly. We do not allow this.');
30
exit;
24
25
// Protect against directly accessing webp-on-demand.php
26
// Only protect on Apache. We know for sure that the method is not reliable on nginx. We have not tested on litespeed yet, so we dare not.
27
+ if (stripos($_SERVER["SERVER_SOFTWARE"], 'apache') !== false && stripos($_SERVER["SERVER_SOFTWARE"], 'nginx') === false) {
28
if (strpos($_SERVER['REQUEST_URI'], 'webp-realizer.php') !== false) {
29
exitWithError('It seems you are visiting this file (plugins/webp-express/wod/webp-realizer.php) directly. We do not allow this.');
30
exit;