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

Version Description

(2021-01-31) = * [Fixed] Encoding paths to files * [Fixed] Retaining PNG transparency using Gd method * [Added] Cron to convert images uploaded to Media Library

Download this release

Release Info

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

Code changes from version 2.2.0 to 2.3.0

app/Convert/Dir.php CHANGED
@@ -31,7 +31,7 @@
31
  foreach ($paths as $path) {
32
  if (in_array($path, $excludedDirs)) continue;
33
 
34
- $currentPath = $dirPath . '/' . $path;
35
  if (is_dir($currentPath)) {
36
  $list = array_merge($list, $this->findFilesInDirectory($currentPath, $allowedExts, $excludedDirs));
37
  } else if (in_array(strtolower(pathinfo($currentPath, PATHINFO_EXTENSION)), $allowedExts)) {
31
  foreach ($paths as $path) {
32
  if (in_array($path, $excludedDirs)) continue;
33
 
34
+ $currentPath = $dirPath . '/' . urlencode($path);
35
  if (is_dir($currentPath)) {
36
  $list = array_merge($list, $this->findFilesInDirectory($currentPath, $allowedExts, $excludedDirs));
37
  } else if (in_array(strtolower(pathinfo($currentPath, PATHINFO_EXTENSION)), $allowedExts)) {
app/Media/Upload.php CHANGED
@@ -25,8 +25,8 @@
25
 
26
  $paths = array_diff($paths, $this->convertedPaths);
27
  $this->convertedPaths = array_merge($this->convertedPaths, $paths);
 
28
 
29
- do_action('webpc_convert_paths', $paths);
30
  return $data;
31
  }
32
 
@@ -50,4 +50,15 @@
50
  $source = str_replace('\\', '/', $source);
51
  return $source;
52
  }
 
 
 
 
 
 
 
 
 
 
 
53
  }
25
 
26
  $paths = array_diff($paths, $this->convertedPaths);
27
  $this->convertedPaths = array_merge($this->convertedPaths, $paths);
28
+ $this->initConversion($paths);
29
 
 
30
  return $data;
31
  }
32
 
50
  $source = str_replace('\\', '/', $source);
51
  return $source;
52
  }
53
+
54
+ private function initConversion($paths)
55
+ {
56
+ $settings = apply_filters('webpc_get_values', []);
57
+
58
+ if (in_array('cron_conversion', $settings['features'])) {
59
+ wp_schedule_single_event((time() + 1), 'webpc_convert_paths', [$paths]);
60
+ } else {
61
+ do_action('webpc_convert_paths', $paths);
62
+ }
63
+ }
64
  }
app/Method/Gd.php CHANGED
@@ -52,10 +52,10 @@
52
  throw $e;
53
  }
54
 
55
- return $this->updateImageResource($image);
56
  }
57
 
58
- private function updateImageResource($image)
59
  {
60
  if (!function_exists('imageistruecolor')) {
61
  $e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imageistruecolor'));
@@ -72,6 +72,24 @@
72
  imagepalettetotruecolor($image);
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  return $image;
76
  }
77
 
52
  throw $e;
53
  }
54
 
55
+ return $this->updateImageResource($image, $extension);
56
  }
57
 
58
+ private function updateImageResource($image, $extension)
59
  {
60
  if (!function_exists('imageistruecolor')) {
61
  $e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imageistruecolor'));
72
  imagepalettetotruecolor($image);
73
  }
74
 
75
+ switch ($extension) {
76
+ case 'png':
77
+ if (!function_exists('imagealphablending')) {
78
+ $e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imagealphablending'));
79
+ $e->status = 'server_configuration';
80
+ throw $e;
81
+ }
82
+ imagealphablending($image, false);
83
+
84
+ if (!function_exists('imagesavealpha')) {
85
+ $e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imagesavealpha'));
86
+ $e->status = 'server_configuration';
87
+ throw $e;
88
+ }
89
+ imagesavealpha($image, true);
90
+ break;
91
+ }
92
+
93
  return $image;
94
  }
95
 
app/Method/MethodAbstract.php CHANGED
@@ -56,13 +56,14 @@
56
 
57
  public function getImageSourcePath($sourcePath)
