@@ -28,336 +28,336 @@ |
||
28 | 28 | class PersistentAdminNotice implements RequiresCapCheckInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var string $name |
|
33 | - */ |
|
34 | - protected $name = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $message |
|
38 | - */ |
|
39 | - protected $message = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var boolean $force_update |
|
43 | - */ |
|
44 | - protected $force_update = false; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $capability |
|
48 | - */ |
|
49 | - protected $capability = 'manage_options'; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string $cap_context |
|
53 | - */ |
|
54 | - protected $cap_context = 'view persistent admin notice'; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var boolean $dismissed |
|
58 | - */ |
|
59 | - protected $dismissed = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var CapCheckInterface $cap_check |
|
63 | - */ |
|
64 | - protected $cap_check; |
|
65 | - |
|
66 | - /** |
|
67 | - * if true, then this notice will be deleted from the database |
|
68 | - * |
|
69 | - * @var boolean $purge |
|
70 | - */ |
|
71 | - protected $purge = false; |
|
72 | - |
|
73 | - /** |
|
74 | - * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
75 | - * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
76 | - * |
|
77 | - * @var boolean $registered |
|
78 | - */ |
|
79 | - private $registered = false; |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * PersistentAdminNotice constructor |
|
85 | - * |
|
86 | - * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
87 | - * @param string $message [required] the message to be stored persistently until dismissed |
|
88 | - * @param bool $force_update enforce the reappearance of a persistent message |
|
89 | - * @param string $capability user capability required to view this notice |
|
90 | - * @param string $cap_context description for why the cap check is being performed |
|
91 | - * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - */ |
|
94 | - public function __construct( |
|
95 | - $name, |
|
96 | - $message, |
|
97 | - $force_update = false, |
|
98 | - $capability = 'manage_options', |
|
99 | - $cap_context = 'view persistent admin notice', |
|
100 | - $dismissed = false |
|
101 | - ) { |
|
102 | - $this->setName($name); |
|
103 | - $this->setMessage($message); |
|
104 | - $this->setForceUpdate($force_update); |
|
105 | - $this->setCapability($capability); |
|
106 | - $this->setCapContext($cap_context); |
|
107 | - $this->setDismissed($dismissed); |
|
108 | - add_action( |
|
109 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
110 | - array($this, 'registerPersistentAdminNotice') |
|
111 | - ); |
|
112 | - add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getName() |
|
121 | - { |
|
122 | - return $this->name; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $name |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - private function setName($name) |
|
132 | - { |
|
133 | - if (! is_string($name)) { |
|
134 | - throw new InvalidDataTypeException('$name', $name, 'string'); |
|
135 | - } |
|
136 | - $this->name = sanitize_key($name); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function getMessage() |
|
145 | - { |
|
146 | - return $this->message; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $message |
|
153 | - * @throws InvalidDataTypeException |
|
154 | - */ |
|
155 | - private function setMessage($message) |
|
156 | - { |
|
157 | - if (! is_string($message)) { |
|
158 | - throw new InvalidDataTypeException('$message', $message, 'string'); |
|
159 | - } |
|
160 | - global $allowedtags; |
|
161 | - $allowedtags['br'] = array(); |
|
162 | - $this->message = wp_kses($message, $allowedtags); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function getForceUpdate() |
|
171 | - { |
|
172 | - return $this->force_update; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param bool $force_update |
|
179 | - */ |
|
180 | - private function setForceUpdate($force_update) |
|
181 | - { |
|
182 | - $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function getCapability() |
|
191 | - { |
|
192 | - return $this->capability; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string $capability |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - */ |
|
201 | - private function setCapability($capability) |
|
202 | - { |
|
203 | - if (! is_string($capability)) { |
|
204 | - throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
205 | - } |
|
206 | - $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
207 | - } |
|
31 | + /** |
|
32 | + * @var string $name |
|
33 | + */ |
|
34 | + protected $name = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $message |
|
38 | + */ |
|
39 | + protected $message = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var boolean $force_update |
|
43 | + */ |
|
44 | + protected $force_update = false; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $capability |
|
48 | + */ |
|
49 | + protected $capability = 'manage_options'; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string $cap_context |
|
53 | + */ |
|
54 | + protected $cap_context = 'view persistent admin notice'; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var boolean $dismissed |
|
58 | + */ |
|
59 | + protected $dismissed = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var CapCheckInterface $cap_check |
|
63 | + */ |
|
64 | + protected $cap_check; |
|
65 | + |
|
66 | + /** |
|
67 | + * if true, then this notice will be deleted from the database |
|
68 | + * |
|
69 | + * @var boolean $purge |
|
70 | + */ |
|
71 | + protected $purge = false; |
|
72 | + |
|
73 | + /** |
|
74 | + * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
75 | + * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
76 | + * |
|
77 | + * @var boolean $registered |
|
78 | + */ |
|
79 | + private $registered = false; |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * PersistentAdminNotice constructor |
|
85 | + * |
|
86 | + * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
87 | + * @param string $message [required] the message to be stored persistently until dismissed |
|
88 | + * @param bool $force_update enforce the reappearance of a persistent message |
|
89 | + * @param string $capability user capability required to view this notice |
|
90 | + * @param string $cap_context description for why the cap check is being performed |
|
91 | + * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + */ |
|
94 | + public function __construct( |
|
95 | + $name, |
|
96 | + $message, |
|
97 | + $force_update = false, |
|
98 | + $capability = 'manage_options', |
|
99 | + $cap_context = 'view persistent admin notice', |
|
100 | + $dismissed = false |
|
101 | + ) { |
|
102 | + $this->setName($name); |
|
103 | + $this->setMessage($message); |
|
104 | + $this->setForceUpdate($force_update); |
|
105 | + $this->setCapability($capability); |
|
106 | + $this->setCapContext($cap_context); |
|
107 | + $this->setDismissed($dismissed); |
|
108 | + add_action( |
|
109 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
110 | + array($this, 'registerPersistentAdminNotice') |
|
111 | + ); |
|
112 | + add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getName() |
|
121 | + { |
|
122 | + return $this->name; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $name |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + private function setName($name) |
|
132 | + { |
|
133 | + if (! is_string($name)) { |
|
134 | + throw new InvalidDataTypeException('$name', $name, 'string'); |
|
135 | + } |
|
136 | + $this->name = sanitize_key($name); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function getMessage() |
|
145 | + { |
|
146 | + return $this->message; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $message |
|
153 | + * @throws InvalidDataTypeException |
|
154 | + */ |
|
155 | + private function setMessage($message) |
|
156 | + { |
|
157 | + if (! is_string($message)) { |
|
158 | + throw new InvalidDataTypeException('$message', $message, 'string'); |
|
159 | + } |
|
160 | + global $allowedtags; |
|
161 | + $allowedtags['br'] = array(); |
|
162 | + $this->message = wp_kses($message, $allowedtags); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + public function getForceUpdate() |
|
171 | + { |
|
172 | + return $this->force_update; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param bool $force_update |
|
179 | + */ |
|
180 | + private function setForceUpdate($force_update) |
|
181 | + { |
|
182 | + $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public function getCapability() |
|
191 | + { |
|
192 | + return $this->capability; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param string $capability |
|
199 | + * @throws InvalidDataTypeException |
|
200 | + */ |
|
201 | + private function setCapability($capability) |
|
202 | + { |
|
203 | + if (! is_string($capability)) { |
|
204 | + throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
205 | + } |
|
206 | + $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
207 | + } |
|
208 | 208 | |
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function getCapContext() |
|
215 | - { |
|
216 | - return $this->cap_context; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $cap_context |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - */ |
|
225 | - private function setCapContext($cap_context) |
|
226 | - { |
|
227 | - if (! is_string($cap_context)) { |
|
228 | - throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
229 | - } |
|
230 | - $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - public function getDismissed() |
|
239 | - { |
|
240 | - return $this->dismissed; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param bool $dismissed |
|
247 | - */ |
|
248 | - public function setDismissed($dismissed) |
|
249 | - { |
|
250 | - $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @return CapCheckInterface |
|
257 | - * @throws InvalidDataTypeException |
|
258 | - */ |
|
259 | - public function getCapCheck() |
|
260 | - { |
|
261 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
262 | - $this->setCapCheck( |
|
263 | - new CapCheck( |
|
264 | - $this->capability, |
|
265 | - $this->cap_context |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
269 | - return $this->cap_check; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param CapCheckInterface $cap_check |
|
276 | - */ |
|
277 | - private function setCapCheck(CapCheckInterface $cap_check) |
|
278 | - { |
|
279 | - $this->cap_check = $cap_check; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @return bool |
|
286 | - */ |
|
287 | - public function getPurge() |
|
288 | - { |
|
289 | - return $this->purge; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param bool $purge |
|
296 | - */ |
|
297 | - public function setPurge($purge) |
|
298 | - { |
|
299 | - $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * given a valid PersistentAdminNotice Collection, |
|
306 | - * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
307 | - * if an existing notice is found that has already been dismissed, |
|
308 | - * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
309 | - * so that the notice is displayed again |
|
310 | - * |
|
311 | - * @param Collection $persistent_admin_notice_collection |
|
312 | - * @throws InvalidEntityException |
|
313 | - * @throws InvalidDataTypeException |
|
314 | - */ |
|
315 | - public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
316 | - { |
|
317 | - if ($this->registered) { |
|
318 | - return; |
|
319 | - } |
|
320 | - // first check if this notice has already been added to the collection |
|
321 | - if ($persistent_admin_notice_collection->has($this->name)) { |
|
322 | - /** @var PersistentAdminNotice $existing */ |
|
323 | - $existing = $persistent_admin_notice_collection->get($this->name); |
|
324 | - // we don't need to add it again (we can't actually) |
|
325 | - // but if it has already been dismissed, and we are overriding with a forced update |
|
326 | - if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
327 | - // then toggle the notice's dismissed state to true |
|
328 | - // so that it gets displayed again |
|
329 | - $existing->setDismissed(false); |
|
330 | - // and make sure the message is set |
|
331 | - $existing->setMessage($this->message); |
|
332 | - } |
|
333 | - } else { |
|
334 | - $persistent_admin_notice_collection->add($this, $this->name); |
|
335 | - } |
|
336 | - $this->registered = true; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @throws Exception |
|
343 | - */ |
|
344 | - public function confirmRegistered() |
|
345 | - { |
|
346 | - if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
347 | - PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
348 | - } |
|
349 | - if (! $this->registered && WP_DEBUG) { |
|
350 | - throw new DomainException( |
|
351 | - sprintf( |
|
352 | - esc_html__( |
|
353 | - 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
354 | - 'event_espresso' |
|
355 | - ), |
|
356 | - $this->name |
|
357 | - ) |
|
358 | - ); |
|
359 | - } |
|
360 | - } |
|
211 | + /** |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function getCapContext() |
|
215 | + { |
|
216 | + return $this->cap_context; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $cap_context |
|
223 | + * @throws InvalidDataTypeException |
|
224 | + */ |
|
225 | + private function setCapContext($cap_context) |
|
226 | + { |
|
227 | + if (! is_string($cap_context)) { |
|
228 | + throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
229 | + } |
|
230 | + $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + public function getDismissed() |
|
239 | + { |
|
240 | + return $this->dismissed; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @param bool $dismissed |
|
247 | + */ |
|
248 | + public function setDismissed($dismissed) |
|
249 | + { |
|
250 | + $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @return CapCheckInterface |
|
257 | + * @throws InvalidDataTypeException |
|
258 | + */ |
|
259 | + public function getCapCheck() |
|
260 | + { |
|
261 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
262 | + $this->setCapCheck( |
|
263 | + new CapCheck( |
|
264 | + $this->capability, |
|
265 | + $this->cap_context |
|
266 | + ) |
|
267 | + ); |
|
268 | + } |
|
269 | + return $this->cap_check; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param CapCheckInterface $cap_check |
|
276 | + */ |
|
277 | + private function setCapCheck(CapCheckInterface $cap_check) |
|
278 | + { |
|
279 | + $this->cap_check = $cap_check; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @return bool |
|
286 | + */ |
|
287 | + public function getPurge() |
|
288 | + { |
|
289 | + return $this->purge; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param bool $purge |
|
296 | + */ |
|
297 | + public function setPurge($purge) |
|
298 | + { |
|
299 | + $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * given a valid PersistentAdminNotice Collection, |
|
306 | + * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
307 | + * if an existing notice is found that has already been dismissed, |
|
308 | + * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
309 | + * so that the notice is displayed again |
|
310 | + * |
|
311 | + * @param Collection $persistent_admin_notice_collection |
|
312 | + * @throws InvalidEntityException |
|
313 | + * @throws InvalidDataTypeException |
|
314 | + */ |
|
315 | + public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
316 | + { |
|
317 | + if ($this->registered) { |
|
318 | + return; |
|
319 | + } |
|
320 | + // first check if this notice has already been added to the collection |
|
321 | + if ($persistent_admin_notice_collection->has($this->name)) { |
|
322 | + /** @var PersistentAdminNotice $existing */ |
|
323 | + $existing = $persistent_admin_notice_collection->get($this->name); |
|
324 | + // we don't need to add it again (we can't actually) |
|
325 | + // but if it has already been dismissed, and we are overriding with a forced update |
|
326 | + if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
327 | + // then toggle the notice's dismissed state to true |
|
328 | + // so that it gets displayed again |
|
329 | + $existing->setDismissed(false); |
|
330 | + // and make sure the message is set |
|
331 | + $existing->setMessage($this->message); |
|
332 | + } |
|
333 | + } else { |
|
334 | + $persistent_admin_notice_collection->add($this, $this->name); |
|
335 | + } |
|
336 | + $this->registered = true; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @throws Exception |
|
343 | + */ |
|
344 | + public function confirmRegistered() |
|
345 | + { |
|
346 | + if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
347 | + PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
348 | + } |
|
349 | + if (! $this->registered && WP_DEBUG) { |
|
350 | + throw new DomainException( |
|
351 | + sprintf( |
|
352 | + esc_html__( |
|
353 | + 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
354 | + 'event_espresso' |
|
355 | + ), |
|
356 | + $this->name |
|
357 | + ) |
|
358 | + ); |
|
359 | + } |
|
360 | + } |
|
361 | 361 | |
362 | 362 | |
363 | 363 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function setName($name) |
132 | 132 | { |
133 | - if (! is_string($name)) { |
|
133 | + if ( ! is_string($name)) { |
|
134 | 134 | throw new InvalidDataTypeException('$name', $name, 'string'); |
135 | 135 | } |
136 | 136 | $this->name = sanitize_key($name); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | private function setMessage($message) |
156 | 156 | { |
157 | - if (! is_string($message)) { |
|
157 | + if ( ! is_string($message)) { |
|
158 | 158 | throw new InvalidDataTypeException('$message', $message, 'string'); |
159 | 159 | } |
160 | 160 | global $allowedtags; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private function setCapability($capability) |
202 | 202 | { |
203 | - if (! is_string($capability)) { |
|
203 | + if ( ! is_string($capability)) { |
|
204 | 204 | throw new InvalidDataTypeException('$capability', $capability, 'string'); |
205 | 205 | } |
206 | 206 | $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | private function setCapContext($cap_context) |
226 | 226 | { |
227 | - if (! is_string($cap_context)) { |
|
227 | + if ( ! is_string($cap_context)) { |
|
228 | 228 | throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
229 | 229 | } |
230 | 230 | $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function getCapCheck() |
260 | 260 | { |
261 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
261 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
262 | 262 | $this->setCapCheck( |
263 | 263 | new CapCheck( |
264 | 264 | $this->capability, |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function confirmRegistered() |
345 | 345 | { |
346 | - if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
346 | + if ( ! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
347 | 347 | PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
348 | 348 | } |
349 | - if (! $this->registered && WP_DEBUG) { |
|
349 | + if ( ! $this->registered && WP_DEBUG) { |
|
350 | 350 | throw new DomainException( |
351 | 351 | sprintf( |
352 | 352 | esc_html__( |
@@ -32,390 +32,390 @@ |
||
32 | 32 | class PersistentAdminNoticeManager |
33 | 33 | { |
34 | 34 | |
35 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
39 | - */ |
|
40 | - private $notice_collection; |
|
41 | - |
|
42 | - /** |
|
43 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
44 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
45 | - * |
|
46 | - * @var string $return_url |
|
47 | - */ |
|
48 | - private $return_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var CapabilitiesChecker $capabilities_checker |
|
52 | - */ |
|
53 | - private $capabilities_checker; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Request $request |
|
57 | - */ |
|
58 | - private $request; |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * PersistentAdminNoticeManager constructor |
|
64 | - * |
|
65 | - * @param string $return_url where to redirect to after dismissing notices |
|
66 | - * @param CapabilitiesChecker $capabilities_checker |
|
67 | - * @param EE_Request $request |
|
68 | - * @throws InvalidDataTypeException |
|
69 | - */ |
|
70 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
71 | - { |
|
72 | - $this->setReturnUrl($return_url); |
|
73 | - $this->capabilities_checker = $capabilities_checker; |
|
74 | - $this->request = $request; |
|
75 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
76 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
77 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
78 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
79 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
80 | - add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $return_url |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - */ |
|
89 | - public function setReturnUrl($return_url) |
|
90 | - { |
|
91 | - if (! is_string($return_url)) { |
|
92 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
93 | - } |
|
94 | - $this->return_url = $return_url; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return Collection |
|
101 | - * @throws InvalidEntityException |
|
102 | - * @throws InvalidInterfaceException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws DomainException |
|
105 | - */ |
|
106 | - protected function getPersistentAdminNoticeCollection() |
|
107 | - { |
|
108 | - if (! $this->notice_collection instanceof Collection) { |
|
109 | - $this->notice_collection = new Collection( |
|
110 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
111 | - ); |
|
112 | - $this->retrieveStoredNotices(); |
|
113 | - $this->registerNotices(); |
|
114 | - } |
|
115 | - return $this->notice_collection; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
122 | - * |
|
123 | - * @return void |
|
124 | - * @throws InvalidEntityException |
|
125 | - * @throws DomainException |
|
126 | - * @throws InvalidDataTypeException |
|
127 | - */ |
|
128 | - protected function retrieveStoredNotices() |
|
129 | - { |
|
130 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
131 | - // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
132 | - if (! empty($persistent_admin_notices)) { |
|
133 | - foreach ($persistent_admin_notices as $name => $details) { |
|
134 | - if (is_array($details)) { |
|
135 | - if ( |
|
136 | - ! isset( |
|
137 | - $details['message'], |
|
138 | - $details['capability'], |
|
139 | - $details['cap_context'], |
|
140 | - $details['dismissed'] |
|
141 | - ) |
|
142 | - ) { |
|
143 | - throw new DomainException( |
|
144 | - sprintf( |
|
145 | - esc_html__( |
|
146 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - $name |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
153 | - // new format for nag notices |
|
154 | - $this->notice_collection->add( |
|
155 | - new PersistentAdminNotice( |
|
156 | - $name, |
|
157 | - $details['message'], |
|
158 | - false, |
|
159 | - $details['capability'], |
|
160 | - $details['cap_context'], |
|
161 | - $details['dismissed'] |
|
162 | - ), |
|
163 | - $name |
|
164 | - ); |
|
165 | - } else { |
|
166 | - try { |
|
167 | - // old nag notices, that we want to convert to the new format |
|
168 | - $this->notice_collection->add( |
|
169 | - new PersistentAdminNotice( |
|
170 | - $name, |
|
171 | - (string)$details, |
|
172 | - false, |
|
173 | - '', |
|
174 | - '', |
|
175 | - empty($details) |
|
176 | - ), |
|
177 | - $name |
|
178 | - ); |
|
179 | - } catch (Exception $e) { |
|
180 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
181 | - } |
|
182 | - } |
|
183 | - // each notice will self register when the action hook in registerNotices is triggered |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * exposes the Persistent Admin Notice Collection via an action |
|
192 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
193 | - * without compromising the actual collection like a filter would |
|
194 | - */ |
|
195 | - protected function registerNotices() |
|
196 | - { |
|
197 | - do_action( |
|
198 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
199 | - $this->notice_collection |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @throws DomainException |
|
207 | - * @throws InvalidClassException |
|
208 | - * @throws InvalidDataTypeException |
|
209 | - * @throws InvalidInterfaceException |
|
210 | - * @throws InvalidEntityException |
|
211 | - */ |
|
212 | - public function displayNotices() |
|
213 | - { |
|
214 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
215 | - if ($this->notice_collection->hasObjects()) { |
|
216 | - $enqueue_assets = false; |
|
217 | - // and display notices |
|
218 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
219 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
220 | - // don't display notices that have already been dismissed |
|
221 | - if ($persistent_admin_notice->getDismissed()) { |
|
222 | - continue; |
|
223 | - } |
|
224 | - try { |
|
225 | - $this->capabilities_checker->processCapCheck( |
|
226 | - $persistent_admin_notice->getCapCheck() |
|
227 | - ); |
|
228 | - } catch (InsufficientPermissionsException $e) { |
|
229 | - // user does not have required cap, so skip to next notice |
|
230 | - // and just eat the exception - nom nom nom nom |
|
231 | - continue; |
|
232 | - } |
|
233 | - if ($persistent_admin_notice->getMessage() === '') { |
|
234 | - continue; |
|
235 | - } |
|
236 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
237 | - $enqueue_assets = true; |
|
238 | - } |
|
239 | - if ($enqueue_assets) { |
|
240 | - $this->enqueueAssets(); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * does what it's named |
|
249 | - * |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - public function enqueueAssets() |
|
253 | - { |
|
254 | - wp_register_script( |
|
255 | - 'espresso_core', |
|
256 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
257 | - array('jquery'), |
|
258 | - EVENT_ESPRESSO_VERSION, |
|
259 | - true |
|
260 | - ); |
|
261 | - wp_register_script( |
|
262 | - 'ee_error_js', |
|
263 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
264 | - array('espresso_core'), |
|
265 | - EVENT_ESPRESSO_VERSION, |
|
266 | - true |
|
267 | - ); |
|
268 | - wp_localize_script( |
|
269 | - 'ee_error_js', |
|
270 | - 'ee_dismiss', |
|
271 | - array( |
|
272 | - 'return_url' => urlencode($this->return_url), |
|
273 | - 'ajax_url' => WP_AJAX_URL, |
|
274 | - 'unknown_error' => esc_html__( |
|
275 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
276 | - 'event_espresso' |
|
277 | - ), |
|
278 | - ) |
|
279 | - ); |
|
280 | - wp_enqueue_script('ee_error_js'); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * displayPersistentAdminNoticeHtml |
|
287 | - * |
|
288 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
289 | - */ |
|
290 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
291 | - { |
|
292 | - // used in template |
|
293 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
294 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
295 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * dismissNotice |
|
302 | - * |
|
303 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
304 | - * @param bool $purge if true, then delete it from the db |
|
305 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
306 | - * @return void |
|
307 | - * @throws InvalidEntityException |
|
308 | - * @throws InvalidInterfaceException |
|
309 | - * @throws InvalidDataTypeException |
|
310 | - * @throws DomainException |
|
311 | - */ |
|
312 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
313 | - { |
|
314 | - $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
315 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
316 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
317 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
318 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
319 | - $persistent_admin_notice->setDismissed(true); |
|
320 | - $persistent_admin_notice->setPurge($purge); |
|
321 | - $this->saveNotices(); |
|
322 | - } |
|
323 | - if ($return) { |
|
324 | - return; |
|
325 | - } |
|
326 | - if ($this->request->ajax) { |
|
327 | - // grab any notices and concatenate into string |
|
328 | - echo wp_json_encode( |
|
329 | - array( |
|
330 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
331 | - ) |
|
332 | - ); |
|
333 | - exit(); |
|
334 | - } |
|
335 | - // save errors to a transient to be displayed on next request (after redirect) |
|
336 | - EE_Error::get_notices(false, true); |
|
337 | - wp_safe_redirect( |
|
338 | - urldecode( |
|
339 | - $this->request->get('return_url', '') |
|
340 | - ) |
|
341 | - ); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * saveNotices |
|
348 | - * |
|
349 | - * @throws DomainException |
|
350 | - * @throws InvalidDataTypeException |
|
351 | - * @throws InvalidInterfaceException |
|
352 | - * @throws InvalidEntityException |
|
353 | - */ |
|
354 | - public function saveNotices() |
|
355 | - { |
|
356 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
357 | - if ($this->notice_collection->hasObjects()) { |
|
358 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
359 | - //maybe initialize persistent_admin_notices |
|
360 | - if (empty($persistent_admin_notices)) { |
|
361 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
362 | - } |
|
363 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
364 | - // are we deleting this notice ? |
|
365 | - if ($persistent_admin_notice->getPurge()) { |
|
366 | - unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
367 | - } else { |
|
368 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
369 | - $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
370 | - 'message' => $persistent_admin_notice->getMessage(), |
|
371 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
372 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
373 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
374 | - ); |
|
375 | - } |
|
376 | - } |
|
377 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @throws DomainException |
|
385 | - * @throws InvalidDataTypeException |
|
386 | - * @throws InvalidEntityException |
|
387 | - * @throws InvalidInterfaceException |
|
388 | - */ |
|
389 | - public function registerAndSaveNotices() |
|
390 | - { |
|
391 | - $this->getPersistentAdminNoticeCollection(); |
|
392 | - $this->registerNotices(); |
|
393 | - $this->saveNotices(); |
|
394 | - add_filter( |
|
395 | - 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
396 | - '__return_true' |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @throws DomainException |
|
403 | - * @throws InvalidDataTypeException |
|
404 | - * @throws InvalidEntityException |
|
405 | - * @throws InvalidInterfaceException |
|
406 | - * @throws InvalidArgumentException |
|
407 | - */ |
|
408 | - public static function loadRegisterAndSaveNotices() |
|
409 | - { |
|
410 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
411 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
412 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
413 | - ); |
|
414 | - // if shutdown has already run, then call registerAndSaveNotices() manually |
|
415 | - if(did_action('shutdown')){ |
|
416 | - $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
417 | - } |
|
418 | - } |
|
35 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
39 | + */ |
|
40 | + private $notice_collection; |
|
41 | + |
|
42 | + /** |
|
43 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
44 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
45 | + * |
|
46 | + * @var string $return_url |
|
47 | + */ |
|
48 | + private $return_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var CapabilitiesChecker $capabilities_checker |
|
52 | + */ |
|
53 | + private $capabilities_checker; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Request $request |
|
57 | + */ |
|
58 | + private $request; |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * PersistentAdminNoticeManager constructor |
|
64 | + * |
|
65 | + * @param string $return_url where to redirect to after dismissing notices |
|
66 | + * @param CapabilitiesChecker $capabilities_checker |
|
67 | + * @param EE_Request $request |
|
68 | + * @throws InvalidDataTypeException |
|
69 | + */ |
|
70 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
71 | + { |
|
72 | + $this->setReturnUrl($return_url); |
|
73 | + $this->capabilities_checker = $capabilities_checker; |
|
74 | + $this->request = $request; |
|
75 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
76 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
77 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
78 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
79 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
80 | + add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $return_url |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + */ |
|
89 | + public function setReturnUrl($return_url) |
|
90 | + { |
|
91 | + if (! is_string($return_url)) { |
|
92 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
93 | + } |
|
94 | + $this->return_url = $return_url; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return Collection |
|
101 | + * @throws InvalidEntityException |
|
102 | + * @throws InvalidInterfaceException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws DomainException |
|
105 | + */ |
|
106 | + protected function getPersistentAdminNoticeCollection() |
|
107 | + { |
|
108 | + if (! $this->notice_collection instanceof Collection) { |
|
109 | + $this->notice_collection = new Collection( |
|
110 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
111 | + ); |
|
112 | + $this->retrieveStoredNotices(); |
|
113 | + $this->registerNotices(); |
|
114 | + } |
|
115 | + return $this->notice_collection; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
122 | + * |
|
123 | + * @return void |
|
124 | + * @throws InvalidEntityException |
|
125 | + * @throws DomainException |
|
126 | + * @throws InvalidDataTypeException |
|
127 | + */ |
|
128 | + protected function retrieveStoredNotices() |
|
129 | + { |
|
130 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
131 | + // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
132 | + if (! empty($persistent_admin_notices)) { |
|
133 | + foreach ($persistent_admin_notices as $name => $details) { |
|
134 | + if (is_array($details)) { |
|
135 | + if ( |
|
136 | + ! isset( |
|
137 | + $details['message'], |
|
138 | + $details['capability'], |
|
139 | + $details['cap_context'], |
|
140 | + $details['dismissed'] |
|
141 | + ) |
|
142 | + ) { |
|
143 | + throw new DomainException( |
|
144 | + sprintf( |
|
145 | + esc_html__( |
|
146 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + $name |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | + // new format for nag notices |
|
154 | + $this->notice_collection->add( |
|
155 | + new PersistentAdminNotice( |
|
156 | + $name, |
|
157 | + $details['message'], |
|
158 | + false, |
|
159 | + $details['capability'], |
|
160 | + $details['cap_context'], |
|
161 | + $details['dismissed'] |
|
162 | + ), |
|
163 | + $name |
|
164 | + ); |
|
165 | + } else { |
|
166 | + try { |
|
167 | + // old nag notices, that we want to convert to the new format |
|
168 | + $this->notice_collection->add( |
|
169 | + new PersistentAdminNotice( |
|
170 | + $name, |
|
171 | + (string)$details, |
|
172 | + false, |
|
173 | + '', |
|
174 | + '', |
|
175 | + empty($details) |
|
176 | + ), |
|
177 | + $name |
|
178 | + ); |
|
179 | + } catch (Exception $e) { |
|
180 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
181 | + } |
|
182 | + } |
|
183 | + // each notice will self register when the action hook in registerNotices is triggered |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * exposes the Persistent Admin Notice Collection via an action |
|
192 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
193 | + * without compromising the actual collection like a filter would |
|
194 | + */ |
|
195 | + protected function registerNotices() |
|
196 | + { |
|
197 | + do_action( |
|
198 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
199 | + $this->notice_collection |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @throws DomainException |
|
207 | + * @throws InvalidClassException |
|
208 | + * @throws InvalidDataTypeException |
|
209 | + * @throws InvalidInterfaceException |
|
210 | + * @throws InvalidEntityException |
|
211 | + */ |
|
212 | + public function displayNotices() |
|
213 | + { |
|
214 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
215 | + if ($this->notice_collection->hasObjects()) { |
|
216 | + $enqueue_assets = false; |
|
217 | + // and display notices |
|
218 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
219 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
220 | + // don't display notices that have already been dismissed |
|
221 | + if ($persistent_admin_notice->getDismissed()) { |
|
222 | + continue; |
|
223 | + } |
|
224 | + try { |
|
225 | + $this->capabilities_checker->processCapCheck( |
|
226 | + $persistent_admin_notice->getCapCheck() |
|
227 | + ); |
|
228 | + } catch (InsufficientPermissionsException $e) { |
|
229 | + // user does not have required cap, so skip to next notice |
|
230 | + // and just eat the exception - nom nom nom nom |
|
231 | + continue; |
|
232 | + } |
|
233 | + if ($persistent_admin_notice->getMessage() === '') { |
|
234 | + continue; |
|
235 | + } |
|
236 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
237 | + $enqueue_assets = true; |
|
238 | + } |
|
239 | + if ($enqueue_assets) { |
|
240 | + $this->enqueueAssets(); |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * does what it's named |
|
249 | + * |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + public function enqueueAssets() |
|
253 | + { |
|
254 | + wp_register_script( |
|
255 | + 'espresso_core', |
|
256 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
257 | + array('jquery'), |
|
258 | + EVENT_ESPRESSO_VERSION, |
|
259 | + true |
|
260 | + ); |
|
261 | + wp_register_script( |
|
262 | + 'ee_error_js', |
|
263 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
264 | + array('espresso_core'), |
|
265 | + EVENT_ESPRESSO_VERSION, |
|
266 | + true |
|
267 | + ); |
|
268 | + wp_localize_script( |
|
269 | + 'ee_error_js', |
|
270 | + 'ee_dismiss', |
|
271 | + array( |
|
272 | + 'return_url' => urlencode($this->return_url), |
|
273 | + 'ajax_url' => WP_AJAX_URL, |
|
274 | + 'unknown_error' => esc_html__( |
|
275 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
276 | + 'event_espresso' |
|
277 | + ), |
|
278 | + ) |
|
279 | + ); |
|
280 | + wp_enqueue_script('ee_error_js'); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * displayPersistentAdminNoticeHtml |
|
287 | + * |
|
288 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
289 | + */ |
|
290 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
291 | + { |
|
292 | + // used in template |
|
293 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
294 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
295 | + require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * dismissNotice |
|
302 | + * |
|
303 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
304 | + * @param bool $purge if true, then delete it from the db |
|
305 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
306 | + * @return void |
|
307 | + * @throws InvalidEntityException |
|
308 | + * @throws InvalidInterfaceException |
|
309 | + * @throws InvalidDataTypeException |
|
310 | + * @throws DomainException |
|
311 | + */ |
|
312 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
313 | + { |
|
314 | + $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
315 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
316 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
317 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
318 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
319 | + $persistent_admin_notice->setDismissed(true); |
|
320 | + $persistent_admin_notice->setPurge($purge); |
|
321 | + $this->saveNotices(); |
|
322 | + } |
|
323 | + if ($return) { |
|
324 | + return; |
|
325 | + } |
|
326 | + if ($this->request->ajax) { |
|
327 | + // grab any notices and concatenate into string |
|
328 | + echo wp_json_encode( |
|
329 | + array( |
|
330 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
331 | + ) |
|
332 | + ); |
|
333 | + exit(); |
|
334 | + } |
|
335 | + // save errors to a transient to be displayed on next request (after redirect) |
|
336 | + EE_Error::get_notices(false, true); |
|
337 | + wp_safe_redirect( |
|
338 | + urldecode( |
|
339 | + $this->request->get('return_url', '') |
|
340 | + ) |
|
341 | + ); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * saveNotices |
|
348 | + * |
|
349 | + * @throws DomainException |
|
350 | + * @throws InvalidDataTypeException |
|
351 | + * @throws InvalidInterfaceException |
|
352 | + * @throws InvalidEntityException |
|
353 | + */ |
|
354 | + public function saveNotices() |
|
355 | + { |
|
356 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
357 | + if ($this->notice_collection->hasObjects()) { |
|
358 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
359 | + //maybe initialize persistent_admin_notices |
|
360 | + if (empty($persistent_admin_notices)) { |
|
361 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
362 | + } |
|
363 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
364 | + // are we deleting this notice ? |
|
365 | + if ($persistent_admin_notice->getPurge()) { |
|
366 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
367 | + } else { |
|
368 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
369 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
370 | + 'message' => $persistent_admin_notice->getMessage(), |
|
371 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
372 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
373 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
374 | + ); |
|
375 | + } |
|
376 | + } |
|
377 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @throws DomainException |
|
385 | + * @throws InvalidDataTypeException |
|
386 | + * @throws InvalidEntityException |
|
387 | + * @throws InvalidInterfaceException |
|
388 | + */ |
|
389 | + public function registerAndSaveNotices() |
|
390 | + { |
|
391 | + $this->getPersistentAdminNoticeCollection(); |
|
392 | + $this->registerNotices(); |
|
393 | + $this->saveNotices(); |
|
394 | + add_filter( |
|
395 | + 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
396 | + '__return_true' |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @throws DomainException |
|
403 | + * @throws InvalidDataTypeException |
|
404 | + * @throws InvalidEntityException |
|
405 | + * @throws InvalidInterfaceException |
|
406 | + * @throws InvalidArgumentException |
|
407 | + */ |
|
408 | + public static function loadRegisterAndSaveNotices() |
|
409 | + { |
|
410 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
411 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
412 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
413 | + ); |
|
414 | + // if shutdown has already run, then call registerAndSaveNotices() manually |
|
415 | + if(did_action('shutdown')){ |
|
416 | + $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
417 | + } |
|
418 | + } |
|
419 | 419 | |
420 | 420 | |
421 | 421 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function setReturnUrl($return_url) |
90 | 90 | { |
91 | - if (! is_string($return_url)) { |
|
91 | + if ( ! is_string($return_url)) { |
|
92 | 92 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
93 | 93 | } |
94 | 94 | $this->return_url = $return_url; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function getPersistentAdminNoticeCollection() |
107 | 107 | { |
108 | - if (! $this->notice_collection instanceof Collection) { |
|
108 | + if ( ! $this->notice_collection instanceof Collection) { |
|
109 | 109 | $this->notice_collection = new Collection( |
110 | 110 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
111 | 111 | ); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
131 | 131 | // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
132 | - if (! empty($persistent_admin_notices)) { |
|
132 | + if ( ! empty($persistent_admin_notices)) { |
|
133 | 133 | foreach ($persistent_admin_notices as $name => $details) { |
134 | 134 | if (is_array($details)) { |
135 | 135 | if ( |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $this->notice_collection->add( |
169 | 169 | new PersistentAdminNotice( |
170 | 170 | $name, |
171 | - (string)$details, |
|
171 | + (string) $details, |
|
172 | 172 | false, |
173 | 173 | '', |
174 | 174 | '', |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | { |
254 | 254 | wp_register_script( |
255 | 255 | 'espresso_core', |
256 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
256 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
257 | 257 | array('jquery'), |
258 | 258 | EVENT_ESPRESSO_VERSION, |
259 | 259 | true |
260 | 260 | ); |
261 | 261 | wp_register_script( |
262 | 262 | 'ee_error_js', |
263 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
263 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
264 | 264 | array('espresso_core'), |
265 | 265 | EVENT_ESPRESSO_VERSION, |
266 | 266 | true |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | // used in template |
293 | 293 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
294 | 294 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
295 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
295 | + require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php'; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | { |
314 | 314 | $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
315 | 315 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
316 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
316 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
317 | 317 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
318 | 318 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
319 | 319 | $persistent_admin_notice->setDismissed(true); |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
413 | 413 | ); |
414 | 414 | // if shutdown has already run, then call registerAndSaveNotices() manually |
415 | - if(did_action('shutdown')){ |
|
415 | + if (did_action('shutdown')) { |
|
416 | 416 | $persistent_admin_notice_manager->registerAndSaveNotices(); |
417 | 417 | } |
418 | 418 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\widgets\EspressoWidget; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -27,380 +27,380 @@ discard block |
||
27 | 27 | final class EE_Front_Controller |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var string $_template_path |
|
32 | - */ |
|
33 | - private $_template_path; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $_template |
|
37 | - */ |
|
38 | - private $_template; |
|
39 | - |
|
40 | - /** |
|
41 | - * @type EE_Registry $Registry |
|
42 | - */ |
|
43 | - protected $Registry; |
|
44 | - |
|
45 | - /** |
|
46 | - * @type EE_Request_Handler $Request_Handler |
|
47 | - */ |
|
48 | - protected $Request_Handler; |
|
49 | - |
|
50 | - /** |
|
51 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
52 | - */ |
|
53 | - protected $Module_Request_Router; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * class constructor |
|
58 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @param \EE_Registry $Registry |
|
62 | - * @param \EE_Request_Handler $Request_Handler |
|
63 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
64 | - */ |
|
65 | - public function __construct( |
|
66 | - EE_Registry $Registry, |
|
67 | - EE_Request_Handler $Request_Handler, |
|
68 | - EE_Module_Request_Router $Module_Request_Router |
|
69 | - ) { |
|
70 | - $this->Registry = $Registry; |
|
71 | - $this->Request_Handler = $Request_Handler; |
|
72 | - $this->Module_Request_Router = $Module_Request_Router; |
|
73 | - // determine how to integrate WP_Query with the EE models |
|
74 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
75 | - // load other resources and begin to actually run shortcodes and modules |
|
76 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
77 | - // analyse the incoming WP request |
|
78 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
79 | - // process request with module factory |
|
80 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
81 | - // before headers sent |
|
82 | - add_action('wp', array($this, 'wp'), 5); |
|
83 | - // primarily used to process any content shortcodes |
|
84 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
85 | - // header |
|
86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | - // display errors |
|
90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | - // the content |
|
92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | - //exclude our private cpt comments |
|
94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | - // action hook EE |
|
98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return EE_Request_Handler |
|
104 | - */ |
|
105 | - public function Request_Handler() |
|
106 | - { |
|
107 | - return $this->Request_Handler; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return EE_Module_Request_Router |
|
113 | - */ |
|
114 | - public function Module_Request_Router() |
|
115 | - { |
|
116 | - return $this->Module_Request_Router; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return LegacyShortcodesManager |
|
123 | - */ |
|
124 | - public function getLegacyShortcodesManager() |
|
125 | - { |
|
126 | - return EE_Config::getLegacyShortcodesManager(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * filter_wp_comments |
|
139 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
140 | - * widgets/queries done on frontend |
|
141 | - * |
|
142 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
143 | - * @return array array of comment clauses with modifications. |
|
144 | - */ |
|
145 | - public function filter_wp_comments($clauses) |
|
146 | - { |
|
147 | - global $wpdb; |
|
148 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
149 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
150 | - foreach ($cpts as $cpt => $details) { |
|
151 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
152 | - } |
|
153 | - } |
|
154 | - return $clauses; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return void |
|
160 | - * @throws EE_Error |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public function employ_CPT_Strategy() |
|
164 | - { |
|
165 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
166 | - $this->Registry->load_core('CPT_Strategy'); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
173 | - * |
|
174 | - * @param string $url incoming url |
|
175 | - * @return string final assembled url |
|
176 | - */ |
|
177 | - public function maybe_force_admin_ajax_ssl($url) |
|
178 | - { |
|
179 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
180 | - $url = str_replace('http://', 'https://', $url); |
|
181 | - } |
|
182 | - return $url; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
195 | - * default priority init phases have run |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public function wp_loaded() |
|
201 | - { |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
209 | - /** |
|
210 | - * _get_request |
|
211 | - * |
|
212 | - * @access public |
|
213 | - * @param WP $WP |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function get_request(WP $WP) |
|
217 | - { |
|
218 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
219 | - $this->Request_Handler->parse_request($WP); |
|
220 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @param WP_Query $WP_Query |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function pre_get_posts($WP_Query) |
|
233 | - { |
|
234 | - // only load Module_Request_Router if this is the main query |
|
235 | - if ( |
|
236 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
237 | - && $WP_Query->is_main_query() |
|
238 | - ) { |
|
239 | - // cycle thru module routes |
|
240 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
241 | - // determine module and method for route |
|
242 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
243 | - if ($module instanceof EED_Module) { |
|
244 | - // get registered view for route |
|
245 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
246 | - // grab module name |
|
247 | - $module_name = $module->module_name(); |
|
248 | - // map the module to the module objects |
|
249 | - $this->Registry->modules->{$module_name} = $module; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /*********************************************** WP HOOK ***********************************************/ |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * wp - basically last chance to do stuff before headers sent |
|
264 | - * |
|
265 | - * @access public |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function wp() |
|
269 | - { |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * callback for the "template_redirect" hook point |
|
280 | - * checks sidebars for EE widgets |
|
281 | - * loads resources and assets accordingly |
|
282 | - * |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - public function templateRedirect() |
|
286 | - { |
|
287 | - global $wp_query; |
|
288 | - if (empty($wp_query->posts)){ |
|
289 | - return; |
|
290 | - } |
|
291 | - // if we already know this is an espresso page, then load assets |
|
292 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
293 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
294 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
295 | - if ( $load_assets){ |
|
296 | - add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
297 | - add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * builds list of active widgets then scans active sidebars looking for them |
|
305 | - * returns true is an EE widget is found in an active sidebar |
|
306 | - * Please Note: this does NOT mean that the sidebar or widget |
|
307 | - * is actually in use in a given template, as that is unfortunately not known |
|
308 | - * until a sidebar and it's widgets are actually loaded |
|
309 | - * |
|
310 | - * @return boolean |
|
311 | - */ |
|
312 | - private function espresso_widgets_in_active_sidebars() |
|
313 | - { |
|
314 | - $espresso_widgets = array(); |
|
315 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
316 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
317 | - if (is_active_widget(false, false, $id_base)) { |
|
318 | - $espresso_widgets[] = $id_base; |
|
319 | - } |
|
320 | - } |
|
321 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
322 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
323 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
324 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
325 | - foreach ($espresso_widgets as $espresso_widget) { |
|
326 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
327 | - return true; |
|
328 | - } |
|
329 | - } |
|
330 | - } |
|
331 | - } |
|
332 | - } |
|
333 | - return false; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * header_meta_tag |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - public function header_meta_tag() |
|
346 | - { |
|
347 | - print( |
|
348 | - apply_filters( |
|
349 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
350 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
351 | - ); |
|
352 | - |
|
353 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
354 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
355 | - //also exclude all critical pages from indexing |
|
356 | - if ( |
|
357 | - ( |
|
358 | - is_tax('espresso_event_type') |
|
359 | - && get_option( 'blog_public' ) !== '0' |
|
360 | - ) |
|
361 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
362 | - ) { |
|
363 | - print( |
|
364 | - apply_filters( |
|
365 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
366 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * wp_print_scripts |
|
376 | - * |
|
377 | - * @return void |
|
378 | - */ |
|
379 | - public function wp_print_scripts() |
|
380 | - { |
|
381 | - global $post; |
|
382 | - if ( |
|
383 | - isset($post->EE_Event) |
|
384 | - && $post->EE_Event instanceof EE_Event |
|
385 | - && get_post_type() === 'espresso_events' |
|
386 | - && is_singular() |
|
387 | - ) { |
|
388 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - public function enqueueStyle() |
|
395 | - { |
|
396 | - wp_enqueue_style('espresso_default'); |
|
397 | - wp_enqueue_style('espresso_custom_css'); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
30 | + /** |
|
31 | + * @var string $_template_path |
|
32 | + */ |
|
33 | + private $_template_path; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $_template |
|
37 | + */ |
|
38 | + private $_template; |
|
39 | + |
|
40 | + /** |
|
41 | + * @type EE_Registry $Registry |
|
42 | + */ |
|
43 | + protected $Registry; |
|
44 | + |
|
45 | + /** |
|
46 | + * @type EE_Request_Handler $Request_Handler |
|
47 | + */ |
|
48 | + protected $Request_Handler; |
|
49 | + |
|
50 | + /** |
|
51 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
52 | + */ |
|
53 | + protected $Module_Request_Router; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * class constructor |
|
58 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @param \EE_Registry $Registry |
|
62 | + * @param \EE_Request_Handler $Request_Handler |
|
63 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
64 | + */ |
|
65 | + public function __construct( |
|
66 | + EE_Registry $Registry, |
|
67 | + EE_Request_Handler $Request_Handler, |
|
68 | + EE_Module_Request_Router $Module_Request_Router |
|
69 | + ) { |
|
70 | + $this->Registry = $Registry; |
|
71 | + $this->Request_Handler = $Request_Handler; |
|
72 | + $this->Module_Request_Router = $Module_Request_Router; |
|
73 | + // determine how to integrate WP_Query with the EE models |
|
74 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
75 | + // load other resources and begin to actually run shortcodes and modules |
|
76 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
77 | + // analyse the incoming WP request |
|
78 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
79 | + // process request with module factory |
|
80 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
81 | + // before headers sent |
|
82 | + add_action('wp', array($this, 'wp'), 5); |
|
83 | + // primarily used to process any content shortcodes |
|
84 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
85 | + // header |
|
86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | + // display errors |
|
90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | + // the content |
|
92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | + //exclude our private cpt comments |
|
94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | + // action hook EE |
|
98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return EE_Request_Handler |
|
104 | + */ |
|
105 | + public function Request_Handler() |
|
106 | + { |
|
107 | + return $this->Request_Handler; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return EE_Module_Request_Router |
|
113 | + */ |
|
114 | + public function Module_Request_Router() |
|
115 | + { |
|
116 | + return $this->Module_Request_Router; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return LegacyShortcodesManager |
|
123 | + */ |
|
124 | + public function getLegacyShortcodesManager() |
|
125 | + { |
|
126 | + return EE_Config::getLegacyShortcodesManager(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * filter_wp_comments |
|
139 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
140 | + * widgets/queries done on frontend |
|
141 | + * |
|
142 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
143 | + * @return array array of comment clauses with modifications. |
|
144 | + */ |
|
145 | + public function filter_wp_comments($clauses) |
|
146 | + { |
|
147 | + global $wpdb; |
|
148 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
149 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
150 | + foreach ($cpts as $cpt => $details) { |
|
151 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
152 | + } |
|
153 | + } |
|
154 | + return $clauses; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + * @throws EE_Error |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public function employ_CPT_Strategy() |
|
164 | + { |
|
165 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
166 | + $this->Registry->load_core('CPT_Strategy'); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
173 | + * |
|
174 | + * @param string $url incoming url |
|
175 | + * @return string final assembled url |
|
176 | + */ |
|
177 | + public function maybe_force_admin_ajax_ssl($url) |
|
178 | + { |
|
179 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
180 | + $url = str_replace('http://', 'https://', $url); |
|
181 | + } |
|
182 | + return $url; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
195 | + * default priority init phases have run |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public function wp_loaded() |
|
201 | + { |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
209 | + /** |
|
210 | + * _get_request |
|
211 | + * |
|
212 | + * @access public |
|
213 | + * @param WP $WP |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function get_request(WP $WP) |
|
217 | + { |
|
218 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
219 | + $this->Request_Handler->parse_request($WP); |
|
220 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @param WP_Query $WP_Query |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function pre_get_posts($WP_Query) |
|
233 | + { |
|
234 | + // only load Module_Request_Router if this is the main query |
|
235 | + if ( |
|
236 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
237 | + && $WP_Query->is_main_query() |
|
238 | + ) { |
|
239 | + // cycle thru module routes |
|
240 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
241 | + // determine module and method for route |
|
242 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
243 | + if ($module instanceof EED_Module) { |
|
244 | + // get registered view for route |
|
245 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
246 | + // grab module name |
|
247 | + $module_name = $module->module_name(); |
|
248 | + // map the module to the module objects |
|
249 | + $this->Registry->modules->{$module_name} = $module; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /*********************************************** WP HOOK ***********************************************/ |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * wp - basically last chance to do stuff before headers sent |
|
264 | + * |
|
265 | + * @access public |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function wp() |
|
269 | + { |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * callback for the "template_redirect" hook point |
|
280 | + * checks sidebars for EE widgets |
|
281 | + * loads resources and assets accordingly |
|
282 | + * |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + public function templateRedirect() |
|
286 | + { |
|
287 | + global $wp_query; |
|
288 | + if (empty($wp_query->posts)){ |
|
289 | + return; |
|
290 | + } |
|
291 | + // if we already know this is an espresso page, then load assets |
|
292 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
293 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
294 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
295 | + if ( $load_assets){ |
|
296 | + add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
297 | + add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * builds list of active widgets then scans active sidebars looking for them |
|
305 | + * returns true is an EE widget is found in an active sidebar |
|
306 | + * Please Note: this does NOT mean that the sidebar or widget |
|
307 | + * is actually in use in a given template, as that is unfortunately not known |
|
308 | + * until a sidebar and it's widgets are actually loaded |
|
309 | + * |
|
310 | + * @return boolean |
|
311 | + */ |
|
312 | + private function espresso_widgets_in_active_sidebars() |
|
313 | + { |
|
314 | + $espresso_widgets = array(); |
|
315 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
316 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
317 | + if (is_active_widget(false, false, $id_base)) { |
|
318 | + $espresso_widgets[] = $id_base; |
|
319 | + } |
|
320 | + } |
|
321 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
322 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
323 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
324 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
325 | + foreach ($espresso_widgets as $espresso_widget) { |
|
326 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
327 | + return true; |
|
328 | + } |
|
329 | + } |
|
330 | + } |
|
331 | + } |
|
332 | + } |
|
333 | + return false; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * header_meta_tag |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + public function header_meta_tag() |
|
346 | + { |
|
347 | + print( |
|
348 | + apply_filters( |
|
349 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
350 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
351 | + ); |
|
352 | + |
|
353 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
354 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
355 | + //also exclude all critical pages from indexing |
|
356 | + if ( |
|
357 | + ( |
|
358 | + is_tax('espresso_event_type') |
|
359 | + && get_option( 'blog_public' ) !== '0' |
|
360 | + ) |
|
361 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
362 | + ) { |
|
363 | + print( |
|
364 | + apply_filters( |
|
365 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
366 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * wp_print_scripts |
|
376 | + * |
|
377 | + * @return void |
|
378 | + */ |
|
379 | + public function wp_print_scripts() |
|
380 | + { |
|
381 | + global $post; |
|
382 | + if ( |
|
383 | + isset($post->EE_Event) |
|
384 | + && $post->EE_Event instanceof EE_Event |
|
385 | + && get_post_type() === 'espresso_events' |
|
386 | + && is_singular() |
|
387 | + ) { |
|
388 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + public function enqueueStyle() |
|
395 | + { |
|
396 | + wp_enqueue_style('espresso_default'); |
|
397 | + wp_enqueue_style('espresso_custom_css'); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
404 | 404 | |
405 | 405 | |
406 | 406 | |
@@ -411,117 +411,117 @@ discard block |
||
411 | 411 | // * @param $the_content |
412 | 412 | // * @return string |
413 | 413 | // */ |
414 | - // public function the_content( $the_content ) { |
|
415 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
416 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
417 | - // } |
|
418 | - // return $the_content; |
|
419 | - // } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - public function enqueueScripts() |
|
428 | - { |
|
429 | - wp_enqueue_script('espresso_core'); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * display_errors |
|
436 | - * |
|
437 | - * @access public |
|
438 | - * @return void |
|
439 | - * @throws DomainException |
|
440 | - */ |
|
441 | - public function display_errors() |
|
442 | - { |
|
443 | - static $shown_already = false; |
|
444 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
445 | - if ( |
|
446 | - ! $shown_already |
|
447 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
448 | - && is_main_query() |
|
449 | - && ! is_feed() |
|
450 | - && in_the_loop() |
|
451 | - && $this->Request_Handler->is_espresso_page() |
|
452 | - ) { |
|
453 | - echo EE_Error::get_notices(); |
|
454 | - $shown_already = true; |
|
455 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
456 | - } |
|
457 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /*********************************************** UTILITIES ***********************************************/ |
|
465 | - /** |
|
466 | - * template_include |
|
467 | - * |
|
468 | - * @access public |
|
469 | - * @param string $template_include_path |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function template_include($template_include_path = null) |
|
473 | - { |
|
474 | - if ($this->Request_Handler->is_espresso_page()) { |
|
475 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
476 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
477 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
478 | - $this->_template = basename($this->_template_path); |
|
479 | - return $this->_template_path; |
|
480 | - } |
|
481 | - return $template_include_path; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * get_selected_template |
|
487 | - * |
|
488 | - * @access public |
|
489 | - * @param bool $with_path |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - public function get_selected_template($with_path = false) |
|
493 | - { |
|
494 | - return $with_path ? $this->_template_path : $this->_template; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @deprecated 4.9.26 |
|
501 | - * @param string $shortcode_class |
|
502 | - * @param \WP $wp |
|
503 | - */ |
|
504 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
505 | - { |
|
506 | - \EE_Error::doing_it_wrong( |
|
507 | - __METHOD__, |
|
508 | - __( |
|
509 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
510 | - 'event_espresso' |
|
511 | - ), |
|
512 | - '4.9.26' |
|
513 | - ); |
|
514 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * @return void |
|
520 | - * @deprecated $VID:$ |
|
521 | - */ |
|
522 | - public function loadPersistentAdminNoticeManager() |
|
523 | - { |
|
524 | - } |
|
414 | + // public function the_content( $the_content ) { |
|
415 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
416 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
417 | + // } |
|
418 | + // return $the_content; |
|
419 | + // } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + public function enqueueScripts() |
|
428 | + { |
|
429 | + wp_enqueue_script('espresso_core'); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * display_errors |
|
436 | + * |
|
437 | + * @access public |
|
438 | + * @return void |
|
439 | + * @throws DomainException |
|
440 | + */ |
|
441 | + public function display_errors() |
|
442 | + { |
|
443 | + static $shown_already = false; |
|
444 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
445 | + if ( |
|
446 | + ! $shown_already |
|
447 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
448 | + && is_main_query() |
|
449 | + && ! is_feed() |
|
450 | + && in_the_loop() |
|
451 | + && $this->Request_Handler->is_espresso_page() |
|
452 | + ) { |
|
453 | + echo EE_Error::get_notices(); |
|
454 | + $shown_already = true; |
|
455 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
456 | + } |
|
457 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /*********************************************** UTILITIES ***********************************************/ |
|
465 | + /** |
|
466 | + * template_include |
|
467 | + * |
|
468 | + * @access public |
|
469 | + * @param string $template_include_path |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function template_include($template_include_path = null) |
|
473 | + { |
|
474 | + if ($this->Request_Handler->is_espresso_page()) { |
|
475 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
476 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
477 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
478 | + $this->_template = basename($this->_template_path); |
|
479 | + return $this->_template_path; |
|
480 | + } |
|
481 | + return $template_include_path; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * get_selected_template |
|
487 | + * |
|
488 | + * @access public |
|
489 | + * @param bool $with_path |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + public function get_selected_template($with_path = false) |
|
493 | + { |
|
494 | + return $with_path ? $this->_template_path : $this->_template; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @deprecated 4.9.26 |
|
501 | + * @param string $shortcode_class |
|
502 | + * @param \WP $wp |
|
503 | + */ |
|
504 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
505 | + { |
|
506 | + \EE_Error::doing_it_wrong( |
|
507 | + __METHOD__, |
|
508 | + __( |
|
509 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
510 | + 'event_espresso' |
|
511 | + ), |
|
512 | + '4.9.26' |
|
513 | + ); |
|
514 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * @return void |
|
520 | + * @deprecated $VID:$ |
|
521 | + */ |
|
522 | + public function loadPersistentAdminNoticeManager() |
|
523 | + { |
|
524 | + } |
|
525 | 525 | } |
526 | 526 | // End of file EE_Front_Controller.core.php |
527 | 527 | // Location: /core/EE_Front_Controller.core.php |
@@ -22,457 +22,457 @@ discard block |
||
22 | 22 | final class EE_Admin implements InterminableInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Admin $_instance |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | - */ |
|
33 | - private $persistent_admin_notice_manager; |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @return EE_Admin |
|
38 | - * @throws EE_Error |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated |
|
43 | - if (! self::$_instance instanceof EE_Admin) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @return EE_Admin |
|
52 | - * @throws EE_Error |
|
53 | - */ |
|
54 | - public static function reset() |
|
55 | - { |
|
56 | - self::$_instance = null; |
|
57 | - return self::instance(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * class constructor |
|
63 | - * |
|
64 | - * @throws EE_Error |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidInterfaceException |
|
67 | - * @throws InvalidArgumentException |
|
68 | - */ |
|
69 | - protected function __construct() |
|
70 | - { |
|
71 | - // define global EE_Admin constants |
|
72 | - $this->_define_all_constants(); |
|
73 | - // set autoloaders for our admin page classes based on included path information |
|
74 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | - // admin hooks |
|
76 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | - // load EE_Request_Handler early |
|
78 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | - //reset Environment config (we only do this on admin page loads); |
|
89 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | - do_action('AHEE__EE_Admin__loaded'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * _define_all_constants |
|
97 | - * define constants that are set globally for all admin pages |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - private function _define_all_constants() |
|
102 | - { |
|
103 | - if (! defined('EE_ADMIN_URL')) { |
|
104 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | - * |
|
116 | - * @param array $links |
|
117 | - * @param string $plugin |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function filter_plugin_actions($links, $plugin) |
|
121 | - { |
|
122 | - // set $main_file in stone |
|
123 | - static $main_file; |
|
124 | - // if $main_file is not set yet |
|
125 | - if (! $main_file) { |
|
126 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | - } |
|
128 | - if ($plugin === $main_file) { |
|
129 | - // compare current plugin to this one |
|
130 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | - . '</a>'; |
|
135 | - array_unshift($links, $maintenance_link); |
|
136 | - } else { |
|
137 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | - . esc_html__('Settings', 'event_espresso') |
|
139 | - . '</a>'; |
|
140 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | - . esc_html__('Events', 'event_espresso') |
|
142 | - . '</a>'; |
|
143 | - // add before other links |
|
144 | - array_unshift($links, $org_settings_link, $events_link); |
|
145 | - } |
|
146 | - } |
|
147 | - return $links; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * _get_request |
|
153 | - * |
|
154 | - * @return void |
|
155 | - * @throws EE_Error |
|
156 | - * @throws InvalidArgumentException |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - * @throws InvalidInterfaceException |
|
159 | - * @throws ReflectionException |
|
160 | - */ |
|
161 | - public function get_request() |
|
162 | - { |
|
163 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * hide_admin_pages_except_maintenance_mode |
|
171 | - * |
|
172 | - * @param array $admin_page_folder_names |
|
173 | - * @return array |
|
174 | - */ |
|
175 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | - { |
|
177 | - return array( |
|
178 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | - * EE_Front_Controller's init phases have run |
|
189 | - * |
|
190 | - * @return void |
|
191 | - * @throws EE_Error |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws ReflectionException |
|
196 | - * @throws ServiceNotFoundException |
|
197 | - */ |
|
198 | - public function init() |
|
199 | - { |
|
200 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | - //ok so we want to enable the entire admin |
|
203 | - $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
205 | - ); |
|
206 | - $this->persistent_admin_notice_manager->setReturnUrl( |
|
207 | - EE_Admin_Page::add_query_args_and_nonce( |
|
208 | - array( |
|
209 | - 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
210 | - 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
211 | - ), |
|
212 | - EE_ADMIN_URL |
|
213 | - ) |
|
214 | - ); |
|
215 | - $this->maybeSetDatetimeWarningNotice(); |
|
216 | - //at a glance dashboard widget |
|
217 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | - //filter for get_edit_post_link used on comments for custom post types |
|
219 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | - } |
|
221 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | - try { |
|
224 | - //this loads the controller for the admin pages which will setup routing etc |
|
225 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | - } catch (EE_Error $e) { |
|
227 | - $e->get_error(); |
|
228 | - } |
|
229 | - } |
|
230 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * get_persistent_admin_notices |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return void |
|
244 | - * @throws EE_Error |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function maybeSetDatetimeWarningNotice() |
|
250 | - { |
|
251 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | - if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | - && ! get_option('timezone_string') |
|
257 | - && EEM_Event::instance()->count() > 0 |
|
258 | - ) { |
|
259 | - new PersistentAdminNotice( |
|
260 | - 'datetime_fix_notice', |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - '<strong>', |
|
267 | - '</strong>', |
|
268 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | - '</a>', |
|
270 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | - array( |
|
272 | - 'page' => 'espresso_maintenance_settings', |
|
273 | - 'action' => 'datetime_tools' |
|
274 | - ), |
|
275 | - admin_url('admin.php') |
|
276 | - ) . '">' |
|
277 | - ), |
|
278 | - false, |
|
279 | - 'manage_options', |
|
280 | - 'datetime_fix_persistent_notice' |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | - * |
|
294 | - * @param WP_Post $post_type WP post type object |
|
295 | - * @return WP_Post |
|
296 | - * @throws InvalidArgumentException |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - */ |
|
300 | - public function remove_pages_from_nav_menu($post_type) |
|
301 | - { |
|
302 | - //if this isn't the "pages" post type let's get out |
|
303 | - if ($post_type->name !== 'page') { |
|
304 | - return $post_type; |
|
305 | - } |
|
306 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | - $post_type->_default_query = array( |
|
308 | - 'post__not_in' => $critical_pages, |
|
309 | - ); |
|
310 | - return $post_type; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | - * metaboxes get shown as well |
|
318 | - * |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | - { |
|
323 | - global $wp_meta_boxes, $pagenow; |
|
324 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | - return; |
|
326 | - } |
|
327 | - $user = wp_get_current_user(); |
|
328 | - //has this been done yet? |
|
329 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | - return; |
|
331 | - } |
|
332 | - |
|
333 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | - $initial_meta_boxes = apply_filters( |
|
335 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | - array( |
|
337 | - 'nav-menu-theme-locations', |
|
338 | - 'add-page', |
|
339 | - 'add-custom-links', |
|
340 | - 'add-category', |
|
341 | - 'add-espresso_events', |
|
342 | - 'add-espresso_venues', |
|
343 | - 'add-espresso_event_categories', |
|
344 | - 'add-espresso_venue_categories', |
|
345 | - 'add-post-type-post', |
|
346 | - 'add-post-type-page', |
|
347 | - ) |
|
348 | - ); |
|
349 | - |
|
350 | - if (is_array($hidden_meta_boxes)) { |
|
351 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | - unset($hidden_meta_boxes[$key]); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | - * |
|
367 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | - * addons etc. |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function register_custom_nav_menu_boxes() |
|
372 | - { |
|
373 | - add_meta_box( |
|
374 | - 'add-extra-nav-menu-pages', |
|
375 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | - array($this, 'ee_cpt_archive_pages'), |
|
377 | - 'nav-menus', |
|
378 | - 'side', |
|
379 | - 'core' |
|
380 | - ); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | - * |
|
388 | - * @since 4.3.0 |
|
389 | - * @param string $link the original link generated by wp |
|
390 | - * @param int $id post id |
|
391 | - * @return string the (maybe) modified link |
|
392 | - */ |
|
393 | - public function modify_edit_post_link($link, $id) |
|
394 | - { |
|
395 | - if (! $post = get_post($id)) { |
|
396 | - return $link; |
|
397 | - } |
|
398 | - if ($post->post_type === 'espresso_attendees') { |
|
399 | - $query_args = array( |
|
400 | - 'action' => 'edit_attendee', |
|
401 | - 'post' => $id, |
|
402 | - ); |
|
403 | - return EEH_URL::add_query_args_and_nonce( |
|
404 | - $query_args, |
|
405 | - admin_url('admin.php?page=espresso_registrations') |
|
406 | - ); |
|
407 | - } |
|
408 | - return $link; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - public function ee_cpt_archive_pages() |
|
414 | - { |
|
415 | - global $nav_menu_selected_id; |
|
416 | - $db_fields = false; |
|
417 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | - $current_tab = 'event-archives'; |
|
419 | - $removed_args = array( |
|
420 | - 'action', |
|
421 | - 'customlink-tab', |
|
422 | - 'edit-menu-item', |
|
423 | - 'menu-item', |
|
424 | - 'page-tab', |
|
425 | - '_wpnonce', |
|
426 | - ); |
|
427 | - ?> |
|
25 | + /** |
|
26 | + * @var EE_Admin $_instance |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | + */ |
|
33 | + private $persistent_admin_notice_manager; |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @return EE_Admin |
|
38 | + * @throws EE_Error |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated |
|
43 | + if (! self::$_instance instanceof EE_Admin) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @return EE_Admin |
|
52 | + * @throws EE_Error |
|
53 | + */ |
|
54 | + public static function reset() |
|
55 | + { |
|
56 | + self::$_instance = null; |
|
57 | + return self::instance(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * class constructor |
|
63 | + * |
|
64 | + * @throws EE_Error |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidInterfaceException |
|
67 | + * @throws InvalidArgumentException |
|
68 | + */ |
|
69 | + protected function __construct() |
|
70 | + { |
|
71 | + // define global EE_Admin constants |
|
72 | + $this->_define_all_constants(); |
|
73 | + // set autoloaders for our admin page classes based on included path information |
|
74 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | + // admin hooks |
|
76 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | + // load EE_Request_Handler early |
|
78 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | + //reset Environment config (we only do this on admin page loads); |
|
89 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | + do_action('AHEE__EE_Admin__loaded'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * _define_all_constants |
|
97 | + * define constants that are set globally for all admin pages |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + private function _define_all_constants() |
|
102 | + { |
|
103 | + if (! defined('EE_ADMIN_URL')) { |
|
104 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | + * |
|
116 | + * @param array $links |
|
117 | + * @param string $plugin |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function filter_plugin_actions($links, $plugin) |
|
121 | + { |
|
122 | + // set $main_file in stone |
|
123 | + static $main_file; |
|
124 | + // if $main_file is not set yet |
|
125 | + if (! $main_file) { |
|
126 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | + } |
|
128 | + if ($plugin === $main_file) { |
|
129 | + // compare current plugin to this one |
|
130 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | + . '</a>'; |
|
135 | + array_unshift($links, $maintenance_link); |
|
136 | + } else { |
|
137 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | + . esc_html__('Settings', 'event_espresso') |
|
139 | + . '</a>'; |
|
140 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | + . esc_html__('Events', 'event_espresso') |
|
142 | + . '</a>'; |
|
143 | + // add before other links |
|
144 | + array_unshift($links, $org_settings_link, $events_link); |
|
145 | + } |
|
146 | + } |
|
147 | + return $links; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * _get_request |
|
153 | + * |
|
154 | + * @return void |
|
155 | + * @throws EE_Error |
|
156 | + * @throws InvalidArgumentException |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + * @throws InvalidInterfaceException |
|
159 | + * @throws ReflectionException |
|
160 | + */ |
|
161 | + public function get_request() |
|
162 | + { |
|
163 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * hide_admin_pages_except_maintenance_mode |
|
171 | + * |
|
172 | + * @param array $admin_page_folder_names |
|
173 | + * @return array |
|
174 | + */ |
|
175 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | + { |
|
177 | + return array( |
|
178 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | + * EE_Front_Controller's init phases have run |
|
189 | + * |
|
190 | + * @return void |
|
191 | + * @throws EE_Error |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws ReflectionException |
|
196 | + * @throws ServiceNotFoundException |
|
197 | + */ |
|
198 | + public function init() |
|
199 | + { |
|
200 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | + //ok so we want to enable the entire admin |
|
203 | + $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
205 | + ); |
|
206 | + $this->persistent_admin_notice_manager->setReturnUrl( |
|
207 | + EE_Admin_Page::add_query_args_and_nonce( |
|
208 | + array( |
|
209 | + 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
210 | + 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
211 | + ), |
|
212 | + EE_ADMIN_URL |
|
213 | + ) |
|
214 | + ); |
|
215 | + $this->maybeSetDatetimeWarningNotice(); |
|
216 | + //at a glance dashboard widget |
|
217 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | + //filter for get_edit_post_link used on comments for custom post types |
|
219 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | + } |
|
221 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | + try { |
|
224 | + //this loads the controller for the admin pages which will setup routing etc |
|
225 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | + } catch (EE_Error $e) { |
|
227 | + $e->get_error(); |
|
228 | + } |
|
229 | + } |
|
230 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * get_persistent_admin_notices |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return void |
|
244 | + * @throws EE_Error |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function maybeSetDatetimeWarningNotice() |
|
250 | + { |
|
251 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | + if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | + && ! get_option('timezone_string') |
|
257 | + && EEM_Event::instance()->count() > 0 |
|
258 | + ) { |
|
259 | + new PersistentAdminNotice( |
|
260 | + 'datetime_fix_notice', |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + '<strong>', |
|
267 | + '</strong>', |
|
268 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | + '</a>', |
|
270 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | + array( |
|
272 | + 'page' => 'espresso_maintenance_settings', |
|
273 | + 'action' => 'datetime_tools' |
|
274 | + ), |
|
275 | + admin_url('admin.php') |
|
276 | + ) . '">' |
|
277 | + ), |
|
278 | + false, |
|
279 | + 'manage_options', |
|
280 | + 'datetime_fix_persistent_notice' |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | + * |
|
294 | + * @param WP_Post $post_type WP post type object |
|
295 | + * @return WP_Post |
|
296 | + * @throws InvalidArgumentException |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + */ |
|
300 | + public function remove_pages_from_nav_menu($post_type) |
|
301 | + { |
|
302 | + //if this isn't the "pages" post type let's get out |
|
303 | + if ($post_type->name !== 'page') { |
|
304 | + return $post_type; |
|
305 | + } |
|
306 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | + $post_type->_default_query = array( |
|
308 | + 'post__not_in' => $critical_pages, |
|
309 | + ); |
|
310 | + return $post_type; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | + * metaboxes get shown as well |
|
318 | + * |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | + { |
|
323 | + global $wp_meta_boxes, $pagenow; |
|
324 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | + return; |
|
326 | + } |
|
327 | + $user = wp_get_current_user(); |
|
328 | + //has this been done yet? |
|
329 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | + return; |
|
331 | + } |
|
332 | + |
|
333 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | + $initial_meta_boxes = apply_filters( |
|
335 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | + array( |
|
337 | + 'nav-menu-theme-locations', |
|
338 | + 'add-page', |
|
339 | + 'add-custom-links', |
|
340 | + 'add-category', |
|
341 | + 'add-espresso_events', |
|
342 | + 'add-espresso_venues', |
|
343 | + 'add-espresso_event_categories', |
|
344 | + 'add-espresso_venue_categories', |
|
345 | + 'add-post-type-post', |
|
346 | + 'add-post-type-page', |
|
347 | + ) |
|
348 | + ); |
|
349 | + |
|
350 | + if (is_array($hidden_meta_boxes)) { |
|
351 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | + unset($hidden_meta_boxes[$key]); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | + * |
|
367 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | + * addons etc. |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function register_custom_nav_menu_boxes() |
|
372 | + { |
|
373 | + add_meta_box( |
|
374 | + 'add-extra-nav-menu-pages', |
|
375 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | + array($this, 'ee_cpt_archive_pages'), |
|
377 | + 'nav-menus', |
|
378 | + 'side', |
|
379 | + 'core' |
|
380 | + ); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | + * |
|
388 | + * @since 4.3.0 |
|
389 | + * @param string $link the original link generated by wp |
|
390 | + * @param int $id post id |
|
391 | + * @return string the (maybe) modified link |
|
392 | + */ |
|
393 | + public function modify_edit_post_link($link, $id) |
|
394 | + { |
|
395 | + if (! $post = get_post($id)) { |
|
396 | + return $link; |
|
397 | + } |
|
398 | + if ($post->post_type === 'espresso_attendees') { |
|
399 | + $query_args = array( |
|
400 | + 'action' => 'edit_attendee', |
|
401 | + 'post' => $id, |
|
402 | + ); |
|
403 | + return EEH_URL::add_query_args_and_nonce( |
|
404 | + $query_args, |
|
405 | + admin_url('admin.php?page=espresso_registrations') |
|
406 | + ); |
|
407 | + } |
|
408 | + return $link; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + public function ee_cpt_archive_pages() |
|
414 | + { |
|
415 | + global $nav_menu_selected_id; |
|
416 | + $db_fields = false; |
|
417 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | + $current_tab = 'event-archives'; |
|
419 | + $removed_args = array( |
|
420 | + 'action', |
|
421 | + 'customlink-tab', |
|
422 | + 'edit-menu-item', |
|
423 | + 'menu-item', |
|
424 | + 'page-tab', |
|
425 | + '_wpnonce', |
|
426 | + ); |
|
427 | + ?> |
|
428 | 428 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
429 | 429 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
430 | 430 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
431 | 431 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
432 | 432 | href="<?php if ($nav_menu_selected_id) { |
433 | - echo esc_url( |
|
434 | - add_query_arg( |
|
435 | - 'extra-nav-menu-pages-tab', |
|
436 | - 'event-archives', |
|
437 | - remove_query_arg($removed_args) |
|
438 | - ) |
|
439 | - ); |
|
440 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
433 | + echo esc_url( |
|
434 | + add_query_arg( |
|
435 | + 'extra-nav-menu-pages-tab', |
|
436 | + 'event-archives', |
|
437 | + remove_query_arg($removed_args) |
|
438 | + ) |
|
439 | + ); |
|
440 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
441 | 441 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
442 | 442 | </a> |
443 | 443 | </li> |
444 | 444 | </ul><!-- .posttype-tabs --> |
445 | 445 | |
446 | 446 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
447 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | - ?>"> |
|
447 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | + ?>"> |
|
449 | 449 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
450 | 450 | <?php |
451 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | - $args['walker'] = $walker; |
|
453 | - echo walk_nav_menu_tree( |
|
454 | - array_map( |
|
455 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | - $pages |
|
457 | - ), |
|
458 | - 0, |
|
459 | - (object) $args |
|
460 | - ); |
|
461 | - ?> |
|
451 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | + $args['walker'] = $walker; |
|
453 | + echo walk_nav_menu_tree( |
|
454 | + array_map( |
|
455 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | + $pages |
|
457 | + ), |
|
458 | + 0, |
|
459 | + (object) $args |
|
460 | + ); |
|
461 | + ?> |
|
462 | 462 | </ul> |
463 | 463 | </div><!-- /.tabs-panel --> |
464 | 464 | |
465 | 465 | <p class="button-controls"> |
466 | 466 | <span class="list-controls"> |
467 | 467 | <a href="<?php |
468 | - echo esc_url(add_query_arg( |
|
469 | - array( |
|
470 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | - 'selectall' => 1, |
|
472 | - ), |
|
473 | - remove_query_arg($removed_args) |
|
474 | - )); |
|
475 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
468 | + echo esc_url(add_query_arg( |
|
469 | + array( |
|
470 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | + 'selectall' => 1, |
|
472 | + ), |
|
473 | + remove_query_arg($removed_args) |
|
474 | + )); |
|
475 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
476 | 476 | </span> |
477 | 477 | <span class="add-to-menu"> |
478 | 478 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -485,471 +485,471 @@ discard block |
||
485 | 485 | |
486 | 486 | </div><!-- /.posttypediv --> |
487 | 487 | <?php |
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Returns an array of event archive nav items. |
|
493 | - * |
|
494 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | - * method we use for getting the extra nav menu items |
|
496 | - * @return array |
|
497 | - */ |
|
498 | - private function _get_extra_nav_menu_pages_items() |
|
499 | - { |
|
500 | - $menuitems[] = array( |
|
501 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | - ); |
|
505 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | - * the properties and converts it to the menu item object. |
|
512 | - * |
|
513 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | - * @param $menu_item_values |
|
515 | - * @return stdClass |
|
516 | - */ |
|
517 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | - { |
|
519 | - $menu_item = new stdClass(); |
|
520 | - $keys = array( |
|
521 | - 'ID' => 0, |
|
522 | - 'db_id' => 0, |
|
523 | - 'menu_item_parent' => 0, |
|
524 | - 'object_id' => -1, |
|
525 | - 'post_parent' => 0, |
|
526 | - 'type' => 'custom', |
|
527 | - 'object' => '', |
|
528 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | - 'title' => '', |
|
530 | - 'url' => '', |
|
531 | - 'target' => '', |
|
532 | - 'attr_title' => '', |
|
533 | - 'description' => '', |
|
534 | - 'classes' => array(), |
|
535 | - 'xfn' => '', |
|
536 | - ); |
|
537 | - |
|
538 | - foreach ($keys as $key => $value) { |
|
539 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | - } |
|
541 | - return $menu_item; |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | - * EE_Admin_Page route is called. |
|
548 | - * |
|
549 | - * @return void |
|
550 | - */ |
|
551 | - public function route_admin_request() |
|
552 | - { |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | - * |
|
559 | - * @return void |
|
560 | - */ |
|
561 | - public function wp_loaded() |
|
562 | - { |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * admin_init |
|
568 | - * |
|
569 | - * @return void |
|
570 | - * @throws EE_Error |
|
571 | - * @throws InvalidArgumentException |
|
572 | - * @throws InvalidDataTypeException |
|
573 | - * @throws InvalidInterfaceException |
|
574 | - * @throws ReflectionException |
|
575 | - */ |
|
576 | - public function admin_init() |
|
577 | - { |
|
578 | - |
|
579 | - /** |
|
580 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | - * - check if doing post processing. |
|
583 | - * - check if doing post processing of one of EE CPTs |
|
584 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | - */ |
|
586 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | - * Pages" tab in the EE General Settings Admin page. |
|
596 | - * This is for user-proofing. |
|
597 | - */ |
|
598 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | - * |
|
605 | - * @param string $output Current output. |
|
606 | - * @return string |
|
607 | - * @throws InvalidArgumentException |
|
608 | - * @throws InvalidDataTypeException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - */ |
|
611 | - public function modify_dropdown_pages($output) |
|
612 | - { |
|
613 | - //get critical pages |
|
614 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | - |
|
616 | - //split current output by line break for easier parsing. |
|
617 | - $split_output = explode("\n", $output); |
|
618 | - |
|
619 | - //loop through to remove any critical pages from the array. |
|
620 | - foreach ($critical_pages as $page_id) { |
|
621 | - $needle = 'value="' . $page_id . '"'; |
|
622 | - foreach ($split_output as $key => $haystack) { |
|
623 | - if (strpos($haystack, $needle) !== false) { |
|
624 | - unset($split_output[$key]); |
|
625 | - } |
|
626 | - } |
|
627 | - } |
|
628 | - //replace output with the new contents |
|
629 | - return implode("\n", $split_output); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * enqueue all admin scripts that need loaded for admin pages |
|
635 | - * |
|
636 | - * @return void |
|
637 | - */ |
|
638 | - public function enqueue_admin_scripts() |
|
639 | - { |
|
640 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | - // calls. |
|
643 | - wp_enqueue_script( |
|
644 | - 'ee-inject-wp', |
|
645 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | - array('jquery'), |
|
647 | - EVENT_ESPRESSO_VERSION, |
|
648 | - true |
|
649 | - ); |
|
650 | - // register cookie script for future dependencies |
|
651 | - wp_register_script( |
|
652 | - 'jquery-cookie', |
|
653 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | - array('jquery'), |
|
655 | - '2.1', |
|
656 | - true |
|
657 | - ); |
|
658 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | - //joyride style |
|
662 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | - wp_register_style( |
|
664 | - 'ee-joyride-css', |
|
665 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | - array('joyride-css'), |
|
667 | - EVENT_ESPRESSO_VERSION |
|
668 | - ); |
|
669 | - wp_register_script( |
|
670 | - 'joyride-modernizr', |
|
671 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | - array(), |
|
673 | - '2.1', |
|
674 | - true |
|
675 | - ); |
|
676 | - //joyride JS |
|
677 | - wp_register_script( |
|
678 | - 'jquery-joyride', |
|
679 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | - array('jquery-cookie', 'joyride-modernizr'), |
|
681 | - '2.1', |
|
682 | - true |
|
683 | - ); |
|
684 | - // wanna go for a joyride? |
|
685 | - wp_enqueue_style('ee-joyride-css'); |
|
686 | - wp_enqueue_script('jquery-joyride'); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * display_admin_notices |
|
693 | - * |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function display_admin_notices() |
|
697 | - { |
|
698 | - echo EE_Error::get_notices(); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * @param array $elements |
|
705 | - * @return array |
|
706 | - * @throws EE_Error |
|
707 | - * @throws InvalidArgumentException |
|
708 | - * @throws InvalidDataTypeException |
|
709 | - * @throws InvalidInterfaceException |
|
710 | - */ |
|
711 | - public function dashboard_glance_items($elements) |
|
712 | - { |
|
713 | - $elements = is_array($elements) ? $elements : array($elements); |
|
714 | - $events = EEM_Event::instance()->count(); |
|
715 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | - array('page' => 'espresso_events'), |
|
717 | - admin_url('admin.php') |
|
718 | - ); |
|
719 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | - $registrations = EEM_Registration::instance()->count( |
|
722 | - array( |
|
723 | - array( |
|
724 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | - ), |
|
726 | - ) |
|
727 | - ); |
|
728 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | - array('page' => 'espresso_registrations'), |
|
730 | - admin_url('admin.php') |
|
731 | - ); |
|
732 | - $items['registrations']['text'] = sprintf( |
|
733 | - _n('%s Registration', '%s Registrations', $registrations), |
|
734 | - number_format_i18n($registrations) |
|
735 | - ); |
|
736 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | - |
|
738 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | - |
|
740 | - foreach ($items as $type => $item_properties) { |
|
741 | - $elements[] = sprintf( |
|
742 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | - $item_properties['url'], |
|
744 | - $item_properties['title'], |
|
745 | - $item_properties['text'] |
|
746 | - ); |
|
747 | - } |
|
748 | - return $elements; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * check_for_invalid_datetime_formats |
|
754 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | - * their selected format can be parsed by PHP |
|
756 | - * |
|
757 | - * @param $value |
|
758 | - * @param $option |
|
759 | - * @throws EE_Error |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - public function check_for_invalid_datetime_formats($value, $option) |
|
763 | - { |
|
764 | - // check for date_format or time_format |
|
765 | - switch ($option) { |
|
766 | - case 'date_format': |
|
767 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | - break; |
|
769 | - case 'time_format': |
|
770 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | - break; |
|
772 | - default: |
|
773 | - $date_time_format = false; |
|
774 | - } |
|
775 | - // do we have a date_time format to check ? |
|
776 | - if ($date_time_format) { |
|
777 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | - |
|
779 | - if (is_array($error_msg)) { |
|
780 | - $msg = '<p>' |
|
781 | - . sprintf( |
|
782 | - esc_html__( |
|
783 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | - 'event_espresso' |
|
785 | - ), |
|
786 | - date($date_time_format), |
|
787 | - $date_time_format |
|
788 | - ) |
|
789 | - . '</p><p><ul>'; |
|
790 | - |
|
791 | - |
|
792 | - foreach ($error_msg as $error) { |
|
793 | - $msg .= '<li>' . $error . '</li>'; |
|
794 | - } |
|
795 | - |
|
796 | - $msg .= '</ul></p><p>' |
|
797 | - . sprintf( |
|
798 | - esc_html__( |
|
799 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | - 'event_espresso' |
|
801 | - ), |
|
802 | - '<span style="color:#D54E21;">', |
|
803 | - '</span>' |
|
804 | - ) |
|
805 | - . '</p>'; |
|
806 | - |
|
807 | - // trigger WP settings error |
|
808 | - add_settings_error( |
|
809 | - 'date_format', |
|
810 | - 'date_format', |
|
811 | - $msg |
|
812 | - ); |
|
813 | - |
|
814 | - // set format to something valid |
|
815 | - switch ($option) { |
|
816 | - case 'date_format': |
|
817 | - $value = 'F j, Y'; |
|
818 | - break; |
|
819 | - case 'time_format': |
|
820 | - $value = 'g:i a'; |
|
821 | - break; |
|
822 | - } |
|
823 | - } |
|
824 | - } |
|
825 | - return $value; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | - * |
|
832 | - * @param $content |
|
833 | - * @return string |
|
834 | - */ |
|
835 | - public function its_eSpresso($content) |
|
836 | - { |
|
837 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * espresso_admin_footer |
|
843 | - * |
|
844 | - * @return string |
|
845 | - */ |
|
846 | - public function espresso_admin_footer() |
|
847 | - { |
|
848 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * static method for registering ee admin page. |
|
854 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | - * |
|
856 | - * @since 4.3.0 |
|
857 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | - * @see EE_Register_Admin_Page::register() |
|
859 | - * @param $page_basename |
|
860 | - * @param $page_path |
|
861 | - * @param array $config |
|
862 | - * @return void |
|
863 | - * @throws EE_Error |
|
864 | - */ |
|
865 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | - { |
|
867 | - EE_Error::doing_it_wrong( |
|
868 | - __METHOD__, |
|
869 | - sprintf( |
|
870 | - esc_html__( |
|
871 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | - 'event_espresso' |
|
873 | - ), |
|
874 | - $page_basename |
|
875 | - ), |
|
876 | - '4.3' |
|
877 | - ); |
|
878 | - if (class_exists('EE_Register_Admin_Page')) { |
|
879 | - $config['page_path'] = $page_path; |
|
880 | - } |
|
881 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * @deprecated 4.8.41 |
|
887 | - * @param int $post_ID |
|
888 | - * @param \WP_Post $post |
|
889 | - * @return void |
|
890 | - */ |
|
891 | - public static function parse_post_content_on_save($post_ID, $post) |
|
892 | - { |
|
893 | - EE_Error::doing_it_wrong( |
|
894 | - __METHOD__, |
|
895 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | - '4.8.41' |
|
897 | - ); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * @deprecated 4.8.41 |
|
903 | - * @param $option |
|
904 | - * @param $old_value |
|
905 | - * @param $value |
|
906 | - * @return void |
|
907 | - */ |
|
908 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | - { |
|
910 | - EE_Error::doing_it_wrong( |
|
911 | - __METHOD__, |
|
912 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | - '4.8.41' |
|
914 | - ); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @deprecated 4.9.27 |
|
921 | - * @return void |
|
922 | - */ |
|
923 | - public function get_persistent_admin_notices() |
|
924 | - { |
|
925 | - EE_Error::doing_it_wrong( |
|
926 | - __METHOD__, |
|
927 | - sprintf( |
|
928 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | - ), |
|
931 | - '4.9.27' |
|
932 | - ); |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * @deprecated 4.9.27 |
|
939 | - * @throws InvalidInterfaceException |
|
940 | - * @throws InvalidDataTypeException |
|
941 | - * @throws DomainException |
|
942 | - */ |
|
943 | - public function dismiss_ee_nag_notice_callback() |
|
944 | - { |
|
945 | - EE_Error::doing_it_wrong( |
|
946 | - __METHOD__, |
|
947 | - sprintf( |
|
948 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | - ), |
|
951 | - '4.9.27' |
|
952 | - ); |
|
953 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | - } |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Returns an array of event archive nav items. |
|
493 | + * |
|
494 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | + * method we use for getting the extra nav menu items |
|
496 | + * @return array |
|
497 | + */ |
|
498 | + private function _get_extra_nav_menu_pages_items() |
|
499 | + { |
|
500 | + $menuitems[] = array( |
|
501 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | + ); |
|
505 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | + * the properties and converts it to the menu item object. |
|
512 | + * |
|
513 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | + * @param $menu_item_values |
|
515 | + * @return stdClass |
|
516 | + */ |
|
517 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | + { |
|
519 | + $menu_item = new stdClass(); |
|
520 | + $keys = array( |
|
521 | + 'ID' => 0, |
|
522 | + 'db_id' => 0, |
|
523 | + 'menu_item_parent' => 0, |
|
524 | + 'object_id' => -1, |
|
525 | + 'post_parent' => 0, |
|
526 | + 'type' => 'custom', |
|
527 | + 'object' => '', |
|
528 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | + 'title' => '', |
|
530 | + 'url' => '', |
|
531 | + 'target' => '', |
|
532 | + 'attr_title' => '', |
|
533 | + 'description' => '', |
|
534 | + 'classes' => array(), |
|
535 | + 'xfn' => '', |
|
536 | + ); |
|
537 | + |
|
538 | + foreach ($keys as $key => $value) { |
|
539 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | + } |
|
541 | + return $menu_item; |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | + * EE_Admin_Page route is called. |
|
548 | + * |
|
549 | + * @return void |
|
550 | + */ |
|
551 | + public function route_admin_request() |
|
552 | + { |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | + * |
|
559 | + * @return void |
|
560 | + */ |
|
561 | + public function wp_loaded() |
|
562 | + { |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * admin_init |
|
568 | + * |
|
569 | + * @return void |
|
570 | + * @throws EE_Error |
|
571 | + * @throws InvalidArgumentException |
|
572 | + * @throws InvalidDataTypeException |
|
573 | + * @throws InvalidInterfaceException |
|
574 | + * @throws ReflectionException |
|
575 | + */ |
|
576 | + public function admin_init() |
|
577 | + { |
|
578 | + |
|
579 | + /** |
|
580 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | + * - check if doing post processing. |
|
583 | + * - check if doing post processing of one of EE CPTs |
|
584 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | + */ |
|
586 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | + * Pages" tab in the EE General Settings Admin page. |
|
596 | + * This is for user-proofing. |
|
597 | + */ |
|
598 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | + * |
|
605 | + * @param string $output Current output. |
|
606 | + * @return string |
|
607 | + * @throws InvalidArgumentException |
|
608 | + * @throws InvalidDataTypeException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + */ |
|
611 | + public function modify_dropdown_pages($output) |
|
612 | + { |
|
613 | + //get critical pages |
|
614 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | + |
|
616 | + //split current output by line break for easier parsing. |
|
617 | + $split_output = explode("\n", $output); |
|
618 | + |
|
619 | + //loop through to remove any critical pages from the array. |
|
620 | + foreach ($critical_pages as $page_id) { |
|
621 | + $needle = 'value="' . $page_id . '"'; |
|
622 | + foreach ($split_output as $key => $haystack) { |
|
623 | + if (strpos($haystack, $needle) !== false) { |
|
624 | + unset($split_output[$key]); |
|
625 | + } |
|
626 | + } |
|
627 | + } |
|
628 | + //replace output with the new contents |
|
629 | + return implode("\n", $split_output); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * enqueue all admin scripts that need loaded for admin pages |
|
635 | + * |
|
636 | + * @return void |
|
637 | + */ |
|
638 | + public function enqueue_admin_scripts() |
|
639 | + { |
|
640 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | + // calls. |
|
643 | + wp_enqueue_script( |
|
644 | + 'ee-inject-wp', |
|
645 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | + array('jquery'), |
|
647 | + EVENT_ESPRESSO_VERSION, |
|
648 | + true |
|
649 | + ); |
|
650 | + // register cookie script for future dependencies |
|
651 | + wp_register_script( |
|
652 | + 'jquery-cookie', |
|
653 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | + array('jquery'), |
|
655 | + '2.1', |
|
656 | + true |
|
657 | + ); |
|
658 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | + //joyride style |
|
662 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | + wp_register_style( |
|
664 | + 'ee-joyride-css', |
|
665 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | + array('joyride-css'), |
|
667 | + EVENT_ESPRESSO_VERSION |
|
668 | + ); |
|
669 | + wp_register_script( |
|
670 | + 'joyride-modernizr', |
|
671 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | + array(), |
|
673 | + '2.1', |
|
674 | + true |
|
675 | + ); |
|
676 | + //joyride JS |
|
677 | + wp_register_script( |
|
678 | + 'jquery-joyride', |
|
679 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | + array('jquery-cookie', 'joyride-modernizr'), |
|
681 | + '2.1', |
|
682 | + true |
|
683 | + ); |
|
684 | + // wanna go for a joyride? |
|
685 | + wp_enqueue_style('ee-joyride-css'); |
|
686 | + wp_enqueue_script('jquery-joyride'); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * display_admin_notices |
|
693 | + * |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function display_admin_notices() |
|
697 | + { |
|
698 | + echo EE_Error::get_notices(); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * @param array $elements |
|
705 | + * @return array |
|
706 | + * @throws EE_Error |
|
707 | + * @throws InvalidArgumentException |
|
708 | + * @throws InvalidDataTypeException |
|
709 | + * @throws InvalidInterfaceException |
|
710 | + */ |
|
711 | + public function dashboard_glance_items($elements) |
|
712 | + { |
|
713 | + $elements = is_array($elements) ? $elements : array($elements); |
|
714 | + $events = EEM_Event::instance()->count(); |
|
715 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | + array('page' => 'espresso_events'), |
|
717 | + admin_url('admin.php') |
|
718 | + ); |
|
719 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | + $registrations = EEM_Registration::instance()->count( |
|
722 | + array( |
|
723 | + array( |
|
724 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | + ), |
|
726 | + ) |
|
727 | + ); |
|
728 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | + array('page' => 'espresso_registrations'), |
|
730 | + admin_url('admin.php') |
|
731 | + ); |
|
732 | + $items['registrations']['text'] = sprintf( |
|
733 | + _n('%s Registration', '%s Registrations', $registrations), |
|
734 | + number_format_i18n($registrations) |
|
735 | + ); |
|
736 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | + |
|
738 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | + |
|
740 | + foreach ($items as $type => $item_properties) { |
|
741 | + $elements[] = sprintf( |
|
742 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | + $item_properties['url'], |
|
744 | + $item_properties['title'], |
|
745 | + $item_properties['text'] |
|
746 | + ); |
|
747 | + } |
|
748 | + return $elements; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * check_for_invalid_datetime_formats |
|
754 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | + * their selected format can be parsed by PHP |
|
756 | + * |
|
757 | + * @param $value |
|
758 | + * @param $option |
|
759 | + * @throws EE_Error |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + public function check_for_invalid_datetime_formats($value, $option) |
|
763 | + { |
|
764 | + // check for date_format or time_format |
|
765 | + switch ($option) { |
|
766 | + case 'date_format': |
|
767 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | + break; |
|
769 | + case 'time_format': |
|
770 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | + break; |
|
772 | + default: |
|
773 | + $date_time_format = false; |
|
774 | + } |
|
775 | + // do we have a date_time format to check ? |
|
776 | + if ($date_time_format) { |
|
777 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | + |
|
779 | + if (is_array($error_msg)) { |
|
780 | + $msg = '<p>' |
|
781 | + . sprintf( |
|
782 | + esc_html__( |
|
783 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | + 'event_espresso' |
|
785 | + ), |
|
786 | + date($date_time_format), |
|
787 | + $date_time_format |
|
788 | + ) |
|
789 | + . '</p><p><ul>'; |
|
790 | + |
|
791 | + |
|
792 | + foreach ($error_msg as $error) { |
|
793 | + $msg .= '<li>' . $error . '</li>'; |
|
794 | + } |
|
795 | + |
|
796 | + $msg .= '</ul></p><p>' |
|
797 | + . sprintf( |
|
798 | + esc_html__( |
|
799 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | + 'event_espresso' |
|
801 | + ), |
|
802 | + '<span style="color:#D54E21;">', |
|
803 | + '</span>' |
|
804 | + ) |
|
805 | + . '</p>'; |
|
806 | + |
|
807 | + // trigger WP settings error |
|
808 | + add_settings_error( |
|
809 | + 'date_format', |
|
810 | + 'date_format', |
|
811 | + $msg |
|
812 | + ); |
|
813 | + |
|
814 | + // set format to something valid |
|
815 | + switch ($option) { |
|
816 | + case 'date_format': |
|
817 | + $value = 'F j, Y'; |
|
818 | + break; |
|
819 | + case 'time_format': |
|
820 | + $value = 'g:i a'; |
|
821 | + break; |
|
822 | + } |
|
823 | + } |
|
824 | + } |
|
825 | + return $value; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | + * |
|
832 | + * @param $content |
|
833 | + * @return string |
|
834 | + */ |
|
835 | + public function its_eSpresso($content) |
|
836 | + { |
|
837 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * espresso_admin_footer |
|
843 | + * |
|
844 | + * @return string |
|
845 | + */ |
|
846 | + public function espresso_admin_footer() |
|
847 | + { |
|
848 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * static method for registering ee admin page. |
|
854 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | + * |
|
856 | + * @since 4.3.0 |
|
857 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | + * @see EE_Register_Admin_Page::register() |
|
859 | + * @param $page_basename |
|
860 | + * @param $page_path |
|
861 | + * @param array $config |
|
862 | + * @return void |
|
863 | + * @throws EE_Error |
|
864 | + */ |
|
865 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | + { |
|
867 | + EE_Error::doing_it_wrong( |
|
868 | + __METHOD__, |
|
869 | + sprintf( |
|
870 | + esc_html__( |
|
871 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | + 'event_espresso' |
|
873 | + ), |
|
874 | + $page_basename |
|
875 | + ), |
|
876 | + '4.3' |
|
877 | + ); |
|
878 | + if (class_exists('EE_Register_Admin_Page')) { |
|
879 | + $config['page_path'] = $page_path; |
|
880 | + } |
|
881 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * @deprecated 4.8.41 |
|
887 | + * @param int $post_ID |
|
888 | + * @param \WP_Post $post |
|
889 | + * @return void |
|
890 | + */ |
|
891 | + public static function parse_post_content_on_save($post_ID, $post) |
|
892 | + { |
|
893 | + EE_Error::doing_it_wrong( |
|
894 | + __METHOD__, |
|
895 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | + '4.8.41' |
|
897 | + ); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * @deprecated 4.8.41 |
|
903 | + * @param $option |
|
904 | + * @param $old_value |
|
905 | + * @param $value |
|
906 | + * @return void |
|
907 | + */ |
|
908 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | + { |
|
910 | + EE_Error::doing_it_wrong( |
|
911 | + __METHOD__, |
|
912 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | + '4.8.41' |
|
914 | + ); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @deprecated 4.9.27 |
|
921 | + * @return void |
|
922 | + */ |
|
923 | + public function get_persistent_admin_notices() |
|
924 | + { |
|
925 | + EE_Error::doing_it_wrong( |
|
926 | + __METHOD__, |
|
927 | + sprintf( |
|
928 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | + ), |
|
931 | + '4.9.27' |
|
932 | + ); |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * @deprecated 4.9.27 |
|
939 | + * @throws InvalidInterfaceException |
|
940 | + * @throws InvalidDataTypeException |
|
941 | + * @throws DomainException |
|
942 | + */ |
|
943 | + public function dismiss_ee_nag_notice_callback() |
|
944 | + { |
|
945 | + EE_Error::doing_it_wrong( |
|
946 | + __METHOD__, |
|
947 | + sprintf( |
|
948 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | + ), |
|
951 | + '4.9.27' |
|
952 | + ); |
|
953 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | + } |
|
955 | 955 | } |
@@ -28,223 +28,223 @@ |
||
28 | 28 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var EE_Request $request |
|
33 | - */ |
|
34 | - protected $request; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Response $response |
|
38 | - */ |
|
39 | - protected $response; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var EE_Dependency_Map $dependency_map |
|
43 | - */ |
|
44 | - protected $dependency_map; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EE_Registry $registry |
|
48 | - */ |
|
49 | - protected $registry; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * EE_Load_Espresso_Core constructor |
|
54 | - * |
|
55 | - * @throws EE_Error |
|
56 | - */ |
|
31 | + /** |
|
32 | + * @var EE_Request $request |
|
33 | + */ |
|
34 | + protected $request; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Response $response |
|
38 | + */ |
|
39 | + protected $response; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var EE_Dependency_Map $dependency_map |
|
43 | + */ |
|
44 | + protected $dependency_map; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EE_Registry $registry |
|
48 | + */ |
|
49 | + protected $registry; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * EE_Load_Espresso_Core constructor |
|
54 | + * |
|
55 | + * @throws EE_Error |
|
56 | + */ |
|
57 | 57 | public function __construct() { |
58 | - // deprecated functions |
|
59 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
60 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * handle |
|
66 | - * sets hooks for running rest of system |
|
67 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | - * starting EE Addons from any other point may lead to problems |
|
69 | - * |
|
70 | - * @param EE_Request $request |
|
71 | - * @param EE_Response $response |
|
72 | - * @return EE_Response |
|
73 | - * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
74 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
75 | - * @throws EE_Error |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws DomainException |
|
80 | - */ |
|
81 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
82 | - { |
|
83 | - $this->request = $request; |
|
84 | - $this->response = $response; |
|
85 | - // info about how to load classes required by other classes |
|
86 | - $this->dependency_map = $this->_load_dependency_map(); |
|
87 | - // central repository for classes |
|
88 | - $this->registry = $this->_load_registry(); |
|
89 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
90 | - $loader = LoaderFactory::getLoader($this->registry); |
|
91 | - $this->dependency_map->setLoader($loader); |
|
92 | - // instantiate core Domain class |
|
93 | - DomainFactory::getShared( |
|
94 | - new FullyQualifiedName( |
|
95 | - 'EventEspresso\core\domain\Domain' |
|
96 | - ), |
|
97 | - array( |
|
98 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
99 | - Version::fromString(espresso_version()) |
|
100 | - ) |
|
101 | - ); |
|
102 | - // build DI container |
|
103 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
104 | - // $OpenCoffeeShop->addRecipes(); |
|
105 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
106 | - // workarounds for PHP < 5.3 |
|
107 | - $this->_load_class_tools(); |
|
108 | - // deprecated functions |
|
109 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
110 | - $loader->getShared( |
|
111 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
112 | - ); |
|
113 | - // WP cron jobs |
|
114 | - $loader->getShared('EE_Cron_Tasks'); |
|
115 | - $loader->getShared('EE_Request_Handler'); |
|
116 | - $loader->getShared('EE_System'); |
|
117 | - return $this->response; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return EE_Request |
|
124 | - */ |
|
125 | - public function request() |
|
126 | - { |
|
127 | - return $this->request; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return EE_Response |
|
134 | - */ |
|
135 | - public function response() |
|
136 | - { |
|
137 | - return $this->response; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return EE_Dependency_Map |
|
144 | - * @throws EE_Error |
|
145 | - */ |
|
146 | - public function dependency_map() |
|
147 | - { |
|
148 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
149 | - throw new EE_Error( |
|
150 | - sprintf( |
|
151 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
152 | - print_r($this->dependency_map, true) |
|
153 | - ) |
|
154 | - ); |
|
155 | - } |
|
156 | - return $this->dependency_map; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return EE_Registry |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - public function registry() |
|
166 | - { |
|
167 | - if (! $this->registry instanceof EE_Registry) { |
|
168 | - throw new EE_Error( |
|
169 | - sprintf( |
|
170 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
171 | - print_r($this->registry, true) |
|
172 | - ) |
|
173 | - ); |
|
174 | - } |
|
175 | - return $this->registry; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @return EE_Dependency_Map |
|
182 | - */ |
|
183 | - private function _load_dependency_map() |
|
184 | - { |
|
185 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
186 | - EE_Error::add_error( |
|
187 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
188 | - __FILE__, __FUNCTION__, __LINE__ |
|
189 | - ); |
|
190 | - wp_die(EE_Error::get_notices()); |
|
191 | - } |
|
192 | - require_once EE_CORE . 'EE_Dependency_Map.core.php'; |
|
193 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @return EE_Registry |
|
200 | - * @throws \InvalidArgumentException |
|
201 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
202 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
203 | - */ |
|
204 | - private function _load_registry() |
|
205 | - { |
|
206 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
207 | - EE_Error::add_error( |
|
208 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
209 | - __FILE__, __FUNCTION__, __LINE__ |
|
210 | - ); |
|
211 | - wp_die(EE_Error::get_notices()); |
|
212 | - } |
|
213 | - require_once EE_CORE . 'EE_Registry.core.php'; |
|
214 | - return EE_Registry::instance($this->dependency_map); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - private function _load_class_tools() |
|
223 | - { |
|
224 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
225 | - EE_Error::add_error( |
|
226 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
227 | - __FILE__, __FUNCTION__, __LINE__ |
|
228 | - ); |
|
229 | - } |
|
230 | - require_once EE_HELPERS . 'EEH_Class_Tools.helper.php'; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * called after the request stack has been fully processed |
|
237 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
238 | - * |
|
239 | - * @param EE_Request $request |
|
240 | - * @param EE_Response $response |
|
241 | - */ |
|
242 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
243 | - { |
|
244 | - if ($response->plugin_deactivated()) { |
|
245 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
246 | - } |
|
247 | - } |
|
58 | + // deprecated functions |
|
59 | + espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
60 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * handle |
|
66 | + * sets hooks for running rest of system |
|
67 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | + * starting EE Addons from any other point may lead to problems |
|
69 | + * |
|
70 | + * @param EE_Request $request |
|
71 | + * @param EE_Response $response |
|
72 | + * @return EE_Response |
|
73 | + * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
74 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
75 | + * @throws EE_Error |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws DomainException |
|
80 | + */ |
|
81 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
82 | + { |
|
83 | + $this->request = $request; |
|
84 | + $this->response = $response; |
|
85 | + // info about how to load classes required by other classes |
|
86 | + $this->dependency_map = $this->_load_dependency_map(); |
|
87 | + // central repository for classes |
|
88 | + $this->registry = $this->_load_registry(); |
|
89 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
90 | + $loader = LoaderFactory::getLoader($this->registry); |
|
91 | + $this->dependency_map->setLoader($loader); |
|
92 | + // instantiate core Domain class |
|
93 | + DomainFactory::getShared( |
|
94 | + new FullyQualifiedName( |
|
95 | + 'EventEspresso\core\domain\Domain' |
|
96 | + ), |
|
97 | + array( |
|
98 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
99 | + Version::fromString(espresso_version()) |
|
100 | + ) |
|
101 | + ); |
|
102 | + // build DI container |
|
103 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
104 | + // $OpenCoffeeShop->addRecipes(); |
|
105 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
106 | + // workarounds for PHP < 5.3 |
|
107 | + $this->_load_class_tools(); |
|
108 | + // deprecated functions |
|
109 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
110 | + $loader->getShared( |
|
111 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
112 | + ); |
|
113 | + // WP cron jobs |
|
114 | + $loader->getShared('EE_Cron_Tasks'); |
|
115 | + $loader->getShared('EE_Request_Handler'); |
|
116 | + $loader->getShared('EE_System'); |
|
117 | + return $this->response; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return EE_Request |
|
124 | + */ |
|
125 | + public function request() |
|
126 | + { |
|
127 | + return $this->request; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return EE_Response |
|
134 | + */ |
|
135 | + public function response() |
|
136 | + { |
|
137 | + return $this->response; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return EE_Dependency_Map |
|
144 | + * @throws EE_Error |
|
145 | + */ |
|
146 | + public function dependency_map() |
|
147 | + { |
|
148 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
149 | + throw new EE_Error( |
|
150 | + sprintf( |
|
151 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
152 | + print_r($this->dependency_map, true) |
|
153 | + ) |
|
154 | + ); |
|
155 | + } |
|
156 | + return $this->dependency_map; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return EE_Registry |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + public function registry() |
|
166 | + { |
|
167 | + if (! $this->registry instanceof EE_Registry) { |
|
168 | + throw new EE_Error( |
|
169 | + sprintf( |
|
170 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
171 | + print_r($this->registry, true) |
|
172 | + ) |
|
173 | + ); |
|
174 | + } |
|
175 | + return $this->registry; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @return EE_Dependency_Map |
|
182 | + */ |
|
183 | + private function _load_dependency_map() |
|
184 | + { |
|
185 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
186 | + EE_Error::add_error( |
|
187 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
188 | + __FILE__, __FUNCTION__, __LINE__ |
|
189 | + ); |
|
190 | + wp_die(EE_Error::get_notices()); |
|
191 | + } |
|
192 | + require_once EE_CORE . 'EE_Dependency_Map.core.php'; |
|
193 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @return EE_Registry |
|
200 | + * @throws \InvalidArgumentException |
|
201 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
202 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
203 | + */ |
|
204 | + private function _load_registry() |
|
205 | + { |
|
206 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
207 | + EE_Error::add_error( |
|
208 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
209 | + __FILE__, __FUNCTION__, __LINE__ |
|
210 | + ); |
|
211 | + wp_die(EE_Error::get_notices()); |
|
212 | + } |
|
213 | + require_once EE_CORE . 'EE_Registry.core.php'; |
|
214 | + return EE_Registry::instance($this->dependency_map); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + private function _load_class_tools() |
|
223 | + { |
|
224 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
225 | + EE_Error::add_error( |
|
226 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
227 | + __FILE__, __FUNCTION__, __LINE__ |
|
228 | + ); |
|
229 | + } |
|
230 | + require_once EE_HELPERS . 'EEH_Class_Tools.helper.php'; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * called after the request stack has been fully processed |
|
237 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
238 | + * |
|
239 | + * @param EE_Request $request |
|
240 | + * @param EE_Response $response |
|
241 | + */ |
|
242 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
243 | + { |
|
244 | + if ($response->plugin_deactivated()) { |
|
245 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | 250 |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function __construct() { |
58 | 58 | // deprecated functions |
59 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
60 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
59 | + espresso_load_required('EE_Base', EE_CORE.'EE_Base.core.php'); |
|
60 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | // workarounds for PHP < 5.3 |
107 | 107 | $this->_load_class_tools(); |
108 | 108 | // deprecated functions |
109 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
109 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
110 | 110 | $loader->getShared( |
111 | 111 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
112 | 112 | ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function dependency_map() |
147 | 147 | { |
148 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
148 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
149 | 149 | throw new EE_Error( |
150 | 150 | sprintf( |
151 | 151 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function registry() |
166 | 166 | { |
167 | - if (! $this->registry instanceof EE_Registry) { |
|
167 | + if ( ! $this->registry instanceof EE_Registry) { |
|
168 | 168 | throw new EE_Error( |
169 | 169 | sprintf( |
170 | 170 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function _load_dependency_map() |
184 | 184 | { |
185 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
185 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
186 | 186 | EE_Error::add_error( |
187 | 187 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
188 | 188 | __FILE__, __FUNCTION__, __LINE__ |
189 | 189 | ); |
190 | 190 | wp_die(EE_Error::get_notices()); |
191 | 191 | } |
192 | - require_once EE_CORE . 'EE_Dependency_Map.core.php'; |
|
192 | + require_once EE_CORE.'EE_Dependency_Map.core.php'; |
|
193 | 193 | return EE_Dependency_Map::instance($this->request, $this->response); |
194 | 194 | } |
195 | 195 | |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | */ |
204 | 204 | private function _load_registry() |
205 | 205 | { |
206 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
206 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
207 | 207 | EE_Error::add_error( |
208 | 208 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
209 | 209 | __FILE__, __FUNCTION__, __LINE__ |
210 | 210 | ); |
211 | 211 | wp_die(EE_Error::get_notices()); |
212 | 212 | } |
213 | - require_once EE_CORE . 'EE_Registry.core.php'; |
|
213 | + require_once EE_CORE.'EE_Registry.core.php'; |
|
214 | 214 | return EE_Registry::instance($this->dependency_map); |
215 | 215 | } |
216 | 216 | |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | */ |
222 | 222 | private function _load_class_tools() |
223 | 223 | { |
224 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
224 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
225 | 225 | EE_Error::add_error( |
226 | 226 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
227 | 227 | __FILE__, __FUNCTION__, __LINE__ |
228 | 228 | ); |
229 | 229 | } |
230 | - require_once EE_HELPERS . 'EEH_Class_Tools.helper.php'; |
|
230 | + require_once EE_HELPERS.'EEH_Class_Tools.helper.php'; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 |