| 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 |
|