58
  {
59
- if (!$status = Server::checkIfFileExists($sourcePath)) {
60
- $e = new \Exception(sprintf('Source path "%s" for image does not exist.', $sourcePath));
 
61
  $e->status = 'file_unreadable';
62
  throw $e;
63
  }
64
 
65
- return $sourcePath;
66
  }
67
 
68
  public function getImageOutputPath($sourcePath)
56
 
57
  public function getImageSourcePath($sourcePath)
58
  {
59
+ $path = urldecode($sourcePath);
60
+ if (!$status = Server::checkIfFileExists($path)) {
61
+ $e = new \Exception(sprintf('Source path "%s" for image does not exist.', $path));
62
  $e->status = 'file_unreadable';
63
  throw $e;
64
  }
65
 
66
+ return $path;
67
  }
68
 
69
  public function getImageOutputPath($sourcePath)
app/Settings/Options.php CHANGED
@@ -97,6 +97,7 @@
97
  'mod_expires' => __('Browser Caching for WebP files (saving images in browser cache memory)', 'webp-converter-for-media'),
98
  'keep_metadata' => __('Keep images metadata stored in EXIF or XMP formats (only available for Imagick conversion method)', 'webp-converter-for-media'),
99
  'cron_enabled' => __('Enable cron to automatically convert images from outside Media Library (images from Media Library are converted immediately after upload)', 'webp-converter-for-media'),
 
100
  'referer_disabled' => __('Force redirections to WebP for all domains (by default, images in WebP are loaded only in domain of your website - when image is displayed via URL on another domain that original file is loaded)', 'webp-converter-for-media'),
101
  'debug_enabled' => __('Log errors while converting to debug.log file (when debugging in WordPress is active)', 'webp-converter-for-media'),
102
  ],
97
  'mod_expires' => __('Browser Caching for WebP files (saving images in browser cache memory)', 'webp-converter-for-media'),
98
  'keep_metadata' => __('Keep images metadata stored in EXIF or XMP formats (only available for Imagick conversion method)', 'webp-converter-for-media'),
99
  'cron_enabled' => __('Enable cron to automatically convert images from outside Media Library (images from Media Library are converted immediately after upload)', 'webp-converter-for-media'),
100
+ 'cron_conversion' => __('Enable cron to convert images uploaded to Media Library to speed up process of adding images (deactivate this option if images added to Media Library are not automatically converted)', 'webp-converter-for-media'),
101
  'referer_disabled' => __('Force redirections to WebP for all domains (by default, images in WebP are loaded only in domain of your website - when image is displayed via URL on another domain that original file is loaded)', 'webp-converter-for-media'),
102
  'debug_enabled' => __('Log errors while converting to debug.log file (when debugging in WordPress is active)', 'webp-converter-for-media'),
103
  ],
app/Settings/Values.php CHANGED
@@ -25,7 +25,7 @@
25
  'extensions' => ['jpg', 'jpeg', 'png'],
26
  'dirs' => ['uploads'],
27
  'method' => ($methods) ? $methods[0] : '',
28
- 'features' => ['only_smaller', 'mod_expires', 'debug_enabled'],
29
  'quality' => 85,
30
  ]);
31
  return $this->cache;
25
  'extensions' => ['jpg', 'jpeg', 'png'],
26
  'dirs' => ['uploads'],
27
  'method' => ($methods) ? $methods[0] : '',
28
+ 'features' => ['only_smaller', 'mod_expires', 'cron_conversion', 'debug_enabled'],
29
  'quality' => 85,
30
  ]);
31
  return $this->cache;
