PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
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 1.6.6 All 32 releases
image-optimization / modules / backups / classes / remove-all-backups.php

remove-all-backups.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/backups/classes/remove-all-backups.php

36 lines 818 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Backups\Classes;
4
5 use ImageOptimization\Classes\Async_Operation\{
6 Async_Operation,
7 Async_Operation_Hook,
8 Async_Operation_Queue,
9 };
10 use ImageOptimization\Classes\Image\Image_Query_Builder;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class Remove_All_Backups {
17 private const CHUNK_SIZE = 100;
18
19 public static function find_and_schedule_removing(): void {
20 $query = ( new Image_Query_Builder() )
21 ->return_images_only_with_backups()
22 ->execute();
23
24 $attachment_ids = $query->posts;
25 $chunks = array_chunk( $attachment_ids, self::CHUNK_SIZE );
26
27 foreach ( $chunks as $chunk ) {
28 Async_Operation::create(
29 Async_Operation_Hook::REMOVE_MANY_BACKUPS,
30 [ 'attachment_ids' => $chunk ],
31 Async_Operation_Queue::BACKUP
32 );
33 }
34 }
35 }
36