@@ -30,344 +30,344 @@ |
||
30 | 30 | class PersistentAdminNoticeManager |
31 | 31 | { |
32 | 32 | |
33 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
37 | - */ |
|
38 | - private $notice_collection; |
|
39 | - |
|
40 | - /** |
|
41 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
42 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
43 | - * |
|
44 | - * @type string $return_url |
|
45 | - */ |
|
46 | - private $return_url; |
|
47 | - |
|
48 | - /** |
|
49 | - * @type CapabilitiesChecker $capabilities_checker |
|
50 | - */ |
|
51 | - private $capabilities_checker; |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Request $request |
|
55 | - */ |
|
56 | - private $request; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * CapChecker constructor |
|
62 | - * |
|
63 | - * @param string $return_url where to redirect to after dismissing notices |
|
64 | - * @param CapabilitiesChecker $capabilities_checker |
|
65 | - * @param EE_Request $request |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - */ |
|
68 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
69 | - { |
|
70 | - $this->setReturnUrl($return_url); |
|
71 | - $this->capabilities_checker = $capabilities_checker; |
|
72 | - $this->request = $request; |
|
73 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | - add_action('shutdown', array($this, 'saveNotices')); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $return_url |
|
85 | - * @throws InvalidDataTypeException |
|
86 | - */ |
|
87 | - private function setReturnUrl($return_url) |
|
88 | - { |
|
89 | - if (! is_string($return_url)) { |
|
90 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
91 | - } |
|
92 | - $this->return_url = $return_url; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return Collection |
|
99 | - * @throws InvalidEntityException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - * @throws InvalidDataTypeException |
|
102 | - * @throws DomainException |
|
103 | - */ |
|
104 | - protected function getPersistentAdminNoticeCollection() |
|
105 | - { |
|
106 | - if (! $this->notice_collection instanceof Collection) { |
|
107 | - $this->notice_collection = new Collection( |
|
108 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
109 | - ); |
|
110 | - $this->retrieveStoredNotices(); |
|
111 | - $this->registerNotices(); |
|
112 | - } |
|
113 | - return $this->notice_collection; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
120 | - * |
|
121 | - * @return void |
|
122 | - * @throws InvalidEntityException |
|
123 | - * @throws DomainException |
|
124 | - * @throws InvalidDataTypeException |
|
125 | - */ |
|
126 | - protected function retrieveStoredNotices() |
|
127 | - { |
|
128 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
129 | - // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
130 | - if (! empty($persistent_admin_notices)) { |
|
131 | - foreach ($persistent_admin_notices as $name => $details) { |
|
132 | - if (is_array($details)) { |
|
133 | - if ( |
|
134 | - ! isset( |
|
135 | - $details['message'], |
|
136 | - $details['capability'], |
|
137 | - $details['cap_context'], |
|
138 | - $details['dismissed'] |
|
139 | - ) |
|
140 | - ) { |
|
141 | - throw new DomainException( |
|
142 | - sprintf( |
|
143 | - esc_html__( |
|
144 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
145 | - 'event_espresso' |
|
146 | - ), |
|
147 | - $name |
|
148 | - ) |
|
149 | - ); |
|
150 | - } |
|
151 | - // new format for nag notices |
|
152 | - $this->notice_collection->add( |
|
153 | - new PersistentAdminNotice( |
|
154 | - $name, |
|
155 | - $details['message'], |
|
156 | - false, |
|
157 | - $details['capability'], |
|
158 | - $details['cap_context'], |
|
159 | - $details['dismissed'] |
|
160 | - ), |
|
161 | - $name |
|
162 | - ); |
|
163 | - } else { |
|
164 | - try { |
|
165 | - // old nag notices, that we want to convert to the new format |
|
166 | - $this->notice_collection->add( |
|
167 | - new PersistentAdminNotice( |
|
168 | - $name, |
|
169 | - (string)$details, |
|
170 | - false, |
|
171 | - '', |
|
172 | - '', |
|
173 | - empty($details) |
|
174 | - ), |
|
175 | - $name |
|
176 | - ); |
|
177 | - } catch (Exception $e) { |
|
178 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
179 | - } |
|
180 | - } |
|
181 | - // each notice will self register when the action hook in registerNotices is triggered |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * exposes the Persistent Admin Notice Collection via an action |
|
190 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
191 | - * without compromising the actual collection like a filter would |
|
192 | - */ |
|
193 | - protected function registerNotices() |
|
194 | - { |
|
195 | - do_action( |
|
196 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
197 | - $this->notice_collection |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @throws DomainException |
|
205 | - * @throws InvalidClassException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - * @throws InvalidInterfaceException |
|
208 | - * @throws InvalidEntityException |
|
209 | - */ |
|
210 | - public function displayNotices() |
|
211 | - { |
|
212 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
213 | - if ($this->notice_collection->hasObjects()) { |
|
214 | - // and display notices |
|
215 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
216 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
217 | - // don't display notices that have already been dismissed |
|
218 | - if ($persistent_admin_notice->getDismissed()) { |
|
219 | - continue; |
|
220 | - } |
|
221 | - try { |
|
222 | - $this->capabilities_checker->processCapCheck( |
|
223 | - $persistent_admin_notice->getCapCheck() |
|
224 | - ); |
|
225 | - } catch (InsufficientPermissionsException $e) { |
|
226 | - // user does not have required cap, so skip to next notice |
|
227 | - // and just eat the exception - nom nom nom nom |
|
228 | - continue; |
|
229 | - } |
|
230 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
231 | - } |
|
232 | - $this->enqueueAssets(); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * does what it's named |
|
240 | - * |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - public function enqueueAssets() |
|
244 | - { |
|
245 | - wp_register_script( |
|
246 | - 'espresso_core', |
|
247 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
248 | - array('jquery'), |
|
249 | - EVENT_ESPRESSO_VERSION, |
|
250 | - true |
|
251 | - ); |
|
252 | - wp_register_script( |
|
253 | - 'ee_error_js', |
|
254 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
255 | - array('espresso_core'), |
|
256 | - EVENT_ESPRESSO_VERSION, |
|
257 | - true |
|
258 | - ); |
|
259 | - wp_localize_script( |
|
260 | - 'ee_error_js', |
|
261 | - 'ee_dismiss', |
|
262 | - array( |
|
263 | - 'return_url' => urlencode($this->return_url), |
|
264 | - 'ajax_url' => WP_AJAX_URL, |
|
265 | - 'unknown_error' => esc_html__( |
|
266 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
267 | - 'event_espresso' |
|
268 | - ), |
|
269 | - ) |
|
270 | - ); |
|
271 | - wp_enqueue_script('ee_error_js'); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * displayPersistentAdminNoticeHtml |
|
278 | - * |
|
279 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | - */ |
|
281 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | - { |
|
283 | - // used in template |
|
284 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * dismissNotice |
|
293 | - * |
|
294 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
295 | - * @param bool $purge if true, then delete it from the db |
|
296 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
297 | - * @return void |
|
298 | - * @throws InvalidEntityException |
|
299 | - * @throws InvalidInterfaceException |
|
300 | - * @throws InvalidDataTypeException |
|
301 | - * @throws DomainException |
|
302 | - */ |
|
303 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
304 | - { |
|
305 | - $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
306 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
307 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
308 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
309 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
310 | - $persistent_admin_notice->setDismissed(true); |
|
311 | - $persistent_admin_notice->setPurge($purge); |
|
312 | - $this->saveNotices(); |
|
313 | - } |
|
314 | - if ($return) { |
|
315 | - return; |
|
316 | - } |
|
317 | - if ($this->request->ajax) { |
|
318 | - // grab any notices and concatenate into string |
|
319 | - echo wp_json_encode( |
|
320 | - array( |
|
321 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
322 | - ) |
|
323 | - ); |
|
324 | - exit(); |
|
325 | - } |
|
326 | - // save errors to a transient to be displayed on next request (after redirect) |
|
327 | - EE_Error::get_notices(false, true); |
|
328 | - wp_safe_redirect( |
|
329 | - urldecode( |
|
330 | - $this->request->get('return_url', '') |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * saveNotices |
|
339 | - * |
|
340 | - * @throws DomainException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - * @throws InvalidEntityException |
|
344 | - */ |
|
345 | - public function saveNotices() |
|
346 | - { |
|
347 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
348 | - if ($this->notice_collection->hasObjects()) { |
|
349 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
350 | - //maybe initialize persistent_admin_notices |
|
351 | - if (empty($persistent_admin_notices)) { |
|
352 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
353 | - } |
|
354 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
355 | - // are we deleting this notice ? |
|
356 | - if ($persistent_admin_notice->getPurge()) { |
|
357 | - unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
358 | - } else { |
|
359 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
360 | - $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
361 | - 'message' => $persistent_admin_notice->getMessage(), |
|
362 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
363 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
364 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
365 | - ); |
|
366 | - } |
|
367 | - } |
|
368 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
369 | - } |
|
370 | - } |
|
33 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
37 | + */ |
|
38 | + private $notice_collection; |
|
39 | + |
|
40 | + /** |
|
41 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
42 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
43 | + * |
|
44 | + * @type string $return_url |
|
45 | + */ |
|
46 | + private $return_url; |
|
47 | + |
|
48 | + /** |
|
49 | + * @type CapabilitiesChecker $capabilities_checker |
|
50 | + */ |
|
51 | + private $capabilities_checker; |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Request $request |
|
55 | + */ |
|
56 | + private $request; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * CapChecker constructor |
|
62 | + * |
|
63 | + * @param string $return_url where to redirect to after dismissing notices |
|
64 | + * @param CapabilitiesChecker $capabilities_checker |
|
65 | + * @param EE_Request $request |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + */ |
|
68 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
69 | + { |
|
70 | + $this->setReturnUrl($return_url); |
|
71 | + $this->capabilities_checker = $capabilities_checker; |
|
72 | + $this->request = $request; |
|
73 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | + add_action('shutdown', array($this, 'saveNotices')); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $return_url |
|
85 | + * @throws InvalidDataTypeException |
|
86 | + */ |
|
87 | + private function setReturnUrl($return_url) |
|
88 | + { |
|
89 | + if (! is_string($return_url)) { |
|
90 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
91 | + } |
|
92 | + $this->return_url = $return_url; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return Collection |
|
99 | + * @throws InvalidEntityException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + * @throws InvalidDataTypeException |
|
102 | + * @throws DomainException |
|
103 | + */ |
|
104 | + protected function getPersistentAdminNoticeCollection() |
|
105 | + { |
|
106 | + if (! $this->notice_collection instanceof Collection) { |
|
107 | + $this->notice_collection = new Collection( |
|
108 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
109 | + ); |
|
110 | + $this->retrieveStoredNotices(); |
|
111 | + $this->registerNotices(); |
|
112 | + } |
|
113 | + return $this->notice_collection; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
120 | + * |
|
121 | + * @return void |
|
122 | + * @throws InvalidEntityException |
|
123 | + * @throws DomainException |
|
124 | + * @throws InvalidDataTypeException |
|
125 | + */ |
|
126 | + protected function retrieveStoredNotices() |
|
127 | + { |
|
128 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
129 | + // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
130 | + if (! empty($persistent_admin_notices)) { |
|
131 | + foreach ($persistent_admin_notices as $name => $details) { |
|
132 | + if (is_array($details)) { |
|
133 | + if ( |
|
134 | + ! isset( |
|
135 | + $details['message'], |
|
136 | + $details['capability'], |
|
137 | + $details['cap_context'], |
|
138 | + $details['dismissed'] |
|
139 | + ) |
|
140 | + ) { |
|
141 | + throw new DomainException( |
|
142 | + sprintf( |
|
143 | + esc_html__( |
|
144 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
145 | + 'event_espresso' |
|
146 | + ), |
|
147 | + $name |
|
148 | + ) |
|
149 | + ); |
|
150 | + } |
|
151 | + // new format for nag notices |
|
152 | + $this->notice_collection->add( |
|
153 | + new PersistentAdminNotice( |
|
154 | + $name, |
|
155 | + $details['message'], |
|
156 | + false, |
|
157 | + $details['capability'], |
|
158 | + $details['cap_context'], |
|
159 | + $details['dismissed'] |
|
160 | + ), |
|
161 | + $name |
|
162 | + ); |
|
163 | + } else { |
|
164 | + try { |
|
165 | + // old nag notices, that we want to convert to the new format |
|
166 | + $this->notice_collection->add( |
|
167 | + new PersistentAdminNotice( |
|
168 | + $name, |
|
169 | + (string)$details, |
|
170 | + false, |
|
171 | + '', |
|
172 | + '', |
|
173 | + empty($details) |
|
174 | + ), |
|
175 | + $name |
|
176 | + ); |
|
177 | + } catch (Exception $e) { |
|
178 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
179 | + } |
|
180 | + } |
|
181 | + // each notice will self register when the action hook in registerNotices is triggered |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * exposes the Persistent Admin Notice Collection via an action |
|
190 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
191 | + * without compromising the actual collection like a filter would |
|
192 | + */ |
|
193 | + protected function registerNotices() |
|
194 | + { |
|
195 | + do_action( |
|
196 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
197 | + $this->notice_collection |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @throws DomainException |
|
205 | + * @throws InvalidClassException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + * @throws InvalidInterfaceException |
|
208 | + * @throws InvalidEntityException |
|
209 | + */ |
|
210 | + public function displayNotices() |
|
211 | + { |
|
212 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
213 | + if ($this->notice_collection->hasObjects()) { |
|
214 | + // and display notices |
|
215 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
216 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
217 | + // don't display notices that have already been dismissed |
|
218 | + if ($persistent_admin_notice->getDismissed()) { |
|
219 | + continue; |
|
220 | + } |
|
221 | + try { |
|
222 | + $this->capabilities_checker->processCapCheck( |
|
223 | + $persistent_admin_notice->getCapCheck() |
|
224 | + ); |
|
225 | + } catch (InsufficientPermissionsException $e) { |
|
226 | + // user does not have required cap, so skip to next notice |
|
227 | + // and just eat the exception - nom nom nom nom |
|
228 | + continue; |
|
229 | + } |
|
230 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
231 | + } |
|
232 | + $this->enqueueAssets(); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * does what it's named |
|
240 | + * |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + public function enqueueAssets() |
|
244 | + { |
|
245 | + wp_register_script( |
|
246 | + 'espresso_core', |
|
247 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
248 | + array('jquery'), |
|
249 | + EVENT_ESPRESSO_VERSION, |
|
250 | + true |
|
251 | + ); |
|
252 | + wp_register_script( |
|
253 | + 'ee_error_js', |
|
254 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
255 | + array('espresso_core'), |
|
256 | + EVENT_ESPRESSO_VERSION, |
|
257 | + true |
|
258 | + ); |
|
259 | + wp_localize_script( |
|
260 | + 'ee_error_js', |
|
261 | + 'ee_dismiss', |
|
262 | + array( |
|
263 | + 'return_url' => urlencode($this->return_url), |
|
264 | + 'ajax_url' => WP_AJAX_URL, |
|
265 | + 'unknown_error' => esc_html__( |
|
266 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
267 | + 'event_espresso' |
|
268 | + ), |
|
269 | + ) |
|
270 | + ); |
|
271 | + wp_enqueue_script('ee_error_js'); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * displayPersistentAdminNoticeHtml |
|
278 | + * |
|
279 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | + */ |
|
281 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | + { |
|
283 | + // used in template |
|
284 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | + require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * dismissNotice |
|
293 | + * |
|
294 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
295 | + * @param bool $purge if true, then delete it from the db |
|
296 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
297 | + * @return void |
|
298 | + * @throws InvalidEntityException |
|
299 | + * @throws InvalidInterfaceException |
|
300 | + * @throws InvalidDataTypeException |
|
301 | + * @throws DomainException |
|
302 | + */ |
|
303 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
304 | + { |
|
305 | + $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
306 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
307 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
308 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
309 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
310 | + $persistent_admin_notice->setDismissed(true); |
|
311 | + $persistent_admin_notice->setPurge($purge); |
|
312 | + $this->saveNotices(); |
|
313 | + } |
|
314 | + if ($return) { |
|
315 | + return; |
|
316 | + } |
|
317 | + if ($this->request->ajax) { |
|
318 | + // grab any notices and concatenate into string |
|
319 | + echo wp_json_encode( |
|
320 | + array( |
|
321 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
322 | + ) |
|
323 | + ); |
|
324 | + exit(); |
|
325 | + } |
|
326 | + // save errors to a transient to be displayed on next request (after redirect) |
|
327 | + EE_Error::get_notices(false, true); |
|
328 | + wp_safe_redirect( |
|
329 | + urldecode( |
|
330 | + $this->request->get('return_url', '') |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * saveNotices |
|
339 | + * |
|
340 | + * @throws DomainException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + * @throws InvalidEntityException |
|
344 | + */ |
|
345 | + public function saveNotices() |
|
346 | + { |
|
347 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
348 | + if ($this->notice_collection->hasObjects()) { |
|
349 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
350 | + //maybe initialize persistent_admin_notices |
|
351 | + if (empty($persistent_admin_notices)) { |
|
352 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
353 | + } |
|
354 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
355 | + // are we deleting this notice ? |
|
356 | + if ($persistent_admin_notice->getPurge()) { |
|
357 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
358 | + } else { |
|
359 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
360 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
361 | + 'message' => $persistent_admin_notice->getMessage(), |
|
362 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
363 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
364 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
365 | + ); |
|
366 | + } |
|
367 | + } |
|
368 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
369 | + } |
|
370 | + } |
|
371 | 371 | |
372 | 372 | |
373 | 373 |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | private function setReturnUrl($return_url) |
88 | 88 | { |
89 | - if (! is_string($return_url)) { |
|
89 | + if ( ! is_string($return_url)) { |
|
90 | 90 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
91 | 91 | } |
92 | 92 | $this->return_url = $return_url; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function getPersistentAdminNoticeCollection() |
105 | 105 | { |
106 | - if (! $this->notice_collection instanceof Collection) { |
|
106 | + if ( ! $this->notice_collection instanceof Collection) { |
|
107 | 107 | $this->notice_collection = new Collection( |
108 | 108 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
109 | 109 | ); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
129 | 129 | // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
130 | - if (! empty($persistent_admin_notices)) { |
|
130 | + if ( ! empty($persistent_admin_notices)) { |
|
131 | 131 | foreach ($persistent_admin_notices as $name => $details) { |
132 | 132 | if (is_array($details)) { |
133 | 133 | if ( |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $this->notice_collection->add( |
167 | 167 | new PersistentAdminNotice( |
168 | 168 | $name, |
169 | - (string)$details, |
|
169 | + (string) $details, |
|
170 | 170 | false, |
171 | 171 | '', |
172 | 172 | '', |
@@ -244,14 +244,14 @@ discard block |
||
244 | 244 | { |
245 | 245 | wp_register_script( |
246 | 246 | 'espresso_core', |
247 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
247 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
248 | 248 | array('jquery'), |
249 | 249 | EVENT_ESPRESSO_VERSION, |
250 | 250 | true |
251 | 251 | ); |
252 | 252 | wp_register_script( |
253 | 253 | 'ee_error_js', |
254 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
254 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
255 | 255 | array('espresso_core'), |
256 | 256 | EVENT_ESPRESSO_VERSION, |
257 | 257 | true |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // used in template |
284 | 284 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
285 | 285 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
286 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
286 | + require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php'; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | { |
305 | 305 | $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
306 | 306 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
307 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
307 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
308 | 308 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
309 | 309 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
310 | 310 | $persistent_admin_notice->setDismissed(true); |
@@ -26,330 +26,330 @@ |
||
26 | 26 | class PersistentAdminNotice implements RequiresCapCheckInterface |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string $name |
|
31 | - */ |
|
32 | - protected $name = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $message |
|
36 | - */ |
|
37 | - protected $message = ''; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var boolean $force_update |
|
41 | - */ |
|
42 | - protected $force_update = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $capability |
|
46 | - */ |
|
47 | - protected $capability = 'manage_options'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string $cap_context |
|
51 | - */ |
|
52 | - protected $cap_context = 'view persistent admin notice'; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var boolean $dismissed |
|
56 | - */ |
|
57 | - protected $dismissed = false; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var CapCheckInterface $cap_check |
|
61 | - */ |
|
62 | - protected $cap_check; |
|
63 | - |
|
64 | - /** |
|
65 | - * if true, then this notice will be deleted from the database |
|
66 | - * |
|
67 | - * @var boolean $purge |
|
68 | - */ |
|
69 | - protected $purge = false; |
|
70 | - |
|
71 | - /** |
|
72 | - * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
73 | - * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
74 | - * |
|
75 | - * @var boolean $registered |
|
76 | - */ |
|
77 | - private $registered = false; |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * PersistentAdminNotice constructor |
|
83 | - * |
|
84 | - * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
85 | - * @param string $message [required] the message to be stored persistently until dismissed |
|
86 | - * @param bool $force_update enforce the reappearance of a persistent message |
|
87 | - * @param string $capability user capability required to view this notice |
|
88 | - * @param string $cap_context description for why the cap check is being performed |
|
89 | - * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - */ |
|
92 | - public function __construct( |
|
93 | - $name, |
|
94 | - $message, |
|
95 | - $force_update = false, |
|
96 | - $capability = 'manage_options', |
|
97 | - $cap_context = 'view persistent admin notice', |
|
98 | - $dismissed = false |
|
99 | - ) { |
|
100 | - $this->setName($name); |
|
101 | - $this->setMessage($message); |
|
102 | - $this->setForceUpdate($force_update); |
|
103 | - $this->setCapability($capability); |
|
104 | - $this->setCapContext($cap_context); |
|
105 | - $this->setDismissed($dismissed); |
|
106 | - add_action( |
|
107 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
108 | - array($this, 'registerPersistentAdminNotice') |
|
109 | - ); |
|
110 | - add_action('admin_footer', array($this, 'confirmRegistered')); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function getName() |
|
119 | - { |
|
120 | - return $this->name; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $name |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - */ |
|
129 | - private function setName($name) |
|
130 | - { |
|
131 | - if (! is_string($name)) { |
|
132 | - throw new InvalidDataTypeException('$name', $name, 'string'); |
|
133 | - } |
|
134 | - $this->name = sanitize_key($name); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function getMessage() |
|
143 | - { |
|
144 | - return $this->message; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @param string $message |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - */ |
|
153 | - private function setMessage($message) |
|
154 | - { |
|
155 | - if (! is_string($message)) { |
|
156 | - throw new InvalidDataTypeException('$message', $message, 'string'); |
|
157 | - } |
|
158 | - global $allowedtags; |
|
159 | - $allowedtags['br'] = array(); |
|
160 | - $this->message = wp_kses($message, $allowedtags); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function getForceUpdate() |
|
169 | - { |
|
170 | - return $this->force_update; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param bool $force_update |
|
177 | - */ |
|
178 | - private function setForceUpdate($force_update) |
|
179 | - { |
|
180 | - $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function getCapability() |
|
189 | - { |
|
190 | - return $this->capability; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $capability |
|
197 | - * @throws InvalidDataTypeException |
|
198 | - */ |
|
199 | - private function setCapability($capability) |
|
200 | - { |
|
201 | - if (! is_string($capability)) { |
|
202 | - throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
203 | - } |
|
204 | - $this->capability = $capability; |
|
205 | - } |
|
29 | + /** |
|
30 | + * @var string $name |
|
31 | + */ |
|
32 | + protected $name = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $message |
|
36 | + */ |
|
37 | + protected $message = ''; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var boolean $force_update |
|
41 | + */ |
|
42 | + protected $force_update = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $capability |
|
46 | + */ |
|
47 | + protected $capability = 'manage_options'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string $cap_context |
|
51 | + */ |
|
52 | + protected $cap_context = 'view persistent admin notice'; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var boolean $dismissed |
|
56 | + */ |
|
57 | + protected $dismissed = false; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var CapCheckInterface $cap_check |
|
61 | + */ |
|
62 | + protected $cap_check; |
|
63 | + |
|
64 | + /** |
|
65 | + * if true, then this notice will be deleted from the database |
|
66 | + * |
|
67 | + * @var boolean $purge |
|
68 | + */ |
|
69 | + protected $purge = false; |
|
70 | + |
|
71 | + /** |
|
72 | + * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
73 | + * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
74 | + * |
|
75 | + * @var boolean $registered |
|
76 | + */ |
|
77 | + private $registered = false; |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * PersistentAdminNotice constructor |
|
83 | + * |
|
84 | + * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
85 | + * @param string $message [required] the message to be stored persistently until dismissed |
|
86 | + * @param bool $force_update enforce the reappearance of a persistent message |
|
87 | + * @param string $capability user capability required to view this notice |
|
88 | + * @param string $cap_context description for why the cap check is being performed |
|
89 | + * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + */ |
|
92 | + public function __construct( |
|
93 | + $name, |
|
94 | + $message, |
|
95 | + $force_update = false, |
|
96 | + $capability = 'manage_options', |
|
97 | + $cap_context = 'view persistent admin notice', |
|
98 | + $dismissed = false |
|
99 | + ) { |
|
100 | + $this->setName($name); |
|
101 | + $this->setMessage($message); |
|
102 | + $this->setForceUpdate($force_update); |
|
103 | + $this->setCapability($capability); |
|
104 | + $this->setCapContext($cap_context); |
|
105 | + $this->setDismissed($dismissed); |
|
106 | + add_action( |
|
107 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
108 | + array($this, 'registerPersistentAdminNotice') |
|
109 | + ); |
|
110 | + add_action('admin_footer', array($this, 'confirmRegistered')); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function getName() |
|
119 | + { |
|
120 | + return $this->name; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $name |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + */ |
|
129 | + private function setName($name) |
|
130 | + { |
|
131 | + if (! is_string($name)) { |
|
132 | + throw new InvalidDataTypeException('$name', $name, 'string'); |
|
133 | + } |
|
134 | + $this->name = sanitize_key($name); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function getMessage() |
|
143 | + { |
|
144 | + return $this->message; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @param string $message |
|
151 | + * @throws InvalidDataTypeException |
|
152 | + */ |
|
153 | + private function setMessage($message) |
|
154 | + { |
|
155 | + if (! is_string($message)) { |
|
156 | + throw new InvalidDataTypeException('$message', $message, 'string'); |
|
157 | + } |
|
158 | + global $allowedtags; |
|
159 | + $allowedtags['br'] = array(); |
|
160 | + $this->message = wp_kses($message, $allowedtags); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function getForceUpdate() |
|
169 | + { |
|
170 | + return $this->force_update; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param bool $force_update |
|
177 | + */ |
|
178 | + private function setForceUpdate($force_update) |
|
179 | + { |
|
180 | + $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function getCapability() |
|
189 | + { |
|
190 | + return $this->capability; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $capability |
|
197 | + * @throws InvalidDataTypeException |
|
198 | + */ |
|
199 | + private function setCapability($capability) |
|
200 | + { |
|
201 | + if (! is_string($capability)) { |
|
202 | + throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
203 | + } |
|
204 | + $this->capability = $capability; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function getCapContext() |
|
213 | - { |
|
214 | - return $this->cap_context; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @param string $cap_context |
|
221 | - * @throws InvalidDataTypeException |
|
222 | - */ |
|
223 | - private function setCapContext($cap_context) |
|
224 | - { |
|
225 | - if (! is_string($cap_context)) { |
|
226 | - throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
227 | - } |
|
228 | - $this->cap_context = $cap_context; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @return bool |
|
235 | - */ |
|
236 | - public function getDismissed() |
|
237 | - { |
|
238 | - return $this->dismissed; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param bool $dismissed |
|
245 | - */ |
|
246 | - public function setDismissed($dismissed) |
|
247 | - { |
|
248 | - $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @return CapCheckInterface |
|
255 | - * @throws InvalidDataTypeException |
|
256 | - */ |
|
257 | - public function getCapCheck() |
|
258 | - { |
|
259 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
260 | - $this->setCapCheck( |
|
261 | - new CapCheck( |
|
262 | - $this->capability, |
|
263 | - $this->cap_context |
|
264 | - ) |
|
265 | - ); |
|
266 | - } |
|
267 | - return $this->cap_check; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @param CapCheckInterface $cap_check |
|
274 | - */ |
|
275 | - private function setCapCheck(CapCheckInterface $cap_check) |
|
276 | - { |
|
277 | - $this->cap_check = $cap_check; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @return bool |
|
284 | - */ |
|
285 | - public function getPurge() |
|
286 | - { |
|
287 | - return $this->purge; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * @param bool $purge |
|
294 | - */ |
|
295 | - public function setPurge($purge) |
|
296 | - { |
|
297 | - $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * given a valid PersistentAdminNotice Collection, |
|
304 | - * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
305 | - * if an existing notice is found that has already been dismissed, |
|
306 | - * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
307 | - * so that the notice is displayed again |
|
308 | - * |
|
309 | - * @param Collection $persistent_admin_notice_collection |
|
310 | - * @throws InvalidEntityException |
|
311 | - */ |
|
312 | - public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
313 | - { |
|
314 | - if ($this->registered) { |
|
315 | - return; |
|
316 | - } |
|
317 | - // first check if this notice has already been added to the collection |
|
318 | - if ($persistent_admin_notice_collection->has($this->name)) { |
|
319 | - /** @var PersistentAdminNotice $existing */ |
|
320 | - $existing = $persistent_admin_notice_collection->get($this->name); |
|
321 | - // we don't need to add it again (we can't actually) |
|
322 | - // but if it has already been dismissed, and we are overriding with a forced update |
|
323 | - if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
324 | - // then toggle the notice's dismissed state to true |
|
325 | - // so that it gets displayed again |
|
326 | - $existing->setDismissed(false); |
|
327 | - } |
|
328 | - } else { |
|
329 | - $persistent_admin_notice_collection->add($this, $this->name); |
|
330 | - } |
|
331 | - $this->registered = true; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @throws DomainException |
|
338 | - */ |
|
339 | - public function confirmRegistered() |
|
340 | - { |
|
341 | - if (! $this->registered && WP_DEBUG) { |
|
342 | - throw new DomainException( |
|
343 | - sprintf( |
|
344 | - esc_html__( |
|
345 | - '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.', |
|
346 | - 'event_espresso' |
|
347 | - ), |
|
348 | - $this->name |
|
349 | - ) |
|
350 | - ); |
|
351 | - } |
|
352 | - } |
|
209 | + /** |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function getCapContext() |
|
213 | + { |
|
214 | + return $this->cap_context; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @param string $cap_context |
|
221 | + * @throws InvalidDataTypeException |
|
222 | + */ |
|
223 | + private function setCapContext($cap_context) |
|
224 | + { |
|
225 | + if (! is_string($cap_context)) { |
|
226 | + throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
227 | + } |
|
228 | + $this->cap_context = $cap_context; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | + public function getDismissed() |
|
237 | + { |
|
238 | + return $this->dismissed; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param bool $dismissed |
|
245 | + */ |
|
246 | + public function setDismissed($dismissed) |
|
247 | + { |
|
248 | + $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @return CapCheckInterface |
|
255 | + * @throws InvalidDataTypeException |
|
256 | + */ |
|
257 | + public function getCapCheck() |
|
258 | + { |
|
259 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
260 | + $this->setCapCheck( |
|
261 | + new CapCheck( |
|
262 | + $this->capability, |
|
263 | + $this->cap_context |
|
264 | + ) |
|
265 | + ); |
|
266 | + } |
|
267 | + return $this->cap_check; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @param CapCheckInterface $cap_check |
|
274 | + */ |
|
275 | + private function setCapCheck(CapCheckInterface $cap_check) |
|
276 | + { |
|
277 | + $this->cap_check = $cap_check; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @return bool |
|
284 | + */ |
|
285 | + public function getPurge() |
|
286 | + { |
|
287 | + return $this->purge; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * @param bool $purge |
|
294 | + */ |
|
295 | + public function setPurge($purge) |
|
296 | + { |
|
297 | + $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * given a valid PersistentAdminNotice Collection, |
|
304 | + * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
305 | + * if an existing notice is found that has already been dismissed, |
|
306 | + * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
307 | + * so that the notice is displayed again |
|
308 | + * |
|
309 | + * @param Collection $persistent_admin_notice_collection |
|
310 | + * @throws InvalidEntityException |
|
311 | + */ |
|
312 | + public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
313 | + { |
|
314 | + if ($this->registered) { |
|
315 | + return; |
|
316 | + } |
|
317 | + // first check if this notice has already been added to the collection |
|
318 | + if ($persistent_admin_notice_collection->has($this->name)) { |
|
319 | + /** @var PersistentAdminNotice $existing */ |
|
320 | + $existing = $persistent_admin_notice_collection->get($this->name); |
|
321 | + // we don't need to add it again (we can't actually) |
|
322 | + // but if it has already been dismissed, and we are overriding with a forced update |
|
323 | + if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
324 | + // then toggle the notice's dismissed state to true |
|
325 | + // so that it gets displayed again |
|
326 | + $existing->setDismissed(false); |
|
327 | + } |
|
328 | + } else { |
|
329 | + $persistent_admin_notice_collection->add($this, $this->name); |
|
330 | + } |
|
331 | + $this->registered = true; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @throws DomainException |
|
338 | + */ |
|
339 | + public function confirmRegistered() |
|
340 | + { |
|
341 | + if (! $this->registered && WP_DEBUG) { |
|
342 | + throw new DomainException( |
|
343 | + sprintf( |
|
344 | + esc_html__( |
|
345 | + '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.', |
|
346 | + 'event_espresso' |
|
347 | + ), |
|
348 | + $this->name |
|
349 | + ) |
|
350 | + ); |
|
351 | + } |
|
352 | + } |
|
353 | 353 | |
354 | 354 | |
355 | 355 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | private function setName($name) |
130 | 130 | { |
131 | - if (! is_string($name)) { |
|
131 | + if ( ! is_string($name)) { |
|
132 | 132 | throw new InvalidDataTypeException('$name', $name, 'string'); |
133 | 133 | } |
134 | 134 | $this->name = sanitize_key($name); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | private function setMessage($message) |
154 | 154 | { |
155 | - if (! is_string($message)) { |
|
155 | + if ( ! is_string($message)) { |
|
156 | 156 | throw new InvalidDataTypeException('$message', $message, 'string'); |
157 | 157 | } |
158 | 158 | global $allowedtags; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function setCapability($capability) |
200 | 200 | { |
201 | - if (! is_string($capability)) { |
|
201 | + if ( ! is_string($capability)) { |
|
202 | 202 | throw new InvalidDataTypeException('$capability', $capability, 'string'); |
203 | 203 | } |
204 | 204 | $this->capability = $capability; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | private function setCapContext($cap_context) |
224 | 224 | { |
225 | - if (! is_string($cap_context)) { |
|
225 | + if ( ! is_string($cap_context)) { |
|
226 | 226 | throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
227 | 227 | } |
228 | 228 | $this->cap_context = $cap_context; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function getCapCheck() |
258 | 258 | { |
259 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
259 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
260 | 260 | $this->setCapCheck( |
261 | 261 | new CapCheck( |
262 | 262 | $this->capability, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public function confirmRegistered() |
340 | 340 | { |
341 | - if (! $this->registered && WP_DEBUG) { |
|
341 | + if ( ! $this->registered && WP_DEBUG) { |
|
342 | 342 | throw new DomainException( |
343 | 343 | sprintf( |
344 | 344 | esc_html__( |
@@ -38,217 +38,217 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - function espresso_minimum_php_version_error() |
|
73 | - { |
|
74 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + function espresso_minimum_php_version_error() |
|
73 | + { |
|
74 | + ?> |
|
75 | 75 | <div class="error"> |
76 | 76 | <p> |
77 | 77 | <?php |
78 | - printf( |
|
79 | - esc_html__( |
|
80 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - EE_MIN_PHP_VER_REQUIRED, |
|
84 | - PHP_VERSION, |
|
85 | - '<br/>', |
|
86 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | - ); |
|
88 | - ?> |
|
78 | + printf( |
|
79 | + esc_html__( |
|
80 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + EE_MIN_PHP_VER_REQUIRED, |
|
84 | + PHP_VERSION, |
|
85 | + '<br/>', |
|
86 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | + ); |
|
88 | + ?> |
|
89 | 89 | </p> |
90 | 90 | </div> |
91 | 91 | <?php |
92 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | - } |
|
92 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | + } |
|
94 | 94 | |
95 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | - } else { |
|
97 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | - /** |
|
99 | - * espresso_version |
|
100 | - * Returns the plugin version |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - function espresso_version() |
|
105 | - { |
|
106 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.075'); |
|
107 | - } |
|
95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | + } else { |
|
97 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | + /** |
|
99 | + * espresso_version |
|
100 | + * Returns the plugin version |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + function espresso_version() |
|
105 | + { |
|
106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.075'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * espresso_plugin_activation |
|
111 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | - */ |
|
113 | - function espresso_plugin_activation() |
|
114 | - { |
|
115 | - update_option('ee_espresso_activation', true); |
|
116 | - } |
|
109 | + /** |
|
110 | + * espresso_plugin_activation |
|
111 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | + */ |
|
113 | + function espresso_plugin_activation() |
|
114 | + { |
|
115 | + update_option('ee_espresso_activation', true); |
|
116 | + } |
|
117 | 117 | |
118 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | - /** |
|
120 | - * espresso_load_error_handling |
|
121 | - * this function loads EE's class for handling exceptions and errors |
|
122 | - */ |
|
123 | - function espresso_load_error_handling() |
|
124 | - { |
|
125 | - static $error_handling_loaded = false; |
|
126 | - if ($error_handling_loaded) { |
|
127 | - return; |
|
128 | - } |
|
129 | - // load debugging tools |
|
130 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | - \EEH_Debug_Tools::instance(); |
|
133 | - } |
|
134 | - // load error handling |
|
135 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | - } else { |
|
138 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | - } |
|
140 | - $error_handling_loaded = true; |
|
141 | - } |
|
118 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | + /** |
|
120 | + * espresso_load_error_handling |
|
121 | + * this function loads EE's class for handling exceptions and errors |
|
122 | + */ |
|
123 | + function espresso_load_error_handling() |
|
124 | + { |
|
125 | + static $error_handling_loaded = false; |
|
126 | + if ($error_handling_loaded) { |
|
127 | + return; |
|
128 | + } |
|
129 | + // load debugging tools |
|
130 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | + \EEH_Debug_Tools::instance(); |
|
133 | + } |
|
134 | + // load error handling |
|
135 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | + } else { |
|
138 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | + } |
|
140 | + $error_handling_loaded = true; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * espresso_load_required |
|
145 | - * given a class name and path, this function will load that file or throw an exception |
|
146 | - * |
|
147 | - * @param string $classname |
|
148 | - * @param string $full_path_to_file |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - function espresso_load_required($classname, $full_path_to_file) |
|
152 | - { |
|
153 | - if (is_readable($full_path_to_file)) { |
|
154 | - require_once $full_path_to_file; |
|
155 | - } else { |
|
156 | - throw new \EE_Error ( |
|
157 | - sprintf( |
|
158 | - esc_html__( |
|
159 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - $classname |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
143 | + /** |
|
144 | + * espresso_load_required |
|
145 | + * given a class name and path, this function will load that file or throw an exception |
|
146 | + * |
|
147 | + * @param string $classname |
|
148 | + * @param string $full_path_to_file |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + function espresso_load_required($classname, $full_path_to_file) |
|
152 | + { |
|
153 | + if (is_readable($full_path_to_file)) { |
|
154 | + require_once $full_path_to_file; |
|
155 | + } else { |
|
156 | + throw new \EE_Error ( |
|
157 | + sprintf( |
|
158 | + esc_html__( |
|
159 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + $classname |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @since 4.9.27 |
|
170 | - * @throws \EE_Error |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | - * @throws \OutOfBoundsException |
|
179 | - */ |
|
180 | - function bootstrap_espresso() |
|
181 | - { |
|
182 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | - try { |
|
184 | - espresso_load_error_handling(); |
|
185 | - espresso_load_required( |
|
186 | - 'EEH_Base', |
|
187 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | - ); |
|
189 | - espresso_load_required( |
|
190 | - 'EEH_File', |
|
191 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | - ); |
|
193 | - espresso_load_required( |
|
194 | - 'EEH_File', |
|
195 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | - ); |
|
197 | - espresso_load_required( |
|
198 | - 'EEH_Array', |
|
199 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | - ); |
|
201 | - // instantiate and configure PSR4 autoloader |
|
202 | - espresso_load_required( |
|
203 | - 'Psr4Autoloader', |
|
204 | - EE_CORE . 'Psr4Autoloader.php' |
|
205 | - ); |
|
206 | - espresso_load_required( |
|
207 | - 'EE_Psr4AutoloaderInit', |
|
208 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | - ); |
|
210 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | - $AutoloaderInit->initializeAutoloader(); |
|
212 | - espresso_load_required( |
|
213 | - 'EE_Request', |
|
214 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | - ); |
|
216 | - espresso_load_required( |
|
217 | - 'EE_Response', |
|
218 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | - ); |
|
220 | - espresso_load_required( |
|
221 | - 'EE_Bootstrap', |
|
222 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | - ); |
|
224 | - // bootstrap EE and the request stack |
|
225 | - new EE_Bootstrap( |
|
226 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | - new EE_Response() |
|
228 | - ); |
|
229 | - } catch (Exception $e) { |
|
230 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | - } |
|
233 | - } |
|
234 | - bootstrap_espresso(); |
|
235 | - } |
|
168 | + /** |
|
169 | + * @since 4.9.27 |
|
170 | + * @throws \EE_Error |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | + * @throws \OutOfBoundsException |
|
179 | + */ |
|
180 | + function bootstrap_espresso() |
|
181 | + { |
|
182 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | + try { |
|
184 | + espresso_load_error_handling(); |
|
185 | + espresso_load_required( |
|
186 | + 'EEH_Base', |
|
187 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | + ); |
|
189 | + espresso_load_required( |
|
190 | + 'EEH_File', |
|
191 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | + ); |
|
193 | + espresso_load_required( |
|
194 | + 'EEH_File', |
|
195 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | + ); |
|
197 | + espresso_load_required( |
|
198 | + 'EEH_Array', |
|
199 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | + ); |
|
201 | + // instantiate and configure PSR4 autoloader |
|
202 | + espresso_load_required( |
|
203 | + 'Psr4Autoloader', |
|
204 | + EE_CORE . 'Psr4Autoloader.php' |
|
205 | + ); |
|
206 | + espresso_load_required( |
|
207 | + 'EE_Psr4AutoloaderInit', |
|
208 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | + ); |
|
210 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | + $AutoloaderInit->initializeAutoloader(); |
|
212 | + espresso_load_required( |
|
213 | + 'EE_Request', |
|
214 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | + ); |
|
216 | + espresso_load_required( |
|
217 | + 'EE_Response', |
|
218 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | + ); |
|
220 | + espresso_load_required( |
|
221 | + 'EE_Bootstrap', |
|
222 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | + ); |
|
224 | + // bootstrap EE and the request stack |
|
225 | + new EE_Bootstrap( |
|
226 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | + new EE_Response() |
|
228 | + ); |
|
229 | + } catch (Exception $e) { |
|
230 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | + } |
|
233 | + } |
|
234 | + bootstrap_espresso(); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | if (! function_exists('espresso_deactivate_plugin')) { |
238 | - /** |
|
239 | - * deactivate_plugin |
|
240 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | - { |
|
248 | - if (! function_exists('deactivate_plugins')) { |
|
249 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | - } |
|
251 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | - deactivate_plugins($plugin_basename); |
|
253 | - } |
|
238 | + /** |
|
239 | + * deactivate_plugin |
|
240 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | + { |
|
248 | + if (! function_exists('deactivate_plugins')) { |
|
249 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | + } |
|
251 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | + deactivate_plugins($plugin_basename); |
|
253 | + } |
|
254 | 254 | } |