public/build/js/scripts.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="/",r(r.s=0)}([function(t,e,r){r(1),t.exports=r(2)},function(t,e,r){"use strict";function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r.r(e);var i=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setVars()&&this.setEvents()}var e,r,i;return e=t,(r=[{key:"setVars",value:function(){if(this.buttonOpen=document.querySelector('[data-slug="webp-converter-for-media"] a[href*="action=deactivate"]'),this.modal=document.querySelector(".webpModal"),this.buttonOpen&&this.modal)return this.outer=this.modal.querySelector(".webpModal__outer"),this.form=this.outer.querySelector(".webpModal__form"),this.formOptions=this.form.querySelectorAll('[name="webpc_reason"]'),this.formComment=this.form.querySelector('[name="webpc_comment"]'),this.buttonSubmit=this.form.querySelector('button[type="submit"]'),this.buttonCancel=this.form.querySelector('button[type="button"]'),this.events={openModal:this.openModal.bind(this)},this.atts={optionPlaceholder:"data-placeholder"},!0}},{key:"setEvents",value:function(){var t=this;this.buttonOpen.addEventListener("click",this.events.openModal),this.buttonSubmit.addEventListener("click",this.submitForm.bind(this)),this.buttonCancel.addEventListener("click",this.cancelForm.bind(this)),this.outer.addEventListener("click",this.closeModal.bind(this)),this.form.addEventListener("click",(function(t){t.stopPropagation()}));for(var e=this.formOptions.length,r=function(e){t.formOptions[e].addEventListener("change",(function(){t.setCurrentOption(e)}))},n=0;n<e;n++)r(n)}},{key:"openModal",value:function(t){t.preventDefault(),this.buttonOpen.removeEventListener("click",this.events.openModal),this.modal.removeAttribute("hidden")}},{key:"closeModal",value:function(){this.modal.setAttribute("hidden","hidden")}},{key:"submitForm",value:function(t){var e=this;t.preventDefault(),this.closeModal(),setTimeout((function(){var t=new FormData(e.form),r=e.form.getAttribute("action"),n=new XMLHttpRequest;n.open("POST",r,!0),n.send(t),e.buttonOpen.click()}),0)}},{key:"cancelForm",value:function(t){var e=this;t.preventDefault(),this.closeModal(),setTimeout((function(){e.buttonOpen.click()}),0)}},{key:"setCurrentOption",value:function(t){this.formComment.value="";var e=this.formOptions[t].getAttribute(this.atts.optionPlaceholder);this.formComment.setAttribute("placeholder",e)}}])&&n(e.prototype,r),i&&n(e,i),t}();function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var o=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setVars()&&this.setEvents()}var e,r,n;return e=t,(r=[{key:"setVars",value:function(){if(this.notice=document.querySelector(".notice[data-notice=webp-converter]"),this.notice)return this.settings={isHidden:!1,ajaxUrl:this.notice.getAttribute("data-url")},!0}},{key:"setEvents",value:function(){window.addEventListener("load",this.getButtons.bind(this))}},{key:"getButtons",value:function(){this.buttonClose=this.notice.querySelector(".notice-dismiss"),this.buttonPermanently=this.notice.querySelector("[data-permanently]"),this.setButtonsEvents()}},{key:"setButtonsEvents",value:function(){var t=this;this.buttonClose.addEventListener("click",(function(){t.hideNotice(!1)})),this.buttonPermanently.addEventListener("click",(function(e){e.preventDefault(),t.hideNotice(!0)}))}},{key:"hideNotice",value:function(t){this.settings.isHidden||(this.settings.isHidden=!0,jQuery.ajax(this.settings.ajaxUrl,{type:"POST",data:{action:"webpc_notice",is_permanently:t?1:0}}),this.buttonClose.click())}}])&&s(e.prototype,r),n&&s(e,n),t}();function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var u=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setVars()&&this.setEvents()}var e,r,n;return e=t,(r=[{key:"setVars",value:function(){if(this.section=document.querySelector(".webpLoader"),this.section)return this.wrapper=this.section.querySelector(".webpLoader__status"),this.progress=this.wrapper.querySelector(".webpLoader__barProgress"),this.progressSize=this.section.querySelector(".webpLoader__sizeProgress"),this.errors=this.section.querySelector(".webpLoader__errors"),this.errorsInner=this.errors.querySelector(".webpLoader__errorsContentList"),this.errorsMessage=this.errors.querySelector(".webpLoader__errorsContentMessage"),this.success=this.section.querySelector(".webpLoader__success"),this.succesPopup=this.section.querySelector(".webpLoader__popup"),this.inputOptions=this.section.querySelectorAll('input[type="checkbox"]'),this.button=this.section.querySelector(".webpLoader__button"),this.data={count:0,max:0,items:[],size:{before:0,after:0},errors:[]},this.settings={isDisabled:!1,ajax:{urlPaths:this.section.getAttribute("data-api-paths"),urlRegenerate:this.section.getAttribute("data-api-regenerate"),errorMessage:this.section.getAttribute("data-api-error-message")},units:["kB","MB","GB"]},this.atts={progress:"data-percent"},this.classes={progressError:"webpLoader__barProgress--error",buttonDisabled:"webpLoader__button--disabled"},!0}},{key:"setEvents",value:function(){this.button.addEventListener("click",this.initRegenerate.bind(this))}},{key:"initRegenerate",value:function(t){if(t.preventDefault(),!this.settings.isDisabled){this.settings.isDisabled=!0,this.button.classList.add(this.classes.buttonDisabled);for(var e=this.inputOptions.length,r=0;r<e;r++)this.inputOptions[r].setAttribute("disabled",!0);this.wrapper.removeAttribute("hidden"),this.getImagesList()}}},{key:"getImagesList",value:function(){var t=this;jQuery.ajax(this.settings.ajax.urlPaths,{type:"POST",data:this.getDataForPathsRequest()}).done((function(e){t.data.items=e,t.data.max=e.length,t.regenerateNextImages()})).fail((function(){t.progress.classList.add(t.classes.progressError),t.errorsMessage.removeAttribute("hidden"),t.errors.removeAttribute("hidden")}))}},{key:"getDataForPathsRequest",value:function(){for(var t={},e=this.inputOptions.length,r=0;r<e;r++)t[this.inputOptions[r].getAttribute("name")]=this.inputOptions[r].checked?1:0;return t}},{key:"regenerateNextImages",value:function(){if(0===this.data.max&&this.updateProgress(),!(this.data.count>=this.data.max)){var t=this.data.items[this.data.count];this.data.count++,this.sendRequest(t)}}},{key:"sendRequest",value:function(t){var e=this;jQuery.ajax(this.settings.ajax.urlRegenerate,{type:"POST",data:{paths:t}}).done((function(t){e.updateErrors(t.errors),e.updateSize(t),e.updateProgress(),e.regenerateNextImages()})).fail((function(){var r=JSON.stringify(t),n=e.settings.ajax.errorMessage.replace("%s","<code>".concat(r,"</code>"));e.updateErrors([n]),e.regenerateNextImages()}))}},{key:"updateErrors",value:function(t){0!==t.length&&(this.data.errors=this.data.errors.concat(t),this.errorsInner.innerHTML=this.data.errors.join("<br>"),this.errors.removeAttribute("hidden"))}},{key:"updateSize",value:function(t){var e=this.data.size;e.before+=t.size.before,e.after+=t.size.after;var r=e.before-e.after;if(r<0&&(r=0),0!==r){var n=Math.round(100*(1-e.after/e.before));n<0&&(n=0);var i=-1;do{i++,r/=1024}while(r>1024);var s=r.toFixed(2),o=this.settings.units[i],a="".concat(s," ").concat(o," (").concat(n,"%)");this.progressSize.innerHTML=a}}},{key:"updateProgress",value:function(){var t=this.data.max>0?Math.floor(this.data.count/this.data.max*100):100;t>100&&(t=100),100===t&&(this.success.removeAttribute("hidden"),this.succesPopup.removeAttribute("hidden")),this.progress.setAttribute(this.atts.progress,t)}}])&&a(e.prototype,r),n&&a(e,n),t}();new function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),new i,new o,new u}},function(t,e){}]);
1
+ !function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s=0)}([function(e,t,r){r(1),e.exports=r(2)},function(e,t,r){"use strict";function s(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}r.r(t);var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,i;return t=e,(r=[{key:"setVars",value:function(){if(this.buttonOpen=document.querySelector('[data-slug="webp-converter-for-media"] a[href*="action=deactivate"]'),this.modal=document.querySelector(".webpModal"),this.buttonOpen&&this.modal)return this.outer=this.modal.querySelector(".webpModal__outer"),this.form=this.outer.querySelector(".webpModal__form"),this.formOptions=this.form.querySelectorAll('[name="webpc_reason"]'),this.formComment=this.form.querySelector('[name="webpc_comment"]'),this.buttonSubmit=this.form.querySelector('button[type="submit"]'),this.buttonCancel=this.form.querySelector('button[type="button"]'),this.events={openModal:this.openModal.bind(this)},this.atts={optionPlaceholder:"data-placeholder"},!0}},{key:"setEvents",value:function(){var e=this;this.buttonOpen.addEventListener("click",this.events.openModal),this.buttonSubmit.addEventListener("click",this.submitForm.bind(this)),this.buttonCancel.addEventListener("click",this.cancelForm.bind(this)),this.outer.addEventListener("click",this.closeModal.bind(this)),this.form.addEventListener("click",(function(e){e.stopPropagation()}));for(var t=this.formOptions.length,r=function(t){e.formOptions[t].addEventListener("change",(function(){e.setCurrentOption(t)}))},s=0;s<t;s++)r(s)}},{key:"openModal",value:function(e){e.preventDefault(),this.buttonOpen.removeEventListener("click",this.events.openModal),this.modal.removeAttribute("hidden")}},{key:"closeModal",value:function(){this.modal.setAttribute("hidden","hidden")}},{key:"submitForm",value:function(e){var t=this;e.preventDefault(),this.closeModal(),setTimeout((function(){var e=new FormData(t.form),r=t.form.getAttribute("action"),s=new XMLHttpRequest;s.open("POST",r,!0),s.send(e),t.buttonOpen.click()}),0)}},{key:"cancelForm",value:function(e){var t=this;e.preventDefault(),this.closeModal(),setTimeout((function(){t.buttonOpen.click()}),0)}},{key:"setCurrentOption",value:function(e){this.formComment.value="";var t=this.formOptions[e].getAttribute(this.atts.optionPlaceholder);this.formComment.setAttribute("placeholder",t)}}])&&s(t.prototype,r),i&&s(t,i),e}();function n(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,s;return t=e,(r=[{key:"setVars",value:function(){if(this.notice=document.querySelector(".notice[data-notice=webp-converter]"),this.notice)return this.settings={ajaxUrl:this.notice.getAttribute("data-url"),ajaxAction:"webpc_notice",buttonCloseClass:".notice[data-notice=webp-converter] .notice-dismiss",buttonHideClass:".notice[data-notice=webp-converter] [data-permanently]"},this.status={isHidden:!1},!0}},{key:"setEvents",value:function(){var e=this,t=this.settings,r=t.buttonCloseClass,s=t.buttonHideClass;window.addEventListener("click",(function(t){t.target.matches(r)?e.hideNotice(!1):t.target.matches(s)&&(t.preventDefault(),e.hideNotice(!0))}))}},{key:"hideNotice",value:function(e){if(!this.status.isHidden){this.status.isHidden=!0;var t=this.settings,r=t.ajaxUrl,s=t.ajaxAction,i=t.buttonCloseClass;jQuery.ajax(r,{type:"POST",data:{action:s,is_permanently:e?1:0}}),document.querySelector(i).click()}}}])&&n(t.prototype,r),s&&n(t,s),e}();function a(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}var u=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,s;return t=e,(r=[{key:"setVars",value:function(){if(this.section=document.querySelector(".webpLoader"),this.section)return this.wrapper=this.section.querySelector(".webpLoader__status"),this.progress=this.wrapper.querySelector(".webpLoader__barProgress"),this.progressSize=this.section.querySelector(".webpLoader__sizeProgress"),this.errors=this.section.querySelector(".webpLoader__errors"),this.errorsInner=this.errors.querySelector(".webpLoader__errorsContentList"),this.errorsMessage=this.errors.querySelector(".webpLoader__errorsContentMessage"),this.success=this.section.querySelector(".webpLoader__success"),this.succesPopup=this.section.querySelector(".webpLoader__popup"),this.inputOptions=this.section.querySelectorAll('input[type="checkbox"]'),this.button=this.section.querySelector(".webpLoader__button"),this.data={count:0,max:0,items:[],size:{before:0,after:0},errors:[]},this.settings={isDisabled:!1,ajax:{urlPaths:this.section.getAttribute("data-api-paths"),urlRegenerate:this.section.getAttribute("data-api-regenerate"),errorMessage:this.section.getAttribute("data-api-error-message")},units:["kB","MB","GB"]},this.atts={progress:"data-percent"},this.classes={progressError:"webpLoader__barProgress--error",buttonDisabled:"webpLoader__button--disabled"},!0}},{key:"setEvents",value:function(){this.button.addEventListener("click",this.initRegenerate.bind(this))}},{key:"initRegenerate",value:function(e){if(e.preventDefault(),!this.settings.isDisabled){this.settings.isDisabled=!0,this.button.classList.add(this.classes.buttonDisabled);for(var t=this.inputOptions.length,r=0;r<t;r++)this.inputOptions[r].setAttribute("disabled",!0);this.wrapper.removeAttribute("hidden"),this.getImagesList()}}},{key:"getImagesList",value:function(){var e=this;jQuery.ajax(this.settings.ajax.urlPaths,{type:"POST",data:this.getDataForPathsRequest()}).done((function(t){e.data.items=t,e.data.max=t.length,e.regenerateNextImages()})).fail((function(){e.progress.classList.add(e.classes.progressError),e.errorsMessage.removeAttribute("hidden"),e.errors.removeAttribute("hidden")}))}},{key:"getDataForPathsRequest",value:function(){for(var e={},t=this.inputOptions.length,r=0;r<t;r++)e[this.inputOptions[r].getAttribute("name")]=this.inputOptions[r].checked?1:0;return e}},{key:"regenerateNextImages",value:function(){if(0===this.data.max&&this.updateProgress(),!(this.data.count>=this.data.max)){var e=this.data.items[this.data.count];this.data.count++,this.sendRequest(e)}}},{key:"sendRequest",value:function(e){var t=this;jQuery.ajax(this.settings.ajax.urlRegenerate,{type:"POST",data:{paths:e}}).done((function(e){t.updateErrors(e.errors),t.updateSize(e),t.updateProgress(),t.regenerateNextImages()})).fail((function(){var r=JSON.stringify(e),s=t.settings.ajax.errorMessage.replace("%s","<code>".concat(r,"</code>"));t.updateErrors([s]),t.regenerateNextImages()}))}},{key:"updateErrors",value:function(e){0!==e.length&&(this.data.errors=this.data.errors.concat(e),this.errorsInner.innerHTML=this.data.errors.join("<br>"),this.errors.removeAttribute("hidden"))}},{key:"updateSize",value:function(e){var t=this.data.size;t.before+=e.size.before,t.after+=e.size.after;var r=t.before-t.after;if(r<0&&(r=0),0!==r){var s=Math.round(100*(1-t.after/t.before));s<0&&(s=0);var i=-1;do{i++,r/=1024}while(r>1024);var n=r.toFixed(2),o=this.settings.units[i],a="".concat(n," ").concat(o," (").concat(s,"%)");this.progressSize.innerHTML=a}}},{key:"updateProgress",value:function(){var e=this.data.max>0?Math.floor(this.data.count/this.data.max*100):100;e>100&&(e=100),100===e&&(this.success.removeAttribute("hidden"),this.succesPopup.removeAttribute("hidden")),this.progress.setAttribute(this.atts.progress,e)}}])&&a(t.prototype,r),s&&a(t,s),e}();new function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),new i,new o,new u}},function(e,t){}]);
readme.txt CHANGED
@@ -477,12 +477,18 @@ This is all very important to us and allows us to do even better things for you!
477
 
