PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.0.0
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.0.0
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 / optimization / components / admin-bulk-actions.php

admin-bulk-actions.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.0.0, at modules/optimization/components/admin-bulk-actions.php

37 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimizer\Modules\Optimization\Components;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 use ImageOptimizer\Modules\Backups\Classes\Restore_Images;
10 use ImageOptimizer\Modules\Optimization\Classes\Single_Optimization as Single_Optimization_Controller;
11
12 class Admin_Bulk_Actions {
13 public function add_bulk_actions( array $bulk_actions ): array {
14 $bulk_actions['image-optimizer-optimize'] = esc_html__( 'Optimize', 'image-optimizer' );
15 $bulk_actions['image-optimizer-restore'] = esc_html__( 'Restore original', 'image-optimizer' );
16
17 return $bulk_actions;
18 }
19
20 public function handle_bulk_actions( $redirect_url, $action, $post_ids ): string {
21 if ( 'image-optimizer-optimize' === $action ) {
22 Single_Optimization_Controller::optimize_many( $post_ids );
23 }
24
25 if ( 'image-optimizer-restore' === $action ) {
26 Restore_Images::find_and_schedule_restoring( $post_ids );
27 }
28
29 return $redirect_url;
30 }
31
32 public function __construct() {
33 add_filter( 'bulk_actions-upload', [ $this, 'add_bulk_actions' ] );
34 add_filter( 'handle_bulk_actions-upload', [ $this, 'handle_bulk_actions' ], 10, 3 );
35 }
36 }
37