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