@@ -20,822 +20,822 @@ |
||
20 | 20 | */ |
21 | 21 | class AdminToolBar |
22 | 22 | { |
23 | - private ?WP_Admin_Bar $admin_bar = null; |
|
24 | - |
|
25 | - private EE_Capabilities $capabilities; |
|
26 | - |
|
27 | - private string $events_admin_url = ''; |
|
28 | - |
|
29 | - private string $menu_class = 'espresso_menu_item_class'; |
|
30 | - |
|
31 | - private string $reg_admin_url = ''; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * AdminToolBar constructor. |
|
36 | - * |
|
37 | - * @param EE_Capabilities $capabilities |
|
38 | - */ |
|
39 | - public function __construct(EE_Capabilities $capabilities) |
|
40 | - { |
|
41 | - $this->capabilities = $capabilities; |
|
42 | - add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100); |
|
43 | - $this->enqueueAssets(); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * espresso_toolbar_items |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param WP_Admin_Bar $admin_bar |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
55 | - { |
|
56 | - // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
57 | - if ( |
|
58 | - defined('DOING_AJAX') |
|
59 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
60 | - || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
61 | - ) { |
|
62 | - return; |
|
63 | - } |
|
64 | - $this->admin_bar = $admin_bar; |
|
65 | - // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
66 | - // because they're only defined in each of their respective constructors |
|
67 | - // and this might be a frontend request, in which case they aren't available |
|
68 | - $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
69 | - $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
70 | - // now let's add all of the menu items |
|
71 | - $this->addTopLevelMenu(); |
|
72 | - $this->addEventsSubMenu(); |
|
73 | - $this->addEventsAddEditHeader(); |
|
74 | - $this->addEventsAddNew(); |
|
75 | - $this->addEventsEditCurrentEvent(); |
|
76 | - $this->addEventsViewHeader(); |
|
77 | - $this->addEventsViewAll(); |
|
78 | - $this->addEventsViewToday(); |
|
79 | - $this->addEventsViewThisMonth(); |
|
80 | - $this->addRegistrationSubMenu(); |
|
81 | - $this->addRegistrationOverviewToday(); |
|
82 | - $this->addRegistrationOverviewTodayApproved(); |
|
83 | - $this->addRegistrationOverviewTodayPendingPayment(); |
|
84 | - $this->addRegistrationOverviewTodayNotApproved(); |
|
85 | - $this->addRegistrationOverviewTodayCancelled(); |
|
86 | - $this->addRegistrationOverviewThisMonth(); |
|
87 | - $this->addRegistrationOverviewThisMonthApproved(); |
|
88 | - $this->addRegistrationOverviewThisMonthPending(); |
|
89 | - $this->addRegistrationOverviewThisMonthNotApproved(); |
|
90 | - $this->addRegistrationOverviewThisMonthCancelled(); |
|
91 | - $this->addExtensionsAndServices(); |
|
92 | - $this->addFontSizeSubMenu(); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - private function enqueueAssets() |
|
100 | - { |
|
101 | - wp_register_style( |
|
102 | - 'espresso-admin-toolbar', |
|
103 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
104 | - ['dashicons'], |
|
105 | - EVENT_ESPRESSO_VERSION |
|
106 | - ); |
|
107 | - wp_enqueue_style('espresso-admin-toolbar'); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - private function addTopLevelMenu() |
|
115 | - { |
|
116 | - $this->admin_bar->add_menu( |
|
117 | - [ |
|
118 | - 'id' => 'espresso-toolbar', |
|
119 | - 'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
120 | - . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
121 | - . '</span>', |
|
122 | - 'href' => $this->events_admin_url, |
|
123 | - 'meta' => [ |
|
124 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
125 | - 'class' => $this->menu_class . 'first', |
|
126 | - ], |
|
127 | - ] |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - private function addEventsSubMenu() |
|
136 | - { |
|
137 | - if ( |
|
138 | - $this->capabilities->current_user_can( |
|
139 | - 'ee_read_events', |
|
140 | - 'ee_admin_bar_menu_espresso-toolbar-events' |
|
141 | - ) |
|
142 | - ) { |
|
143 | - $this->admin_bar->add_menu( |
|
144 | - [ |
|
145 | - 'id' => 'espresso-toolbar-events', |
|
146 | - 'parent' => 'espresso-toolbar', |
|
147 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
148 | - . esc_html__('Events', 'event_espresso'), |
|
149 | - 'href' => $this->events_admin_url, |
|
150 | - 'meta' => [ |
|
151 | - 'title' => esc_html__('Events', 'event_espresso'), |
|
152 | - 'target' => '', |
|
153 | - 'class' => $this->menu_class, |
|
154 | - ], |
|
155 | - ] |
|
156 | - ); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - private function addEventsAddEditHeader() |
|
165 | - { |
|
166 | - if ( |
|
167 | - $this->capabilities->current_user_can( |
|
168 | - 'ee_read_events', |
|
169 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
170 | - ) |
|
171 | - ) { |
|
172 | - $this->admin_bar->add_menu( |
|
173 | - [ |
|
174 | - 'id' => 'espresso-toolbar-events-add-edit', |
|
175 | - 'parent' => 'espresso-toolbar-events', |
|
176 | - 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
177 | - 'href' => '', |
|
178 | - ] |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - private function addEventsAddNew() |
|
188 | - { |
|
189 | - if ( |
|
190 | - $this->capabilities->current_user_can( |
|
191 | - 'ee_edit_events', |
|
192 | - 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
193 | - ) |
|
194 | - ) { |
|
195 | - $this->admin_bar->add_menu( |
|
196 | - [ |
|
197 | - 'id' => 'espresso-toolbar-events-new', |
|
198 | - 'parent' => 'espresso-toolbar-events', |
|
199 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
200 | - . esc_html__('Add New', 'event_espresso'), |
|
201 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
202 | - ['action' => 'create_new'], |
|
203 | - $this->events_admin_url |
|
204 | - ), |
|
205 | - 'meta' => [ |
|
206 | - 'title' => esc_html__('Add New', 'event_espresso'), |
|
207 | - 'target' => '', |
|
208 | - 'class' => $this->menu_class, |
|
209 | - ], |
|
210 | - ] |
|
211 | - ); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - private function addEventsEditCurrentEvent() |
|
220 | - { |
|
221 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
222 | - // Current post |
|
223 | - global $post; |
|
224 | - if ( |
|
225 | - $this->capabilities->current_user_can( |
|
226 | - 'ee_edit_event', |
|
227 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', |
|
228 | - $post->ID |
|
229 | - ) |
|
230 | - ) { |
|
231 | - $this->admin_bar->add_menu( |
|
232 | - [ |
|
233 | - 'id' => 'espresso-toolbar-events-edit', |
|
234 | - 'parent' => 'espresso-toolbar-events', |
|
235 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
236 | - . esc_html__('Edit Event', 'event_espresso'), |
|
237 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
238 | - [ |
|
239 | - 'action' => 'edit', |
|
240 | - 'post' => $post->ID, |
|
241 | - ], |
|
242 | - $this->events_admin_url |
|
243 | - ), |
|
244 | - 'meta' => [ |
|
245 | - 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
246 | - 'target' => '', |
|
247 | - 'class' => $this->menu_class, |
|
248 | - ], |
|
249 | - ] |
|
250 | - ); |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - private function addEventsViewHeader() |
|
260 | - { |
|
261 | - if ( |
|
262 | - $this->capabilities->current_user_can( |
|
263 | - 'ee_read_events', |
|
264 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $this->admin_bar->add_menu( |
|
268 | - [ |
|
269 | - 'id' => 'espresso-toolbar-events-view', |
|
270 | - 'parent' => 'espresso-toolbar-events', |
|
271 | - 'title' => esc_html__('View', 'event_espresso'), |
|
272 | - 'href' => '', |
|
273 | - ] |
|
274 | - ); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - private function addEventsViewAll() |
|
283 | - { |
|
284 | - if ( |
|
285 | - $this->capabilities->current_user_can( |
|
286 | - 'ee_read_events', |
|
287 | - 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
288 | - ) |
|
289 | - ) { |
|
290 | - $this->admin_bar->add_menu( |
|
291 | - [ |
|
292 | - 'id' => 'espresso-toolbar-events-all', |
|
293 | - 'parent' => 'espresso-toolbar-events', |
|
294 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
295 | - . esc_html__('All', 'event_espresso'), |
|
296 | - 'href' => $this->events_admin_url, |
|
297 | - 'meta' => [ |
|
298 | - 'title' => esc_html__('All', 'event_espresso'), |
|
299 | - 'target' => '', |
|
300 | - 'class' => $this->menu_class, |
|
301 | - ], |
|
302 | - ] |
|
303 | - ); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - private function addEventsViewToday() |
|
312 | - { |
|
313 | - if ( |
|
314 | - $this->capabilities->current_user_can( |
|
315 | - 'ee_read_events', |
|
316 | - 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
317 | - ) |
|
318 | - ) { |
|
319 | - $this->admin_bar->add_menu( |
|
320 | - [ |
|
321 | - 'id' => 'espresso-toolbar-events-today', |
|
322 | - 'parent' => 'espresso-toolbar-events', |
|
323 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
324 | - . esc_html__('Today', 'event_espresso'), |
|
325 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
326 | - [ |
|
327 | - 'action' => 'default', |
|
328 | - 'status' => 'today', |
|
329 | - ], |
|
330 | - $this->events_admin_url |
|
331 | - ), |
|
332 | - 'meta' => [ |
|
333 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
334 | - 'target' => '', |
|
335 | - 'class' => $this->menu_class, |
|
336 | - ], |
|
337 | - ] |
|
338 | - ); |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @return void |
|
345 | - */ |
|
346 | - private function addEventsViewThisMonth() |
|
347 | - { |
|
348 | - if ( |
|
349 | - $this->capabilities->current_user_can( |
|
350 | - 'ee_read_events', |
|
351 | - 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
352 | - ) |
|
353 | - ) { |
|
354 | - $this->admin_bar->add_menu( |
|
355 | - [ |
|
356 | - 'id' => 'espresso-toolbar-events-month', |
|
357 | - 'parent' => 'espresso-toolbar-events', |
|
358 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
359 | - . esc_html__('This Month', 'event_espresso'), |
|
360 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
361 | - [ |
|
362 | - 'action' => 'default', |
|
363 | - 'status' => 'month', |
|
364 | - ], |
|
365 | - $this->events_admin_url |
|
366 | - ), |
|
367 | - 'meta' => [ |
|
368 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
369 | - 'target' => '', |
|
370 | - 'class' => $this->menu_class, |
|
371 | - ], |
|
372 | - ] |
|
373 | - ); |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @return void |
|
380 | - */ |
|
381 | - private function addRegistrationSubMenu() |
|
382 | - { |
|
383 | - if ( |
|
384 | - $this->capabilities->current_user_can( |
|
385 | - 'ee_read_registrations', |
|
386 | - 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
387 | - ) |
|
388 | - ) { |
|
389 | - $this->admin_bar->add_menu( |
|
390 | - [ |
|
391 | - 'id' => 'espresso-toolbar-registrations', |
|
392 | - 'parent' => 'espresso-toolbar', |
|
393 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
394 | - . esc_html__('Registrations', 'event_espresso'), |
|
395 | - 'href' => $this->reg_admin_url, |
|
396 | - 'meta' => [ |
|
397 | - 'title' => esc_html__('Registrations', 'event_espresso'), |
|
398 | - 'target' => '', |
|
399 | - 'class' => $this->menu_class, |
|
400 | - ], |
|
401 | - ] |
|
402 | - ); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @return void |
|
409 | - */ |
|
410 | - private function addRegistrationOverviewToday() |
|
411 | - { |
|
412 | - if ( |
|
413 | - $this->capabilities->current_user_can( |
|
414 | - 'ee_read_registrations', |
|
415 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
416 | - ) |
|
417 | - ) { |
|
418 | - $this->admin_bar->add_menu( |
|
419 | - [ |
|
420 | - 'id' => 'espresso-toolbar-registrations-today', |
|
421 | - 'parent' => 'espresso-toolbar-registrations', |
|
422 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
423 | - 'href' => '', |
|
424 | - 'meta' => [ |
|
425 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
426 | - 'target' => '', |
|
427 | - 'class' => $this->menu_class, |
|
428 | - ], |
|
429 | - ] |
|
430 | - ); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @return void |
|
437 | - */ |
|
438 | - private function addRegistrationOverviewTodayApproved() |
|
439 | - { |
|
440 | - if ( |
|
441 | - $this->capabilities->current_user_can( |
|
442 | - 'ee_read_registrations', |
|
443 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
444 | - ) |
|
445 | - ) { |
|
446 | - $this->admin_bar->add_menu( |
|
447 | - [ |
|
448 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
449 | - 'parent' => 'espresso-toolbar-registrations', |
|
450 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
451 | - . esc_html__('Approved', 'event_espresso'), |
|
452 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
453 | - [ |
|
454 | - 'action' => 'default', |
|
455 | - 'status' => 'today', |
|
456 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
457 | - ], |
|
458 | - $this->reg_admin_url |
|
459 | - ), |
|
460 | - 'meta' => [ |
|
461 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
462 | - 'target' => '', |
|
463 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
464 | - ], |
|
465 | - ] |
|
466 | - ); |
|
467 | - } |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * @return void |
|
473 | - */ |
|
474 | - private function addRegistrationOverviewTodayPendingPayment() |
|
475 | - { |
|
476 | - if ( |
|
477 | - $this->capabilities->current_user_can( |
|
478 | - 'ee_read_registrations', |
|
479 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
480 | - ) |
|
481 | - ) { |
|
482 | - $this->admin_bar->add_menu( |
|
483 | - [ |
|
484 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
485 | - 'parent' => 'espresso-toolbar-registrations', |
|
486 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
487 | - . esc_html__('Pending', 'event_espresso'), |
|
488 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
489 | - [ |
|
490 | - 'action' => 'default', |
|
491 | - 'status' => 'today', |
|
492 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
493 | - ], |
|
494 | - $this->reg_admin_url |
|
495 | - ), |
|
496 | - 'meta' => [ |
|
497 | - 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
498 | - 'target' => '', |
|
499 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
500 | - ], |
|
501 | - ] |
|
502 | - ); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * @return void |
|
509 | - */ |
|
510 | - private function addRegistrationOverviewTodayNotApproved() |
|
511 | - { |
|
512 | - if ( |
|
513 | - $this->capabilities->current_user_can( |
|
514 | - 'ee_read_registrations', |
|
515 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
516 | - ) |
|
517 | - ) { |
|
518 | - $this->admin_bar->add_menu( |
|
519 | - [ |
|
520 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
521 | - 'parent' => 'espresso-toolbar-registrations', |
|
522 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
523 | - . esc_html__('Not Approved', 'event_espresso'), |
|
524 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
525 | - [ |
|
526 | - 'action' => 'default', |
|
527 | - 'status' => 'today', |
|
528 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
529 | - ], |
|
530 | - $this->reg_admin_url |
|
531 | - ), |
|
532 | - 'meta' => [ |
|
533 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
534 | - 'target' => '', |
|
535 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
536 | - ], |
|
537 | - ] |
|
538 | - ); |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @return void |
|
545 | - */ |
|
546 | - private function addRegistrationOverviewTodayCancelled() |
|
547 | - { |
|
548 | - if ( |
|
549 | - $this->capabilities->current_user_can( |
|
550 | - 'ee_read_registrations', |
|
551 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
552 | - ) |
|
553 | - ) { |
|
554 | - $this->admin_bar->add_menu( |
|
555 | - [ |
|
556 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
557 | - 'parent' => 'espresso-toolbar-registrations', |
|
558 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
559 | - . esc_html__('Cancelled', 'event_espresso'), |
|
560 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
561 | - [ |
|
562 | - 'action' => 'default', |
|
563 | - 'status' => 'today', |
|
564 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
565 | - ], |
|
566 | - $this->reg_admin_url |
|
567 | - ), |
|
568 | - 'meta' => [ |
|
569 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
570 | - 'target' => '', |
|
571 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
572 | - ], |
|
573 | - ] |
|
574 | - ); |
|
575 | - } |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * @return void |
|
581 | - */ |
|
582 | - private function addRegistrationOverviewThisMonth() |
|
583 | - { |
|
584 | - if ( |
|
585 | - $this->capabilities->current_user_can( |
|
586 | - 'ee_read_registrations', |
|
587 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
588 | - ) |
|
589 | - ) { |
|
590 | - $this->admin_bar->add_menu( |
|
591 | - [ |
|
592 | - 'id' => 'espresso-toolbar-registrations-month', |
|
593 | - 'parent' => 'espresso-toolbar-registrations', |
|
594 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
595 | - 'href' => '', // EEH_URL::add_query_args_and_nonce( |
|
596 | - // array( |
|
597 | - // 'action' => 'default', |
|
598 | - // 'status' => 'month' |
|
599 | - // ), |
|
600 | - // $this->reg_admin_url |
|
601 | - // ), |
|
602 | - 'meta' => [ |
|
603 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
604 | - 'target' => '', |
|
605 | - 'class' => $this->menu_class, |
|
606 | - ], |
|
607 | - ] |
|
608 | - ); |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * @return void |
|
615 | - */ |
|
616 | - private function addRegistrationOverviewThisMonthApproved() |
|
617 | - { |
|
618 | - if ( |
|
619 | - $this->capabilities->current_user_can( |
|
620 | - 'ee_read_registrations', |
|
621 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
622 | - ) |
|
623 | - ) { |
|
624 | - $this->admin_bar->add_menu( |
|
625 | - [ |
|
626 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
627 | - 'parent' => 'espresso-toolbar-registrations', |
|
628 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
629 | - . esc_html__('Approved', 'event_espresso'), |
|
630 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
631 | - [ |
|
632 | - 'action' => 'default', |
|
633 | - 'status' => 'month', |
|
634 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
635 | - ], |
|
636 | - $this->reg_admin_url |
|
637 | - ), |
|
638 | - 'meta' => [ |
|
639 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
640 | - 'target' => '', |
|
641 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
642 | - ], |
|
643 | - ] |
|
644 | - ); |
|
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @return void |
|
651 | - */ |
|
652 | - private function addRegistrationOverviewThisMonthPending() |
|
653 | - { |
|
654 | - if ( |
|
655 | - $this->capabilities->current_user_can( |
|
656 | - 'ee_read_registrations', |
|
657 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
658 | - ) |
|
659 | - ) { |
|
660 | - $this->admin_bar->add_menu( |
|
661 | - [ |
|
662 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
663 | - 'parent' => 'espresso-toolbar-registrations', |
|
664 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
665 | - . esc_html__('Pending', 'event_espresso'), |
|
666 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
667 | - [ |
|
668 | - 'action' => 'default', |
|
669 | - 'status' => 'month', |
|
670 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
671 | - ], |
|
672 | - $this->reg_admin_url |
|
673 | - ), |
|
674 | - 'meta' => [ |
|
675 | - 'title' => esc_html__('Pending', 'event_espresso'), |
|
676 | - 'target' => '', |
|
677 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
678 | - ], |
|
679 | - ] |
|
680 | - ); |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * @return void |
|
687 | - */ |
|
688 | - private function addRegistrationOverviewThisMonthNotApproved() |
|
689 | - { |
|
690 | - if ( |
|
691 | - $this->capabilities->current_user_can( |
|
692 | - 'ee_read_registrations', |
|
693 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
694 | - ) |
|
695 | - ) { |
|
696 | - $this->admin_bar->add_menu( |
|
697 | - [ |
|
698 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
699 | - 'parent' => 'espresso-toolbar-registrations', |
|
700 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
701 | - . esc_html__('Not Approved', 'event_espresso'), |
|
702 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
703 | - [ |
|
704 | - 'action' => 'default', |
|
705 | - 'status' => 'month', |
|
706 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
707 | - ], |
|
708 | - $this->reg_admin_url |
|
709 | - ), |
|
710 | - 'meta' => [ |
|
711 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
712 | - 'target' => '', |
|
713 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
714 | - ], |
|
715 | - ] |
|
716 | - ); |
|
717 | - } |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * @return void |
|
723 | - */ |
|
724 | - private function addRegistrationOverviewThisMonthCancelled() |
|
725 | - { |
|
726 | - if ( |
|
727 | - $this->capabilities->current_user_can( |
|
728 | - 'ee_read_registrations', |
|
729 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
730 | - ) |
|
731 | - ) { |
|
732 | - $this->admin_bar->add_menu( |
|
733 | - [ |
|
734 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
735 | - 'parent' => 'espresso-toolbar-registrations', |
|
736 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
737 | - . esc_html__('Cancelled', 'event_espresso'), |
|
738 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
739 | - [ |
|
740 | - 'action' => 'default', |
|
741 | - 'status' => 'month', |
|
742 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
743 | - ], |
|
744 | - $this->reg_admin_url |
|
745 | - ), |
|
746 | - 'meta' => [ |
|
747 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
748 | - 'target' => '', |
|
749 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
750 | - ], |
|
751 | - ] |
|
752 | - ); |
|
753 | - } |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * @return void |
|
759 | - */ |
|
760 | - private function addExtensionsAndServices() |
|
761 | - { |
|
762 | - if ( |
|
763 | - $this->capabilities->current_user_can( |
|
764 | - 'ee_read_ee', |
|
765 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
766 | - ) |
|
767 | - ) { |
|
768 | - $this->admin_bar->add_menu( |
|
769 | - [ |
|
770 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
771 | - 'parent' => 'espresso-toolbar', |
|
772 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
773 | - . esc_html__('Extensions & Services', 'event_espresso'), |
|
774 | - 'href' => admin_url('admin.php?page=espresso_packages'), |
|
775 | - 'meta' => [ |
|
776 | - 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
777 | - 'target' => '', |
|
778 | - 'class' => $this->menu_class, |
|
779 | - ], |
|
780 | - ] |
|
781 | - ); |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * @return void |
|
788 | - */ |
|
789 | - private function addFontSizeSubMenu() |
|
790 | - { |
|
791 | - $this->admin_bar->add_menu( |
|
792 | - [ |
|
793 | - 'id' => 'espresso-toolbar-font-size', |
|
794 | - 'parent' => 'espresso-toolbar', |
|
795 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
796 | - . esc_html__('Set Font Size', 'event_espresso'), |
|
797 | - 'href' => '', |
|
798 | - 'meta' => [ |
|
799 | - 'title' => esc_html__('Set Font Size', 'event_espresso'), |
|
800 | - 'target' => '', |
|
801 | - 'class' => $this->menu_class, |
|
802 | - ], |
|
803 | - ] |
|
804 | - ); |
|
805 | - |
|
806 | - $settings_admin_url = admin_url('admin.php?page=espresso_general_settings'); |
|
807 | - |
|
808 | - $font_sizes = [ |
|
809 | - 'tiny' => AdminFontSize::FONT_SIZE_TINY, |
|
810 | - 'smaller' => AdminFontSize::FONT_SIZE_SMALLER, |
|
811 | - 'small' => AdminFontSize::FONT_SIZE_SMALL, |
|
812 | - 'default' => AdminFontSize::FONT_SIZE_DEFAULT, |
|
813 | - 'big' => AdminFontSize::FONT_SIZE_BIG, |
|
814 | - 'bigger' => AdminFontSize::FONT_SIZE_BIGGER, |
|
815 | - ]; |
|
816 | - |
|
817 | - foreach ($font_sizes as $font_size => $value) { |
|
818 | - $this->admin_bar->add_menu( |
|
819 | - [ |
|
820 | - 'id' => "espresso-toolbar-set-font-size-$font_size", |
|
821 | - 'parent' => 'espresso-toolbar-font-size', |
|
822 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
823 | - . sprintf( |
|
824 | - /* translators: Font Size Small */ |
|
825 | - esc_html__('Font Size %1$s', 'event_espresso'), |
|
826 | - ucwords($font_size) |
|
827 | - ), |
|
828 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
829 | - ['action' => 'set_font_size', 'font_size' => $value], |
|
830 | - $settings_admin_url |
|
831 | - ), |
|
832 | - 'meta' => [ |
|
833 | - 'title' => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'), |
|
834 | - 'target' => '', |
|
835 | - 'class' => $this->menu_class, |
|
836 | - ], |
|
837 | - ] |
|
838 | - ); |
|
839 | - } |
|
840 | - } |
|
23 | + private ?WP_Admin_Bar $admin_bar = null; |
|
24 | + |
|
25 | + private EE_Capabilities $capabilities; |
|
26 | + |
|
27 | + private string $events_admin_url = ''; |
|
28 | + |
|
29 | + private string $menu_class = 'espresso_menu_item_class'; |
|
30 | + |
|
31 | + private string $reg_admin_url = ''; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * AdminToolBar constructor. |
|
36 | + * |
|
37 | + * @param EE_Capabilities $capabilities |
|
38 | + */ |
|
39 | + public function __construct(EE_Capabilities $capabilities) |
|
40 | + { |
|
41 | + $this->capabilities = $capabilities; |
|
42 | + add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100); |
|
43 | + $this->enqueueAssets(); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * espresso_toolbar_items |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param WP_Admin_Bar $admin_bar |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
55 | + { |
|
56 | + // if its an AJAX request, or user is NOT an admin, or in full M-Mode |
|
57 | + if ( |
|
58 | + defined('DOING_AJAX') |
|
59 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
60 | + || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
61 | + ) { |
|
62 | + return; |
|
63 | + } |
|
64 | + $this->admin_bar = $admin_bar; |
|
65 | + // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
66 | + // because they're only defined in each of their respective constructors |
|
67 | + // and this might be a frontend request, in which case they aren't available |
|
68 | + $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
69 | + $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
70 | + // now let's add all of the menu items |
|
71 | + $this->addTopLevelMenu(); |
|
72 | + $this->addEventsSubMenu(); |
|
73 | + $this->addEventsAddEditHeader(); |
|
74 | + $this->addEventsAddNew(); |
|
75 | + $this->addEventsEditCurrentEvent(); |
|
76 | + $this->addEventsViewHeader(); |
|
77 | + $this->addEventsViewAll(); |
|
78 | + $this->addEventsViewToday(); |
|
79 | + $this->addEventsViewThisMonth(); |
|
80 | + $this->addRegistrationSubMenu(); |
|
81 | + $this->addRegistrationOverviewToday(); |
|
82 | + $this->addRegistrationOverviewTodayApproved(); |
|
83 | + $this->addRegistrationOverviewTodayPendingPayment(); |
|
84 | + $this->addRegistrationOverviewTodayNotApproved(); |
|
85 | + $this->addRegistrationOverviewTodayCancelled(); |
|
86 | + $this->addRegistrationOverviewThisMonth(); |
|
87 | + $this->addRegistrationOverviewThisMonthApproved(); |
|
88 | + $this->addRegistrationOverviewThisMonthPending(); |
|
89 | + $this->addRegistrationOverviewThisMonthNotApproved(); |
|
90 | + $this->addRegistrationOverviewThisMonthCancelled(); |
|
91 | + $this->addExtensionsAndServices(); |
|
92 | + $this->addFontSizeSubMenu(); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + private function enqueueAssets() |
|
100 | + { |
|
101 | + wp_register_style( |
|
102 | + 'espresso-admin-toolbar', |
|
103 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
104 | + ['dashicons'], |
|
105 | + EVENT_ESPRESSO_VERSION |
|
106 | + ); |
|
107 | + wp_enqueue_style('espresso-admin-toolbar'); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + private function addTopLevelMenu() |
|
115 | + { |
|
116 | + $this->admin_bar->add_menu( |
|
117 | + [ |
|
118 | + 'id' => 'espresso-toolbar', |
|
119 | + 'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
120 | + . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
121 | + . '</span>', |
|
122 | + 'href' => $this->events_admin_url, |
|
123 | + 'meta' => [ |
|
124 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
125 | + 'class' => $this->menu_class . 'first', |
|
126 | + ], |
|
127 | + ] |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + private function addEventsSubMenu() |
|
136 | + { |
|
137 | + if ( |
|
138 | + $this->capabilities->current_user_can( |
|
139 | + 'ee_read_events', |
|
140 | + 'ee_admin_bar_menu_espresso-toolbar-events' |
|
141 | + ) |
|
142 | + ) { |
|
143 | + $this->admin_bar->add_menu( |
|
144 | + [ |
|
145 | + 'id' => 'espresso-toolbar-events', |
|
146 | + 'parent' => 'espresso-toolbar', |
|
147 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
148 | + . esc_html__('Events', 'event_espresso'), |
|
149 | + 'href' => $this->events_admin_url, |
|
150 | + 'meta' => [ |
|
151 | + 'title' => esc_html__('Events', 'event_espresso'), |
|
152 | + 'target' => '', |
|
153 | + 'class' => $this->menu_class, |
|
154 | + ], |
|
155 | + ] |
|
156 | + ); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + private function addEventsAddEditHeader() |
|
165 | + { |
|
166 | + if ( |
|
167 | + $this->capabilities->current_user_can( |
|
168 | + 'ee_read_events', |
|
169 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
170 | + ) |
|
171 | + ) { |
|
172 | + $this->admin_bar->add_menu( |
|
173 | + [ |
|
174 | + 'id' => 'espresso-toolbar-events-add-edit', |
|
175 | + 'parent' => 'espresso-toolbar-events', |
|
176 | + 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
177 | + 'href' => '', |
|
178 | + ] |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + private function addEventsAddNew() |
|
188 | + { |
|
189 | + if ( |
|
190 | + $this->capabilities->current_user_can( |
|
191 | + 'ee_edit_events', |
|
192 | + 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
193 | + ) |
|
194 | + ) { |
|
195 | + $this->admin_bar->add_menu( |
|
196 | + [ |
|
197 | + 'id' => 'espresso-toolbar-events-new', |
|
198 | + 'parent' => 'espresso-toolbar-events', |
|
199 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
200 | + . esc_html__('Add New', 'event_espresso'), |
|
201 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
202 | + ['action' => 'create_new'], |
|
203 | + $this->events_admin_url |
|
204 | + ), |
|
205 | + 'meta' => [ |
|
206 | + 'title' => esc_html__('Add New', 'event_espresso'), |
|
207 | + 'target' => '', |
|
208 | + 'class' => $this->menu_class, |
|
209 | + ], |
|
210 | + ] |
|
211 | + ); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + private function addEventsEditCurrentEvent() |
|
220 | + { |
|
221 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
222 | + // Current post |
|
223 | + global $post; |
|
224 | + if ( |
|
225 | + $this->capabilities->current_user_can( |
|
226 | + 'ee_edit_event', |
|
227 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', |
|
228 | + $post->ID |
|
229 | + ) |
|
230 | + ) { |
|
231 | + $this->admin_bar->add_menu( |
|
232 | + [ |
|
233 | + 'id' => 'espresso-toolbar-events-edit', |
|
234 | + 'parent' => 'espresso-toolbar-events', |
|
235 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
236 | + . esc_html__('Edit Event', 'event_espresso'), |
|
237 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
238 | + [ |
|
239 | + 'action' => 'edit', |
|
240 | + 'post' => $post->ID, |
|
241 | + ], |
|
242 | + $this->events_admin_url |
|
243 | + ), |
|
244 | + 'meta' => [ |
|
245 | + 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
246 | + 'target' => '', |
|
247 | + 'class' => $this->menu_class, |
|
248 | + ], |
|
249 | + ] |
|
250 | + ); |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + private function addEventsViewHeader() |
|
260 | + { |
|
261 | + if ( |
|
262 | + $this->capabilities->current_user_can( |
|
263 | + 'ee_read_events', |
|
264 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $this->admin_bar->add_menu( |
|
268 | + [ |
|
269 | + 'id' => 'espresso-toolbar-events-view', |
|
270 | + 'parent' => 'espresso-toolbar-events', |
|
271 | + 'title' => esc_html__('View', 'event_espresso'), |
|
272 | + 'href' => '', |
|
273 | + ] |
|
274 | + ); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + private function addEventsViewAll() |
|
283 | + { |
|
284 | + if ( |
|
285 | + $this->capabilities->current_user_can( |
|
286 | + 'ee_read_events', |
|
287 | + 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
288 | + ) |
|
289 | + ) { |
|
290 | + $this->admin_bar->add_menu( |
|
291 | + [ |
|
292 | + 'id' => 'espresso-toolbar-events-all', |
|
293 | + 'parent' => 'espresso-toolbar-events', |
|
294 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
295 | + . esc_html__('All', 'event_espresso'), |
|
296 | + 'href' => $this->events_admin_url, |
|
297 | + 'meta' => [ |
|
298 | + 'title' => esc_html__('All', 'event_espresso'), |
|
299 | + 'target' => '', |
|
300 | + 'class' => $this->menu_class, |
|
301 | + ], |
|
302 | + ] |
|
303 | + ); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + private function addEventsViewToday() |
|
312 | + { |
|
313 | + if ( |
|
314 | + $this->capabilities->current_user_can( |
|
315 | + 'ee_read_events', |
|
316 | + 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
317 | + ) |
|
318 | + ) { |
|
319 | + $this->admin_bar->add_menu( |
|
320 | + [ |
|
321 | + 'id' => 'espresso-toolbar-events-today', |
|
322 | + 'parent' => 'espresso-toolbar-events', |
|
323 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
324 | + . esc_html__('Today', 'event_espresso'), |
|
325 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
326 | + [ |
|
327 | + 'action' => 'default', |
|
328 | + 'status' => 'today', |
|
329 | + ], |
|
330 | + $this->events_admin_url |
|
331 | + ), |
|
332 | + 'meta' => [ |
|
333 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
334 | + 'target' => '', |
|
335 | + 'class' => $this->menu_class, |
|
336 | + ], |
|
337 | + ] |
|
338 | + ); |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @return void |
|
345 | + */ |
|
346 | + private function addEventsViewThisMonth() |
|
347 | + { |
|
348 | + if ( |
|
349 | + $this->capabilities->current_user_can( |
|
350 | + 'ee_read_events', |
|
351 | + 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
352 | + ) |
|
353 | + ) { |
|
354 | + $this->admin_bar->add_menu( |
|
355 | + [ |
|
356 | + 'id' => 'espresso-toolbar-events-month', |
|
357 | + 'parent' => 'espresso-toolbar-events', |
|
358 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
359 | + . esc_html__('This Month', 'event_espresso'), |
|
360 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
361 | + [ |
|
362 | + 'action' => 'default', |
|
363 | + 'status' => 'month', |
|
364 | + ], |
|
365 | + $this->events_admin_url |
|
366 | + ), |
|
367 | + 'meta' => [ |
|
368 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
369 | + 'target' => '', |
|
370 | + 'class' => $this->menu_class, |
|
371 | + ], |
|
372 | + ] |
|
373 | + ); |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @return void |
|
380 | + */ |
|
381 | + private function addRegistrationSubMenu() |
|
382 | + { |
|
383 | + if ( |
|
384 | + $this->capabilities->current_user_can( |
|
385 | + 'ee_read_registrations', |
|
386 | + 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
387 | + ) |
|
388 | + ) { |
|
389 | + $this->admin_bar->add_menu( |
|
390 | + [ |
|
391 | + 'id' => 'espresso-toolbar-registrations', |
|
392 | + 'parent' => 'espresso-toolbar', |
|
393 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
394 | + . esc_html__('Registrations', 'event_espresso'), |
|
395 | + 'href' => $this->reg_admin_url, |
|
396 | + 'meta' => [ |
|
397 | + 'title' => esc_html__('Registrations', 'event_espresso'), |
|
398 | + 'target' => '', |
|
399 | + 'class' => $this->menu_class, |
|
400 | + ], |
|
401 | + ] |
|
402 | + ); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @return void |
|
409 | + */ |
|
410 | + private function addRegistrationOverviewToday() |
|
411 | + { |
|
412 | + if ( |
|
413 | + $this->capabilities->current_user_can( |
|
414 | + 'ee_read_registrations', |
|
415 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
416 | + ) |
|
417 | + ) { |
|
418 | + $this->admin_bar->add_menu( |
|
419 | + [ |
|
420 | + 'id' => 'espresso-toolbar-registrations-today', |
|
421 | + 'parent' => 'espresso-toolbar-registrations', |
|
422 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
423 | + 'href' => '', |
|
424 | + 'meta' => [ |
|
425 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
426 | + 'target' => '', |
|
427 | + 'class' => $this->menu_class, |
|
428 | + ], |
|
429 | + ] |
|
430 | + ); |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @return void |
|
437 | + */ |
|
438 | + private function addRegistrationOverviewTodayApproved() |
|
439 | + { |
|
440 | + if ( |
|
441 | + $this->capabilities->current_user_can( |
|
442 | + 'ee_read_registrations', |
|
443 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
444 | + ) |
|
445 | + ) { |
|
446 | + $this->admin_bar->add_menu( |
|
447 | + [ |
|
448 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
449 | + 'parent' => 'espresso-toolbar-registrations', |
|
450 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
451 | + . esc_html__('Approved', 'event_espresso'), |
|
452 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
453 | + [ |
|
454 | + 'action' => 'default', |
|
455 | + 'status' => 'today', |
|
456 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
457 | + ], |
|
458 | + $this->reg_admin_url |
|
459 | + ), |
|
460 | + 'meta' => [ |
|
461 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
462 | + 'target' => '', |
|
463 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
464 | + ], |
|
465 | + ] |
|
466 | + ); |
|
467 | + } |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * @return void |
|
473 | + */ |
|
474 | + private function addRegistrationOverviewTodayPendingPayment() |
|
475 | + { |
|
476 | + if ( |
|
477 | + $this->capabilities->current_user_can( |
|
478 | + 'ee_read_registrations', |
|
479 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
480 | + ) |
|
481 | + ) { |
|
482 | + $this->admin_bar->add_menu( |
|
483 | + [ |
|
484 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
485 | + 'parent' => 'espresso-toolbar-registrations', |
|
486 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
487 | + . esc_html__('Pending', 'event_espresso'), |
|
488 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
489 | + [ |
|
490 | + 'action' => 'default', |
|
491 | + 'status' => 'today', |
|
492 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
493 | + ], |
|
494 | + $this->reg_admin_url |
|
495 | + ), |
|
496 | + 'meta' => [ |
|
497 | + 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
498 | + 'target' => '', |
|
499 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
500 | + ], |
|
501 | + ] |
|
502 | + ); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * @return void |
|
509 | + */ |
|
510 | + private function addRegistrationOverviewTodayNotApproved() |
|
511 | + { |
|
512 | + if ( |
|
513 | + $this->capabilities->current_user_can( |
|
514 | + 'ee_read_registrations', |
|
515 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
516 | + ) |
|
517 | + ) { |
|
518 | + $this->admin_bar->add_menu( |
|
519 | + [ |
|
520 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
521 | + 'parent' => 'espresso-toolbar-registrations', |
|
522 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
523 | + . esc_html__('Not Approved', 'event_espresso'), |
|
524 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
525 | + [ |
|
526 | + 'action' => 'default', |
|
527 | + 'status' => 'today', |
|
528 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
529 | + ], |
|
530 | + $this->reg_admin_url |
|
531 | + ), |
|
532 | + 'meta' => [ |
|
533 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
534 | + 'target' => '', |
|
535 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
536 | + ], |
|
537 | + ] |
|
538 | + ); |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @return void |
|
545 | + */ |
|
546 | + private function addRegistrationOverviewTodayCancelled() |
|
547 | + { |
|
548 | + if ( |
|
549 | + $this->capabilities->current_user_can( |
|
550 | + 'ee_read_registrations', |
|
551 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
552 | + ) |
|
553 | + ) { |
|
554 | + $this->admin_bar->add_menu( |
|
555 | + [ |
|
556 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
557 | + 'parent' => 'espresso-toolbar-registrations', |
|
558 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
559 | + . esc_html__('Cancelled', 'event_espresso'), |
|
560 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
561 | + [ |
|
562 | + 'action' => 'default', |
|
563 | + 'status' => 'today', |
|
564 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
565 | + ], |
|
566 | + $this->reg_admin_url |
|
567 | + ), |
|
568 | + 'meta' => [ |
|
569 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
570 | + 'target' => '', |
|
571 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
572 | + ], |
|
573 | + ] |
|
574 | + ); |
|
575 | + } |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * @return void |
|
581 | + */ |
|
582 | + private function addRegistrationOverviewThisMonth() |
|
583 | + { |
|
584 | + if ( |
|
585 | + $this->capabilities->current_user_can( |
|
586 | + 'ee_read_registrations', |
|
587 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
588 | + ) |
|
589 | + ) { |
|
590 | + $this->admin_bar->add_menu( |
|
591 | + [ |
|
592 | + 'id' => 'espresso-toolbar-registrations-month', |
|
593 | + 'parent' => 'espresso-toolbar-registrations', |
|
594 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
595 | + 'href' => '', // EEH_URL::add_query_args_and_nonce( |
|
596 | + // array( |
|
597 | + // 'action' => 'default', |
|
598 | + // 'status' => 'month' |
|
599 | + // ), |
|
600 | + // $this->reg_admin_url |
|
601 | + // ), |
|
602 | + 'meta' => [ |
|
603 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
604 | + 'target' => '', |
|
605 | + 'class' => $this->menu_class, |
|
606 | + ], |
|
607 | + ] |
|
608 | + ); |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * @return void |
|
615 | + */ |
|
616 | + private function addRegistrationOverviewThisMonthApproved() |
|
617 | + { |
|
618 | + if ( |
|
619 | + $this->capabilities->current_user_can( |
|
620 | + 'ee_read_registrations', |
|
621 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
622 | + ) |
|
623 | + ) { |
|
624 | + $this->admin_bar->add_menu( |
|
625 | + [ |
|
626 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
627 | + 'parent' => 'espresso-toolbar-registrations', |
|
628 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
629 | + . esc_html__('Approved', 'event_espresso'), |
|
630 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
631 | + [ |
|
632 | + 'action' => 'default', |
|
633 | + 'status' => 'month', |
|
634 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
635 | + ], |
|
636 | + $this->reg_admin_url |
|
637 | + ), |
|
638 | + 'meta' => [ |
|
639 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
640 | + 'target' => '', |
|
641 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
642 | + ], |
|
643 | + ] |
|
644 | + ); |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @return void |
|
651 | + */ |
|
652 | + private function addRegistrationOverviewThisMonthPending() |
|
653 | + { |
|
654 | + if ( |
|
655 | + $this->capabilities->current_user_can( |
|
656 | + 'ee_read_registrations', |
|
657 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
658 | + ) |
|
659 | + ) { |
|
660 | + $this->admin_bar->add_menu( |
|
661 | + [ |
|
662 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
663 | + 'parent' => 'espresso-toolbar-registrations', |
|
664 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
665 | + . esc_html__('Pending', 'event_espresso'), |
|
666 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
667 | + [ |
|
668 | + 'action' => 'default', |
|
669 | + 'status' => 'month', |
|
670 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
671 | + ], |
|
672 | + $this->reg_admin_url |
|
673 | + ), |
|
674 | + 'meta' => [ |
|
675 | + 'title' => esc_html__('Pending', 'event_espresso'), |
|
676 | + 'target' => '', |
|
677 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
678 | + ], |
|
679 | + ] |
|
680 | + ); |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * @return void |
|
687 | + */ |
|
688 | + private function addRegistrationOverviewThisMonthNotApproved() |
|
689 | + { |
|
690 | + if ( |
|
691 | + $this->capabilities->current_user_can( |
|
692 | + 'ee_read_registrations', |
|
693 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
694 | + ) |
|
695 | + ) { |
|
696 | + $this->admin_bar->add_menu( |
|
697 | + [ |
|
698 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
699 | + 'parent' => 'espresso-toolbar-registrations', |
|
700 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
701 | + . esc_html__('Not Approved', 'event_espresso'), |
|
702 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
703 | + [ |
|
704 | + 'action' => 'default', |
|
705 | + 'status' => 'month', |
|
706 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
707 | + ], |
|
708 | + $this->reg_admin_url |
|
709 | + ), |
|
710 | + 'meta' => [ |
|
711 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
712 | + 'target' => '', |
|
713 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
714 | + ], |
|
715 | + ] |
|
716 | + ); |
|
717 | + } |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * @return void |
|
723 | + */ |
|
724 | + private function addRegistrationOverviewThisMonthCancelled() |
|
725 | + { |
|
726 | + if ( |
|
727 | + $this->capabilities->current_user_can( |
|
728 | + 'ee_read_registrations', |
|
729 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
730 | + ) |
|
731 | + ) { |
|
732 | + $this->admin_bar->add_menu( |
|
733 | + [ |
|
734 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
735 | + 'parent' => 'espresso-toolbar-registrations', |
|
736 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
737 | + . esc_html__('Cancelled', 'event_espresso'), |
|
738 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
739 | + [ |
|
740 | + 'action' => 'default', |
|
741 | + 'status' => 'month', |
|
742 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
743 | + ], |
|
744 | + $this->reg_admin_url |
|
745 | + ), |
|
746 | + 'meta' => [ |
|
747 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
748 | + 'target' => '', |
|
749 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
750 | + ], |
|
751 | + ] |
|
752 | + ); |
|
753 | + } |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * @return void |
|
759 | + */ |
|
760 | + private function addExtensionsAndServices() |
|
761 | + { |
|
762 | + if ( |
|
763 | + $this->capabilities->current_user_can( |
|
764 | + 'ee_read_ee', |
|
765 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
766 | + ) |
|
767 | + ) { |
|
768 | + $this->admin_bar->add_menu( |
|
769 | + [ |
|
770 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
771 | + 'parent' => 'espresso-toolbar', |
|
772 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
773 | + . esc_html__('Extensions & Services', 'event_espresso'), |
|
774 | + 'href' => admin_url('admin.php?page=espresso_packages'), |
|
775 | + 'meta' => [ |
|
776 | + 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
777 | + 'target' => '', |
|
778 | + 'class' => $this->menu_class, |
|
779 | + ], |
|
780 | + ] |
|
781 | + ); |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * @return void |
|
788 | + */ |
|
789 | + private function addFontSizeSubMenu() |
|
790 | + { |
|
791 | + $this->admin_bar->add_menu( |
|
792 | + [ |
|
793 | + 'id' => 'espresso-toolbar-font-size', |
|
794 | + 'parent' => 'espresso-toolbar', |
|
795 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
796 | + . esc_html__('Set Font Size', 'event_espresso'), |
|
797 | + 'href' => '', |
|
798 | + 'meta' => [ |
|
799 | + 'title' => esc_html__('Set Font Size', 'event_espresso'), |
|
800 | + 'target' => '', |
|
801 | + 'class' => $this->menu_class, |
|
802 | + ], |
|
803 | + ] |
|
804 | + ); |
|
805 | + |
|
806 | + $settings_admin_url = admin_url('admin.php?page=espresso_general_settings'); |
|
807 | + |
|
808 | + $font_sizes = [ |
|
809 | + 'tiny' => AdminFontSize::FONT_SIZE_TINY, |
|
810 | + 'smaller' => AdminFontSize::FONT_SIZE_SMALLER, |
|
811 | + 'small' => AdminFontSize::FONT_SIZE_SMALL, |
|
812 | + 'default' => AdminFontSize::FONT_SIZE_DEFAULT, |
|
813 | + 'big' => AdminFontSize::FONT_SIZE_BIG, |
|
814 | + 'bigger' => AdminFontSize::FONT_SIZE_BIGGER, |
|
815 | + ]; |
|
816 | + |
|
817 | + foreach ($font_sizes as $font_size => $value) { |
|
818 | + $this->admin_bar->add_menu( |
|
819 | + [ |
|
820 | + 'id' => "espresso-toolbar-set-font-size-$font_size", |
|
821 | + 'parent' => 'espresso-toolbar-font-size', |
|
822 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
823 | + . sprintf( |
|
824 | + /* translators: Font Size Small */ |
|
825 | + esc_html__('Font Size %1$s', 'event_espresso'), |
|
826 | + ucwords($font_size) |
|
827 | + ), |
|
828 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
829 | + ['action' => 'set_font_size', 'font_size' => $value], |
|
830 | + $settings_admin_url |
|
831 | + ), |
|
832 | + 'meta' => [ |
|
833 | + 'title' => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'), |
|
834 | + 'target' => '', |
|
835 | + 'class' => $this->menu_class, |
|
836 | + ], |
|
837 | + ] |
|
838 | + ); |
|
839 | + } |
|
840 | + } |
|
841 | 841 | } |
@@ -14,61 +14,61 @@ |
||
14 | 14 | |
15 | 15 | class DatetimeUpdate extends EntityMutator |
16 | 16 | { |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Datetime $model |
|
21 | - * @param Datetime $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Updates an entity. |
|
28 | - * |
|
29 | - * @param array $input The input for the mutation |
|
30 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | - * @return array |
|
33 | - * @throws EE_Error |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | - try { |
|
38 | - /** @var EE_Datetime $entity */ |
|
39 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
40 | - $args = DatetimeMutation::prepareFields($input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Datetime $model |
|
21 | + * @param Datetime $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Updates an entity. |
|
28 | + * |
|
29 | + * @param array $input The input for the mutation |
|
30 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | + * @return array |
|
33 | + * @throws EE_Error |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | + try { |
|
38 | + /** @var EE_Datetime $entity */ |
|
39 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
40 | + $args = DatetimeMutation::prepareFields($input); |
|
41 | 41 | |
42 | - // extract tickets and venue from args then unset them |
|
43 | - $tickets = $args['tickets'] ?? null; |
|
44 | - $venue = $args['venue'] ?? null; |
|
45 | - unset($args['tickets'], $args['venue']); |
|
42 | + // extract tickets and venue from args then unset them |
|
43 | + $tickets = $args['tickets'] ?? null; |
|
44 | + $venue = $args['venue'] ?? null; |
|
45 | + unset($args['tickets'], $args['venue']); |
|
46 | 46 | |
47 | - // Update the entity |
|
48 | - $entity->save($args); |
|
47 | + // Update the entity |
|
48 | + $entity->save($args); |
|
49 | 49 | |
50 | - if ($tickets) { |
|
51 | - DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
52 | - } |
|
50 | + if ($tickets) { |
|
51 | + DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
52 | + } |
|
53 | 53 | |
54 | - if ($venue) { |
|
55 | - DatetimeMutation::setVenue($entity, $venue); |
|
56 | - } |
|
54 | + if ($venue) { |
|
55 | + DatetimeMutation::setVenue($entity, $venue); |
|
56 | + } |
|
57 | 57 | |
58 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_update', $entity, $input); |
|
59 | - } catch (Exception $exception) { |
|
60 | - EntityMutator::handleExceptions( |
|
61 | - $exception, |
|
62 | - esc_html__( |
|
63 | - 'The datetime could not be updated because of the following error(s)', |
|
64 | - 'event_espresso' |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
58 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_update', $entity, $input); |
|
59 | + } catch (Exception $exception) { |
|
60 | + EntityMutator::handleExceptions( |
|
61 | + $exception, |
|
62 | + esc_html__( |
|
63 | + 'The datetime could not be updated because of the following error(s)', |
|
64 | + 'event_espresso' |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - return [ |
|
70 | - 'id' => $entity->ID(), |
|
71 | - ]; |
|
72 | - }; |
|
73 | - } |
|
69 | + return [ |
|
70 | + 'id' => $entity->ID(), |
|
71 | + ]; |
|
72 | + }; |
|
73 | + } |
|
74 | 74 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @throws EE_Error |
34 | 34 | * @throws ReflectionException |
35 | 35 | */ |
36 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
36 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
37 | 37 | try { |
38 | 38 | /** @var EE_Datetime $entity */ |
39 | 39 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -12,58 +12,58 @@ |
||
12 | 12 | |
13 | 13 | class DatetimeCreate extends EntityMutator |
14 | 14 | { |
15 | - /** |
|
16 | - * Defines the mutation data modification closure. |
|
17 | - * |
|
18 | - * @param EEM_Datetime $model |
|
19 | - * @param Datetime $type |
|
20 | - * @return callable |
|
21 | - */ |
|
22 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
23 | - { |
|
24 | - /** |
|
25 | - * Creates an entity. |
|
26 | - * |
|
27 | - * @param array $input The input for the mutation |
|
28 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
29 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
33 | - $id = null; |
|
34 | - try { |
|
35 | - EntityMutator::checkPermissions($model); |
|
36 | - $args = DatetimeMutation::prepareFields($input); |
|
15 | + /** |
|
16 | + * Defines the mutation data modification closure. |
|
17 | + * |
|
18 | + * @param EEM_Datetime $model |
|
19 | + * @param Datetime $type |
|
20 | + * @return callable |
|
21 | + */ |
|
22 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
23 | + { |
|
24 | + /** |
|
25 | + * Creates an entity. |
|
26 | + * |
|
27 | + * @param array $input The input for the mutation |
|
28 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
29 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
33 | + $id = null; |
|
34 | + try { |
|
35 | + EntityMutator::checkPermissions($model); |
|
36 | + $args = DatetimeMutation::prepareFields($input); |
|
37 | 37 | |
38 | - // extract tickets and venue from args then unset them |
|
39 | - $tickets = $args['tickets'] ?? null; |
|
40 | - $venue = $args['venue'] ?? null; |
|
41 | - unset($args['tickets'], $args['venue']); |
|
38 | + // extract tickets and venue from args then unset them |
|
39 | + $tickets = $args['tickets'] ?? null; |
|
40 | + $venue = $args['venue'] ?? null; |
|
41 | + unset($args['tickets'], $args['venue']); |
|
42 | 42 | |
43 | - $entity = EE_Datetime::new_instance($args); |
|
44 | - $id = $entity->save(); |
|
45 | - EntityMutator::validateResults($id); |
|
43 | + $entity = EE_Datetime::new_instance($args); |
|
44 | + $id = $entity->save(); |
|
45 | + EntityMutator::validateResults($id); |
|
46 | 46 | |
47 | - if ($tickets) { |
|
48 | - DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
49 | - } |
|
47 | + if ($tickets) { |
|
48 | + DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
49 | + } |
|
50 | 50 | |
51 | - if ($venue) { |
|
52 | - DatetimeMutation::setVenue($entity, $venue); |
|
53 | - } |
|
51 | + if ($venue) { |
|
52 | + DatetimeMutation::setVenue($entity, $venue); |
|
53 | + } |
|
54 | 54 | |
55 | - do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_create', $entity, $input); |
|
56 | - } catch (Exception $exception) { |
|
57 | - EntityMutator::handleExceptions( |
|
58 | - $exception, |
|
59 | - esc_html__( |
|
60 | - 'The datetime could not be created because of the following error(s)', |
|
61 | - 'event_espresso' |
|
62 | - ) |
|
63 | - ); |
|
64 | - } |
|
55 | + do_action('AHEE__EventEspresso_core_domain_services_graphql_mutators_datetime_create', $entity, $input); |
|
56 | + } catch (Exception $exception) { |
|
57 | + EntityMutator::handleExceptions( |
|
58 | + $exception, |
|
59 | + esc_html__( |
|
60 | + 'The datetime could not be created because of the following error(s)', |
|
61 | + 'event_espresso' |
|
62 | + ) |
|
63 | + ); |
|
64 | + } |
|
65 | 65 | |
66 | - return $id ? [ 'id' => $id ] : []; |
|
67 | - }; |
|
68 | - } |
|
66 | + return $id ? [ 'id' => $id ] : []; |
|
67 | + }; |
|
68 | + } |
|
69 | 69 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
32 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model, $type): array { |
|
33 | 33 | $id = null; |
34 | 34 | try { |
35 | 35 | EntityMutator::checkPermissions($model); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | - return $id ? [ 'id' => $id ] : []; |
|
66 | + return $id ? ['id' => $id] : []; |
|
67 | 67 | }; |
68 | 68 | } |
69 | 69 | } |
@@ -20,134 +20,134 @@ |
||
20 | 20 | */ |
21 | 21 | class DatetimeMutation |
22 | 22 | { |
23 | - /** |
|
24 | - * Maps the GraphQL input to a format that the model functions can use |
|
25 | - * |
|
26 | - * @param array $input Data coming from the GraphQL mutation query input |
|
27 | - * @return array |
|
28 | - * @throws Exception |
|
29 | - */ |
|
30 | - public static function prepareFields(array $input): array |
|
31 | - { |
|
32 | - $args = []; |
|
33 | - |
|
34 | - if (array_key_exists('capacity', $input)) { |
|
35 | - $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
36 | - } |
|
37 | - |
|
38 | - if (isset($input['description'])) { |
|
39 | - $args['DTT_description'] = wp_kses_post($input['description']); |
|
40 | - } |
|
41 | - |
|
42 | - if (! empty($input['endDate'])) { |
|
43 | - $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
44 | - } |
|
45 | - |
|
46 | - if (! empty($input['eventId'])) { |
|
47 | - $args['EVT_ID'] = absint($input['eventId']); |
|
48 | - } elseif (! empty($input['event'])) { |
|
49 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
50 | - $args['EVT_ID'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
51 | - } |
|
52 | - |
|
53 | - if (array_key_exists('isPrimary', $input)) { |
|
54 | - $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
55 | - } |
|
56 | - |
|
57 | - if (array_key_exists('isTrashed', $input)) { |
|
58 | - $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
59 | - } |
|
60 | - |
|
61 | - if (isset($input['name'])) { |
|
62 | - $args['DTT_name'] = sanitize_text_field($input['name']); |
|
63 | - } |
|
64 | - |
|
65 | - if (array_key_exists('order', $input)) { |
|
66 | - $args['DTT_order'] = (int) $input['order']; |
|
67 | - } |
|
68 | - |
|
69 | - if (! empty($input['parent'])) { |
|
70 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
71 | - $args['DTT_parent'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - if (array_key_exists('reserved', $input)) { |
|
75 | - $args['DTT_reserved'] = (int) $input['reserved']; |
|
76 | - } |
|
77 | - |
|
78 | - if (array_key_exists('sold', $input)) { |
|
79 | - $args['DTT_sold'] = (int) $input['sold']; |
|
80 | - } |
|
81 | - |
|
82 | - if (! empty($input['startDate'])) { |
|
83 | - $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
84 | - } |
|
85 | - |
|
86 | - if (! empty($input['tickets'])) { |
|
87 | - $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
88 | - } |
|
89 | - |
|
90 | - if (array_key_exists('venue', $input)) { |
|
91 | - $venue_id = sanitize_text_field($input['venue']); |
|
92 | - $parts = Relay::fromGlobalId($venue_id); |
|
93 | - $venue_id = ! empty($parts['id']) ? $parts['id'] : $venue_id; |
|
94 | - $args['venue'] = absint($venue_id); |
|
95 | - } |
|
96 | - |
|
97 | - return apply_filters( |
|
98 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args', |
|
99 | - $args, |
|
100 | - $input |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Sets the related tickets for the given datetime. |
|
107 | - * |
|
108 | - * @param EE_Datetime $entity The datetime instance. |
|
109 | - * @param array $tickets Array of ticket IDs to relate. |
|
110 | - * @throws EE_Error |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public static function setRelatedTickets(EE_Datetime $entity, array $tickets) |
|
117 | - { |
|
118 | - $relationName = 'Ticket'; |
|
119 | - // Remove all the existing related tickets |
|
120 | - $entity->_remove_relations($relationName); |
|
121 | - |
|
122 | - foreach ($tickets as $ID) { |
|
123 | - $parts = Relay::fromGlobalId($ID); |
|
124 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
125 | - $entity->_add_relation_to( |
|
126 | - $parts['id'], |
|
127 | - $relationName |
|
128 | - ); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Sets the venue for the datetime. |
|
136 | - * |
|
137 | - * @param EE_Datetime $entity The datetime instance. |
|
138 | - * @param int $venue The venue ID |
|
139 | - * @throws EE_Error |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - * @throws InvalidArgumentException |
|
143 | - * @throws ReflectionException |
|
144 | - */ |
|
145 | - public static function setVenue(EE_Datetime $entity, int $venue) |
|
146 | - { |
|
147 | - if (empty($venue)) { |
|
148 | - $entity->remove_venue($venue); |
|
149 | - } else { |
|
150 | - $entity->add_venue($venue); |
|
151 | - } |
|
152 | - } |
|
23 | + /** |
|
24 | + * Maps the GraphQL input to a format that the model functions can use |
|
25 | + * |
|
26 | + * @param array $input Data coming from the GraphQL mutation query input |
|
27 | + * @return array |
|
28 | + * @throws Exception |
|
29 | + */ |
|
30 | + public static function prepareFields(array $input): array |
|
31 | + { |
|
32 | + $args = []; |
|
33 | + |
|
34 | + if (array_key_exists('capacity', $input)) { |
|
35 | + $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
36 | + } |
|
37 | + |
|
38 | + if (isset($input['description'])) { |
|
39 | + $args['DTT_description'] = wp_kses_post($input['description']); |
|
40 | + } |
|
41 | + |
|
42 | + if (! empty($input['endDate'])) { |
|
43 | + $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
44 | + } |
|
45 | + |
|
46 | + if (! empty($input['eventId'])) { |
|
47 | + $args['EVT_ID'] = absint($input['eventId']); |
|
48 | + } elseif (! empty($input['event'])) { |
|
49 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
50 | + $args['EVT_ID'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
51 | + } |
|
52 | + |
|
53 | + if (array_key_exists('isPrimary', $input)) { |
|
54 | + $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
55 | + } |
|
56 | + |
|
57 | + if (array_key_exists('isTrashed', $input)) { |
|
58 | + $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
59 | + } |
|
60 | + |
|
61 | + if (isset($input['name'])) { |
|
62 | + $args['DTT_name'] = sanitize_text_field($input['name']); |
|
63 | + } |
|
64 | + |
|
65 | + if (array_key_exists('order', $input)) { |
|
66 | + $args['DTT_order'] = (int) $input['order']; |
|
67 | + } |
|
68 | + |
|
69 | + if (! empty($input['parent'])) { |
|
70 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
71 | + $args['DTT_parent'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + if (array_key_exists('reserved', $input)) { |
|
75 | + $args['DTT_reserved'] = (int) $input['reserved']; |
|
76 | + } |
|
77 | + |
|
78 | + if (array_key_exists('sold', $input)) { |
|
79 | + $args['DTT_sold'] = (int) $input['sold']; |
|
80 | + } |
|
81 | + |
|
82 | + if (! empty($input['startDate'])) { |
|
83 | + $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
84 | + } |
|
85 | + |
|
86 | + if (! empty($input['tickets'])) { |
|
87 | + $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
88 | + } |
|
89 | + |
|
90 | + if (array_key_exists('venue', $input)) { |
|
91 | + $venue_id = sanitize_text_field($input['venue']); |
|
92 | + $parts = Relay::fromGlobalId($venue_id); |
|
93 | + $venue_id = ! empty($parts['id']) ? $parts['id'] : $venue_id; |
|
94 | + $args['venue'] = absint($venue_id); |
|
95 | + } |
|
96 | + |
|
97 | + return apply_filters( |
|
98 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args', |
|
99 | + $args, |
|
100 | + $input |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Sets the related tickets for the given datetime. |
|
107 | + * |
|
108 | + * @param EE_Datetime $entity The datetime instance. |
|
109 | + * @param array $tickets Array of ticket IDs to relate. |
|
110 | + * @throws EE_Error |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public static function setRelatedTickets(EE_Datetime $entity, array $tickets) |
|
117 | + { |
|
118 | + $relationName = 'Ticket'; |
|
119 | + // Remove all the existing related tickets |
|
120 | + $entity->_remove_relations($relationName); |
|
121 | + |
|
122 | + foreach ($tickets as $ID) { |
|
123 | + $parts = Relay::fromGlobalId($ID); |
|
124 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
125 | + $entity->_add_relation_to( |
|
126 | + $parts['id'], |
|
127 | + $relationName |
|
128 | + ); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Sets the venue for the datetime. |
|
136 | + * |
|
137 | + * @param EE_Datetime $entity The datetime instance. |
|
138 | + * @param int $venue The venue ID |
|
139 | + * @throws EE_Error |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + * @throws InvalidArgumentException |
|
143 | + * @throws ReflectionException |
|
144 | + */ |
|
145 | + public static function setVenue(EE_Datetime $entity, int $venue) |
|
146 | + { |
|
147 | + if (empty($venue)) { |
|
148 | + $entity->remove_venue($venue); |
|
149 | + } else { |
|
150 | + $entity->add_venue($venue); |
|
151 | + } |
|
152 | + } |
|
153 | 153 | } |
@@ -14,260 +14,260 @@ |
||
14 | 14 | */ |
15 | 15 | class MessageTemplateRequestData |
16 | 16 | { |
17 | - protected ?RequestInterface $request = null; |
|
17 | + protected ?RequestInterface $request = null; |
|
18 | 18 | |
19 | - protected string $context = ''; |
|
19 | + protected string $context = ''; |
|
20 | 20 | |
21 | - protected string $description = ''; |
|
21 | + protected string $description = ''; |
|
22 | 22 | |
23 | - protected string $messenger = ''; |
|
23 | + protected string $messenger = ''; |
|
24 | 24 | |
25 | - protected string $message_type = ''; |
|
25 | + protected string $message_type = ''; |
|
26 | 26 | |
27 | - protected string $name = ''; |
|
27 | + protected string $name = ''; |
|
28 | 28 | |
29 | - protected array $template_fields = []; |
|
29 | + protected array $template_fields = []; |
|
30 | 30 | |
31 | - protected int $group_ID = 0; |
|
31 | + protected int $group_ID = 0; |
|
32 | 32 | |
33 | - protected int $user_ID = 0; |
|
33 | + protected int $user_ID = 0; |
|
34 | 34 | |
35 | - protected bool $is_active = false; |
|
35 | + protected bool $is_active = false; |
|
36 | 36 | |
37 | - protected bool $is_deleted = false; |
|
37 | + protected bool $is_deleted = false; |
|
38 | 38 | |
39 | - protected bool $is_global = false; |
|
39 | + protected bool $is_global = false; |
|
40 | 40 | |
41 | - protected bool $is_override = false; |
|
41 | + protected bool $is_override = false; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param RequestInterface|null $request |
|
46 | - */ |
|
47 | - public function __construct(?RequestInterface $request) |
|
48 | - { |
|
49 | - $this->request = $request; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @param RequestInterface|null $request |
|
46 | + */ |
|
47 | + public function __construct(?RequestInterface $request) |
|
48 | + { |
|
49 | + $this->request = $request; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - public function setMessageTemplateRequestData() |
|
54 | - { |
|
55 | - $this->setContext(); |
|
56 | - $this->setDescription(); |
|
57 | - $this->setGroupID(); |
|
58 | - $this->setIsActive(); |
|
59 | - $this->setIsDeleted(); |
|
60 | - $this->setIsGlobal(); |
|
61 | - $this->setIsOverride(); |
|
62 | - $this->setMessenger(); |
|
63 | - $this->setMessageType(); |
|
64 | - $this->setName(); |
|
65 | - $this->setUserID(); |
|
66 | - $this->setTemplateFields(); |
|
67 | - } |
|
53 | + public function setMessageTemplateRequestData() |
|
54 | + { |
|
55 | + $this->setContext(); |
|
56 | + $this->setDescription(); |
|
57 | + $this->setGroupID(); |
|
58 | + $this->setIsActive(); |
|
59 | + $this->setIsDeleted(); |
|
60 | + $this->setIsGlobal(); |
|
61 | + $this->setIsOverride(); |
|
62 | + $this->setMessenger(); |
|
63 | + $this->setMessageType(); |
|
64 | + $this->setName(); |
|
65 | + $this->setUserID(); |
|
66 | + $this->setTemplateFields(); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - public function context(): string |
|
71 | - { |
|
72 | - return $this->context; |
|
73 | - } |
|
70 | + public function context(): string |
|
71 | + { |
|
72 | + return $this->context; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - public function description(): string |
|
77 | - { |
|
78 | - return $this->description; |
|
79 | - } |
|
76 | + public function description(): string |
|
77 | + { |
|
78 | + return $this->description; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - public function messenger(): string |
|
83 | - { |
|
84 | - return $this->messenger; |
|
85 | - } |
|
82 | + public function messenger(): string |
|
83 | + { |
|
84 | + return $this->messenger; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - public function messageType(): string |
|
89 | - { |
|
90 | - return $this->message_type; |
|
91 | - } |
|
88 | + public function messageType(): string |
|
89 | + { |
|
90 | + return $this->message_type; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - public function name(): string |
|
95 | - { |
|
96 | - return $this->name; |
|
97 | - } |
|
94 | + public function name(): string |
|
95 | + { |
|
96 | + return $this->name; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - public function templateFields(): array |
|
101 | - { |
|
102 | - return $this->template_fields; |
|
103 | - } |
|
100 | + public function templateFields(): array |
|
101 | + { |
|
102 | + return $this->template_fields; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - public function groupID(): int |
|
107 | - { |
|
108 | - return $this->group_ID; |
|
109 | - } |
|
106 | + public function groupID(): int |
|
107 | + { |
|
108 | + return $this->group_ID; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | - public function userID(): int |
|
113 | - { |
|
114 | - return $this->user_ID; |
|
115 | - } |
|
112 | + public function userID(): int |
|
113 | + { |
|
114 | + return $this->user_ID; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - public function isActive(): bool |
|
119 | - { |
|
120 | - return $this->is_active; |
|
121 | - } |
|
118 | + public function isActive(): bool |
|
119 | + { |
|
120 | + return $this->is_active; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - public function isDeleted(): bool |
|
125 | - { |
|
126 | - return $this->is_deleted; |
|
127 | - } |
|
124 | + public function isDeleted(): bool |
|
125 | + { |
|
126 | + return $this->is_deleted; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - public function isGlobal(): bool |
|
131 | - { |
|
132 | - return $this->is_global; |
|
133 | - } |
|
130 | + public function isGlobal(): bool |
|
131 | + { |
|
132 | + return $this->is_global; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - public function isOverride(): bool |
|
137 | - { |
|
138 | - return $this->is_override; |
|
139 | - } |
|
136 | + public function isOverride(): bool |
|
137 | + { |
|
138 | + return $this->is_override; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - public function setContext(?string $context = ''): void |
|
143 | - { |
|
144 | - $this->context = $this->request->getRequestParam('context', $context); |
|
145 | - $this->context = $this->request->getRequestParam('MTP_context', $this->context); |
|
146 | - $this->context = strtolower($this->context); |
|
147 | - } |
|
142 | + public function setContext(?string $context = ''): void |
|
143 | + { |
|
144 | + $this->context = $this->request->getRequestParam('context', $context); |
|
145 | + $this->context = $this->request->getRequestParam('MTP_context', $this->context); |
|
146 | + $this->context = strtolower($this->context); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - public function setDescription(?string $description = ''): void |
|
151 | - { |
|
152 | - $this->description = $this->request->getRequestParam( |
|
153 | - 'ee_msg_non_global_fields[MTP_description]', |
|
154 | - $description |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function setGroupID(?int $group_ID = 0): void |
|
160 | - { |
|
161 | - $this->group_ID = $this->request->getRequestParam('group_ID', $group_ID, DataType::INTEGER); |
|
162 | - $this->group_ID = $this->request->getRequestParam('GRP_ID', $this->group_ID, DataType::INTEGER); |
|
163 | - // we need the GRP_ID for the template being used as the base for the new template |
|
164 | - if (empty($this->group_ID)) { |
|
165 | - throw new RuntimeException( |
|
166 | - esc_html__( |
|
167 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
168 | - 'event_espresso' |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - public function setIsActive(bool $is_active = false): void |
|
176 | - { |
|
177 | - $this->is_active = $this->request->getRequestParam('MTP_is_active', $is_active, DataType::BOOLEAN); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - public function setIsDeleted(bool $is_deleted = false): void |
|
182 | - { |
|
183 | - $this->is_deleted = $this->request->getRequestParam('MTP_deleted', $is_deleted, DataType::BOOLEAN); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - public function setIsGlobal(bool $is_global = false): void |
|
188 | - { |
|
189 | - $this->is_global = $this->request->getRequestParam('MTP_is_global', $is_global, DataType::BOOLEAN); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - public function setIsOverride(bool $is_override = false): void |
|
194 | - { |
|
195 | - $this->is_override = $this->request->getRequestParam('MTP_is_override', $is_override, DataType::BOOLEAN); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - public function setMessenger(?string $messenger = ''): void |
|
200 | - { |
|
201 | - // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
202 | - $this->messenger = $this->request->getRequestParam('msgr', $messenger); |
|
203 | - $this->messenger = $this->request->getRequestParam('messenger', $this->messenger); |
|
204 | - $this->messenger = $this->request->getRequestParam('MTP_messenger', $this->messenger); |
|
205 | - $this->messenger = strtolower($this->messenger); |
|
206 | - if (empty($this->messenger)) { |
|
207 | - throw new RuntimeException( |
|
208 | - esc_html__( |
|
209 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger', |
|
210 | - 'event_espresso' |
|
211 | - ) |
|
212 | - ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - public function setMessageType(?string $message_type = ''): void |
|
218 | - { |
|
219 | - // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
220 | - $this->message_type = $this->request->getRequestParam('mt', $message_type); |
|
221 | - $this->message_type = $this->request->getRequestParam('message_type', $this->message_type); |
|
222 | - $this->message_type = $this->request->getRequestParam('MTP_message_type', $this->message_type); |
|
223 | - $this->message_type = strtolower($this->message_type); |
|
224 | - if (empty($this->message_type)) { |
|
225 | - throw new RuntimeException( |
|
226 | - esc_html__( |
|
227 | - 'Sorry, but we can\'t create new templates because we\'re missing the message type', |
|
228 | - 'event_espresso' |
|
229 | - ) |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - public function setName(?string $name = ''): void |
|
236 | - { |
|
237 | - $this->name = $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', $name); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - public function setUserID(?int $user_ID = 0): void |
|
242 | - { |
|
243 | - $this->user_ID = $this->request->getRequestParam('user_id', $user_ID, DataType::INTEGER); |
|
244 | - $this->user_ID = $this->request->getRequestParam('MTP_user_id', $this->user_ID, DataType::INTEGER); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - private function setTemplateFields(): void |
|
249 | - { |
|
250 | - $this->template_fields = $this->request->getRequestParam( |
|
251 | - 'template_fields', |
|
252 | - null, |
|
253 | - DataType::EDITOR, |
|
254 | - true |
|
255 | - ); |
|
256 | - $this->template_fields = $this->request->getRequestParam( |
|
257 | - 'MTP_template_fields', |
|
258 | - $this->template_fields, |
|
259 | - DataType::EDITOR, |
|
260 | - true |
|
261 | - ); |
|
262 | - if (empty($this->template_fields)) { |
|
263 | - throw new RuntimeException( |
|
264 | - esc_html__( |
|
265 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
266 | - 'event_espresso' |
|
267 | - ) |
|
268 | - ); |
|
269 | - } |
|
270 | - // messages content is expected to be escaped |
|
271 | - $this->template_fields = EEH_Array::addSlashesRecursively($this->template_fields); |
|
272 | - } |
|
150 | + public function setDescription(?string $description = ''): void |
|
151 | + { |
|
152 | + $this->description = $this->request->getRequestParam( |
|
153 | + 'ee_msg_non_global_fields[MTP_description]', |
|
154 | + $description |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function setGroupID(?int $group_ID = 0): void |
|
160 | + { |
|
161 | + $this->group_ID = $this->request->getRequestParam('group_ID', $group_ID, DataType::INTEGER); |
|
162 | + $this->group_ID = $this->request->getRequestParam('GRP_ID', $this->group_ID, DataType::INTEGER); |
|
163 | + // we need the GRP_ID for the template being used as the base for the new template |
|
164 | + if (empty($this->group_ID)) { |
|
165 | + throw new RuntimeException( |
|
166 | + esc_html__( |
|
167 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
168 | + 'event_espresso' |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + public function setIsActive(bool $is_active = false): void |
|
176 | + { |
|
177 | + $this->is_active = $this->request->getRequestParam('MTP_is_active', $is_active, DataType::BOOLEAN); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + public function setIsDeleted(bool $is_deleted = false): void |
|
182 | + { |
|
183 | + $this->is_deleted = $this->request->getRequestParam('MTP_deleted', $is_deleted, DataType::BOOLEAN); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + public function setIsGlobal(bool $is_global = false): void |
|
188 | + { |
|
189 | + $this->is_global = $this->request->getRequestParam('MTP_is_global', $is_global, DataType::BOOLEAN); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + public function setIsOverride(bool $is_override = false): void |
|
194 | + { |
|
195 | + $this->is_override = $this->request->getRequestParam('MTP_is_override', $is_override, DataType::BOOLEAN); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + public function setMessenger(?string $messenger = ''): void |
|
200 | + { |
|
201 | + // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
202 | + $this->messenger = $this->request->getRequestParam('msgr', $messenger); |
|
203 | + $this->messenger = $this->request->getRequestParam('messenger', $this->messenger); |
|
204 | + $this->messenger = $this->request->getRequestParam('MTP_messenger', $this->messenger); |
|
205 | + $this->messenger = strtolower($this->messenger); |
|
206 | + if (empty($this->messenger)) { |
|
207 | + throw new RuntimeException( |
|
208 | + esc_html__( |
|
209 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger', |
|
210 | + 'event_espresso' |
|
211 | + ) |
|
212 | + ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + public function setMessageType(?string $message_type = ''): void |
|
218 | + { |
|
219 | + // have to check for multiple params because a previouv dev used different names for the same param >:( |
|
220 | + $this->message_type = $this->request->getRequestParam('mt', $message_type); |
|
221 | + $this->message_type = $this->request->getRequestParam('message_type', $this->message_type); |
|
222 | + $this->message_type = $this->request->getRequestParam('MTP_message_type', $this->message_type); |
|
223 | + $this->message_type = strtolower($this->message_type); |
|
224 | + if (empty($this->message_type)) { |
|
225 | + throw new RuntimeException( |
|
226 | + esc_html__( |
|
227 | + 'Sorry, but we can\'t create new templates because we\'re missing the message type', |
|
228 | + 'event_espresso' |
|
229 | + ) |
|
230 | + ); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + public function setName(?string $name = ''): void |
|
236 | + { |
|
237 | + $this->name = $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', $name); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + public function setUserID(?int $user_ID = 0): void |
|
242 | + { |
|
243 | + $this->user_ID = $this->request->getRequestParam('user_id', $user_ID, DataType::INTEGER); |
|
244 | + $this->user_ID = $this->request->getRequestParam('MTP_user_id', $this->user_ID, DataType::INTEGER); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + private function setTemplateFields(): void |
|
249 | + { |
|
250 | + $this->template_fields = $this->request->getRequestParam( |
|
251 | + 'template_fields', |
|
252 | + null, |
|
253 | + DataType::EDITOR, |
|
254 | + true |
|
255 | + ); |
|
256 | + $this->template_fields = $this->request->getRequestParam( |
|
257 | + 'MTP_template_fields', |
|
258 | + $this->template_fields, |
|
259 | + DataType::EDITOR, |
|
260 | + true |
|
261 | + ); |
|
262 | + if (empty($this->template_fields)) { |
|
263 | + throw new RuntimeException( |
|
264 | + esc_html__( |
|
265 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
266 | + 'event_espresso' |
|
267 | + ) |
|
268 | + ); |
|
269 | + } |
|
270 | + // messages content is expected to be escaped |
|
271 | + $this->template_fields = EEH_Array::addSlashesRecursively($this->template_fields); |
|
272 | + } |
|
273 | 273 | } |
@@ -17,339 +17,339 @@ |
||
17 | 17 | */ |
18 | 18 | class MessageTemplateManager |
19 | 19 | { |
20 | - private EEM_Message_Template $message_template_model; |
|
21 | - |
|
22 | - private EEM_Message_Template_Group $message_template_group_model; |
|
23 | - |
|
24 | - protected MessageTemplateRequestData $form_data; |
|
25 | - |
|
26 | - protected MessageTemplateValidator $validator; |
|
27 | - |
|
28 | - protected RequestInterface $request; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @param EEM_Message_Template $message_template_model |
|
33 | - * @param EEM_Message_Template_Group $message_template_group_model |
|
34 | - * @param MessageTemplateRequestData $form_data |
|
35 | - * @param MessageTemplateValidator $validator |
|
36 | - * @param RequestInterface $request |
|
37 | - */ |
|
38 | - public function __construct( |
|
39 | - EEM_Message_Template $message_template_model, |
|
40 | - EEM_Message_Template_Group $message_template_group_model, |
|
41 | - MessageTemplateRequestData $form_data, |
|
42 | - MessageTemplateValidator $validator, |
|
43 | - RequestInterface $request |
|
44 | - ) { |
|
45 | - $this->message_template_model = $message_template_model; |
|
46 | - $this->message_template_group_model = $message_template_group_model; |
|
47 | - $this->form_data = $form_data; |
|
48 | - $this->validator = $validator; |
|
49 | - $this->request = $request; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string|null $messenger |
|
55 | - * @param string|null $message_type |
|
56 | - * @param int $GRP_ID |
|
57 | - * @param bool $global |
|
58 | - * @return array |
|
59 | - * @throws EE_Error |
|
60 | - * @throws ReflectionException |
|
61 | - */ |
|
62 | - public function generateNewTemplates( |
|
63 | - ?string $messenger = '', |
|
64 | - ?string $message_type = '', |
|
65 | - int $GRP_ID = 0, |
|
66 | - bool $global = false |
|
67 | - ): array { |
|
68 | - $this->form_data->setMessageTemplateRequestData(); |
|
69 | - |
|
70 | - $messenger = $messenger ?: $this->form_data->messenger(); |
|
71 | - $message_type = $message_type ?: $this->form_data->messageType(); |
|
72 | - $GRP_ID = $GRP_ID ?: $this->form_data->groupID(); |
|
73 | - |
|
74 | - // if no $message_types are given then that's okay... |
|
75 | - // this may be a messenger that just adds shortcodes, |
|
76 | - // so we just don't generate any templates. |
|
77 | - if (empty($message_type)) { |
|
78 | - return []; |
|
79 | - } |
|
80 | - $new_templates = EEH_MSG_Template::generate_new_templates($messenger, [$message_type], $GRP_ID, $global); |
|
81 | - return $new_templates[0]; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @throws DomainException |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function updateExistingTemplates(): void |
|
91 | - { |
|
92 | - $this->form_data->setMessageTemplateRequestData(); |
|
93 | - $template_fields = $this->form_data->templateFields(); |
|
94 | - |
|
95 | - if ($template_fields) { |
|
96 | - if ( |
|
97 | - $this->validator->validateTemplateFields( |
|
98 | - $this->form_data->messenger(), |
|
99 | - $this->form_data->messageType(), |
|
100 | - $this->form_data->context(), |
|
101 | - $template_fields |
|
102 | - ) |
|
103 | - ) { |
|
104 | - foreach ($template_fields as $template_field => $data) { |
|
105 | - $this->validateTemplateFieldData($template_field, $data); |
|
106 | - $this->updateMessageTemplate( |
|
107 | - $template_field, |
|
108 | - [ |
|
109 | - 'GRP_ID' => $this->form_data->groupID(), |
|
110 | - 'MTP_ID' => $data['MTP_ID'], |
|
111 | - 'MTP_template_field' => $data['name'], |
|
112 | - 'MTP_context' => $this->form_data->context(), |
|
113 | - // if they aren't allowed to use all JS, restrict them to standard allowed post tags |
|
114 | - 'MTP_content' => ! current_user_can('unfiltered_html') |
|
115 | - ? $this->sanitizeMessageTemplateContent($data['content']) |
|
116 | - : $data['content'], |
|
117 | - ] |
|
118 | - ); |
|
119 | - } |
|
120 | - // we can use the last set_column_values for the Message Template Group update |
|
121 | - // (because its the same for all of these specific MTPs) |
|
122 | - $this->updateMessageTemplateGroup( |
|
123 | - [ |
|
124 | - 'GRP_ID' => $this->form_data->groupID(), |
|
125 | - 'MTP_user_id' => $this->form_data->userID(), |
|
126 | - 'MTP_messenger' => $this->form_data->messenger(), |
|
127 | - 'MTP_message_type' => $this->form_data->messageType(), |
|
128 | - 'MTP_is_global' => $this->form_data->isGlobal(), |
|
129 | - 'MTP_is_override' => $this->form_data->isOverride(), |
|
130 | - 'MTP_deleted' => $this->form_data->isDeleted(), |
|
131 | - 'MTP_is_active' => $this->form_data->isActive(), |
|
132 | - 'MTP_name' => $this->form_data->name(), |
|
133 | - 'MTP_description' => $this->form_data->description(), |
|
134 | - ] |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $template_field |
|
143 | - * @param array $message_template_fields |
|
144 | - * @return void |
|
145 | - * @throws EE_Error |
|
146 | - * @throws ReflectionException |
|
147 | - */ |
|
148 | - private function updateMessageTemplate(string $template_field, array $message_template_fields): void |
|
149 | - { |
|
150 | - $MTP_ID = $message_template_fields['MTP_ID'] ?? 0; |
|
151 | - // if we have a MTP_ID for this field then update it, otherwise insert. |
|
152 | - // this has already been through the template field validator and sanitized, so it will be |
|
153 | - // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
154 | - // message template field in a messenger/message type and existing users don't have the |
|
155 | - // default setup for it. |
|
156 | - // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
157 | - $updated = $MTP_ID |
|
158 | - ? $this->message_template_model->update($message_template_fields, [['MTP_ID' => $MTP_ID]]) |
|
159 | - : $this->message_template_model->insert($message_template_fields); |
|
160 | - |
|
161 | - // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated) |
|
162 | - // but we won't consider that a problem, but if it returns false, then something went BOOM! |
|
163 | - if ($updated === false) { |
|
164 | - EE_Error::add_error( |
|
165 | - sprintf( |
|
166 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
167 | - $template_field |
|
168 | - ), |
|
169 | - __FILE__, |
|
170 | - __FUNCTION__, |
|
171 | - __LINE__ |
|
172 | - ); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param array $form_data |
|
179 | - * @return void |
|
180 | - * @throws EE_Error |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - private function updateMessageTemplateGroup(array $form_data): void |
|
184 | - { |
|
185 | - try { |
|
186 | - $GRP_ID = $form_data['id'] ?? 0; |
|
187 | - $GRP_ID = $form_data['GRP_ID'] ?? $GRP_ID; |
|
188 | - if (! $GRP_ID) { |
|
189 | - throw new RuntimeException( |
|
190 | - esc_html__( |
|
191 | - 'Can not update message template group because no GRP_ID was provided', |
|
192 | - 'event_espresso' |
|
193 | - ) |
|
194 | - ); |
|
195 | - } |
|
196 | - |
|
197 | - $updated = $this->message_template_group_model->update($form_data, [['GRP_ID' => $GRP_ID]]); |
|
198 | - $error_message = esc_html__( |
|
199 | - 'unknown error occurred while updating message template group', |
|
200 | - 'event_espresso' |
|
201 | - ); |
|
202 | - |
|
203 | - if ($updated !== false) { |
|
204 | - $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
205 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
206 | - // k now we need to ensure the template_pack and template_variation fields are set. |
|
207 | - $template_pack = $this->request->getRequestParam('MTP_template_pack', 'default'); |
|
208 | - $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); |
|
209 | - $message_template_group->set_template_pack_name($template_pack); |
|
210 | - $message_template_group->set_template_pack_variation($template_variation); |
|
211 | - } |
|
212 | - return; |
|
213 | - } |
|
214 | - } catch (RuntimeException $exception) { |
|
215 | - $error_message = $exception->getMessage(); |
|
216 | - } |
|
217 | - |
|
218 | - EE_Error::add_error( |
|
219 | - sprintf( |
|
220 | - esc_html__( |
|
221 | - 'The Message Template Group (%1$d) was NOT updated for the following reason: %2$s', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - $form_data['GRP_ID'], |
|
225 | - $error_message |
|
226 | - ), |
|
227 | - __FILE__, |
|
228 | - __FUNCTION__, |
|
229 | - __LINE__ |
|
230 | - ); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * recursively runs wp_kses() on message template content in a model safe manner |
|
236 | - * |
|
237 | - * @param array|string $content |
|
238 | - * @return array|string |
|
239 | - * @since 4.10.29.p |
|
240 | - */ |
|
241 | - private function sanitizeMessageTemplateContent($content) |
|
242 | - { |
|
243 | - if (is_array($content)) { |
|
244 | - foreach ($content as $key => $value) { |
|
245 | - $content[ $key ] = $this->sanitizeMessageTemplateContent($value); |
|
246 | - } |
|
247 | - return $content; |
|
248 | - } |
|
249 | - // remove slashes so wp_kses() works properly |
|
250 | - // wp_kses_stripslashes() only removes slashes from double-quotes, |
|
251 | - // so attributes using single quotes always appear invalid. |
|
252 | - $content = stripslashes($content); |
|
253 | - $content = wp_kses($content, wp_kses_allowed_html('post')); |
|
254 | - // But currently the models expect slashed data, so after wp_kses() |
|
255 | - // runs we need to re-slash the data. Sheesh. |
|
256 | - // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
257 | - return addslashes($content); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @param int $GRP_ID |
|
263 | - * @return false|int |
|
264 | - * @throws EE_Error |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function trashMessageTemplate(int $GRP_ID) |
|
268 | - { |
|
269 | - return $this->message_template_group_model->delete_by_ID($GRP_ID); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param int $GRP_ID |
|
275 | - * @return bool |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function restoreMessageTemplate(int $GRP_ID): bool |
|
279 | - { |
|
280 | - return $this->message_template_group_model->restore_by_ID($GRP_ID); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param int $GRP_ID |
|
286 | - * @return EE_Message_Template_Group |
|
287 | - * @throws EE_Error |
|
288 | - * @throws ReflectionException |
|
289 | - */ |
|
290 | - private function getMessageTemplateGroup(int $GRP_ID): EE_Message_Template_Group |
|
291 | - { |
|
292 | - $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
293 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
294 | - return $message_template_group; |
|
295 | - } |
|
296 | - throw new RuntimeException( |
|
297 | - esc_html__( |
|
298 | - 'Can not permanently delete message template group because an invalid GRP_ID was provided', |
|
299 | - 'event_espresso' |
|
300 | - ) |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param int $GRP_ID |
|
307 | - * @return bool |
|
308 | - * @throws EE_Error |
|
309 | - * @throws ReflectionException |
|
310 | - */ |
|
311 | - public function permanentlyDeleteMessageTemplates(int $GRP_ID): bool |
|
312 | - { |
|
313 | - $message_template_group = $this->getMessageTemplateGroup($GRP_ID); |
|
314 | - // permanently delete all the related Message Templates |
|
315 | - $deleted = $message_template_group->delete_related_permanently('Message_Template'); |
|
316 | - return $deleted > 0; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param int $GRP_ID |
|
322 | - * @return bool |
|
323 | - * @throws EE_Error |
|
324 | - * @throws ReflectionException |
|
325 | - */ |
|
326 | - public function permanentlyDeleteMessageTemplateGroup(int $GRP_ID): bool |
|
327 | - { |
|
328 | - if ($this->permanentlyDeleteMessageTemplates($GRP_ID)) { |
|
329 | - return $this->message_template_group_model->delete_permanently([['GRP_ID' => $GRP_ID]]); |
|
330 | - } |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - private function validateTemplateFieldData(string $template_field, array $data) |
|
336 | - { |
|
337 | - if ( |
|
338 | - ! ( |
|
339 | - array_key_exists('MTP_ID', $data) |
|
340 | - && array_key_exists('name', $data) |
|
341 | - && array_key_exists('content', $data) |
|
342 | - ) |
|
343 | - ) { |
|
344 | - throw new RuntimeException( |
|
345 | - sprintf( |
|
346 | - esc_html__( |
|
347 | - 'Can not update message template field %1$s because of a missing MTP_ID, name, or content.', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - $template_field |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - } |
|
20 | + private EEM_Message_Template $message_template_model; |
|
21 | + |
|
22 | + private EEM_Message_Template_Group $message_template_group_model; |
|
23 | + |
|
24 | + protected MessageTemplateRequestData $form_data; |
|
25 | + |
|
26 | + protected MessageTemplateValidator $validator; |
|
27 | + |
|
28 | + protected RequestInterface $request; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @param EEM_Message_Template $message_template_model |
|
33 | + * @param EEM_Message_Template_Group $message_template_group_model |
|
34 | + * @param MessageTemplateRequestData $form_data |
|
35 | + * @param MessageTemplateValidator $validator |
|
36 | + * @param RequestInterface $request |
|
37 | + */ |
|
38 | + public function __construct( |
|
39 | + EEM_Message_Template $message_template_model, |
|
40 | + EEM_Message_Template_Group $message_template_group_model, |
|
41 | + MessageTemplateRequestData $form_data, |
|
42 | + MessageTemplateValidator $validator, |
|
43 | + RequestInterface $request |
|
44 | + ) { |
|
45 | + $this->message_template_model = $message_template_model; |
|
46 | + $this->message_template_group_model = $message_template_group_model; |
|
47 | + $this->form_data = $form_data; |
|
48 | + $this->validator = $validator; |
|
49 | + $this->request = $request; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string|null $messenger |
|
55 | + * @param string|null $message_type |
|
56 | + * @param int $GRP_ID |
|
57 | + * @param bool $global |
|
58 | + * @return array |
|
59 | + * @throws EE_Error |
|
60 | + * @throws ReflectionException |
|
61 | + */ |
|
62 | + public function generateNewTemplates( |
|
63 | + ?string $messenger = '', |
|
64 | + ?string $message_type = '', |
|
65 | + int $GRP_ID = 0, |
|
66 | + bool $global = false |
|
67 | + ): array { |
|
68 | + $this->form_data->setMessageTemplateRequestData(); |
|
69 | + |
|
70 | + $messenger = $messenger ?: $this->form_data->messenger(); |
|
71 | + $message_type = $message_type ?: $this->form_data->messageType(); |
|
72 | + $GRP_ID = $GRP_ID ?: $this->form_data->groupID(); |
|
73 | + |
|
74 | + // if no $message_types are given then that's okay... |
|
75 | + // this may be a messenger that just adds shortcodes, |
|
76 | + // so we just don't generate any templates. |
|
77 | + if (empty($message_type)) { |
|
78 | + return []; |
|
79 | + } |
|
80 | + $new_templates = EEH_MSG_Template::generate_new_templates($messenger, [$message_type], $GRP_ID, $global); |
|
81 | + return $new_templates[0]; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @throws DomainException |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function updateExistingTemplates(): void |
|
91 | + { |
|
92 | + $this->form_data->setMessageTemplateRequestData(); |
|
93 | + $template_fields = $this->form_data->templateFields(); |
|
94 | + |
|
95 | + if ($template_fields) { |
|
96 | + if ( |
|
97 | + $this->validator->validateTemplateFields( |
|
98 | + $this->form_data->messenger(), |
|
99 | + $this->form_data->messageType(), |
|
100 | + $this->form_data->context(), |
|
101 | + $template_fields |
|
102 | + ) |
|
103 | + ) { |
|
104 | + foreach ($template_fields as $template_field => $data) { |
|
105 | + $this->validateTemplateFieldData($template_field, $data); |
|
106 | + $this->updateMessageTemplate( |
|
107 | + $template_field, |
|
108 | + [ |
|
109 | + 'GRP_ID' => $this->form_data->groupID(), |
|
110 | + 'MTP_ID' => $data['MTP_ID'], |
|
111 | + 'MTP_template_field' => $data['name'], |
|
112 | + 'MTP_context' => $this->form_data->context(), |
|
113 | + // if they aren't allowed to use all JS, restrict them to standard allowed post tags |
|
114 | + 'MTP_content' => ! current_user_can('unfiltered_html') |
|
115 | + ? $this->sanitizeMessageTemplateContent($data['content']) |
|
116 | + : $data['content'], |
|
117 | + ] |
|
118 | + ); |
|
119 | + } |
|
120 | + // we can use the last set_column_values for the Message Template Group update |
|
121 | + // (because its the same for all of these specific MTPs) |
|
122 | + $this->updateMessageTemplateGroup( |
|
123 | + [ |
|
124 | + 'GRP_ID' => $this->form_data->groupID(), |
|
125 | + 'MTP_user_id' => $this->form_data->userID(), |
|
126 | + 'MTP_messenger' => $this->form_data->messenger(), |
|
127 | + 'MTP_message_type' => $this->form_data->messageType(), |
|
128 | + 'MTP_is_global' => $this->form_data->isGlobal(), |
|
129 | + 'MTP_is_override' => $this->form_data->isOverride(), |
|
130 | + 'MTP_deleted' => $this->form_data->isDeleted(), |
|
131 | + 'MTP_is_active' => $this->form_data->isActive(), |
|
132 | + 'MTP_name' => $this->form_data->name(), |
|
133 | + 'MTP_description' => $this->form_data->description(), |
|
134 | + ] |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $template_field |
|
143 | + * @param array $message_template_fields |
|
144 | + * @return void |
|
145 | + * @throws EE_Error |
|
146 | + * @throws ReflectionException |
|
147 | + */ |
|
148 | + private function updateMessageTemplate(string $template_field, array $message_template_fields): void |
|
149 | + { |
|
150 | + $MTP_ID = $message_template_fields['MTP_ID'] ?? 0; |
|
151 | + // if we have a MTP_ID for this field then update it, otherwise insert. |
|
152 | + // this has already been through the template field validator and sanitized, so it will be |
|
153 | + // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
154 | + // message template field in a messenger/message type and existing users don't have the |
|
155 | + // default setup for it. |
|
156 | + // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
157 | + $updated = $MTP_ID |
|
158 | + ? $this->message_template_model->update($message_template_fields, [['MTP_ID' => $MTP_ID]]) |
|
159 | + : $this->message_template_model->insert($message_template_fields); |
|
160 | + |
|
161 | + // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated) |
|
162 | + // but we won't consider that a problem, but if it returns false, then something went BOOM! |
|
163 | + if ($updated === false) { |
|
164 | + EE_Error::add_error( |
|
165 | + sprintf( |
|
166 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
167 | + $template_field |
|
168 | + ), |
|
169 | + __FILE__, |
|
170 | + __FUNCTION__, |
|
171 | + __LINE__ |
|
172 | + ); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param array $form_data |
|
179 | + * @return void |
|
180 | + * @throws EE_Error |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + private function updateMessageTemplateGroup(array $form_data): void |
|
184 | + { |
|
185 | + try { |
|
186 | + $GRP_ID = $form_data['id'] ?? 0; |
|
187 | + $GRP_ID = $form_data['GRP_ID'] ?? $GRP_ID; |
|
188 | + if (! $GRP_ID) { |
|
189 | + throw new RuntimeException( |
|
190 | + esc_html__( |
|
191 | + 'Can not update message template group because no GRP_ID was provided', |
|
192 | + 'event_espresso' |
|
193 | + ) |
|
194 | + ); |
|
195 | + } |
|
196 | + |
|
197 | + $updated = $this->message_template_group_model->update($form_data, [['GRP_ID' => $GRP_ID]]); |
|
198 | + $error_message = esc_html__( |
|
199 | + 'unknown error occurred while updating message template group', |
|
200 | + 'event_espresso' |
|
201 | + ); |
|
202 | + |
|
203 | + if ($updated !== false) { |
|
204 | + $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
205 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
206 | + // k now we need to ensure the template_pack and template_variation fields are set. |
|
207 | + $template_pack = $this->request->getRequestParam('MTP_template_pack', 'default'); |
|
208 | + $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); |
|
209 | + $message_template_group->set_template_pack_name($template_pack); |
|
210 | + $message_template_group->set_template_pack_variation($template_variation); |
|
211 | + } |
|
212 | + return; |
|
213 | + } |
|
214 | + } catch (RuntimeException $exception) { |
|
215 | + $error_message = $exception->getMessage(); |
|
216 | + } |
|
217 | + |
|
218 | + EE_Error::add_error( |
|
219 | + sprintf( |
|
220 | + esc_html__( |
|
221 | + 'The Message Template Group (%1$d) was NOT updated for the following reason: %2$s', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + $form_data['GRP_ID'], |
|
225 | + $error_message |
|
226 | + ), |
|
227 | + __FILE__, |
|
228 | + __FUNCTION__, |
|
229 | + __LINE__ |
|
230 | + ); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * recursively runs wp_kses() on message template content in a model safe manner |
|
236 | + * |
|
237 | + * @param array|string $content |
|
238 | + * @return array|string |
|
239 | + * @since 4.10.29.p |
|
240 | + */ |
|
241 | + private function sanitizeMessageTemplateContent($content) |
|
242 | + { |
|
243 | + if (is_array($content)) { |
|
244 | + foreach ($content as $key => $value) { |
|
245 | + $content[ $key ] = $this->sanitizeMessageTemplateContent($value); |
|
246 | + } |
|
247 | + return $content; |
|
248 | + } |
|
249 | + // remove slashes so wp_kses() works properly |
|
250 | + // wp_kses_stripslashes() only removes slashes from double-quotes, |
|
251 | + // so attributes using single quotes always appear invalid. |
|
252 | + $content = stripslashes($content); |
|
253 | + $content = wp_kses($content, wp_kses_allowed_html('post')); |
|
254 | + // But currently the models expect slashed data, so after wp_kses() |
|
255 | + // runs we need to re-slash the data. Sheesh. |
|
256 | + // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
257 | + return addslashes($content); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @param int $GRP_ID |
|
263 | + * @return false|int |
|
264 | + * @throws EE_Error |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function trashMessageTemplate(int $GRP_ID) |
|
268 | + { |
|
269 | + return $this->message_template_group_model->delete_by_ID($GRP_ID); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param int $GRP_ID |
|
275 | + * @return bool |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function restoreMessageTemplate(int $GRP_ID): bool |
|
279 | + { |
|
280 | + return $this->message_template_group_model->restore_by_ID($GRP_ID); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param int $GRP_ID |
|
286 | + * @return EE_Message_Template_Group |
|
287 | + * @throws EE_Error |
|
288 | + * @throws ReflectionException |
|
289 | + */ |
|
290 | + private function getMessageTemplateGroup(int $GRP_ID): EE_Message_Template_Group |
|
291 | + { |
|
292 | + $message_template_group = $this->message_template_group_model->get_one_by_ID($GRP_ID); |
|
293 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
294 | + return $message_template_group; |
|
295 | + } |
|
296 | + throw new RuntimeException( |
|
297 | + esc_html__( |
|
298 | + 'Can not permanently delete message template group because an invalid GRP_ID was provided', |
|
299 | + 'event_espresso' |
|
300 | + ) |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param int $GRP_ID |
|
307 | + * @return bool |
|
308 | + * @throws EE_Error |
|
309 | + * @throws ReflectionException |
|
310 | + */ |
|
311 | + public function permanentlyDeleteMessageTemplates(int $GRP_ID): bool |
|
312 | + { |
|
313 | + $message_template_group = $this->getMessageTemplateGroup($GRP_ID); |
|
314 | + // permanently delete all the related Message Templates |
|
315 | + $deleted = $message_template_group->delete_related_permanently('Message_Template'); |
|
316 | + return $deleted > 0; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param int $GRP_ID |
|
322 | + * @return bool |
|
323 | + * @throws EE_Error |
|
324 | + * @throws ReflectionException |
|
325 | + */ |
|
326 | + public function permanentlyDeleteMessageTemplateGroup(int $GRP_ID): bool |
|
327 | + { |
|
328 | + if ($this->permanentlyDeleteMessageTemplates($GRP_ID)) { |
|
329 | + return $this->message_template_group_model->delete_permanently([['GRP_ID' => $GRP_ID]]); |
|
330 | + } |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + private function validateTemplateFieldData(string $template_field, array $data) |
|
336 | + { |
|
337 | + if ( |
|
338 | + ! ( |
|
339 | + array_key_exists('MTP_ID', $data) |
|
340 | + && array_key_exists('name', $data) |
|
341 | + && array_key_exists('content', $data) |
|
342 | + ) |
|
343 | + ) { |
|
344 | + throw new RuntimeException( |
|
345 | + sprintf( |
|
346 | + esc_html__( |
|
347 | + 'Can not update message template field %1$s because of a missing MTP_ID, name, or content.', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + $template_field |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + } |
|
355 | 355 | } |
356 | 356 | \ No newline at end of file |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | try { |
186 | 186 | $GRP_ID = $form_data['id'] ?? 0; |
187 | 187 | $GRP_ID = $form_data['GRP_ID'] ?? $GRP_ID; |
188 | - if (! $GRP_ID) { |
|
188 | + if ( ! $GRP_ID) { |
|
189 | 189 | throw new RuntimeException( |
190 | 190 | esc_html__( |
191 | 191 | 'Can not update message template group because no GRP_ID was provided', |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | { |
243 | 243 | if (is_array($content)) { |
244 | 244 | foreach ($content as $key => $value) { |
245 | - $content[ $key ] = $this->sanitizeMessageTemplateContent($value); |
|
245 | + $content[$key] = $this->sanitizeMessageTemplateContent($value); |
|
246 | 246 | } |
247 | 247 | return $content; |
248 | 248 | } |
@@ -14,173 +14,173 @@ |
||
14 | 14 | */ |
15 | 15 | class MessageTemplateValidator |
16 | 16 | { |
17 | - private LoaderInterface $loader; |
|
18 | - |
|
19 | - |
|
20 | - /** |
|
21 | - * @param LoaderInterface $loader |
|
22 | - */ |
|
23 | - public function __construct(LoaderInterface $loader) |
|
24 | - { |
|
25 | - $this->loader = $loader; |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @param string $messenger |
|
31 | - * @param string $message_type |
|
32 | - * @param string $context |
|
33 | - * @param array $template_fields |
|
34 | - * @return bool |
|
35 | - * @throws DomainException |
|
36 | - */ |
|
37 | - public function validateTemplateFields( |
|
38 | - string $messenger, |
|
39 | - string $message_type, |
|
40 | - string $context, |
|
41 | - array $template_fields |
|
42 | - ): bool { |
|
43 | - // first validate all fields! |
|
44 | - // this filter allows client code to add its own validation to the template fields as well. |
|
45 | - // returning an empty array means everything passed validation. |
|
46 | - // errors in validation should be represented in an array with the following shape: |
|
47 | - // array( |
|
48 | - // 'fieldname' => array( |
|
49 | - // 'msg' => 'error message' |
|
50 | - // 'value' => 'value for field producing error' |
|
51 | - // ) |
|
52 | - $custom_validation = (array) apply_filters( |
|
53 | - 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
54 | - [], |
|
55 | - $template_fields, |
|
56 | - $context, |
|
57 | - $messenger, |
|
58 | - $message_type |
|
59 | - ); |
|
60 | - |
|
61 | - $fields_to_validate = $this->prepFieldsToValidate($template_fields); |
|
62 | - $validator = $this->loadValidator($messenger, $message_type, $context, $fields_to_validate); |
|
63 | - $system_validation = $validator->validate(); |
|
64 | - $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation; |
|
65 | - $validation_errors = array_merge($custom_validation, $system_validation); |
|
66 | - |
|
67 | - // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
68 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
69 | - // WE need to make sure there is no actual error messages in validates. |
|
70 | - if (empty($validation_errors)) { |
|
71 | - return true; |
|
72 | - } |
|
73 | - |
|
74 | - // add the transient so when the form loads we know which fields to highlight |
|
75 | - $this->addTransient($validation_errors); |
|
76 | - // setup notices |
|
77 | - foreach ($validation_errors as $error) { |
|
78 | - if (isset($error['msg'])) { |
|
79 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
80 | - } |
|
81 | - } |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * This sends things to the validator for the given messenger and message type. |
|
88 | - * |
|
89 | - * @param array $message_template_fields the incoming fields to check. |
|
90 | - * Note this array is in the formatted fields from the form fields setup. |
|
91 | - * So we need to reformat this into an array of expected field refs by the |
|
92 | - * validator. Note also that this is not only the fields for the Message |
|
93 | - * Template Group but ALSO for Message Template. |
|
94 | - * @throws DomainException |
|
95 | - */ |
|
96 | - public function prepFieldsToValidate(array $message_template_fields): array |
|
97 | - { |
|
98 | - $fields_to_validate = []; |
|
99 | - // let's loop through all the fields and set them up in the right format |
|
100 | - foreach ($message_template_fields as $message_template_field) { |
|
101 | - // first let's figure out if the value['content'] in the current index is an array. |
|
102 | - // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
103 | - if (is_array($message_template_field['content'])) { |
|
104 | - $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']['main']; |
|
105 | - // loop through the content and get the other fields. |
|
106 | - foreach ($message_template_field['content'] as $name => $value) { |
|
107 | - if ($name !== 'main') { |
|
108 | - $fields_to_validate[ $name ] = $value; |
|
109 | - } |
|
110 | - } |
|
111 | - continue; |
|
112 | - } |
|
113 | - |
|
114 | - // okay if we're here then this is just a straight field=>$value arrangement |
|
115 | - $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']; |
|
116 | - } |
|
117 | - return $fields_to_validate; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - private function loadValidator( |
|
122 | - string $messenger, |
|
123 | - string $message_type, |
|
124 | - string $context, |
|
125 | - array $fields_to_validate |
|
126 | - ): ?EE_Messages_Validator { |
|
127 | - // now we've got the assembled_fields. |
|
128 | - // We need to setup the string for the appropriate validator class and call that. |
|
129 | - $messenger_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
130 | - $messenger_ref = str_replace(' ', '_', $messenger_ref); |
|
131 | - |
|
132 | - $message_type_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
133 | - $message_type_ref = str_replace(' ', '_', $message_type_ref); |
|
134 | - |
|
135 | - $classname = "EE_Messages_{$messenger_ref}_{$message_type_ref}_Validator"; |
|
136 | - |
|
137 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
138 | - if (! class_exists($classname)) { |
|
139 | - $msg[] = sprintf( |
|
140 | - esc_html__( |
|
141 | - 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - $classname |
|
145 | - ); |
|
146 | - throw new DomainException(implode('. ', $msg)); |
|
147 | - } |
|
148 | - |
|
149 | - $validator = $this->loader->getShared($classname, [$fields_to_validate, $context]); |
|
150 | - if (! $validator instanceof EE_Messages_Validator) { |
|
151 | - $msg[] = sprintf( |
|
152 | - esc_html__( |
|
153 | - 'Failed to instantiate %s.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $classname |
|
157 | - ); |
|
158 | - throw new DomainException(implode('. ', $msg)); |
|
159 | - } |
|
160 | - return $validator; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * This makes available the WP transient system for temporarily moving data between routes |
|
166 | - * |
|
167 | - * @param array $data the data that gets sent |
|
168 | - */ |
|
169 | - private function addTransient(array $data): void |
|
170 | - { |
|
171 | - $user_id = get_current_user_id(); |
|
172 | - $transient = "rte_tx_edit_message_template_$user_id"; |
|
173 | - $net_admin = is_multisite() && is_network_admin(); |
|
174 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
175 | - $existing = $net_admin ? get_site_transient($transient) : get_transient($transient); |
|
176 | - $data = ! array_key_exists('notices', $data) ? ['notices' => $data] : $data; |
|
177 | - if ($existing) { |
|
178 | - $data = array_merge($data, (array) $existing); |
|
179 | - } |
|
180 | - if ($net_admin) { |
|
181 | - set_site_transient($transient, $data, 8); |
|
182 | - } else { |
|
183 | - set_transient($transient, $data, 8); |
|
184 | - } |
|
185 | - } |
|
17 | + private LoaderInterface $loader; |
|
18 | + |
|
19 | + |
|
20 | + /** |
|
21 | + * @param LoaderInterface $loader |
|
22 | + */ |
|
23 | + public function __construct(LoaderInterface $loader) |
|
24 | + { |
|
25 | + $this->loader = $loader; |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @param string $messenger |
|
31 | + * @param string $message_type |
|
32 | + * @param string $context |
|
33 | + * @param array $template_fields |
|
34 | + * @return bool |
|
35 | + * @throws DomainException |
|
36 | + */ |
|
37 | + public function validateTemplateFields( |
|
38 | + string $messenger, |
|
39 | + string $message_type, |
|
40 | + string $context, |
|
41 | + array $template_fields |
|
42 | + ): bool { |
|
43 | + // first validate all fields! |
|
44 | + // this filter allows client code to add its own validation to the template fields as well. |
|
45 | + // returning an empty array means everything passed validation. |
|
46 | + // errors in validation should be represented in an array with the following shape: |
|
47 | + // array( |
|
48 | + // 'fieldname' => array( |
|
49 | + // 'msg' => 'error message' |
|
50 | + // 'value' => 'value for field producing error' |
|
51 | + // ) |
|
52 | + $custom_validation = (array) apply_filters( |
|
53 | + 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
54 | + [], |
|
55 | + $template_fields, |
|
56 | + $context, |
|
57 | + $messenger, |
|
58 | + $message_type |
|
59 | + ); |
|
60 | + |
|
61 | + $fields_to_validate = $this->prepFieldsToValidate($template_fields); |
|
62 | + $validator = $this->loadValidator($messenger, $message_type, $context, $fields_to_validate); |
|
63 | + $system_validation = $validator->validate(); |
|
64 | + $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation; |
|
65 | + $validation_errors = array_merge($custom_validation, $system_validation); |
|
66 | + |
|
67 | + // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
68 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
69 | + // WE need to make sure there is no actual error messages in validates. |
|
70 | + if (empty($validation_errors)) { |
|
71 | + return true; |
|
72 | + } |
|
73 | + |
|
74 | + // add the transient so when the form loads we know which fields to highlight |
|
75 | + $this->addTransient($validation_errors); |
|
76 | + // setup notices |
|
77 | + foreach ($validation_errors as $error) { |
|
78 | + if (isset($error['msg'])) { |
|
79 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
80 | + } |
|
81 | + } |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * This sends things to the validator for the given messenger and message type. |
|
88 | + * |
|
89 | + * @param array $message_template_fields the incoming fields to check. |
|
90 | + * Note this array is in the formatted fields from the form fields setup. |
|
91 | + * So we need to reformat this into an array of expected field refs by the |
|
92 | + * validator. Note also that this is not only the fields for the Message |
|
93 | + * Template Group but ALSO for Message Template. |
|
94 | + * @throws DomainException |
|
95 | + */ |
|
96 | + public function prepFieldsToValidate(array $message_template_fields): array |
|
97 | + { |
|
98 | + $fields_to_validate = []; |
|
99 | + // let's loop through all the fields and set them up in the right format |
|
100 | + foreach ($message_template_fields as $message_template_field) { |
|
101 | + // first let's figure out if the value['content'] in the current index is an array. |
|
102 | + // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
103 | + if (is_array($message_template_field['content'])) { |
|
104 | + $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']['main']; |
|
105 | + // loop through the content and get the other fields. |
|
106 | + foreach ($message_template_field['content'] as $name => $value) { |
|
107 | + if ($name !== 'main') { |
|
108 | + $fields_to_validate[ $name ] = $value; |
|
109 | + } |
|
110 | + } |
|
111 | + continue; |
|
112 | + } |
|
113 | + |
|
114 | + // okay if we're here then this is just a straight field=>$value arrangement |
|
115 | + $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']; |
|
116 | + } |
|
117 | + return $fields_to_validate; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + private function loadValidator( |
|
122 | + string $messenger, |
|
123 | + string $message_type, |
|
124 | + string $context, |
|
125 | + array $fields_to_validate |
|
126 | + ): ?EE_Messages_Validator { |
|
127 | + // now we've got the assembled_fields. |
|
128 | + // We need to setup the string for the appropriate validator class and call that. |
|
129 | + $messenger_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
130 | + $messenger_ref = str_replace(' ', '_', $messenger_ref); |
|
131 | + |
|
132 | + $message_type_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
133 | + $message_type_ref = str_replace(' ', '_', $message_type_ref); |
|
134 | + |
|
135 | + $classname = "EE_Messages_{$messenger_ref}_{$message_type_ref}_Validator"; |
|
136 | + |
|
137 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
138 | + if (! class_exists($classname)) { |
|
139 | + $msg[] = sprintf( |
|
140 | + esc_html__( |
|
141 | + 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + $classname |
|
145 | + ); |
|
146 | + throw new DomainException(implode('. ', $msg)); |
|
147 | + } |
|
148 | + |
|
149 | + $validator = $this->loader->getShared($classname, [$fields_to_validate, $context]); |
|
150 | + if (! $validator instanceof EE_Messages_Validator) { |
|
151 | + $msg[] = sprintf( |
|
152 | + esc_html__( |
|
153 | + 'Failed to instantiate %s.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $classname |
|
157 | + ); |
|
158 | + throw new DomainException(implode('. ', $msg)); |
|
159 | + } |
|
160 | + return $validator; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * This makes available the WP transient system for temporarily moving data between routes |
|
166 | + * |
|
167 | + * @param array $data the data that gets sent |
|
168 | + */ |
|
169 | + private function addTransient(array $data): void |
|
170 | + { |
|
171 | + $user_id = get_current_user_id(); |
|
172 | + $transient = "rte_tx_edit_message_template_$user_id"; |
|
173 | + $net_admin = is_multisite() && is_network_admin(); |
|
174 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
175 | + $existing = $net_admin ? get_site_transient($transient) : get_transient($transient); |
|
176 | + $data = ! array_key_exists('notices', $data) ? ['notices' => $data] : $data; |
|
177 | + if ($existing) { |
|
178 | + $data = array_merge($data, (array) $existing); |
|
179 | + } |
|
180 | + if ($net_admin) { |
|
181 | + set_site_transient($transient, $data, 8); |
|
182 | + } else { |
|
183 | + set_transient($transient, $data, 8); |
|
184 | + } |
|
185 | + } |
|
186 | 186 | } |
@@ -101,18 +101,18 @@ discard block |
||
101 | 101 | // first let's figure out if the value['content'] in the current index is an array. |
102 | 102 | // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
103 | 103 | if (is_array($message_template_field['content'])) { |
104 | - $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']['main']; |
|
104 | + $fields_to_validate[$message_template_field['name']] = $message_template_field['content']['main']; |
|
105 | 105 | // loop through the content and get the other fields. |
106 | 106 | foreach ($message_template_field['content'] as $name => $value) { |
107 | 107 | if ($name !== 'main') { |
108 | - $fields_to_validate[ $name ] = $value; |
|
108 | + $fields_to_validate[$name] = $value; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
114 | 114 | // okay if we're here then this is just a straight field=>$value arrangement |
115 | - $fields_to_validate[ $message_template_field['name'] ] = $message_template_field['content']; |
|
115 | + $fields_to_validate[$message_template_field['name']] = $message_template_field['content']; |
|
116 | 116 | } |
117 | 117 | return $fields_to_validate; |
118 | 118 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $classname = "EE_Messages_{$messenger_ref}_{$message_type_ref}_Validator"; |
136 | 136 | |
137 | 137 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
138 | - if (! class_exists($classname)) { |
|
138 | + if ( ! class_exists($classname)) { |
|
139 | 139 | $msg[] = sprintf( |
140 | 140 | esc_html__( |
141 | 141 | 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | $validator = $this->loader->getShared($classname, [$fields_to_validate, $context]); |
150 | - if (! $validator instanceof EE_Messages_Validator) { |
|
150 | + if ( ! $validator instanceof EE_Messages_Validator) { |
|
151 | 151 | $msg[] = sprintf( |
152 | 152 | esc_html__( |
153 | 153 | 'Failed to instantiate %s.', |
@@ -14,19 +14,19 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPress extends Basic |
16 | 16 | { |
17 | - /** |
|
18 | - * @param string $email_address |
|
19 | - * @return boolean |
|
20 | - * @throws EmailValidationException |
|
21 | - */ |
|
22 | - public function validate(string $email_address): bool |
|
23 | - { |
|
24 | - parent::validate($email_address); |
|
25 | - if (! is_email($email_address)) { |
|
26 | - throw new EmailValidationException( |
|
27 | - esc_html__('The email address provided is not valid.', 'event_espresso') |
|
28 | - ); |
|
29 | - } |
|
30 | - return true; |
|
31 | - } |
|
17 | + /** |
|
18 | + * @param string $email_address |
|
19 | + * @return boolean |
|
20 | + * @throws EmailValidationException |
|
21 | + */ |
|
22 | + public function validate(string $email_address): bool |
|
23 | + { |
|
24 | + parent::validate($email_address); |
|
25 | + if (! is_email($email_address)) { |
|
26 | + throw new EmailValidationException( |
|
27 | + esc_html__('The email address provided is not valid.', 'event_espresso') |
|
28 | + ); |
|
29 | + } |
|
30 | + return true; |
|
31 | + } |
|
32 | 32 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function validate(string $email_address): bool |
23 | 23 | { |
24 | 24 | parent::validate($email_address); |
25 | - if (! is_email($email_address)) { |
|
25 | + if ( ! is_email($email_address)) { |
|
26 | 26 | throw new EmailValidationException( |
27 | 27 | esc_html__('The email address provided is not valid.', 'event_espresso') |
28 | 28 | ); |
@@ -14,27 +14,27 @@ |
||
14 | 14 | */ |
15 | 15 | class International extends Basic |
16 | 16 | { |
17 | - /** |
|
18 | - * @param string $email_address |
|
19 | - * @return bool |
|
20 | - * @throws EmailValidationException |
|
21 | - */ |
|
22 | - public function validate(string $email_address): bool |
|
23 | - { |
|
24 | - parent::validate($email_address); |
|
25 | - // plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
26 | - if ( |
|
27 | - ! preg_match( |
|
28 | - // @codingStandardsIgnoreStart |
|
29 | - '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
30 | - // @codingStandardsIgnoreEnd |
|
31 | - $email_address |
|
32 | - ) |
|
33 | - ) { |
|
34 | - throw new EmailValidationException( |
|
35 | - esc_html__('Email address is invalid.', 'event_espresso') |
|
36 | - ); |
|
37 | - } |
|
38 | - return true; |
|
39 | - } |
|
17 | + /** |
|
18 | + * @param string $email_address |
|
19 | + * @return bool |
|
20 | + * @throws EmailValidationException |
|
21 | + */ |
|
22 | + public function validate(string $email_address): bool |
|
23 | + { |
|
24 | + parent::validate($email_address); |
|
25 | + // plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
26 | + if ( |
|
27 | + ! preg_match( |
|
28 | + // @codingStandardsIgnoreStart |
|
29 | + '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
30 | + // @codingStandardsIgnoreEnd |
|
31 | + $email_address |
|
32 | + ) |
|
33 | + ) { |
|
34 | + throw new EmailValidationException( |
|
35 | + esc_html__('Email address is invalid.', 'event_espresso') |
|
36 | + ); |
|
37 | + } |
|
38 | + return true; |
|
39 | + } |
|
40 | 40 | } |