PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 28.3, at src/bulk-editor/domain/posts/posts-query.php

163 lines 3.5 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 constructor.
58 *
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.
65 */
66 public function __construct(
67 string $content_type,
68 int $page,
69 int $per_page,
70 string $search,
71 array $statuses,
72 ?int $author_id = null
73 ) {
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;
80 }
81
82 /**
83 * Returns the content type to get posts for.
84 *
85 * @return string The content type.
86 */
87 public function get_content_type(): string {
88 return $this->content_type;
89 }
90
91 /**
92 * Returns the page of results to get.
93 *
94 * @return int The page, starting at 1.
95 */
96 public function get_page(): int {
97 return $this->page;
98 }
99
100 /**
101 * Returns the number of posts per page.
102 *
103 * @return int The number of posts per page.
104 */
105 public function get_per_page(): int {
106 return $this->per_page;
107 }
108
109 /**
110 * Returns the search term.
111 *
112 * @return string The search term, or an empty string for no search.
113 */
114 public function get_search(): string {
115 return $this->search;
116 }
117
118 /**
119 * Returns whether a search term is set.
120 *
121 * @return bool Whether a search term is set.
122 */
123 public function has_search(): bool {
124 return $this->search !== '';
125 }
126
127 /**
128 * Returns the post statuses to include.
129 *
130 * @return array<string> The post statuses.
131 */
132 public function get_statuses(): array {
133 return $this->statuses;
134 }
135
136 /**
137 * Returns the author to limit posts to.
138 *
139 * @return int|null The author ID, or null for no author restriction.
140 */
141 public function get_author_id(): ?int {
142 return $this->author_id;
143 }
144
145 /**
146 * Returns whether posts are limited to a single author.
147 *
148 * @return bool Whether an author restriction is set.
149 */
150 public function has_author_filter(): bool {
151 return $this->author_id !== null;
152 }
153
154 /**
155 * Returns the zero-based offset of the requested page.
156 *
157 * @return int The offset.
158 */
159 public function get_offset(): int {
160 return ( ( $this->page - 1 ) * $this->per_page );
161 }
162 }
163