PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.0.2
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.0.2
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 / classes / async-operation / queries / operation-query.php

operation-query.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.0.2, at classes/async-operation/queries/operation-query.php

74 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimizer\Classes\Async_Operation\Queries;
4
5 use ImageOptimizer\Classes\Async_Operation\Async_Operation_Hook;
6 use ImageOptimizer\Classes\Async_Operation\Interfaces\Operation_Query_Interface;
7 use TypeError;
8
9 class Operation_Query implements Operation_Query_Interface {
10 private array $query;
11
12 public function set_hook( string $hook ): self {
13 if ( ! in_array( $hook, Async_Operation_Hook::get_values(), true ) ) {
14 throw new TypeError( "Hook $hook is not a part of Async_Operation_Hook values" );
15 }
16
17 $this->query['hook'] = $hook;
18
19 return $this;
20 }
21
22 /**
23 * @param string|array $status
24 * @return $this
25 */
26 public function set_status( $status ): self {
27 $this->query['status'] = $status;
28
29 return $this;
30 }
31
32 public function set_image_id( int $image_id ): self {
33 $this->query['args']['attachment_id'] = $image_id;
34
35 return $this;
36 }
37
38 public function set_limit( int $limit ): self {
39 $this->query['per_page'] = $limit;
40
41 return $this;
42 }
43
44 public function get_return_type(): string {
45 return $this->query['_return_type'];
46 }
47
48 public function return_ids(): self {
49 $this->query['_return_type'] = 'ids';
50
51 return $this;
52 }
53
54 public function get_query(): array {
55 $clone = $this->query;
56
57 if ( empty( $clone['args'] ) ) {
58 unset( $clone['args'] );
59 }
60
61 return $clone;
62 }
63
64 public function __construct() {
65 $this->query = [
66 'args' => [],
67 'per_page' => 10,
68 'orderby' => 'date',
69 'order' => 'DESC',
70 '_return_type' => 'object',
71 ];
72 }
73 }
74