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

Version Description

(2021-05-09) = * [Fixed] Filters using for change server paths * [Added] Excluding directories when uploading images to Media Library

Download this release

Release Info

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

Code changes from version 3.0.0 to 3.0.1

readme.txt CHANGED
@@ -1,7 +1,7 @@
1
  === WebP Converter for Media ===
2
  Contributors: mateuszgbiorczyk
3
  Donate link: https://ko-fi.com/gbiorczyk/?utm_source=webp-converter-for-media&utm_medium=readme-donate
4
- Tags: convert webp, webp, optimize images, images, webp converter
5
  Requires at least: 4.9
6
  Tested up to: 5.7
7
  Requires PHP: 7.0
@@ -15,7 +15,7 @@ Speed up your website by serving WebP images instead of standard formats JPEG, P
15
 
16
  Speed up your website by serving WebP images. By replacing files in standard JPEG, PNG and GIF formats with WebP format, you can save over a half of the page weight without losing quality.
17
 
18
- When installing a plugin you do not have to do anything more. Your current images will be converted into a new format. Users will automatically receive new, much lighter images than the original ones.
19
 
20
  As of today, over 90% of users use browsers that support the WebP format. The loading time of your website depends to a large extent on its weight. Now you can speed up it in a few seconds without much effort!
21
 
@@ -23,12 +23,12 @@ This will be a profit both for your users who will not have to download so much
23
 
24
  #### Support for additional directories
25
 
26
- Now you can also convert files not only from `/uploads` directory but also from `/plugins` and `/themes` directories. This allows full integration with the WebP format!
27
 
28
  #### How does this work?
29
 
30
  - By adding images to your Media Library, they are automatically converted and saved in a separate directory.
31
- - If you have just installed the plugin, you can convert all existing images with one click.
32
  - As WebP you will see all the images added to the Media Library and other selected directories.
33
  - When the browser tries to download an image file, the server verifies if it supports `image/webp` files and if the file exists.
34
  - If everything is OK, instead of the original image, the browser will receive its equivalent in WebP format.
@@ -40,7 +40,7 @@ Now you can also convert files not only from `/uploads` directory but also from
40
 
41
  #### WebP images are the future!
42
 
43
- Raise your website to a new level now! Install the plugin and enjoy the website that loads faster. Surely you and your users will appreciate it.
44
 
45
  #### Support to the development of plugin
46
 
@@ -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.0 (2021-05-02) =
440
  * `[Removed]` Filter `webpc_get_values`
441
  * `[Removed]` Filter `webpc_get_options`
1
  === WebP Converter for Media ===
2
  Contributors: mateuszgbiorczyk
3
  Donate link: https://ko-fi.com/gbiorczyk/?utm_source=webp-converter-for-media&utm_medium=readme-donate
4
+ Tags: convert webp, webp, optimize images, compress images, webp converter
5
  Requires at least: 4.9
6
  Tested up to: 5.7
7
  Requires PHP: 7.0
15
 
16
  Speed up your website by serving WebP images. By replacing files in standard JPEG, PNG and GIF formats with WebP format, you can save over a half of the page weight without losing quality.
17
 
18
+ After installing the plugin you do not have to do anything more. Your current images will be converted into a new format. When compress images is finished, users will automatically receive new, much lighter images than the original ones.
19
 
20
  As of today, over 90% of users use browsers that support the WebP format. The loading time of your website depends to a large extent on its weight. Now you can speed up it in a few seconds without much effort!
21
 
23
 
24
  #### Support for additional directories
25
 
26
+ Now you can optimize images not only from `/uploads` directory but also from `/plugins` and `/themes` directories. This allows full integration with the WebP format!
27
 
28
  #### How does this work?
29
 
30
  - By adding images to your Media Library, they are automatically converted and saved in a separate directory.
31
+ - If you have just installed the plugin, you can optimize images with one click.
32
  - As WebP you will see all the images added to the Media Library and other selected directories.
33
  - When the browser tries to download an image file, the server verifies if it supports `image/webp` files and if the file exists.
34
  - If everything is OK, instead of the original image, the browser will receive its equivalent in WebP format.
40
 
41
  #### WebP images are the future!
42
 
43
+ Optimize images and raise your website to a new level now! Install the plugin and enjoy the website that loads faster by image optimization. Surely you and your users will appreciate it.
44
 
45
  #### Support to the development of plugin
46
 
436
 
437
  == Changelog ==
438
 
439
+ = 3.0.1 (2021-05-09) =
440
+ * `[Fixed]` Filters using for change server paths
441
+ * `[Added]` Excluding directories when uploading images to Media Library
442
+
443
  = 3.0.0 (2021-05-02) =
444
  * `[Removed]` Filter `webpc_get_values`
445
  * `[Removed]` Filter `webpc_get_options`
src/Action/ConvertPaths.php CHANGED
@@ -32,6 +32,28 @@ class ConvertPaths extends PluginAccessAbstract implements PluginAccessInterface
32
  public function convert_files_by_paths( array $paths ) {
33
  $method_integrator = new MethodIntegrator();
34
  $method_integrator->set_plugin( $this->get_plugin() );
35
- $method_integrator->init_conversion( $paths );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
  }
