PluginProbe ʕ •ᴥ•ʔ
Core Web Vitals & PageSpeed Booster / 1.0.25
Core Web Vitals & PageSpeed Booster v1.0.25
trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.7.1 1.0.7.2 1.0.8 1.0.9
core-web-vitals-pagespeed-booster / includes / helper-section.php
core-web-vitals-pagespeed-booster / includes Last commit date
admin 1 year ago cache 1 year ago css 1 year ago images 1 year ago javascript 1 year ago vendor 1 year ago class-cwvpsb-treeshaking.php 1 year ago cwvpsb_iframe.css 2 years ago cwvpsb_iframe.js 4 years ago functions.php 1 year ago gravatar.php 1 year ago helper-section.php 2 years ago
helper-section.php
48 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class Core_Web_Vital_Helper_Section{
7 static function convert_to_webp($filename){
8 $source = $filename;
9 $upload = wp_upload_dir();
10 $destinationPath = $upload['basedir']."/cwv-webp-images";
11 if(!is_dir($destinationPath)) { wp_mkdir_p($destinationPath); }
12 $destination = str_replace($upload['basedir'], $destinationPath, $filename).".webp";
13 try {
14 require_once CWVPSB_PLUGIN_DIR."/includes/vendor/autoload.php";
15 $convertOptions = [];
16 \WebPConvert\WebPConvert::convert($source, $destination, $convertOptions);
17 } catch (\WebpConvert\Exceptions\WebPConvertException $e) {
18 if(function_exists('error_log')){ error_log($e->getMessage()); }
19 } catch (\Exception $e) {
20 $message = 'An exception was thrown!';
21 if(function_exists('error_log')){ error_log($e->getMessage()); }
22 }
23 }
24
25
26 static function do_upload_with_webp($filearray, $overrides = false, $ignore = false){
27 if (isset($filearray['file'])) {
28 try {
29 $filename = $filearray['file'];
30 $allowedMimeTypes = [];
31 $allowedMimeTypes[] = 'image/jpeg';
32 $allowedMimeTypes[] = 'image/png';
33
34 if(isset($filearray['type']) && ($filearray['type'] == 'image/svg+xml' || $filearray['type'] == 'image/webp')){
35 return $filearray;
36 }
37
38 if (!in_array(wp_get_image_mime($filename), $allowedMimeTypes)) {
39 return $filearray;
40 }
41 self::convert_to_webp($filename);
42 } catch (Exception $e) {
43 if(function_exists('error_log')){ error_log($e->getMessage()); }
44 }
45 }
46 return $filearray;
47 }
48 }