| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace ImageOptimizer\Classes\Image; | |
| 3 | +namespace ImageOptimization\Classes\Image; | |
| 4 | 4 | |
| 5 | 5 | use WP_Query; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -32,13 +32,43 @@ | ||
| 32 | 32 | 'compare' => 'LIKE', |
| 33 | 33 | 'value' => '-failed";', |
| 34 | 34 | 'key' => Image_Meta::IMAGE_OPTIMIZER_METADATA_KEY, |
| 35 | 35 | ], |
| 36 | + [ | |
| 37 | + 'compare' => 'LIKE', | |
| 38 | + 'value' => ':"not-optimized";', | |
| 39 | + 'key' => Image_Meta::IMAGE_OPTIMIZER_METADATA_KEY, | |
| 40 | + ], | |
| 36 | 41 | ]; |
| 37 | 42 | |
| 38 | 43 | return $this; |
| 39 | 44 | } |
| 40 | 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 | + | |
| 41 | 71 | public function return_optimized_images(): self { |
| 42 | 72 | $this->query['meta_query'][] = [ |
| 43 | 73 | 'compare' => 'LIKE', |
| 44 | 74 | 'value' => '"status";s:9:"optimized"', |
| @@ -47,8 +77,17 @@ | ||
| 47 | 77 | |
| 48 | 78 | return $this; |
| 49 | 79 | } |
| 50 | 80 | |
| 81 | + public function return_images_with_non_empty_meta(): self { | |
| 82 | + $this->query['meta_query'][] = [ | |
| 83 | + 'key' => Image_Meta::IMAGE_OPTIMIZER_METADATA_KEY, | |
| 84 | + 'compare' => 'EXISTS', | |
| 85 | + ]; | |
| 86 | + | |
| 87 | + return $this; | |
| 88 | + } | |
| 89 | + | |
| 51 | 90 | public function set_paging_size( int $paging_size ): self { |
| 52 | 91 | $this->query['posts_per_page'] = $paging_size; |
| 53 | 92 | |
| 54 | 93 | return $this; |
| @@ -60,9 +99,16 @@ | ||
| 60 | 99 | return $this; |
| 61 | 100 | } |
| 62 | 101 | |
| 63 | 102 | public function set_image_ids( array $image_ids ): self { |
| 64 | - $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 ]; | |
| 105 | + | |
| 106 | + return $this; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function set_mime_types( array $mime_types ): self { | |
| 110 | + $this->query['post_mime_type'] = $mime_types; | |
| 65 | 111 | |
| 66 | 112 | return $this; |
| 67 | 113 | } |
| 68 | 114 | |