| @@ -53,16 +53,42 @@ | ||
| 53 | 53 | */ |
| 54 | 54 | private $author_id; |
| 55 | 55 | |
| 56 | 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 | + /** | |
| 57 | 80 | * The constructor. |
| 58 | 81 | * |
| 59 | - * @param string $content_type The content type to get posts for. | |
| 60 | - * @param int $page The page of results to get, starting at 1. | |
| 61 | - * @param int $per_page The number of posts per page. | |
| 62 | - * @param string $search The search term, or an empty string for no search. | |
| 63 | - * @param array<string> $statuses The post statuses to include. | |
| 64 | - * @param int|null $author_id The author to limit posts to, or null for no author restriction. | |
| 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. | |
| 65 | 91 | */ |
| 66 | 92 | public function __construct( |
| 67 | 93 | string $content_type, |
| 68 | 94 | int $page, |
| @@ -68,16 +94,22 @@ | ||
| 68 | 94 | int $page, |
| 69 | 95 | int $per_page, |
| 70 | 96 | string $search, |
| 71 | 97 | array $statuses, |
| 72 | - ?int $author_id = null | |
| 98 | + ?int $author_id = null, | |
| 99 | + array $needs_improvement = [], | |
| 100 | + bool $scores_enabled = true, | |
| 101 | + array $include_ids = [] | |
| 73 | 102 | ) { |
| 74 | - $this->content_type = $content_type; | |
| 75 | - $this->page = $page; | |
| 76 | - $this->per_page = $per_page; | |
| 77 | - $this->search = $search; | |
| 78 | - $this->statuses = $statuses; | |
| 79 | - $this->author_id = $author_id; | |
| 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; | |
| 80 | 112 | } |
| 81 | 113 | |
| 82 | 114 | /** |
| 83 | 115 | * Returns the content type to get posts for. |
| @@ -133,8 +165,26 @@ | ||
| 133 | 165 | return $this->statuses; |
| 134 | 166 | } |
| 135 | 167 | |
| 136 | 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 | + /** | |
| 137 | 187 | * Returns the author to limit posts to. |
| 138 | 188 | * |
| 139 | 189 | * @return int|null The author ID, or null for no author restriction. |
| 140 | 190 | */ |
| @@ -148,8 +198,26 @@ | ||
| 148 | 198 | * @return bool Whether an author restriction is set. |
| 149 | 199 | */ |
| 150 | 200 | public function has_author_filter(): bool { |
| 151 | 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 !== []; | |
| 152 | 220 | } |
| 153 | 221 | |
| 154 | 222 | /** |
| 155 | 223 | * Returns the zero-based offset of the requested page. |