Version Description
(2020-08-24) =
* [Fixed]
Cache-Control for redirects of images to WebP files
* [Added]
Error detection of cached redirects of images to WebP files
Download this release
Release Info
Developer | mateuszgbiorczyk |
Plugin | Converter for Media – Optimize images | Convert WebP & AVIF |
Version | 1.4.2 |
Comparing to | |
See all releases |
Code changes from version 1.4.1 to 1.4.2
- app/Media/Htaccess.php +1 -1
- app/Settings/Errors.php +24 -10
- readme.txt +7 -3
- resources/components/errors/rewrites-cached.php +3 -0
- webp-converter-for-media.php +2 -2
app/Media/Htaccess.php
CHANGED
@@ -80,7 +80,7 @@
|
|
80 |
if (!in_array('referer_disabled', $settings['features'])) {
|
81 |
$content .= " RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} ^([^@]*)@@https?://\\1/.*" . PHP_EOL;
|
82 |
}
|
83 |
-
$content .= " RewriteRule (.+)\.${ext}$ ${path}/$1.${ext}.webp [NC,T=image/webp,E=cache-control:
|
84 |
}
|
85 |
$content .= '</IfModule>';
|
86 |
|
80 |
if (!in_array('referer_disabled', $settings['features'])) {
|
81 |
$content .= " RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} ^([^@]*)@@https?://\\1/.*" . PHP_EOL;
|
82 |
}
|
83 |
+
$content .= " RewriteRule (.+)\.${ext}$ ${path}/$1.${ext}.webp [NC,T=image/webp,E=cache-control:no-cache,L]" . PHP_EOL;
|
84 |
}
|
85 |
$content .= '</IfModule>';
|
86 |
|
app/Settings/Errors.php
CHANGED
@@ -74,8 +74,10 @@
|
|
74 |
if ($this->ifBypassingApacheIsActive() === true) {
|
75 |
$errors[] = 'bypassing_apache';
|
76 |
} else {
|
77 |
-
$errors[] = '
|
78 |
}
|
|
|
|
|
79 |
}
|
80 |
|
81 |
return $errors;
|
@@ -143,27 +145,28 @@
|
|
143 |
WEBPC_PATH . 'public/img/icon-test.png',
|
144 |
], true));
|
145 |
|
146 |
-
$
|
147 |
-
$fileWebp
|
148 |
'Accept: image/webp',
|
149 |
'Referer: ' . WEBPC_URL,
|
150 |
]);
|
151 |
|
152 |
-
return (
|
153 |
}
|
154 |
|
155 |
-
private function
|
156 |
{
|
157 |
$ch = curl_init($url);
|
158 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
159 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
160 |
-
curl_setopt($ch,
|
|
|
161 |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
162 |
$response = curl_exec($ch);
|
163 |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
164 |
curl_close($ch);
|
165 |
|
166 |
-
return ($code === 200) ? $response :
|
167 |
}
|
168 |
|
169 |
private function ifBypassingApacheIsActive()
|
@@ -176,11 +179,11 @@
|
|
176 |
WEBPC_PATH . 'public/img/icon-test.png2',
|
177 |
], true));
|
178 |
|
179 |
-
$filePng = $this->
|
180 |
'Accept: image/webp',
|
181 |
'Referer: ' . WEBPC_URL,
|
182 |
]);
|
183 |
-
$filePng2 = $this->
|
184 |
'Accept: image/webp',
|
185 |
'Referer: ' . WEBPC_URL,
|
186 |
]);
|
@@ -189,7 +192,7 @@
|
|
189 |
remove_filter('webpc_gd_create_methods', [$this, 'addMethodForCustomExtension']);
|
190 |
do_action(Htaccess::ACTION_NAME, true);
|
191 |
|
192 |
-
return (
|
193 |
}
|
194 |
|
195 |
public function addCustomExtension($settings)
|
@@ -203,4 +206,15 @@
|
|
203 |
$methods['imagecreatefrompng'][] = 'png2';
|
204 |
return $methods;
|
205 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
}
|
74 |
if ($this->ifBypassingApacheIsActive() === true) {
|
75 |
$errors[] = 'bypassing_apache';
|
76 |
} else {
|
77 |
+
$errors[] = 'rewrites_not_working';
|
78 |
}
|
79 |
+
} else if ($this->ifRedirectsAreCached() === true) {
|
80 |
+
$errors[] = 'rewrites_cached';
|
81 |
}
|
82 |
|
83 |
return $errors;
|
145 |
WEBPC_PATH . 'public/img/icon-test.png',
|
146 |
], true));
|
147 |
|
148 |
+
$fileSize = filesize(WEBPC_PATH . 'public/img/icon-test.png');
|
149 |
+
$fileWebp = $this->getFileSizeByUrl(WEBPC_URL . 'public/img/icon-test.png', [
|
150 |
'Accept: image/webp',
|
151 |
'Referer: ' . WEBPC_URL,
|
152 |
]);
|
153 |
|
154 |
+
return ($fileWebp < $fileSize);
|
155 |
}
|
156 |
|
157 |
+
private function getFileSizeByUrl($url, $headers = [])
|
158 |
{
|
159 |
$ch = curl_init($url);
|
160 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
161 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
162 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
163 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
164 |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
165 |
$response = curl_exec($ch);
|
166 |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
167 |
curl_close($ch);
|
168 |
|
169 |
+
return ($code === 200) ? strlen($response) : 0;
|
170 |
}
|
171 |
|
172 |
private function ifBypassingApacheIsActive()
|
179 |
WEBPC_PATH . 'public/img/icon-test.png2',
|
180 |
], true));
|
181 |
|
182 |
+
$filePng = $this->getFileSizeByUrl(WEBPC_URL . 'public/img/icon-test.png', [
|
183 |
'Accept: image/webp',
|
184 |
'Referer: ' . WEBPC_URL,
|
185 |
]);
|
186 |
+
$filePng2 = $this->getFileSizeByUrl(WEBPC_URL . 'public/img/icon-test.png2', [
|
187 |
'Accept: image/webp',
|
188 |
'Referer: ' . WEBPC_URL,
|
189 |
]);
|
192 |
remove_filter('webpc_gd_create_methods', [$this, 'addMethodForCustomExtension']);
|
193 |
do_action(Htaccess::ACTION_NAME, true);
|
194 |
|
195 |
+
return ($filePng > $filePng2);
|
196 |
}
|
197 |
|
198 |
public function addCustomExtension($settings)
|
206 |
$methods['imagecreatefrompng'][] = 'png2';
|
207 |
return $methods;
|
208 |
}
|
209 |
+
|
210 |
+
private function ifRedirectsAreCached()
|
211 |
+
{
|
212 |
+
$fileWebp = $this->getFileSizeByUrl(WEBPC_URL . 'public/img/icon-test.png', [
|
213 |
+
'Accept: image/webp',
|
214 |
+
'Referer: ' . WEBPC_URL,
|
215 |
+
]);
|
216 |
+
$fileOriginal = $this->getFileSizeByUrl(WEBPC_URL . 'public/img/icon-test.png');
|
217 |
+
|
218 |
+
return (($fileWebp > 0) && ($fileWebp === $fileOriginal));
|
219 |
+
}
|
220 |
}
|
readme.txt
CHANGED
@@ -441,13 +441,13 @@ Please manually paste the following code **at the beginning of .htaccess file**
|
|
441 |
RewriteEngine On
|
442 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
443 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
|
444 |
-
RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,E=cache-control:
|
445 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
446 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
|
447 |
-
RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,E=cache-control:
|
448 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
449 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
|
450 |
-
RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,E=cache-control:
|
451 |
</IfModule>`
|
452 |
`# ! --- DO NOT EDIT NEXT LINE --- !`
|
453 |
`# END WebP Converter`
|
@@ -485,6 +485,10 @@ This is all very important to us and allows us to do even better things for you!
|
|
485 |
|
486 |
== Changelog ==
|
487 |
|
|
|
|
|
|
|
|
|
488 |
= 1.4.1 (2020-08-19) =
|
489 |
* `[Changed]` Error detection method on plugin settings page
|
490 |
* `[Added]` Error detection of non-working redirects of images to WebP files
|
441 |
RewriteEngine On
|
442 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
443 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
|
444 |
+
RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,E=cache-control:no-cache,L]
|
445 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
446 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
|
447 |
+
RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,E=cache-control:no-cache,L]
|
448 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
449 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
|
450 |
+
RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,E=cache-control:no-cache,L]
|
451 |
</IfModule>`
|
452 |
`# ! --- DO NOT EDIT NEXT LINE --- !`
|
453 |
`# END WebP Converter`
|
485 |
|
486 |
== Changelog ==
|
487 |
|
488 |
+
= 1.4.2 (2020-08-24) =
|
489 |
+
* `[Fixed]` Cache-Control for redirects of images to WebP files
|
490 |
+
* `[Added]` Error detection of cached redirects of images to WebP files
|
491 |
+
|
492 |
= 1.4.1 (2020-08-19) =
|
493 |
* `[Changed]` Error detection method on plugin settings page
|
494 |
* `[Added]` Error detection of non-working redirects of images to WebP files
|
resources/components/errors/rewrites-cached.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<p>
|
2 |
+
<?= __('Your server uses the cache for redirects. The rules from .htaccess file or from Nginx configuration are not executed every time when the image is loaded, but the last redirect from cache is performed. With each request to image, your server should execute the rules from .htaccess file or from Nginx configuration. Now it only does this the first time and then uses cache. This means that if your server redirected image to WebP format the first time, it does so on every request. It should check the rules from .htaccess file or from Nginx configuration each time during request to image and redirect only when the conditions are met. Disable server cache for redirects. Please contact your server administrator.', 'webp-converter-for-media'); ?>
|
3 |
+
</p>
|
webp-converter-for-media.php
CHANGED
@@ -3,13 +3,13 @@
|
|
3 |
/*
|
4 |
Plugin Name: WebP Converter for Media
|
5 |
Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
|
6 |
-
Version: 1.4.
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter-for-media
|
10 |
*/
|
11 |
|
12 |
-
define('WEBPC_VERSION', '1.4.
|
13 |
define('WEBPC_FILE', __FILE__);
|
14 |
define('WEBPC_NAME', plugin_basename(__FILE__));
|
15 |
define('WEBPC_PATH', plugin_dir_path(__FILE__));
|
3 |
/*
|
4 |
Plugin Name: WebP Converter for Media
|
5 |
Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
|
6 |
+
Version: 1.4.2
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter-for-media
|
10 |
*/
|
11 |
|
12 |
+
define('WEBPC_VERSION', '1.4.2');
|
13 |
define('WEBPC_FILE', __FILE__);
|
14 |
define('WEBPC_NAME', plugin_basename(__FILE__));
|
15 |
define('WEBPC_PATH', plugin_dir_path(__FILE__));
|