478
  == Screenshots ==
479
 
480
- 1. Screenshot of the options panel
481
- 2. Screenshot when regenerating images
 
482
 
483
  == Changelog ==
484
 
485
- = 2.2.0 (2020-01-13) =
 
 
 
 
 
486
  * `[Added]` Support for WordPress Multisite
487
 
488
  = 2.1.3 (2020-12-28) =
477
 
478
  == Screenshots ==
479
 
480
+ 1. How to start using plugin few moments?
481
+ 2. Screenshot of the options panel
482
+ 3. Screenshot when regenerating images
483
 
484
  == Changelog ==
485
 
486
+ = 2.3.0 (2021-01-31) =
487
+ * `[Fixed]` Encoding paths to files
488
+ * `[Fixed]` Retaining PNG transparency using Gd method
489
+ * `[Added]` Cron to convert images uploaded to Media Library
490
+
491
+ = 2.2.0 (2021-01-13) =
492
  * `[Added]` Support for WordPress Multisite
493
 
494
  = 2.1.3 (2020-12-28) =
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: 2.2.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', '2.2.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: 2.3.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', '2.3.0');
14
  define('WEBPC_FILE', __FILE__);
15
  define('WEBPC_NAME', plugin_basename(__FILE__));
16
  define('WEBPC_PATH', plugin_dir_path(__FILE__));