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

Version Description

(2021-06-20) = * [Fixed] Generating URLs for images using Pass Thru method * [Added] Filter webpc_passthru_url_nocache to remove nocache param from URL using Pass Thru method

Download this release

Release Info

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

Code changes from version 3.0.5 to 3.0.6

readme.txt CHANGED
@@ -166,25 +166,25 @@ This is possible using the following types of filters to change default paths. I
166
  Path to the root installation directory of WordPress *(`ABSPATH` by default)*:
167
 
168
  `add_filter( 'webpc_site_root', function( $path ) {
169
- return ABSPATH;
170
  } );`
171
 
172
  Path to `/uploads` directory *(relative to the root directory)*:
173
 
174
  `add_filter( 'webpc_dir_name', function( $path, $directory ) {
175
- if ( $directory !== 'uploads' ) {
176
- return $path;
177
- }
178
- return 'wp-content/uploads';
179
  }, 10, 2 );`
180
 
181
  Directory path with converted WebP files *(relative to the root directory)*:
182
 
183
  `add_filter( 'webpc_dir_name', function( $path, $directory ) {
184
- if ( $directory !== 'webp' ) {
185
- return $path;
186
- }
187
- return 'wp-content/uploads-webpc';
188
  }, 10, 2 );`
189
 
190
  **Note that the `/uploads-webpc` directory must be at the same nesting level as the `/uploads`, `/plugins` and `/themes` directories.**
@@ -192,41 +192,41 @@ Directory path with converted WebP files *(relative to the root directory)*:
192
  Prefix in URL of `/wp-content/` directory or equivalent *(used in .htaccess)*:
193
 
194
  `add_filter( 'webpc_uploads_prefix', function( $prefix ) {
195
- return '/';
196
  } );`
197
 
198
  For the following sample custom WordPress structure:
199
 
200
  `...
201
  ├── web
202
- ...
203
- ├── app
204
- ├── mu-plugins
205
- ├── plugins
206
- ├── themes
207
- └── uploads
208
- ├── wp-config.php
209
- ...`
210
 
211
  Use the following filters:
212
 
213
  `add_filter( 'webpc_site_root', function( $path ) {
214
- return 'C:/WAMP/www/project/webp'; // your valid path to root
215
  } );
216
  add_filter( 'webpc_dir_name', function( $path, $directory ) {
217
- if ( $directory !== 'uploads' ) {
218
- return $path;
219
- }
220
- return 'app/uploads';
221
  }, 10, 2 );
222
  add_filter( 'webpc_dir_name', function( $path, $directory ) {
223
- if ( $directory !== 'webp' ) {
224
- return $path;
225
- }
226
- return 'app/uploads-webpc';
227
  }, 10, 2 );`
228
  `add_filter( 'webpc_uploads_prefix', function( $prefix ) {
229
- return '/';
230
  } );`
231
 
232
  After setting the filters go to `Settings -> WebP Converter` in the admin panel and click the `Save Changes` button. `.htaccess` files with appropriate rules should be created in the directories `/uploads` and `/uploads-webpc`.
@@ -248,7 +248,7 @@ You can automatically run the option to regenerate all new images. This is usefu
248
  Below is an example of how to use this action to automatically regenerate images after changing the theme:
249
 
250
  `add_action('init', function() {
251
- do_action( 'webpc_regenerate_all' );
252
  });`
253
 
254
  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)*:
@@ -262,7 +262,7 @@ An alternative method is to manually start converting the selected attachment by
262
  In addition, you can edit the list of files that will be converted. For example, to add some to the exceptions. To do this, use the following filter, which by default returns a list of all paths:
263
 
264
  `add_filter( 'webpc_files_paths', function( $paths, $skip_exists ) {
265
- return $paths;
266
  }, 10, 2 );`
267
 
268
  Argument `$paths` is array of absolute server paths and `$skip_exists` means whether to skip converted images.
@@ -270,7 +270,7 @@ Argument `$paths` is array of absolute server paths and `$skip_exists` means whe
270
  You can also modify the list of image paths for an attachment, e.g. to exclude one image size. To do this, use the following filter:
