| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Optimization\Components; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use ImageOptimization\Modules\Backups\Classes\Restore_Images; |
| 10 |
use ImageOptimization\Modules\Optimization\Classes\Single_Optimization as Single_Optimization_Controller; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Admin_Bulk_Actions { |
| 17 |
public function add_bulk_actions( array $bulk_actions ): array { |
| 18 |
$bulk_actions['image-optimization-optimize'] = esc_html__( 'Optimize', 'image-optimization' ); |
| 19 |
$bulk_actions['image-optimization-restore'] = esc_html__( 'Restore original', 'image-optimization' ); |
| 20 |
|
| 21 |
return $bulk_actions; |
| 22 |
} |
| 23 |
|
| 24 |
public function handle_bulk_actions( $redirect_url, $action, $post_ids ): string { |
| 25 |
if ( 'image-optimization-optimize' === $action ) { |
| 26 |
Single_Optimization_Controller::optimize_many( $post_ids ); |
| 27 |
} |
| 28 |
|
| 29 |
if ( 'image-optimization-restore' === $action ) { |
| 30 |
Restore_Images::find_and_schedule_restoring( $post_ids ); |
| 31 |
} |
| 32 |
|
| 33 |
return $redirect_url; |
| 34 |
} |
| 35 |
|
| 36 |
public function __construct() { |
| 37 |
add_filter( 'bulk_actions-upload', [ $this, 'add_bulk_actions' ] ); |
| 38 |
add_filter( 'handle_bulk_actions-upload', [ $this, 'handle_bulk_actions' ], 10, 3 ); |
| 39 |
} |
| 40 |
} |
| 41 |
|