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

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

78 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 ImageOptimization\Classes\Async_Operation\Queries;
4
5 use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook;
6 use ImageOptimization\Classes\Async_Operation\Interfaces\Operation_Query_Interface;
7 use TypeError;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Operation_Query implements Operation_Query_Interface {
14 private array $query;
15
16 public function set_hook( string $hook ): self {
17 if ( ! in_array( $hook, Async_Operation_Hook::get_values(), true ) ) {
18 throw new TypeError( "Hook $hook is not a part of Async_Operation_Hook values" );
19 }
20
21 $this->query['hook'] = $hook;
22
23 return $this;
24 }
25
26 /**
27 * @param string|array $status
28 * @return $this
29 */
30 public function set_status( $status ): self {
31 $this->query['status'] = $status;
32
33 return $this;
34 }
35
36 public function set_image_id( int $image_id ): self {
37 $this->query['args']['attachment_id'] = $image_id;
38
39 return $this;
40 }
41
42 public function set_limit( int $limit ): self {
43 $this->query['per_page'] = $limit;
44
45 return $this;
46 }
47
48 public function get_return_type(): string {
49 return $this->query['_return_type'];
50 }
51
52 public function return_ids(): self {
53 $this->query['_return_type'] = 'ids';
54
55 return $this;
56 }
57
58 public function get_query(): array {
59 $clone = $this->query;
60
61 if ( empty( $clone['args'] ) ) {
62 unset( $clone['args'] );
63 }
64
65 return $clone;
66 }
67
68 public function __construct() {
69 $this->query = [
70 'args' => [],
71 'per_page' => 10,
72 'orderby' => 'date',
73 'order' => 'DESC',
74 '_return_type' => 'object',
75 ];
76 }
77 }
78