| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Backups\Components; |
| 4 |
|
| 5 |
use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook; |
| 6 |
use ImageOptimization\Classes\Image\Image_Backup; |
| 7 |
use WP_Post; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Handle_Backups_Removing { |
| 14 |
public function remove_backups_on_attachment_removing( int $attachment_id, WP_Post $attachment_post ) { |
| 15 |
if ( ! wp_attachment_is_image( $attachment_post ) ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
Image_Backup::remove( $attachment_id ); |
| 20 |
} |
| 21 |
|
| 22 |
/** @async */ |
| 23 |
public function remove_many_backups( array $attachment_ids ) { |
| 24 |
Image_Backup::remove_many( $attachment_ids ); |
| 25 |
} |
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
add_action( 'delete_attachment', [ $this, 'remove_backups_on_attachment_removing' ], 10, 2 ); |
| 29 |
add_action( Async_Operation_Hook::REMOVE_MANY_BACKUPS, [ $this, 'remove_many_backups' ] ); |
| 30 |
} |
| 31 |
} |
| 32 |
|