Converter for Media – Optimize images | Convert WebP & AVIF - Version 1.2.4

Version Description

(2020-04-24) = * [Changed] Error messages in administration panel * [Added] Action webpc_delete_paths to delete images by paths

Download this release

Release Info

Developer mateuszgbiorczyk
Plugin Icon 128x128 Converter for Media – Optimize images | Convert WebP & AVIF
Version 1.2.4
Comparing to
See all releases

Code changes from version 1.2.3 to 1.2.4

app/{Media → Action}/Convert.php RENAMED
@@ -1,8 +1,9 @@
1
  <?php
2
 
3
- namespace WebpConverter\Media;
4
 
5
  use WebpConverter\Convert as ConvertMethod;
 
6
 
7
  class Convert
8
  {
1
  <?php
2
 
3
+ namespace WebpConverter\Action;
4
 
5
  use WebpConverter\Convert as ConvertMethod;
6
+ use WebpConverter\Media\Attachment;
7
 
8
  class Convert
9
  {
app/Action/Delete.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WebpConverter\Action;
4
+
5
+ use WebpConverter\Convert\Directory;
6
+
7
+ class Delete
8
+ {
9
+ public function __construct()
10
+ {
11
+ add_action('webpc_delete_paths', [$this, 'deleteFilesByPaths']);
12
+ }
13
+
14
+ /* ---
15
+ Functions
16
+ --- */
17
+
18
+ public function deleteFilesByPaths($paths)
19
+ {
20
+ foreach ($paths as $path) {
21
+ $this->deleteFileByPath($path);
22
+ }
23
+ }
24
+
25
+ private function deleteFileByPath($path)
26
+ {
27
+ $directory = new Directory();
28
+ $source = $directory->getPath($path);
29
+ if (is_writable($source) && (pathinfo($source, PATHINFO_EXTENSION) === 'webp')) unlink($source);
30
+ }
31
+ }
app/Action/_Core.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WebpConverter\Action;
4
+
5
+ class _Core
6
+ {
7
+ public function __construct()
8
+ {
9
+ new Convert();
10
+ new Delete();
11
+ }
12
+ }
app/Media/Delete.php CHANGED
@@ -2,8 +2,6 @@
2
 
3
  namespace WebpConverter\Media;
4
 
5
- use WebpConverter\Convert as Convert;
6
-
7
  class Delete
8
  {
9
  public function __construct()
@@ -17,9 +15,7 @@
17
 
18
  public function deleteAttachmentFile($path)
19
  {
20
- $directory = new Convert\Directory();
21
- $source = $directory->getPath($path);
22
- if (is_writable($source) && (pathinfo($source, PATHINFO_EXTENSION) === 'webp')) unlink($source);
23
  return $path;
24
  }
25
  }
2
 
3
  namespace WebpConverter\Media;
4
 
 
 
5
  class Delete
6
  {
7
  public function __construct()
15
 
16
  public function deleteAttachmentFile($path)
17
  {
18
+ do_action('webpc_delete_paths', [$path]);
 
 
19
  return $path;
20
  }
21
  }
app/Media/_Core.php CHANGED
@@ -6,7 +6,6 @@
6
  {
7
  public function __construct()
8
  {
9
- new Convert();
10
  new Delete();
11
  new Htaccess();
12
  new Upload();
6
  {
7
  public function __construct()
8
  {
 
9
  new Delete();
10
  new Htaccess();
11
  new Upload();
app/Regenerate/Paths.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  namespace WebpConverter\Regenerate;
4
 
5
- use WebpConverter\Media\Attachment as Attachment;
6
 
7
  class Paths
8
  {
2
 
3
  namespace WebpConverter\Regenerate;
4
 
5
+ use WebpConverter\Media\Attachment;
6
 
7
  class Paths
8
  {
app/WebpConverter.php CHANGED
@@ -6,6 +6,7 @@
6
  {
7
  public function __construct()
8
  {
 
9
  new Admin\_Core();
10
  new Media\_Core();
11
  new Regenerate\_Core();
6
  {
7
  public function __construct()
8
  {
9
+ new Action\_Core();
10
  new Admin\_Core();
11
  new Media\_Core();
12
  new Regenerate\_Core();
readme.txt CHANGED
@@ -74,13 +74,13 @@ And most importantly - **do not leave the thread unanswered**. If you add a thre
74
 
75
  When adding a thread, follow these steps and reply to each of them:
76
 
77
- **1.** URL of your website. If your site is not publicly available, add it to test environment.
78
 
79
- **2.** Does your server meet the technical requirements described in the FAQ? Please send configuration of your server *(link to it can be found on the settings page of plugin in the section **"We are waiting for your message"**)* - please take a screenshot of the ENTIRE page and send it to me.
80
 
81
- **3.** Do you use CDN? If so, please see the question **"Does the plugin support CDN?"** in plugin FAQ.
82
 
83
- **4.** Do you use other plugins to optimize images? Please disable them and check this plugin without them. Remember not to combine several optimization plugins because they can be mutually exclusive.
84
 
85
  **5.** Check if in `/wp-content/uploads-webpc` directory are all files that should be converted.
86
 
@@ -102,14 +102,30 @@ 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-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
 
109
- Please remember to include the answers for all 7 questions by adding a thread. It is much easier and accelerate the solution of your problem.
 
 
 
 
 
 
110
 
111
  And if we would help and would like to thank us, you can [provide us a coffee](https://ko-fi.com/gbiorczyk/).
112
 
 
 
 
 
 
 
 
 
 
 
113
  = What are requirements of plugin? =
114
 
115
  Practically every hosting meets these requirements. You must use PHP at least 7.0 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format`.**
@@ -163,6 +179,8 @@ Please remember that URLs will remain unchanged. The difference will be only in
163
 
164
  If the file type is `WebP`, then everything is working properly. You can also turn off the plugin for a moment and check the weight of your website, then turn it on and test again. The difference should be visible.
165
 
 
 
166
  = Why are some images not in WebP? =
167
 
168
  If the converted image in WebP format is larger than the original, the browser will use the original file. This converted file will be deleted. Therefore, you can also see files other than WebP on the list.
@@ -239,6 +257,12 @@ After setting the filters go to `Settings -> WebP Converter` in the admin panel
239
 
240
  By default, all images are converted when you click on the `Regenerate All` button. In addition, conversion is automatic when you add new files to your media library.
241
 
 
 
 
 
 
 
242
  To manually start converting selected files, you can use the action to which you will pass an array with a list of paths *(they must be absolute server paths)*:
243
 
244
  `do_action('webpc_convert_paths', $paths);`
@@ -255,6 +279,10 @@ In addition, you can edit the list of files that will be converted. For example,
255
 
256
  Argument `$paths` is array of absolute server paths and `$attachmentId` is the post ID of attachment, added to the media library.
257
 
 
 
 
 
258
  = How to change .htaccess rules? =
259
 
260
  Manually editing the rules in the .htaccess file is a task only for experienced developers. Remember that the wrong rules can cause your website to stop working.
@@ -330,13 +358,13 @@ and add below code in this file:
330
  `server {`
331
  ` # ...
332
 
333
- location ~ (?<root>.+)/uploads/(?<path>.+)\.(?<ext>jp?g|png|gif)$ {
334
  if ($http_accept !~* "image/webp") {
335
  break;
336
  }
337
  add_header Vary Accept;
338
  expires 365d;
339
- try_files $root/uploads-webpc/$path.$ext.webp $uri =404;
340
  }
341
  }`
342
 
@@ -396,6 +424,10 @@ This is all very important to us and allows us to do even better things for you!
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
74
 
75
  When adding a thread, follow these steps and reply to each of them:
76
 
77
+ **1.** Do you have any error on the plugin settings page? If so, which one? Have you consulted your server administrator or developer? If not, please do it first.
78
 
79
+ **2.** URL of your website. If your site is not publicly available, add it to test environment.
80
 
81
+ **3.** Does your server meet the technical requirements described in the FAQ? Please send configuration of your server *(link to it can be found on the settings page of plugin in the section **"We are waiting for your message"**)* - please take a screenshot of the ENTIRE page and send it to me.
82
 
83
+ **4.** Do you use CDN? If so, please see the question **"Does the plugin support CDN?"** in plugin FAQ.
84
 
85
  **5.** Check if in `/wp-content/uploads-webpc` directory are all files that should be converted.
86
 
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.** If in the previous step it turned out that you have files, please do the test, which is described in the FAQ in question `How to check if plugin works?`. Please send a screenshot of Devtools with test results.
106
 
107
+ **7.** 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)*.
108
 
109
+ **8.** What plugin version are you using? If it is not the latest then update and check everything again.
110
+
111
+ **9.** Used Wordpress version.
112
+
113
+ **10.** A list of all the plugins you use. Have you tried checking the plugin operation by turning off all others? If not, please try whenever possible.
114
+
115
+ Please remember to include the answers for all 10 questions by adding a thread. It is much easier and accelerate the solution of your problem.
116
 
117
  And if we would help and would like to thank us, you can [provide us a coffee](https://ko-fi.com/gbiorczyk/).
118
 
119
+ = Error on plugin settings screen? =
120
+
121
+ If you have an error on the plugin settings screen, first of all please read it carefully. They are displayed when there is a problem with the configuration of your server or website.
122
+
123
+ The messages are designed to reduce the number of support requests that are repeated. It saves your and our time. If you have information in the message that you should contact the administrator of your server, please do so.
124
+
125
+ When contacting the administrator, give him all the information available in the message. If you still cannot solve the problem, please contact us.
126
+
127
+ We want to solve as many similar problems as possible automatically. This eliminates the need to wait for our response and you can try to solve the problem alone. This is very important for us.
128
+
129
  = What are requirements of plugin? =
130
 
131
  Practically every hosting meets these requirements. You must use PHP at least 7.0 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format`.**
179
 
180
  If the file type is `WebP`, then everything is working properly. You can also turn off the plugin for a moment and check the weight of your website, then turn it on and test again. The difference should be visible.
181
 
182
+ Only images from the `/uploads` directory are converted. If you use other plugins that also save images in the `/uploads` directory then this may not work because this plugin may not be compatible with WebP Converter for Media. Read question `How to run manually conversion?` in the FAQ to learn more.
183
+
184
  = Why are some images not in WebP? =
185
 
186
  If the converted image in WebP format is larger than the original, the browser will use the original file. This converted file will be deleted. Therefore, you can also see files other than WebP on the list.
257
 
258
  By default, all images are converted when you click on the `Regenerate All` button. In addition, conversion is automatic when you add new files to your media library.
259
 
260
+ Remember that our plugin takes into account images generated by WordPress. There are many plugins that generate, for example, images of a different size or in a different version. Unfortunately, we are not able to integrate with any such plugin.
261
+
262
+ If you would like to integrate with your plugin, which generates images by yourself, you can do it. Our plugin provides the possibility of this type of integration. This works for all images in the `/uploads` directory.
263
+
264
+ It is a solution for advanced users. If you would like to integrate with another plugin, it's best to contact the author of that plugin and give him information about the actions available in our plugin. This will help you find a solution faster.
265
+
266
  To manually start converting selected files, you can use the action to which you will pass an array with a list of paths *(they must be absolute server paths)*:
267
 
268
  `do_action('webpc_convert_paths', $paths);`
279
 
280
  Argument `$paths` is array of absolute server paths and `$attachmentId` is the post ID of attachment, added to the media library.
281
 
282
+ To delete manually converted files, use the following action, providing as an argument an array of absolute server paths to the files *(this will delete manually converted files)*:
283
+
284
+ `do_action('webpc_delete_paths', $paths);`
285
+
286
  = How to change .htaccess rules? =
287
 
288
  Manually editing the rules in the .htaccess file is a task only for experienced developers. Remember that the wrong rules can cause your website to stop working.
358
  `server {`
359
  ` # ...
360
 
361
+ location ~ /wp-content/uploads/(?<path>.+)\.(?<ext>jp?g|png|gif)$ {
362
  if ($http_accept !~* "image/webp") {
363
  break;
364
  }
365
  add_header Vary Accept;
366
  expires 365d;
367
+ try_files /wp-content/uploads-webpc/$path.$ext.webp $uri =404;
368
  }
369
  }`
370
 
424
 
425
  == Changelog ==
426
 
427
+ = 1.2.4 (2020-04-24) =
428
+ * `[Changed]` Error messages in administration panel
429
+ * `[Added]` Action `webpc_delete_paths` to delete images by paths
430
+
431
  = 1.2.3 (2020-04-15) =
432
  * `[Added]` Blocking server cache for rewrite rules
433
  * `[Added]` Detecting whether requests to images are processed by server bypassing Apache
resources/components/widgets/errors.php CHANGED
@@ -7,7 +7,9 @@
7
  <?php if (in_array('path_uploads', $errors)) : ?>
8
  <p>
9
  <?= sprintf(
10
- __('The path for /uploads files does not exist. Please use the %s filter to set the correct path. The current path is: %s.', 'webp-converter'),
 
 
11
  '<strong>webpc_uploads_path</strong>',
12
  '<strong>' . apply_filters('webpc_uploads_path', '') . '</strong>'
13
  ); ?>
@@ -16,7 +18,9 @@
16
  <?php if (in_array('path_htaccess', $errors)) : ?>
17
  <p>
18
  <?= sprintf(
19
- __('Unable to create or edit .htaccess file. Please change directory permissions. The current path of file is: %s.', 'webp-converter'),
 
 
20
  '<strong>' . apply_filters('webpc_uploads_path', '') . '/.htaccess</strong>'
21
  ); ?>
22
  </p>
@@ -24,7 +28,9 @@
24
  <?php if (in_array('path_webp', $errors)) : ?>
25
  <p>
26
  <?= sprintf(
27
- __('The path for saving converted WebP files does not exist and cannot be created. Please check your server configuration and try again. The current path is: %s.', 'webp-converter'),
 
 
28
  '<strong>' . apply_filters('webpc_uploads_webp', '') . '</strong>'
29
  ); ?>
30
  </p>
@@ -32,7 +38,7 @@
32
  <?php if (in_array('path_duplicated', $errors)) : ?>
33
  <p>
34
  <?= sprintf(
35
- __('The paths for /uploads files and for saving converted WebP files are the same. Please change them using filters %s or %s. The current path for them is: %s.', 'webp-converter'),
36
  '<strong>webpc_uploads_path</strong>',
37
  '<strong>webpc_uploads_webp</strong>',
38
  '<strong>' . apply_filters('webpc_uploads_path', '') . '</strong>'
@@ -52,19 +58,28 @@
52
  <?php if (in_array('methods', $errors)) : ?>
53
  <p>
54
  <?= sprintf(
55
- __('On your server is not installed %sGD%s or %sImagick%s library, or installed extension does not support WebP format. Please check your server configuration and try again.', 'webp-converter'),
56
- '<strong>', '</strong>', '<strong>', '</strong>'
 
 
 
 
 
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; ?>
7
  <?php if (in_array('path_uploads', $errors)) : ?>
8
  <p>
9
  <?= sprintf(
10
+ __('The path for /uploads files does not exist %s(function is_dir() returns false)%s. Please use the %s filter to set the correct path. The current using path is: %s.', 'webp-converter'),
11
+ '<em>',
12
+ '</em>',
13
  '<strong>webpc_uploads_path</strong>',
14
  '<strong>' . apply_filters('webpc_uploads_path', '') . '</strong>'
15
  ); ?>
18
  <?php if (in_array('path_htaccess', $errors)) : ?>
19
  <p>
20
  <?= sprintf(
21
+ __('Unable to create or edit .htaccess file %s(function is_readable() or is_writable() returns false)%s. Change directory permissions. The current using path of file is: %s. Please contact your server administrator.', 'webp-converter'),
22
+ '<em>',
23
+ '</em>',
24
  '<strong>' . apply_filters('webpc_uploads_path', '') . '/.htaccess</strong>'
25
  ); ?>
26
  </p>
28
  <?php if (in_array('path_webp', $errors)) : ?>
29
  <p>
30
  <?= sprintf(
31
+ __('The path for saving converted WebP files does not exist and cannot be created %s(function is_writable() returns false)%s. Check your server configuration and try again. The current using path is: %s. Please contact your server administrator.', 'webp-converter'),
32
+ '<em>',
33
+ '</em>',
34
  '<strong>' . apply_filters('webpc_uploads_webp', '') . '</strong>'
35
  ); ?>
36
  </p>
38
  <?php if (in_array('path_duplicated', $errors)) : ?>
39
  <p>
40
  <?= sprintf(
41
+ __('The paths for /uploads files and for saving converted WebP files are the same. Change them using filters %s or %s. The current path for them is: %s.', 'webp-converter'),
42
  '<strong>webpc_uploads_path</strong>',
43
  '<strong>webpc_uploads_webp</strong>',
44
  '<strong>' . apply_filters('webpc_uploads_path', '') . '</strong>'
58
  <?php if (in_array('methods', $errors)) : ?>
59
  <p>
60
  <?= sprintf(
61
+ __('On your server is not installed %sGD%s or %sImagick%s library, or installed extension does not support WebP format. Check your server configuration %shere%s and try again. Please contact your server administrator.', 'webp-converter'),
62
+ '<strong>',
63
+ '</strong>',
64
+ '<strong>',
65
+ '</strong>',
66
+ '<a href="' . sprintf('%s&action=server', menu_page_url('webpc_admin_page', false)) . '">',
67
+ '</a>'
68
  ); ?>
69
  </p>
70
  <?php endif; ?>
71
  <?php if (in_array('bypassing_apache', $errors)) : ?>
72
  <p>
73
  <?= sprintf(
74
+ __('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 %s(for which the redirection does not work)%s and for %s.png2 file%s %s(for which the redirection works correctly)%s. Change the server settings to stop ignoring the rules in the .htaccess file. Please contact your server administrator.', 'webp-converter'),
75
  '<a href="' . WEBPC_URL . 'public/img/icon-before.png" target="_blank">',
76
  '</a>',
77
+ '<em>',
78
+ '</em>',
79
  '<a href="' . WEBPC_URL . 'public/img/icon-before.png2" target="_blank">',
80
+ '</a>',
81
+ '<em>',
82
+ '</em>'
83
  ); ?>
84
  </p>
85
  <?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.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__));
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.4
7
  Author: Mateusz Gbiorczyk
8
  Author URI: https://gbiorczyk.pl/
9
  Text Domain: webp-converter
10
  */
11
 
12
+ define('WEBPC_VERSION', '1.2.4');
13
  define('WEBPC_FILE', __FILE__);
14
  define('WEBPC_NAME', plugin_basename(__FILE__));
15
  define('WEBPC_PATH', plugin_dir_path(__FILE__));