32
  public function convert_files_by_paths( array $paths ) {
33
  $method_integrator = new MethodIntegrator();
34
  $method_integrator->set_plugin( $this->get_plugin() );
35
+ $method_integrator->init_conversion( $this->remove_paths_of_excluded_dirs( $paths ) );
36
+ }
37
+
38
+ /**
39
+ * Removes paths of source images in excluded directories.
40
+ *
41
+ * @param string[] $paths Server paths of images.
42
+ *
43
+ * @return string[] Server paths of images.
44
+ */
45
+ private function remove_paths_of_excluded_dirs( array $paths ): array {
46
+ $excluded_dirs = apply_filters( 'webpc_dir_excluded', [] );
47
+ foreach ( $paths as $path_index => $path ) {
48
+ foreach ( $excluded_dirs as $excluded_dir ) {
49
+ $dir_pattern = str_replace( '.', '\.', $excluded_dir );
50
+ if ( ! preg_match( '/(\\\\|\/)(' . $dir_pattern . ')(\\\\|\/)/', $path ) ) {
51
+ continue;
52
+ }
53
+ unset( $paths[ $path_index ] );
54
+ break;
55
+ }
56
+ }
57
+ return $paths;
58
  }
59
  }
src/Conversion/Directory/DirectoriesIntegration.php CHANGED
@@ -107,10 +107,13 @@ class DirectoriesIntegration implements HookableInterface {
107
  * @internal
108
  */
109
  public function get_dir_as_path( $value, string $directory_type ): string {
110
- if ( isset( $this->directories[ $directory_type ] ) ) {
111
- return $this->directories[ $directory_type ]->get_server_path();
112
- } elseif ( ! ( $directory_name = apply_filters( 'webpc_dir_name', null, $directory_type ) ) ) {
113
- return $value;
 
 
 
114
  }
115
 
116
  $source_path = apply_filters( 'webpc_site_root', realpath( ABSPATH ) );
@@ -127,10 +130,13 @@ class DirectoriesIntegration implements HookableInterface {
127
  * @internal
128
  */
129
  public function get_dir_as_url( $value, string $directory_type ): string {
130
- if ( isset( $this->directories[ $directory_type ] ) ) {
131
- return $this->directories[ $directory_type ]->get_path_url();
132
- } elseif ( ! ( $directory_name = apply_filters( 'webpc_dir_name', null, $directory_type ) ) ) {
133
- return $value;
 
 
 
134
  }
135
 
136
  $source_url = apply_filters( 'webpc_site_url', get_site_url() );
107
  * @internal
108
  */
109
  public function get_dir_as_path( $value, string $directory_type ): string {
110
+ $directory_name = apply_filters( 'webpc_dir_name', '', $directory_type );
111
+ if ( $directory_name === '' ) {
112
+ if ( isset( $this->directories[ $directory_type ] ) ) {
113
+ return $this->directories[ $directory_type ]->get_server_path();
114
+ } else {
115
+ return $value;
116
+ }
117
  }
118
 
119
  $source_path = apply_filters( 'webpc_site_root', realpath( ABSPATH ) );
130
  * @internal
131
  */
132
  public function get_dir_as_url( $value, string $directory_type ): string {
133
+ $directory_name = apply_filters( 'webpc_dir_name', '', $directory_type );
134
+ if ( $directory_name === '' ) {
135
+ if ( isset( $this->directories[ $directory_type ] ) ) {
136
+ return $this->directories[ $directory_type ]->get_path_url();
137
+ } else {
138
+ return $value;
139
+ }
140
  }
141
 
142
  $source_url = apply_filters( 'webpc_site_url', get_site_url() );
src/Loader/PassthruLoader.php CHANGED
@@ -146,7 +146,7 @@ class PassthruLoader extends LoaderAbstract implements LoaderInterface {
146
  private function get_allowed_dirs( array $settings ): array {
147
  $dirs = [];
148
  foreach ( $settings['dirs'] as $dir ) {
149
- $dirs[] = apply_filters( 'webpc_dir_name', null, $dir );
150
  }
151
  return array_filter( $dirs );
152
  }
146
  private function get_allowed_dirs( array $settings ): array {
147
  $dirs = [];
148
  foreach ( $settings['dirs'] as $dir ) {
149
+ $dirs[] = apply_filters( 'webpc_dir_name', '', $dir );
150
  }
151
  return array_filter( $dirs );
152
  }
templates/components/widgets/options.php CHANGED
@@ -33,7 +33,7 @@
33
  echo wp_kses_post(
34
  sprintf(
35
  /* translators: %1$s: open anchor tag, %2$s: close anchor tag, %3$s: open anchor tag, %4$s: close anchor tag, %5$s: open anchor tag, %6$s: close anchor tag */
36
- __( 'If you have a problem %1$scheck our FAQ%2$s first. If you did not find help there, please %3$scheck support forum%2$s for any similar problem or contact us. Before you contact us, %5$scheck the configuration%6$s of your server.', 'webp-converter-for-media' ),
37
  '<a href="https://wordpress.org/plugins/webp-converter-for-media/#faq" target="_blank">',
38
  '</a>',
39
  '<a href="https://wordpress.org/support/plugin/webp-converter-for-media/" target="_blank">',
33
  echo wp_kses_post(
34
  sprintf(
35
  /* translators: %1$s: open anchor tag, %2$s: close anchor tag, %3$s: open anchor tag, %4$s: close anchor tag, %5$s: open anchor tag, %6$s: close anchor tag */
36
+ __( 'If you have a problem %1$scheck our FAQ%2$s first. If you did not find help there, please %3$scheck support forum%4$s for any similar problem or contact us. Before you contact us, %5$scheck the configuration%6$s of your server.', 'webp-converter-for-media' ),
37
  '<a href="https://wordpress.org/plugins/webp-converter-for-media/#faq" target="_blank">',
38
  '</a>',
39
  '<a href="https://wordpress.org/support/plugin/webp-converter-for-media/" target="_blank">',
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.0
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.0' );
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.1
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.1' );
14
  define( 'WEBPC_FILE', __FILE__ );
15
  define( 'WEBPC_NAME', plugin_basename( __FILE__ ) );
16
  define( 'WEBPC_PATH', plugin_dir_path( __FILE__ ) );