PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.6.6
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / backups / components / restore-images.php

restore-images.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/backups/components/restore-images.php

45 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Backups\Components;
4
5 use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook;
6 use ImageOptimization\Classes\Image\{
7 Image_Meta,
8 Image_Restore,
9 Image_Status,
10 };
11
12 use ImageOptimization\Classes\Logger;
13 use Throwable;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 class Restore_Images {
20 /** @async */
21 public function restore_image( int $image_id ) {
22 try {
23 Image_Restore::restore( $image_id );
24 } catch ( Throwable $t ) {
25 Logger::log( Logger::LEVEL_ERROR, 'Image restoring error: ' . $t->getMessage() );
26
27 ( new Image_Meta( $image_id ) )
28 ->set_status( Image_Status::RESTORING_FAILED )
29 ->save();
30
31 throw $t;
32 }
33 }
34
35 /** @async */
36 public function restore_many_images( array $attachment_ids ) {
37 Image_Restore::restore_many( $attachment_ids );
38 }
39
40 public function __construct() {
41 add_action( Async_Operation_Hook::RESTORE_SINGLE_IMAGE, [ $this, 'restore_image' ] );
42 add_action( Async_Operation_Hook::RESTORE_MANY_IMAGES, [ $this, 'restore_many_images' ] );
43 }
44 }
45