| @@ -42,8 +42,33 @@ | ||
| 42 | 42 | |
| 43 | 43 | return $this; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | + public function return_optimization_in_progress_images(): self { | |
| 47 | + $this->query['meta_query'][] = [ | |
| 48 | + 'relation' => 'AND', | |
| 49 | + [ | |
| 50 | + 'key' => '_wp_attachment_metadata', | |
| 51 | + 'compare' => 'EXISTS', | |
| 52 | + ], | |
| 53 | + [ | |
| 54 | + 'relation' => 'OR', | |
| 55 | + [ | |
| 56 | + 'compare' => 'LIKE', | |
| 57 | + 'value' => 'optimization-in-progress";', | |
| 58 | + 'key' => 'image_optimizer_metadata', | |
| 59 | + ], | |
| 60 | + [ | |
| 61 | + 'compare' => 'LIKE', | |
| 62 | + 'value' => 'reoptimizing-in-progress";', | |
| 63 | + 'key' => 'image_optimizer_metadata', | |
| 64 | + ], | |
| 65 | + ], | |
| 66 | + ]; | |
| 67 | + | |
| 68 | + return $this; | |
| 69 | + } | |
| 70 | + | |
| 46 | 71 | public function return_optimized_images(): self { |
| 47 | 72 | $this->query['meta_query'][] = [ |
| 48 | 73 | 'compare' => 'LIKE', |
| 49 | 74 | 'value' => '"status";s:9:"optimized"', |
| @@ -74,9 +99,10 @@ | ||
| 74 | 99 | return $this; |
| 75 | 100 | } |
| 76 | 101 | |
| 77 | 102 | public function set_image_ids( array $image_ids ): self { |
| 78 | - $this->query['post__in'] = $image_ids; | |
| 103 | + // Passing an empty array to post__in will return the last posts instead of an empty result. | |
| 104 | + $this->query['post__in'] = count( $image_ids ) ? $image_ids : [ 0 ]; | |
| 79 | 105 | |
| 80 | 106 | return $this; |
| 81 | 107 | } |
| 82 | 108 | |