Version Description
(2020-04-15) =
* [Added]
Blocking server cache for rewrite rules
* [Added]
Detecting whether requests to images are processed by server bypassing Apache
Download this release
Release Info
Developer | mateuszgbiorczyk |
Plugin | Converter for Media – Optimize images | Convert WebP & AVIF |
Version | 1.2.3 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.2.3
- app/Media/Htaccess.php +1 -1
- app/Settings/Errors.php +25 -10
- public/img/.htaccess +6 -0
- public/img/icon-after.png +0 -0
- public/img/icon-after.png2 +0 -0
- public/img/icon-before.png +0 -0
- public/img/icon-before.png2 +0 -0
- readme.txt +11 -7
- resources/components/widgets/errors.php +11 -0
- webp-converter-for-media.php +2 -2
app/Media/Htaccess.php
CHANGED
@@ -58,7 +58,7 @@
|
|
58 |
foreach ($settings['extensions'] as $ext) {
|
59 |
$content .= ' RewriteCond %{HTTP_ACCEPT} image/webp' . PHP_EOL;
|
60 |
$content .= " RewriteCond %{DOCUMENT_ROOT}${path}/$1.${ext}.webp -f" . PHP_EOL;
|
61 |
-
$content .= " RewriteRule (.+)\.${ext}$ ${path}/$1.${ext}.webp [T=image/webp]" . PHP_EOL;
|
62 |
}
|
63 |
$content .= '</IfModule>';
|
64 |
|
58 |
foreach ($settings['extensions'] as $ext) {
|
59 |
$content .= ' RewriteCond %{HTTP_ACCEPT} image/webp' . PHP_EOL;
|
60 |
$content .= " RewriteCond %{DOCUMENT_ROOT}${path}/$1.${ext}.webp -f" . PHP_EOL;
|
61 |
+
$content .= " RewriteRule (.+)\.${ext}$ ${path}/$1.${ext}.webp [NC,T=image/webp,E=cache-control:private,L]" . PHP_EOL;
|
62 |
}
|
63 |
$content .= '</IfModule>';
|
64 |
|
app/Settings/Errors.php
CHANGED
@@ -4,6 +4,8 @@
|
|
4 |
|
5 |
class Errors
|
6 |
{
|
|
|
|
|
7 |
public function __construct()
|
8 |
{
|
9 |
add_filter('webpc_server_errors', [$this, 'getServerErrors']);
|
@@ -15,15 +17,20 @@
|
|
15 |
|
16 |
public function getServerErrors()
|
17 |
{
|
|
|
|
|
18 |
$list = [
|
19 |
-
'path_uploads'
|
20 |
-
'path_htaccess'
|
21 |
-
'path_webp'
|
22 |
-
'path_duplicated'
|
23 |
-
'rest_api'
|
24 |
-
'methods'
|
|
|
25 |
];
|
26 |
-
|
|
|
|
|
27 |
}
|
28 |
|
29 |
private function ifUploadsPathExists()
|
@@ -32,7 +39,7 @@
|
|
32 |
return (is_dir($path) && ($path !== ABSPATH));
|
33 |
}
|
34 |
|
35 |
-
private function
|
36 |
{
|
37 |
$pathDir = apply_filters('webpc_uploads_path', '');
|
38 |
$pathFile = $pathDir . '/.htaccess';
|
@@ -53,17 +60,25 @@
|
|
53 |
return ($pathUploads !== $pathWebp);
|
54 |
}
|
55 |
|
56 |
-
private function
|
57 |
{
|
58 |
return ((apply_filters('rest_enabled', true) === true)
|
59 |
&& (apply_filters('rest_jsonp_enabled', true) === true)
|
60 |
&& (apply_filters('rest_authentication_errors', true) === true));
|
61 |
}
|
62 |
|
63 |
-
private function
|
64 |
{
|
65 |
$config = apply_filters('webpc_get_values', []);
|
66 |
$methods = apply_filters('webpc_get_methods', []);
|
67 |
return (isset($config['method']) && in_array($config['method'], $methods));
|
68 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
}
|
4 |
|
5 |
class Errors
|
6 |
{
|
7 |
+
private $list = null;
|
8 |
+
|
9 |
public function __construct()
|
10 |
{
|
11 |
add_filter('webpc_server_errors', [$this, 'getServerErrors']);
|
17 |
|
18 |
public function getServerErrors()
|
19 |
{
|
20 |
+
if ($this->list !== null) return $this->list;
|
21 |
+
|
22 |
$list = [
|
23 |
+
'path_uploads' => ($this->ifUploadsPathExists() !== true),
|
24 |
+
'path_htaccess' => ($this->ifHtaccessIsWriteable() !== true),
|
25 |
+
'path_webp' => ($this->ifWebpPathExists() !== true),
|
26 |
+
'path_duplicated' => ($this->ifPathsAreDifferent() !== true),
|
27 |
+
'rest_api' => ($this->ifRestApiIsEnabled() !== true),
|
28 |
+
'methods' => ($this->ifMethodsAreAvailable() !== true),
|
29 |
+
'bypassing_apache' => ($this->ifBypassingApacheIsActive() !== true),
|
30 |
];
|
31 |
+
|
32 |
+
$this->list = array_keys(array_filter($list));
|
33 |
+
return $this->list;
|
34 |
}
|
35 |
|
36 |
private function ifUploadsPathExists()
|
39 |
return (is_dir($path) && ($path !== ABSPATH));
|
40 |
}
|
41 |
|
42 |
+
private function ifHtaccessIsWriteable()
|
43 |
{
|
44 |
$pathDir = apply_filters('webpc_uploads_path', '');
|
45 |
$pathFile = $pathDir . '/.htaccess';
|
60 |
return ($pathUploads !== $pathWebp);
|
61 |
}
|
62 |
|
63 |
+
private function ifRestApiIsEnabled()
|
64 |
{
|
65 |
return ((apply_filters('rest_enabled', true) === true)
|
66 |
&& (apply_filters('rest_jsonp_enabled', true) === true)
|
67 |
&& (apply_filters('rest_authentication_errors', true) === true));
|
68 |
}
|
69 |
|
70 |
+
private function ifMethodsAreAvailable()
|
71 |
{
|
72 |
$config = apply_filters('webpc_get_values', []);
|
73 |
$methods = apply_filters('webpc_get_methods', []);
|
74 |
return (isset($config['method']) && in_array($config['method'], $methods));
|
75 |
}
|
76 |
+
|
77 |
+
private function ifBypassingApacheIsActive()
|
78 |
+
{
|
79 |
+
$pngUrl = WEBPC_URL . 'public/img/icon-before.png';
|
80 |
+
$png2Url = WEBPC_URL . 'public/img/icon-before.png2';
|
81 |
+
|
82 |
+
return (strlen(file_get_contents($pngUrl)) >= strlen(file_get_contents($png2Url)));
|
83 |
+
}
|
84 |
}
|
public/img/.htaccess
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# BEGIN WebP Converter
|
2 |
+
<IfModule mod_rewrite.c>
|
3 |
+
RewriteEngine On
|
4 |
+
RewriteRule icon-before\.(.+)$ ./icon-after.$1 [NC,E=cache-control:private,L]
|
5 |
+
</IfModule>
|
6 |
+
# END WebP Converter
|
public/img/icon-after.png
ADDED
Binary file
|
public/img/icon-after.png2
ADDED
Binary file
|
public/img/icon-before.png
ADDED
Binary file
|
public/img/icon-before.png2
ADDED
Binary file
|
readme.txt
CHANGED
@@ -102,7 +102,7 @@ Then follow these steps:
|
|
102 |
|
103 |
Send a screenshot from console if an error occurred while converting images. Of you have errors in `/wp-content/debug.log` send their?
|
104 |
|
105 |
-
**6.** Content of your `.htaccess` files from directories `/wp-content/uploads` and `/wp-content/uploads-
|
106 |
|
107 |
**7.** What plugin version are you using? If it is not the latest then update and check everything again. Please also provide the version of WordPress and the list of plugins you use.
|
108 |
|
@@ -281,7 +281,7 @@ Rules for Browser Caching: *(returns rules for `mod_expires` module)*:
|
|
281 |
return '';
|
282 |
});`
|
283 |
|
284 |
-
All rules from the files `/uploads/.htaccess` and `/uploads-
|
285 |
|
286 |
`add_filter('webpc_htaccess_rules', function($rules, $path) {
|
287 |
return '';
|
@@ -352,18 +352,18 @@ Please manually paste the following code **at the beginning of .htaccess file**
|
|
352 |
RewriteEngine On
|
353 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
354 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
|
355 |
-
RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [T=image/webp]
|
356 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
357 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
|
358 |
-
RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [T=image/webp]
|
359 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
360 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
|
361 |
-
RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [T=image/webp]
|
362 |
</IfModule>`
|
363 |
`# ! --- DO NOT EDIT NEXT LINE --- !`
|
364 |
`# END WebP Converter`
|
365 |
|
366 |
-
And the following code **at the beginning of .htaccess file** in the `/wp-content/uploads-
|
367 |
|
368 |
`# BEGIN WebP Converter`
|
369 |
`# ! --- DO NOT EDIT PREVIOUS LINE --- !`
|
@@ -396,8 +396,12 @@ This is all very important to us and allows us to do even better things for you!
|
|
396 |
|
397 |
== Changelog ==
|
398 |
|
|
|
|
|
|
|
|
|
399 |
= 1.2.2 (2020-04-08) =
|
400 |
-
* `[Changed]` Moving rules for modules `mod_mime` and `mod_expires` to `/uploads-
|
401 |
* `[Changed]` New argument for filter `webpc_htaccess_rules` with server path of file
|
402 |
|
403 |
= 1.2.1 (2020-04-07) =
|
102 |
|
103 |
Send a screenshot from console if an error occurred while converting images. Of you have errors in `/wp-content/debug.log` send their?
|
104 |
|
105 |
+
**6.** Content of your `.htaccess` files from directories `/wp-content/uploads` and `/wp-content/uploads-webpc` *(pasting the code using the `CODE` shortcode in the editor)*.
|
106 |
|
107 |
**7.** What plugin version are you using? If it is not the latest then update and check everything again. Please also provide the version of WordPress and the list of plugins you use.
|
108 |
|
281 |
return '';
|
282 |
});`
|
283 |
|
284 |
+
All rules from the files `/uploads/.htaccess` and `/uploads-webpc/.htaccess`: *(returns rules for modules: `mod_rewrite`, `mod_mime` and `mod_expires`)*:
|
285 |
|
286 |
`add_filter('webpc_htaccess_rules', function($rules, $path) {
|
287 |
return '';
|
352 |
RewriteEngine On
|
353 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
354 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
|
355 |
+
RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,E=cache-control:private,L]
|
356 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
357 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
|
358 |
+
RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,E=cache-control:private,Lp]
|
359 |
RewriteCond %{HTTP_ACCEPT} image/webp
|
360 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
|
361 |
+
RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,E=cache-control:private,L]
|
362 |
</IfModule>`
|
363 |
`# ! --- DO NOT EDIT NEXT LINE --- !`
|
364 |
`# END WebP Converter`
|
365 |
|
366 |
+
And the following code **at the beginning of .htaccess file** in the `/wp-content/uploads-webpc` directory:
|
367 |
|
368 |
`# BEGIN WebP Converter`
|
369 |
`# ! --- DO NOT EDIT PREVIOUS LINE --- !`
|
396 |
|
397 |
== Changelog ==
|
398 |
|
399 |
+
= 1.2.3 (2020-04-15) =
|
400 |
+
* `[Added]` Blocking server cache for rewrite rules
|
401 |
+
* `[Added]` Detecting whether requests to images are processed by server bypassing Apache
|
402 |
+
|
403 |
= 1.2.2 (2020-04-08) =
|
404 |
+
* `[Changed]` Moving rules for modules `mod_mime` and `mod_expires` to `/uploads-webpc/.htaccess` file
|
405 |
* `[Changed]` New argument for filter `webpc_htaccess_rules` with server path of file
|
406 |
|
407 |
= 1.2.1 (2020-04-07) =
|
resources/components/widgets/errors.php
CHANGED
@@ -57,6 +57,17 @@
|
|
57 |
); ?>
|
58 |
</p>
|
59 |
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
</div>
|
61 |
</div>
|
62 |
<?php endif; ?>
|
57 |
); ?>
|
58 |
</p>
|
59 |
<?php endif; ?>
|
60 |
+
<?php if (in_array('bypassing_apache', $errors)) : ?>
|
61 |
+
<p>
|
62 |
+
<?= sprintf(
|
63 |
+
__('Requests to images are processed by your server bypassing Apache. When loading images, rules from the .htaccess file are not executed. Check the redirects for %s.png file%s (for which the redirection does not work) and for %s.png2 file%s (for which the redirection works correctly). Please contact your server administrator.', 'webp-converter'),
|
64 |
+
'<a href="' . WEBPC_URL . 'public/img/icon-before.png" target="_blank">',
|
65 |
+
'</a>',
|
66 |
+
'<a href="' . WEBPC_URL . 'public/img/icon-before.png2" target="_blank">',
|
67 |
+
'</a>'
|
68 |
+
); ?>
|
69 |
+
</p>
|
70 |
+
<?php endif; ?>
|
71 |
</div>
|
72 |
</div>
|
73 |
<?php endif; ?>
|
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.2.
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter
|
10 |
*/
|
11 |
|
12 |
-
define('WEBPC_VERSION', '1.2.
|
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.2.3
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter
|
10 |
*/
|
11 |
|
12 |
+
define('WEBPC_VERSION', '1.2.3');
|
13 |
define('WEBPC_FILE', __FILE__);
|
14 |
define('WEBPC_NAME', plugin_basename(__FILE__));
|
15 |
define('WEBPC_PATH', plugin_dir_path(__FILE__));
|