271
 
272
  `add_filter( 'webpc_attachment_paths', function( $paths, $attachment_id ) {
273
- return $paths;
274
  }, 10, 2 );`
275
 
276
  Argument `$paths` is array of absolute server paths and `$attachment_id` is the post ID of attachment, added to the Media Library.
@@ -290,7 +290,7 @@ Returning an empty string will delete these rules the next time you save the plu
290
  Rules for redirects: *(returns rules for `mod_rewrite` module)*:
291
 
292
  `add_filter( 'webpc_htaccess_mod_rewrite', function( $rules, $path ) {
293
- return '';
294
  }, 10, 2 );`
295
 
296
  Argument `$path` is absolute server path for `.htaccess` file *(`/wp-content/.htaccess` or `/wp-content/uploads/.htaccess`)*.
@@ -298,19 +298,19 @@ Argument `$path` is absolute server path for `.htaccess` file *(`/wp-content/.ht
298
  Rules for `image/webp` MIME type: *(returns rules for `mod_mime` module)*:
299
 
300
  `add_filter( 'webpc_htaccess_mod_mime', function( $rules ) {
301
- return '';
302
  } );`
303
 
304
  Rules for Browser Caching: *(returns rules for `mod_expires` module)*:
305
 
306
  `add_filter( 'webpc_htaccess_mod_expires', function( $rules ) {
307
- return '';
308
  } );`
309
 
310
  All rules from the files `/wp-content/.htaccess`, `/wp-content/uploads/.htaccess` and `/wp-content/uploads-webpc/.htaccess`: *(returns rules for modules: `mod_rewrite`, `mod_mime` and `mod_expires`)*:
311
 
312
  `add_filter( 'webpc_htaccess_rules', function( $rules, $path ) {
313
- return '';
314
  }, 10, 2 );`
315
 
316
  Argument `$path` is absolute server path for `.htaccess` file.
@@ -348,8 +348,8 @@ Please edit the configuration file:
348
  and add this code line:
349
 
350
  `types {`
351
- ` # ...`
352
- ` image/webp webp;`
353
  `}`
354
 
355
  Then find the configuration file in one of the paths *(remember to select configuration file used by your vhost)*:
@@ -359,16 +359,16 @@ Then find the configuration file in one of the paths *(remember to select config
359
  and add below code in this file *(add these lines to very beginning of file if possible - if they will be at the bottom, other rules may block the rules for WebP from working)*:
360
 
361
  `server {`
362
- ` location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {`
363
- ` if ($http_accept !~* "image/webp") {`
364
- ` break;`
365
- ` }`
366
- ` add_header Vary Accept;`
367
- ` add_header Cache-Control "private" always;`
368
- ` expires 365d;`
369
- ` try_files /wp-content/uploads-webpc/$path.$ext.webp $uri =404;`
370
- ` }`
371
- ` # ...`
372
  `}`
373
 
374
  After making changes, remember to restart the machine: `systemctl restart nginx`.
@@ -382,16 +382,16 @@ Please manually paste the following code **at the beginning of .htaccess file**
382
  `# BEGIN WebP Converter`
383
  `# ! --- DO NOT EDIT PREVIOUS LINE --- !`
384
  `<IfModule mod_rewrite.c>
385
- RewriteEngine On
386
- RewriteCond %{HTTP_ACCEPT} image/webp
387
- RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
388
- RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,L]
389
- RewriteCond %{HTTP_ACCEPT} image/webp
390
- RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
391
- RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,L]
392
- RewriteCond %{HTTP_ACCEPT} image/webp
393
- RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
394
- RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,L]
395
  </IfModule>
396
  <IfModule mod_headers.c>
397
  Header Set Cache-Control "private"
@@ -404,11 +404,11 @@ And the following code **at the beginning of .htaccess file** in the `/wp-conten
404
  `# BEGIN WebP Converter`
405
  `# ! --- DO NOT EDIT PREVIOUS LINE --- !`
406
  `<IfModule mod_mime.c>
407
- AddType image/webp .webp
408
  </IfModule>
409
  <IfModule mod_expires.c>
410
- ExpiresActive On
411
- ExpiresByType image/webp "access plus 1 year"
412
  </IfModule>
413
  <IfModule mod_headers.c>
414
  Header Set Cache-Control "private"
@@ -436,6 +436,10 @@ This is all very important to us and allows us to do even better things for you!
436
 
437
  == Changelog ==
438
 
 
 
 
 
439
  = 3.0.5 (2021-06-09) =
440
  * `[Fixed]` Handling of filters for changing directory paths
441
  * `[Fixed]` Converting using Imagick method for 100% image quality
166
  Path to the root installation directory of WordPress *(`ABSPATH` by default)*:
167
 
168
  `add_filter( 'webpc_site_root', function( $path ) {
169
+ return ABSPATH;
170
  } );`
171
 
172
  Path to `/uploads` directory *(relative to the root directory)*:
173
 
174
  `add_filter( 'webpc_dir_name', function( $path, $directory ) {
175
+ if ( $directory !== 'uploads' ) {
176
+ return $path;
177
+ }
178
+ return 'wp-content/uploads';
179
  }, 10, 2 );`
180
 
181
  Directory path with converted WebP files *(relative to the root directory)*:
182
 
183
  `add_filter( 'webpc_dir_name', function( $path, $directory ) {
184
+ if ( $directory !== 'webp' ) {
185
+ return $path;
186
+ }
187
+ return 'wp-content/uploads-webpc';
188
  }, 10, 2 );`
189
 
190
  **Note that the `/uploads-webpc` directory must be at the same nesting level as the `/uploads`, `/plugins` and `/themes` directories.**
192
  Prefix in URL of `/wp-content/` directory or equivalent *(used in .htaccess)*:
193
 
194
  `add_filter( 'webpc_uploads_prefix', function( $prefix ) {
195
+ return '/';
196
  } );`
197
 
198
  For the following sample custom WordPress structure:
199
 
200
  `...
201
  ├── web
202
+ ...
203
+ ├── app
204
+ ├── mu-plugins
205
+ ├── plugins
206
+ ├── themes
207
+ └── uploads
208
+ ├── wp-config.php
209
+ ...`
210
 
211
  Use the following filters:
212
 
213
  `add_filter( 'webpc_site_root', function( $path ) {
214
+ return 'C:/WAMP/www/project/webp'; // your valid path to root
215
  } );
216
  add_filter( 'webpc_dir_name', function( $path, $directory ) {
217
+ if ( $directory !== 'uploads' ) {
218
+ return $path;
219
+ }
220
+ return 'app/uploads';
221
  }, 10, 2 );
222
  add_filter( 'webpc_dir_name', function( $path, $directory ) {
223
+ if ( $directory !== 'webp' ) {
224
+ return $path;
225
+ }
226
+ return 'app/uploads-webpc';
227
  }, 10, 2 );`
228
  `add_filter( 'webpc_uploads_prefix', function( $prefix ) {
229
+ return '/';
230
  } );`
231
 
232
  After setting the filters go to `Settings -> WebP Converter` in the admin panel and click the `Save Changes` button. `.htaccess` files with appropriate rules should be created in the directories `/uploads` and `/uploads-webpc`.
248
  Below is an example of how to use this action to automatically regenerate images after changing the theme:
249
 
250
  `add_action('init', function() {
251
+ do_action( 'webpc_regenerate_all' );
252
  });`
253
 
254
  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)*:
262
  In addition, you can edit the list of files that will be converted. For example, to add some to the exceptions. To do this, use the following filter, which by default returns a list of all paths:
263
 
264
  `add_filter( 'webpc_files_paths', function( $paths, $skip_exists ) {
265
+ return $paths;
266
  }, 10, 2 );`
267
 
268
  Argument `$paths` is array of absolute server paths and `$skip_exists` means whether to skip converted images.
270
  You can also modify the list of image paths for an attachment, e.g. to exclude one image size. To do this, use the following filter:
271
 
272
  `add_filter( 'webpc_attachment_paths', function( $paths, $attachment_id ) {
273
+ return $paths;
274
  }, 10, 2 );`
275
 
276
  Argument `$paths` is array of absolute server paths and `$attachment_id` is the post ID of attachment, added to the Media Library.
290
  Rules for redirects: *(returns rules for `mod_rewrite` module)*:
291
 
292
  `add_filter( 'webpc_htaccess_mod_rewrite', function( $rules, $path ) {
293
+ return '';
294
  }, 10, 2 );`
295
 
296
  Argument `$path` is absolute server path for `.htaccess` file *(`/wp-content/.htaccess` or `/wp-content/uploads/.htaccess`)*.
298
  Rules for `image/webp` MIME type: *(returns rules for `mod_mime` module)*:
299
 
300
  `add_filter( 'webpc_htaccess_mod_mime', function( $rules ) {
301
+ return '';
302
  } );`
303
 
304
  Rules for Browser Caching: *(returns rules for `mod_expires` module)*:
305
 
306
  `add_filter( 'webpc_htaccess_mod_expires', function( $rules ) {
307
+ return '';
308
  } );`
309
 
310
  All rules from the files `/wp-content/.htaccess`, `/wp-content/uploads/.htaccess` and `/wp-content/uploads-webpc/.htaccess`: *(returns rules for modules: `mod_rewrite`, `mod_mime` and `mod_expires`)*:
311
 
312
  `add_filter( 'webpc_htaccess_rules', function( $rules, $path ) {
313
+ return '';
314
  }, 10, 2 );`
315
 
316
  Argument `$path` is absolute server path for `.htaccess` file.
348
  and add this code line:
349
 
350
  `types {`
351
+ ` # ...`
352
+ ` image/webp webp;`
353
  `}`
354
 
355
  Then find the configuration file in one of the paths *(remember to select configuration file used by your vhost)*:
359
  and add below code in this file *(add these lines to very beginning of file if possible - if they will be at the bottom, other rules may block the rules for WebP from working)*:
360
 
361
  `server {`
362
+ ` location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {`
363
+ ` if ($http_accept !~* "image/webp") {`
364
+ ` break;`
365
+ ` }`
366
+ ` add_header Vary Accept;`
367
+ ` add_header Cache-Control "private" always;`
368
+ ` expires 365d;`
369
+ ` try_files /wp-content/uploads-webpc/$path.$ext.webp $uri =404;`
370
+ ` }`
371
+ ` # ...`
372
  `}`
373
 
374
  After making changes, remember to restart the machine: `systemctl restart nginx`.
382
  `# BEGIN WebP Converter`
383
  `# ! --- DO NOT EDIT PREVIOUS LINE --- !`
384
  `<IfModule mod_rewrite.c>
385
+ RewriteEngine On
386
+ RewriteCond %{HTTP_ACCEPT} image/webp
387
+ RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
388
+ RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,L]
389
+ RewriteCond %{HTTP_ACCEPT} image/webp
390
+ RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
391
+ RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,L]
392
+ RewriteCond %{HTTP_ACCEPT} image/webp
393
+ RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
394
+ RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,L]
395
  </IfModule>
396
  <IfModule mod_headers.c>
397
  Header Set Cache-Control "private"
404
  `# BEGIN WebP Converter`
405
  `# ! --- DO NOT EDIT PREVIOUS LINE --- !`
406
  `<IfModule mod_mime.c>
407
+ AddType image/webp .webp
408
  </IfModule>
409
  <IfModule mod_expires.c>
410
+ ExpiresActive On
411
+ ExpiresByType image/webp "access plus 1 year"
412
  </IfModule>
413
  <IfModule mod_headers.c>
414
  Header Set Cache-Control "private"
436
 
437
  == Changelog ==
438
 
439
+ = 3.0.6 (2021-06-20) =
440
+ * `[Fixed]` Generating URLs for images using Pass Thru method
441
+ * `[Added]` Filter `webpc_passthru_url_nocache` to remove nocache param from URL using Pass Thru method
442
+
443
  = 3.0.5 (2021-06-09) =
444
  * `[Fixed]` Handling of filters for changing directory paths
445
  * `[Fixed]` Converting using Imagick method for 100% image quality
src/Error/RewritesError.php CHANGED
@@ -83,14 +83,16 @@ class RewritesError extends ErrorAbstract implements ErrorInterface {
83
  private function if_redirects_are_works(): bool {
84
  $uploads_dir = apply_filters( 'webpc_dir_path', '', 'uploads' );
85
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
86
- $ver_param = sprintf( '?ver=%s', time() );
87
 
88
  $file_size = FileLoader::get_file_size_by_path(
89
  $uploads_dir . self::PATH_OUTPUT_FILE_PNG
90
  );
91
  $file_webp = FileLoader::get_file_size_by_url(
92
- $uploads_url . self::PATH_OUTPUT_FILE_PNG . $ver_param,
93
- $this->get_plugin()
 
 
94
  );
95
 
96
  return ( $file_webp < $file_size );
@@ -103,15 +105,19 @@ class RewritesError extends ErrorAbstract implements ErrorInterface {
103
  */
104
  private function if_bypassing_apache_is_active(): bool {
105
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
106
- $ver_param = sprintf( '?ver=%s', time() );
107
 
108
  $file_png = FileLoader::get_file_size_by_url(
109
- $uploads_url . self::PATH_OUTPUT_FILE_PNG . $ver_param,
110
- $this->get_plugin()
 
 
111
  );
112
  $file_png2 = FileLoader::get_file_size_by_url(
113
- $uploads_url . self::PATH_OUTPUT_FILE_PNG2 . $ver_param,
114
- $this->get_plugin()
 
 
115
  );
116
 
117
  return ( $file_png > $file_png2 );
@@ -124,16 +130,19 @@ class RewritesError extends ErrorAbstract implements ErrorInterface {
124
  */
125
  private function if_redirects_are_cached(): bool {
126
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
127
- $ver_param = sprintf( '?ver=%s', time() );
128
 
129
  $file_webp = FileLoader::get_file_size_by_url(
130
- $uploads_url . self::PATH_OUTPUT_FILE_PNG . $ver_param,
131
- $this->get_plugin()
 
 
132
  );
133
  $file_original = FileLoader::get_file_size_by_url(
134
- $uploads_url . self::PATH_OUTPUT_FILE_PNG . $ver_param,
135
  $this->get_plugin(),
136
- false
 
137
  );
138
 
139
  return ( ( $file_webp > 0 ) && ( $file_webp === $file_original ) );
83
  private function if_redirects_are_works(): bool {
84
  $uploads_dir = apply_filters( 'webpc_dir_path', '', 'uploads' );
85
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
86
+ $ver_param = sprintf( 'ver=%s', time() );
87
 
88
  $file_size = FileLoader::get_file_size_by_path(
89
  $uploads_dir . self::PATH_OUTPUT_FILE_PNG
90
  );
91
  $file_webp = FileLoader::get_file_size_by_url(
92
+ $uploads_url . self::PATH_OUTPUT_FILE_PNG,
93
+ $this->get_plugin(),
94
+ true,
95
+ $ver_param
96
  );
97
 
98
  return ( $file_webp < $file_size );
105
  */
106
  private function if_bypassing_apache_is_active(): bool {
107
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
108
+ $ver_param = sprintf( '&?ver=%s', time() );
109
 
110
  $file_png = FileLoader::get_file_size_by_url(
111
+ $uploads_url . self::PATH_OUTPUT_FILE_PNG,
112
+ $this->get_plugin(),
113
+ true,
114
+ $ver_param
115
  );
116
  $file_png2 = FileLoader::get_file_size_by_url(
117
+ $uploads_url . self::PATH_OUTPUT_FILE_PNG2,
118
+ $this->get_plugin(),
119
+ true,
120
+ $ver_param
121
  );
122
 
123
  return ( $file_png > $file_png2 );
130
  */
131
  private function if_redirects_are_cached(): bool {
132
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
133
+ $ver_param = sprintf( 'ver=%s', time() );
134
 
135
  $file_webp = FileLoader::get_file_size_by_url(
136
+ $uploads_url . self::PATH_OUTPUT_FILE_PNG,
137
+ $this->get_plugin(),
138
+ true,
139
+ $ver_param
140
  );
141
  $file_original = FileLoader::get_file_size_by_url(
142
+ $uploads_url . self::PATH_OUTPUT_FILE_PNG,
143
  $this->get_plugin(),
144
+ false,
145
+ $ver_param
146
  );
147
 
148
  return ( ( $file_webp > 0 ) && ( $file_webp === $file_original ) );
src/Helper/FileLoader.php CHANGED
@@ -16,10 +16,11 @@ class FileLoader {
16
  * @param string $url URL of image.
17
  * @param WebpConverter $plugin .
18
  * @param bool $set_headers Whether to send headers to confirm that browser supports WebP?
 
19
  *
20
  * @return int Size of retrieved file.
21
  */
22
- public static function get_file_size_by_url( string $url, WebpConverter $plugin, bool $set_headers = true ): int {
23
  $headers = [
24
  'Accept: image/webp',
25
  'Referer: ' . WEBPC_URL,
@@ -29,6 +30,10 @@ class FileLoader {
29
  $loader->set_plugin( $plugin );
30
 
31
  $image_url = $loader->update_image_urls( $url, true );
 
 
 
 
32
  return self::get_file_size_for_loaded_file( $image_url, ( $set_headers ) ? $headers : [] );
33
  }
34
 
16
  * @param string $url URL of image.
17
  * @param WebpConverter $plugin .
18
  * @param bool $set_headers Whether to send headers to confirm that browser supports WebP?
19
+ * @param string $extra_param Additional GET param.
20
  *
21
  * @return int Size of retrieved file.
22
  */
23
+ public static function get_file_size_by_url( string $url, WebpConverter $plugin, bool $set_headers = true, string $extra_param = '' ): int {
24
  $headers = [
25
  'Accept: image/webp',
26
  'Referer: ' . WEBPC_URL,
30
  $loader->set_plugin( $plugin );
31
 
32
  $image_url = $loader->update_image_urls( $url, true );
33
+ if ( $extra_param ) {
34
+ $image_url .= ( ( strpos( $image_url, '?' ) !== false ) ? '&' : '?' ) . $extra_param;
35
+ }
36
+
37
  return self::get_file_size_for_loaded_file( $image_url, ( $set_headers ) ? $headers : [] );
38
  }
39
 
src/Loader/PassthruLoader.php CHANGED
@@ -89,7 +89,11 @@ class PassthruLoader extends LoaderAbstract implements LoaderInterface {
89
  * @internal
90
  */
91
  public function start_buffer() {
92
- ob_start( [ $this, 'update_image_urls' ] );
 
 
 
 
93
  }
94
 
95
  /**
@@ -113,10 +117,12 @@ class PassthruLoader extends LoaderAbstract implements LoaderInterface {
113
  return $buffer;
114
  }
115
 
116
- $dir_paths = str_replace( '/', '\\/', implode( '|', $allowed_dirs ) );
 
 
117
  return preg_replace(
118
  '/(https?:\/\/(?:[^\s()"\']+)(?:' . $dir_paths . ')(?:[^\s()"\']+)\.(?:' . $extensions . '))/',
119
- $source_dir . '?src=$1&nocache=1',
120
  $buffer
121
  ) ?: '';
122
  }
89
  * @internal
90
  */
91
  public function start_buffer() {
92
+ ob_start(
93
+ function( $buffer ) {
94
+ return $this->update_image_urls( $buffer );
95
+ }
96
+ );
97
  }
98
 
99
  /**
117
  return $buffer;
118
  }
119
 
120
+ $dir_paths = str_replace( '/', '\\/', implode( '|', $allowed_dirs ) );
121
+ $has_nocache = apply_filters( 'webpc_passthru_url_nocache', true );
122
+
123
  return preg_replace(
124
  '/(https?:\/\/(?:[^\s()"\']+)(?:' . $dir_paths . ')(?:[^\s()"\']+)\.(?:' . $extensions . '))/',
125
+ $source_dir . '?src=$1' . ( ( $has_nocache ) ? '&nocache=1' : '' ),
126
  $buffer
127
  ) ?: '';
128
  }
src/Settings/Page/DebugPage.php CHANGED
@@ -34,7 +34,7 @@ class DebugPage extends PageAbstract implements PageInterface {
34
  $plugin = $this->get_plugin();
35
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
36
  $uploads_path = apply_filters( 'webpc_dir_path', '', 'uploads' );
37
- $ver_param = sprintf( '?ver=%s', time() );
38
 
39
  do_action( LoaderAbstract::ACTION_NAME, true, true );
40
 
@@ -58,22 +58,28 @@ class DebugPage extends PageAbstract implements PageInterface {
58
  $uploads_path . RewritesError::PATH_OUTPUT_FILE_PNG2
59
  ),
60
  'size_png_url' => FileLoader::get_file_size_by_url(
61
- $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG . $ver_param,
62
  $plugin,
63
- false
 
64
  ),
65
  'size_png2_url' => FileLoader::get_file_size_by_url(
66
- $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG2 . $ver_param,
67
  $plugin,
68
- false
 
69
  ),
70
  'size_png_as_webp_url' => FileLoader::get_file_size_by_url(
71
- $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG . $ver_param,
72
- $plugin
 
 
73
  ),
74
  'size_png2_as_webp_url' => FileLoader::get_file_size_by_url(
75
- $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG2 . $ver_param,
76
- $plugin
 
 
77
  ),
78
  ]
79
  );
34
  $plugin = $this->get_plugin();
35
  $uploads_url = apply_filters( 'webpc_dir_url', '', 'uploads' );
36
  $uploads_path = apply_filters( 'webpc_dir_path', '', 'uploads' );
37
+ $ver_param = sprintf( 'ver=%s', time() );
38
 
39
  do_action( LoaderAbstract::ACTION_NAME, true, true );
40
 
58
  $uploads_path . RewritesError::PATH_OUTPUT_FILE_PNG2
59
  ),
60
  'size_png_url' => FileLoader::get_file_size_by_url(
61
+ $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG,
62
  $plugin,
63
+ false,
64
+ $ver_param
65
  ),
66
  'size_png2_url' => FileLoader::get_file_size_by_url(
67
+ $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG2,
68
  $plugin,
69
+ false,
70
+ $ver_param
71
  ),
72
  'size_png_as_webp_url' => FileLoader::get_file_size_by_url(
73
+ $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG,
74
+ $plugin,
75
+ true,
76
+ $ver_param
77
  ),
78
  'size_png2_as_webp_url' => FileLoader::get_file_size_by_url(
79
+ $uploads_url . RewritesError::PATH_OUTPUT_FILE_PNG2,
80
+ $plugin,
81
+ true,
82
+ $ver_param
83
  ),
84
  ]
85
  );
webp-converter-for-media.php CHANGED
@@ -3,14 +3,14 @@
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: 3.0.5
7
  * Author: Mateusz Gbiorczyk
8
  * Author URI: https://gbiorczyk.pl/
9
  * Text Domain: webp-converter-for-media
10
  * Network: true
11
  */
12
 
13
- define( 'WEBPC_VERSION', '3.0.5' );
14
  define( 'WEBPC_FILE', __FILE__ );
15
  define( 'WEBPC_NAME', plugin_basename( __FILE__ ) );
16
  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: 3.0.6
7
  * Author: Mateusz Gbiorczyk
8
  * Author URI: https://gbiorczyk.pl/
9
  * Text Domain: webp-converter-for-media
10
  * Network: true
11
  */
12
 
13
+ define( 'WEBPC_VERSION', '3.0.6' );
14
  define( 'WEBPC_FILE', __FILE__ );
15
  define( 'WEBPC_NAME', plugin_basename( __FILE__ ) );
16
  define( 'WEBPC_PATH', plugin_dir_path( __FILE__ ) );