@@ -23,319 +23,319 @@ |
||
23 | 23 | */ |
24 | 24 | class CurrentPage |
25 | 25 | { |
26 | - /** |
|
27 | - * @var EE_CPT_Strategy |
|
28 | - */ |
|
29 | - private $cpt_strategy; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $initialized; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - private $is_espresso_page; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - private $post_id = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - private $post_name = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - private $post_type = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var RequestInterface $request |
|
58 | - */ |
|
59 | - private $request; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * CurrentPage constructor. |
|
64 | - * |
|
65 | - * @param EE_CPT_Strategy $cpt_strategy |
|
66 | - * @param RequestInterface $request |
|
67 | - */ |
|
68 | - public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->cpt_strategy = $cpt_strategy; |
|
71 | - $this->request = $request; |
|
72 | - $this->initialized = is_admin(); |
|
73 | - // analyse the incoming WP request |
|
74 | - add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param WP|null $WP |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function parseQueryVars(WP $WP = null) |
|
83 | - { |
|
84 | - if ($this->initialized) { |
|
85 | - return; |
|
86 | - } |
|
87 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | - if (! $WP instanceof WP) { |
|
89 | - global $WP; |
|
90 | - } |
|
91 | - $this->post_id = $this->getPostId($WP); |
|
92 | - $this->post_name = $this->getPostName($WP); |
|
93 | - $this->post_type = $this->getPostType($WP); |
|
94 | - // true or false ? is this page being used by EE ? |
|
95 | - $this->setEspressoPage(); |
|
96 | - remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | - $this->initialized = true; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Just a helper method for getting the url for the displayed page. |
|
103 | - * |
|
104 | - * @param WP|null $WP |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getPermalink(WP $WP = null): string |
|
108 | - { |
|
109 | - $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | - if ($post_id) { |
|
111 | - return get_permalink($post_id); |
|
112 | - } |
|
113 | - if (! $WP instanceof WP) { |
|
114 | - global $WP; |
|
115 | - } |
|
116 | - if ($WP instanceof WP && $WP->request) { |
|
117 | - return site_url($WP->request); |
|
118 | - } |
|
119 | - return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function espressoPostType(): array |
|
127 | - { |
|
128 | - return array_filter( |
|
129 | - $this->post_type, |
|
130 | - function ($post_type) { |
|
131 | - return strpos($post_type, 'espresso_') === 0; |
|
132 | - } |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | - * |
|
140 | - * @param WP|null $WP $WP |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - private function getPostId(WP $WP = null): ?int |
|
144 | - { |
|
145 | - $post_id = 0; |
|
146 | - if ($WP instanceof WP) { |
|
147 | - // look for the post ID in the aptly named 'p' query var |
|
148 | - if (isset($WP->query_vars['p'])) { |
|
149 | - $post_id = $WP->query_vars['p']; |
|
150 | - } |
|
151 | - // not a post? what about a page? |
|
152 | - if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
153 | - $post_id = $WP->query_vars['page_id']; |
|
154 | - } |
|
155 | - // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
156 | - // but hasn't been processed yet ie: this method is being called too early :\ |
|
157 | - if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
158 | - $post_id = basename($WP->request); |
|
159 | - } |
|
160 | - } |
|
161 | - // none of the above? ok what about an explicit "post_id" URL parameter? |
|
162 | - if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
163 | - $post_id = $this->request->getRequestParam('post_id'); |
|
164 | - } |
|
165 | - return $post_id; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
171 | - * |
|
172 | - * @param WP|null $WP $WP |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - private function getPostName(WP $WP = null): ?string |
|
176 | - { |
|
177 | - global $wpdb; |
|
178 | - $post_name = ''; |
|
179 | - if ($WP instanceof WP) { |
|
180 | - // if this is a post, then is the post name set? |
|
181 | - if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
182 | - $post_name = $WP->query_vars['name']; |
|
183 | - } |
|
184 | - // what about the page name? |
|
185 | - if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
186 | - $post_name = $WP->query_vars['pagename']; |
|
187 | - } |
|
188 | - // this stinks but let's run a query to try and get the post name from the URL |
|
189 | - // (assuming pretty permalinks are on) |
|
190 | - if (! $post_name && ! empty($WP->request)) { |
|
191 | - $possible_post_name = basename($WP->request); |
|
192 | - if (! is_numeric($possible_post_name)) { |
|
193 | - $SQL = "SELECT ID from {$wpdb->posts}"; |
|
194 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
195 | - $SQL .= ' AND post_name=%s'; |
|
196 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
197 | - if ($possible_post_name) { |
|
198 | - $post_name = $possible_post_name; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - // ug... ok... nothing yet... but do we have a post ID? |
|
204 | - // if so then... sigh... run a query to get the post name :\ |
|
205 | - if (! $post_name && $this->post_id) { |
|
206 | - $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
207 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
208 | - $SQL .= ' AND ID=%d'; |
|
209 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
210 | - if ($possible_post_name) { |
|
211 | - $post_name = $possible_post_name; |
|
212 | - } |
|
213 | - } |
|
214 | - // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
215 | - if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
216 | - $post_name = $this->request->getRequestParam('post_name'); |
|
217 | - } |
|
218 | - return $post_name; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * also similar to getPostId() and getPostName() above but not as insane |
|
224 | - * |
|
225 | - * @param WP|null $WP $WP |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - private function getPostType(WP $WP = null): array |
|
229 | - { |
|
230 | - $post_types = []; |
|
231 | - if ($WP instanceof WP) { |
|
232 | - $post_types = isset($WP->query_vars['post_type']) |
|
233 | - ? (array) $WP->query_vars['post_type'] |
|
234 | - : []; |
|
235 | - } |
|
236 | - if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
237 | - $post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true); |
|
238 | - } |
|
239 | - return (array) $post_types; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * if TRUE, then the current page is somehow utilizing EE logic |
|
245 | - * |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function isEspressoPage(): bool |
|
249 | - { |
|
250 | - if ($this->is_espresso_page === null) { |
|
251 | - $this->setEspressoPage(); |
|
252 | - } |
|
253 | - return $this->is_espresso_page; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @return int |
|
259 | - */ |
|
260 | - public function postId(): int |
|
261 | - { |
|
262 | - return $this->post_id; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function postName(): string |
|
270 | - { |
|
271 | - return $this->post_name; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return array |
|
277 | - */ |
|
278 | - public function postType(): array |
|
279 | - { |
|
280 | - return $this->post_type; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * for manually indicating the current page will utilize EE logic |
|
286 | - * |
|
287 | - * @param bool|int|string|null $value |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function setEspressoPage($value = null) |
|
291 | - { |
|
292 | - $this->is_espresso_page = $value !== null |
|
293 | - ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
294 | - : $this->testForEspressoPage(); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * attempts to determine if the current page/post is an EE related page/post |
|
300 | - * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
301 | - * |
|
302 | - * @return bool |
|
303 | - */ |
|
304 | - private function testForEspressoPage(): bool |
|
305 | - { |
|
306 | - // in case it has already been set |
|
307 | - if ($this->is_espresso_page) { |
|
308 | - return true; |
|
309 | - } |
|
310 | - global $WP; |
|
311 | - $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
312 | - if (is_array($espresso_CPT_taxonomies)) { |
|
313 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
314 | - if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
315 | - return true; |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
319 | - // load espresso CPT endpoints |
|
320 | - $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
321 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
322 | - foreach ($this->post_type as $post_type) { |
|
323 | - // was a post name passed ? |
|
324 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
325 | - // kk we know this is an espresso page, but is it a specific post ? |
|
326 | - if (! $this->post_name) { |
|
327 | - $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
328 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
329 | - // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
330 | - $post_name = $post_type_CPT_endpoints[ $espresso_post_type ] ?? ''; |
|
331 | - // if the post type matches one of ours then set the post name to the endpoint |
|
332 | - if ($post_name) { |
|
333 | - $this->post_name = $post_name; |
|
334 | - } |
|
335 | - } |
|
336 | - return true; |
|
337 | - } |
|
338 | - } |
|
339 | - return false; |
|
340 | - } |
|
26 | + /** |
|
27 | + * @var EE_CPT_Strategy |
|
28 | + */ |
|
29 | + private $cpt_strategy; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $initialized; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + private $is_espresso_page; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + private $post_id = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + private $post_name = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + private $post_type = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var RequestInterface $request |
|
58 | + */ |
|
59 | + private $request; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * CurrentPage constructor. |
|
64 | + * |
|
65 | + * @param EE_CPT_Strategy $cpt_strategy |
|
66 | + * @param RequestInterface $request |
|
67 | + */ |
|
68 | + public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->cpt_strategy = $cpt_strategy; |
|
71 | + $this->request = $request; |
|
72 | + $this->initialized = is_admin(); |
|
73 | + // analyse the incoming WP request |
|
74 | + add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param WP|null $WP |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function parseQueryVars(WP $WP = null) |
|
83 | + { |
|
84 | + if ($this->initialized) { |
|
85 | + return; |
|
86 | + } |
|
87 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | + if (! $WP instanceof WP) { |
|
89 | + global $WP; |
|
90 | + } |
|
91 | + $this->post_id = $this->getPostId($WP); |
|
92 | + $this->post_name = $this->getPostName($WP); |
|
93 | + $this->post_type = $this->getPostType($WP); |
|
94 | + // true or false ? is this page being used by EE ? |
|
95 | + $this->setEspressoPage(); |
|
96 | + remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | + $this->initialized = true; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Just a helper method for getting the url for the displayed page. |
|
103 | + * |
|
104 | + * @param WP|null $WP |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getPermalink(WP $WP = null): string |
|
108 | + { |
|
109 | + $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | + if ($post_id) { |
|
111 | + return get_permalink($post_id); |
|
112 | + } |
|
113 | + if (! $WP instanceof WP) { |
|
114 | + global $WP; |
|
115 | + } |
|
116 | + if ($WP instanceof WP && $WP->request) { |
|
117 | + return site_url($WP->request); |
|
118 | + } |
|
119 | + return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function espressoPostType(): array |
|
127 | + { |
|
128 | + return array_filter( |
|
129 | + $this->post_type, |
|
130 | + function ($post_type) { |
|
131 | + return strpos($post_type, 'espresso_') === 0; |
|
132 | + } |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | + * |
|
140 | + * @param WP|null $WP $WP |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + private function getPostId(WP $WP = null): ?int |
|
144 | + { |
|
145 | + $post_id = 0; |
|
146 | + if ($WP instanceof WP) { |
|
147 | + // look for the post ID in the aptly named 'p' query var |
|
148 | + if (isset($WP->query_vars['p'])) { |
|
149 | + $post_id = $WP->query_vars['p']; |
|
150 | + } |
|
151 | + // not a post? what about a page? |
|
152 | + if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
153 | + $post_id = $WP->query_vars['page_id']; |
|
154 | + } |
|
155 | + // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
156 | + // but hasn't been processed yet ie: this method is being called too early :\ |
|
157 | + if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
158 | + $post_id = basename($WP->request); |
|
159 | + } |
|
160 | + } |
|
161 | + // none of the above? ok what about an explicit "post_id" URL parameter? |
|
162 | + if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
163 | + $post_id = $this->request->getRequestParam('post_id'); |
|
164 | + } |
|
165 | + return $post_id; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
171 | + * |
|
172 | + * @param WP|null $WP $WP |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + private function getPostName(WP $WP = null): ?string |
|
176 | + { |
|
177 | + global $wpdb; |
|
178 | + $post_name = ''; |
|
179 | + if ($WP instanceof WP) { |
|
180 | + // if this is a post, then is the post name set? |
|
181 | + if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
182 | + $post_name = $WP->query_vars['name']; |
|
183 | + } |
|
184 | + // what about the page name? |
|
185 | + if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
186 | + $post_name = $WP->query_vars['pagename']; |
|
187 | + } |
|
188 | + // this stinks but let's run a query to try and get the post name from the URL |
|
189 | + // (assuming pretty permalinks are on) |
|
190 | + if (! $post_name && ! empty($WP->request)) { |
|
191 | + $possible_post_name = basename($WP->request); |
|
192 | + if (! is_numeric($possible_post_name)) { |
|
193 | + $SQL = "SELECT ID from {$wpdb->posts}"; |
|
194 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
195 | + $SQL .= ' AND post_name=%s'; |
|
196 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
197 | + if ($possible_post_name) { |
|
198 | + $post_name = $possible_post_name; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + // ug... ok... nothing yet... but do we have a post ID? |
|
204 | + // if so then... sigh... run a query to get the post name :\ |
|
205 | + if (! $post_name && $this->post_id) { |
|
206 | + $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
207 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
208 | + $SQL .= ' AND ID=%d'; |
|
209 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
210 | + if ($possible_post_name) { |
|
211 | + $post_name = $possible_post_name; |
|
212 | + } |
|
213 | + } |
|
214 | + // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
215 | + if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
216 | + $post_name = $this->request->getRequestParam('post_name'); |
|
217 | + } |
|
218 | + return $post_name; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * also similar to getPostId() and getPostName() above but not as insane |
|
224 | + * |
|
225 | + * @param WP|null $WP $WP |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + private function getPostType(WP $WP = null): array |
|
229 | + { |
|
230 | + $post_types = []; |
|
231 | + if ($WP instanceof WP) { |
|
232 | + $post_types = isset($WP->query_vars['post_type']) |
|
233 | + ? (array) $WP->query_vars['post_type'] |
|
234 | + : []; |
|
235 | + } |
|
236 | + if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
237 | + $post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true); |
|
238 | + } |
|
239 | + return (array) $post_types; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * if TRUE, then the current page is somehow utilizing EE logic |
|
245 | + * |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function isEspressoPage(): bool |
|
249 | + { |
|
250 | + if ($this->is_espresso_page === null) { |
|
251 | + $this->setEspressoPage(); |
|
252 | + } |
|
253 | + return $this->is_espresso_page; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @return int |
|
259 | + */ |
|
260 | + public function postId(): int |
|
261 | + { |
|
262 | + return $this->post_id; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function postName(): string |
|
270 | + { |
|
271 | + return $this->post_name; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return array |
|
277 | + */ |
|
278 | + public function postType(): array |
|
279 | + { |
|
280 | + return $this->post_type; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * for manually indicating the current page will utilize EE logic |
|
286 | + * |
|
287 | + * @param bool|int|string|null $value |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function setEspressoPage($value = null) |
|
291 | + { |
|
292 | + $this->is_espresso_page = $value !== null |
|
293 | + ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
294 | + : $this->testForEspressoPage(); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * attempts to determine if the current page/post is an EE related page/post |
|
300 | + * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
301 | + * |
|
302 | + * @return bool |
|
303 | + */ |
|
304 | + private function testForEspressoPage(): bool |
|
305 | + { |
|
306 | + // in case it has already been set |
|
307 | + if ($this->is_espresso_page) { |
|
308 | + return true; |
|
309 | + } |
|
310 | + global $WP; |
|
311 | + $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
312 | + if (is_array($espresso_CPT_taxonomies)) { |
|
313 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
314 | + if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
315 | + return true; |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | + // load espresso CPT endpoints |
|
320 | + $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
321 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
322 | + foreach ($this->post_type as $post_type) { |
|
323 | + // was a post name passed ? |
|
324 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
325 | + // kk we know this is an espresso page, but is it a specific post ? |
|
326 | + if (! $this->post_name) { |
|
327 | + $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
328 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
329 | + // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
330 | + $post_name = $post_type_CPT_endpoints[ $espresso_post_type ] ?? ''; |
|
331 | + // if the post type matches one of ours then set the post name to the endpoint |
|
332 | + if ($post_name) { |
|
333 | + $this->post_name = $post_name; |
|
334 | + } |
|
335 | + } |
|
336 | + return true; |
|
337 | + } |
|
338 | + } |
|
339 | + return false; |
|
340 | + } |
|
341 | 341 | } |
@@ -16,215 +16,215 @@ |
||
16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param RequestTypeContextCheckerInterface $type |
|
21 | - */ |
|
22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
19 | + /** |
|
20 | + * @param RequestTypeContextCheckerInterface $type |
|
21 | + */ |
|
22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function getParams(); |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function postParams(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function cookieParams(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function serverParams(); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param string $key |
|
51 | - * @param mixed|null $default |
|
52 | - * @return array|int|float|string |
|
53 | - */ |
|
54 | - public function getServerParam($key, $default = null); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $key |
|
59 | - * @param array|int|float|string $value |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function setServerParam($key, $value); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $key |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function serverParamIsSet($key); |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function filesParams(); |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * returns sanitized contents of $_REQUEST |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function requestParams(); |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $key |
|
88 | - * @param string $value |
|
89 | - * @param bool $override_ee |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function setRequestParam($key, $value, $override_ee = false); |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * returns the value for a request param if the given key exists |
|
97 | - * |
|
98 | - * @param string $key |
|
99 | - * @param mixed|null $default |
|
100 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
101 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
102 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
103 | - * @return array|bool|float|int|string |
|
104 | - */ |
|
105 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * check if param exists |
|
110 | - * |
|
111 | - * @param string $key |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - public function requestParamIsSet($key); |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
119 | - * and return the value for the first match found |
|
120 | - * wildcards can be either of the following: |
|
121 | - * ? to represent a single character of any type |
|
122 | - * * to represent one or more characters of any type |
|
123 | - * |
|
124 | - * @param string $pattern |
|
125 | - * @param mixed|null $default |
|
126 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
127 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
128 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
129 | - * @return array|bool|float|int|string |
|
130 | - */ |
|
131 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
136 | - * wildcards can be either of the following: |
|
137 | - * ? to represent a single character of any type |
|
138 | - * * to represent one or more characters of any type |
|
139 | - * returns true if a match is found or false if not |
|
140 | - * |
|
141 | - * @param string $pattern |
|
142 | - * @return false|int |
|
143 | - */ |
|
144 | - public function matches($pattern); |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * remove param |
|
149 | - * |
|
150 | - * @param string $key |
|
151 | - * @param bool $unset_from_global_too |
|
152 | - */ |
|
153 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * remove params |
|
158 | - * |
|
159 | - * @param array $keys |
|
160 | - * @param bool $unset_from_global_too |
|
161 | - */ |
|
162 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function ipAddress(); |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $relativeToWpRoot whether or not to return the uri relative to WordPress' home URL. |
|
173 | - * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function requestUri($relativeToWpRoot = false, $remove_query_params = false); |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function userAgent(); |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $user_agent |
|
187 | - */ |
|
188 | - public function setUserAgent($user_agent = ''); |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function isBot(); |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param bool $is_bot |
|
199 | - */ |
|
200 | - public function setIsBot($is_bot); |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
205 | - * |
|
206 | - * @return string |
|
207 | - * @since $VID:$ |
|
208 | - */ |
|
209 | - public function requestPath(); |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * returns true if the last segment of the current request path (without params) matches the provided string |
|
214 | - * |
|
215 | - * @param string $uri_segment |
|
216 | - * @return bool |
|
217 | - * @since $VID:$ |
|
218 | - */ |
|
219 | - public function currentPageIs($uri_segment); |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * merges the incoming array of parameters into the existing request parameters |
|
224 | - * |
|
225 | - * @param array $request_params |
|
226 | - * @return mixed |
|
227 | - * @since 4.10.24.p |
|
228 | - */ |
|
229 | - public function mergeRequestParams(array $request_params); |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function getParams(); |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function postParams(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function cookieParams(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function serverParams(); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param string $key |
|
51 | + * @param mixed|null $default |
|
52 | + * @return array|int|float|string |
|
53 | + */ |
|
54 | + public function getServerParam($key, $default = null); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $key |
|
59 | + * @param array|int|float|string $value |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function setServerParam($key, $value); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $key |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function serverParamIsSet($key); |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function filesParams(); |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * returns sanitized contents of $_REQUEST |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function requestParams(); |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $key |
|
88 | + * @param string $value |
|
89 | + * @param bool $override_ee |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function setRequestParam($key, $value, $override_ee = false); |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * returns the value for a request param if the given key exists |
|
97 | + * |
|
98 | + * @param string $key |
|
99 | + * @param mixed|null $default |
|
100 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
101 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
102 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
103 | + * @return array|bool|float|int|string |
|
104 | + */ |
|
105 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * check if param exists |
|
110 | + * |
|
111 | + * @param string $key |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + public function requestParamIsSet($key); |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
119 | + * and return the value for the first match found |
|
120 | + * wildcards can be either of the following: |
|
121 | + * ? to represent a single character of any type |
|
122 | + * * to represent one or more characters of any type |
|
123 | + * |
|
124 | + * @param string $pattern |
|
125 | + * @param mixed|null $default |
|
126 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
127 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
128 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
129 | + * @return array|bool|float|int|string |
|
130 | + */ |
|
131 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
136 | + * wildcards can be either of the following: |
|
137 | + * ? to represent a single character of any type |
|
138 | + * * to represent one or more characters of any type |
|
139 | + * returns true if a match is found or false if not |
|
140 | + * |
|
141 | + * @param string $pattern |
|
142 | + * @return false|int |
|
143 | + */ |
|
144 | + public function matches($pattern); |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * remove param |
|
149 | + * |
|
150 | + * @param string $key |
|
151 | + * @param bool $unset_from_global_too |
|
152 | + */ |
|
153 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * remove params |
|
158 | + * |
|
159 | + * @param array $keys |
|
160 | + * @param bool $unset_from_global_too |
|
161 | + */ |
|
162 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function ipAddress(); |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $relativeToWpRoot whether or not to return the uri relative to WordPress' home URL. |
|
173 | + * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function requestUri($relativeToWpRoot = false, $remove_query_params = false); |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function userAgent(); |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $user_agent |
|
187 | + */ |
|
188 | + public function setUserAgent($user_agent = ''); |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function isBot(); |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param bool $is_bot |
|
199 | + */ |
|
200 | + public function setIsBot($is_bot); |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
205 | + * |
|
206 | + * @return string |
|
207 | + * @since $VID:$ |
|
208 | + */ |
|
209 | + public function requestPath(); |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * returns true if the last segment of the current request path (without params) matches the provided string |
|
214 | + * |
|
215 | + * @param string $uri_segment |
|
216 | + * @return bool |
|
217 | + * @since $VID:$ |
|
218 | + */ |
|
219 | + public function currentPageIs($uri_segment); |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * merges the incoming array of parameters into the existing request parameters |
|
224 | + * |
|
225 | + * @param array $request_params |
|
226 | + * @return mixed |
|
227 | + * @since 4.10.24.p |
|
228 | + */ |
|
229 | + public function mergeRequestParams(array $request_params); |
|
230 | 230 | } |