PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.5.4
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.5.4
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / webp / class-wpo-webp-convert-image-task.php

class-wpo-webp-convert-image-task.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.5.4, at webp/class-wpo-webp-convert-image-task.php

46 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('Access denied.');
4
5 if (!class_exists('Updraft_Task_1_2')) require_once(WPO_PLUGIN_MAIN_PATH . 'vendor/team-updraft/common-libs/src/updraft-tasks/class-updraft-task.php');
6
7 if (!class_exists('WPO_Webp_Convert_Image_Task')) :
8
9 class WPO_Webp_Convert_Image_Task extends Updraft_Task_1_2 {
10
11 /**
12 * Default options.
13 */
14 public function get_default_options() {
15 return array();
16 }
17
18 /**
19 * Run webp conversion for compressed images
20 *
21 * @return bool
22 */
23 public function run() {
24 $blog_id = $this->get_option('blog_id');
25 $attachment_id = $this->get_option('attachment_id');
26 $source = $this->get_option('attachment_source');
27
28 if (is_multisite()) switch_to_blog($blog_id);
29 $images = WPO_Image_Utils::get_attachment_files($attachment_id);
30 $images['original'] = $source;
31
32 foreach ($images as $image) {
33 WPO_WebP_Utils::do_webp_conversion($image);
34 }
35
36 $destination = WPO_WebP_Utils::get_destination_path($source);
37 if (file_exists($destination)) {
38 update_post_meta($attachment_id, 'wpo-webp-conversion-complete', true);
39 }
40
41 if (is_multisite()) restore_current_blog();
42 return true;
43 }
44 }
45 endif;
46