# image-optimization/1.6.6/modules/backups/components/restore-images.php

Image Optimizer – Compress Images and Convert to WebP or AVIF, version 1.6.6. 45 lines.

- Page: https://pluginprobe.com/plugins/image-optimization/1.6.6/code/modules/backups/components/restore-images.php
- Raw: https://pluginprobe.com/plugins/image-optimization/1.6.6/raw/modules/backups/components/restore-images.php
- Modified: 2024-02-06T14:05:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/image-optimization/1.6.6/code/modules/backups/components/restore-images.php#L10-L20`.

```php
<?php

namespace ImageOptimization\Modules\Backups\Components;

use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook;
use ImageOptimization\Classes\Image\{
	Image_Meta,
	Image_Restore,
	Image_Status,
};

use ImageOptimization\Classes\Logger;
use Throwable;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Restore_Images {
	/** @async */
	public function restore_image( int $image_id ) {
		try {
			Image_Restore::restore( $image_id );
		} catch ( Throwable $t ) {
			Logger::log( Logger::LEVEL_ERROR, 'Image restoring error: ' . $t->getMessage() );

			( new Image_Meta( $image_id ) )
				->set_status( Image_Status::RESTORING_FAILED )
				->save();

			throw $t;
		}
	}

	/** @async */
	public function restore_many_images( array $attachment_ids ) {
		Image_Restore::restore_many( $attachment_ids );
	}

	public function __construct() {
		add_action( Async_Operation_Hook::RESTORE_SINGLE_IMAGE, [ $this, 'restore_image' ] );
		add_action( Async_Operation_Hook::RESTORE_MANY_IMAGES, [ $this, 'restore_many_images' ] );
	}
}

```
