PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / bulk-editor / domain / posts / posts-query.php

posts-query.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/bulk-editor/domain/posts/posts-query.php

231 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Bulk_Editor\Domain\Posts;
5
6 /**
7 * Describes a request for a page of bulk editor posts.
8 *
9 * Carries every parameter the collectors need so new filters (status, quality) can be added
10 * to this object instead of growing the collector method signatures.
11 */
12 class Posts_Query {
13
14 /**
15 * The content type to get posts for.
16 *
17 * @var string
18 */
19 private $content_type;
20
21 /**
22 * The page of results to get, starting at 1.
23 *
24 * @var int
25 */
26 private $page;
27
28 /**
29 * The number of posts per page.
30 *
31 * @var int
32 */
33 private $per_page;
34
35 /**
36 * The search term to filter posts by, or an empty string for no search.
37 *
38 * @var string
39 */
40 private $search;
41
42 /**
43 * The post statuses to include.
44 *
45 * @var array<string>
46 */
47 private $statuses;
48
49 /**
50 * The author to limit posts to, or null for no author restriction.
51 *
52 * @var int|null
53 */
54 private $author_id;
55
56 /**
57 * The needs-improvement fields to filter by — a field matches when empty, or (for search fields with SEO
58 * analysis enabled) when its per-field score needs improvement — or an empty array for no such filter.
59 *
60 * @var array<string>
61 */
62 private $needs_improvement;
63
64 /**
65 * Whether the per-field scores may back the needs-improvement filter. False when SEO analysis is
66 * disabled, so the filter falls back to the empty-field check only.
67 *
68 * @var bool
69 */
70 private $scores_enabled;
71
72 /**
73 * The post IDs to limit posts to, or an empty array for no restriction.
74 *
75 * @var array<int>
76 */
77 private $include_ids;
78
79 /**
80 * The constructor.
81 *
82 * @param string $content_type The content type to get posts for.
83 * @param int $page The page of results to get, starting at 1.
84 * @param int $per_page The number of posts per page.
85 * @param string $search The search term, or an empty string for no search.
86 * @param array<string> $statuses The post statuses to include.
87 * @param int|null $author_id The author to limit posts to, or null for no author restriction.
88 * @param array<string> $needs_improvement The needs-improvement fields to filter by (a field matches when empty, or — for search fields with SEO analysis enabled — when its per-field score needs improvement), or an empty array for no such filter.
89 * @param bool $scores_enabled Whether the per-field scores may back the needs-improvement filter.
90 * @param array<int> $include_ids The post IDs to limit posts to, or an empty array for no restriction.
91 */
92 public function __construct(
93 string $content_type,
94 int $page,
95 int $per_page,
96 string $search,
97 array $statuses,
98 ?int $author_id = null,
99 array $needs_improvement = [],
100 bool $scores_enabled = true,
101 array $include_ids = []
102 ) {
103 $this->content_type = $content_type;
104 $this->page = $page;
105 $this->per_page = $per_page;
106 $this->search = $search;
107 $this->statuses = $statuses;
108 $this->author_id = $author_id;
109 $this->needs_improvement = $needs_improvement;
110 $this->scores_enabled = $scores_enabled;
111 $this->include_ids = $include_ids;
112 }
113
114 /**
115 * Returns the content type to get posts for.
116 *
117 * @return string The content type.
118 */
119 public function get_content_type(): string {
120 return $this->content_type;
121 }
122
123 /**
124 * Returns the page of results to get.
125 *
126 * @return int The page, starting at 1.
127 */
128 public function get_page(): int {
129 return $this->page;
130 }
131
132 /**
133 * Returns the number of posts per page.
134 *
135 * @return int The number of posts per page.
136 */
137 public function get_per_page(): int {
138 return $this->per_page;
139 }
140
141 /**
142 * Returns the search term.
143 *
144 * @return string The search term, or an empty string for no search.
145 */
146 public function get_search(): string {
147 return $this->search;
148 }
149
150 /**
151 * Returns whether a search term is set.
152 *
153 * @return bool Whether a search term is set.
154 */
155 public function has_search(): bool {
156 return $this->search !== '';
157 }
158
159 /**
160 * Returns the post statuses to include.
161 *
162 * @return array<string> The post statuses.
163 */
164 public function get_statuses(): array {
165 return $this->statuses;
166 }
167
168 /**
169 * Returns the fields that must be empty for a post to be included.
170 *
171 * @return array<string> The fields, or an empty array for no such filter.
172 */
173 public function get_needs_improvement(): array {
174 return $this->needs_improvement;
175 }
176
177 /**
178 * Returns whether the per-field scores may back the needs-improvement filter.
179 *
180 * @return bool Whether the scores may be used; false falls back to the empty-field check only.
181 */
182 public function are_scores_enabled(): bool {
183 return $this->scores_enabled;
184 }
185
186 /**
187 * Returns the author to limit posts to.
188 *
189 * @return int|null The author ID, or null for no author restriction.
190 */
191 public function get_author_id(): ?int {
192 return $this->author_id;
193 }
194
195 /**
196 * Returns whether posts are limited to a single author.
197 *
198 * @return bool Whether an author restriction is set.
199 */
200 public function has_author_filter(): bool {
201 return $this->author_id !== null;
202 }
203
204 /**
205 * Returns the post IDs to limit posts to.
206 *
207 * @return array<int> The post IDs, or an empty array for no restriction.
208 */
209 public function get_include_ids(): array {
210 return $this->include_ids;
211 }
212
213 /**
214 * Returns whether posts are limited to specific post IDs.
215 *
216 * @return bool Whether a post ID restriction is set.
217 */
218 public function has_include(): bool {
219 return $this->include_ids !== [];
220 }
221
222 /**
223 * Returns the zero-based offset of the requested page.
224 *
225 * @return int The offset.
226 */
227 public function get_offset(): int {
228 return ( ( $this->page - 1 ) * $this->per_page );
229 }
230 }
231