Completed
Branch dev (65a946)
by
unknown
35:11 queued 25:50
created
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3730 added lines, -3730 removed lines patch added patch discarded remove patch
@@ -18,2249 +18,2249 @@  discard block
 block discarded – undo
18 18
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration
23
-     */
24
-    private $_registration;
25
-
26
-    /**
27
-     * @var EE_Event
28
-     */
29
-    private $_reg_event;
30
-
31
-    /**
32
-     * @var EE_Session
33
-     */
34
-    private $_session;
35
-
36
-    private static $_reg_status;
37
-
38
-    /**
39
-     * Form for displaying the custom questions for this registration.
40
-     * This gets used a few times throughout the request so its best to cache it
41
-     *
42
-     * @var EE_Registration_Custom_Questions_Form
43
-     */
44
-    protected $_reg_custom_questions_form;
45
-
46
-    /**
47
-     * @var EEM_Registration $registration_model
48
-     */
49
-    private $registration_model;
50
-
51
-    /**
52
-     * @var EEM_Attendee $attendee_model
53
-     */
54
-    private $attendee_model;
55
-
56
-    /**
57
-     * @var EEM_Event $event_model
58
-     */
59
-    private $event_model;
60
-
61
-    /**
62
-     * @var EEM_Status $status_model
63
-     */
64
-    private $status_model;
65
-
66
-
67
-    /**
68
-     * @param bool $routing
69
-     * @throws EE_Error
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws ReflectionException
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        parent::__construct($routing);
78
-        add_action('wp_loaded', array($this, 'wp_loaded'));
79
-    }
80
-
81
-    /**
82
-     * @return EEM_Registration
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @since 4.10.2.p
87
-     */
88
-    protected function getRegistrationModel()
89
-    {
90
-        if (! $this->registration_model instanceof EEM_Registration) {
91
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
92
-        }
93
-        return $this->registration_model;
94
-    }
95
-
96
-    /**
97
-     * @return EEM_Attendee
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     * @since 4.10.2.p
102
-     */
103
-    protected function getAttendeeModel()
104
-    {
105
-        if (! $this->attendee_model instanceof EEM_Attendee) {
106
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
107
-        }
108
-        return $this->attendee_model;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Event
114
-     * @throws InvalidArgumentException
115
-     * @throws InvalidDataTypeException
116
-     * @throws InvalidInterfaceException
117
-     * @since 4.10.2.p
118
-     */
119
-    protected function getEventModel()
120
-    {
121
-        if (! $this->event_model instanceof EEM_Event) {
122
-            $this->event_model = $this->loader->getShared('EEM_Event');
123
-        }
124
-        return $this->event_model;
125
-    }
126
-
127
-    /**
128
-     * @return EEM_Status
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidInterfaceException
132
-     * @since 4.10.2.p
133
-     */
134
-    protected function getStatusModel()
135
-    {
136
-        if (! $this->status_model instanceof EEM_Status) {
137
-            $this->status_model = $this->loader->getShared('EEM_Status');
138
-        }
139
-        return $this->status_model;
140
-    }
141
-
142
-
143
-    public function wp_loaded()
144
-    {
145
-        // when adding a new registration...
146
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
-            EE_System::do_not_cache();
148
-            if (
149
-                ! isset($this->_req_data['processing_registration'])
150
-                || absint($this->_req_data['processing_registration']) !== 1
151
-            ) {
152
-                // and it's NOT the attendee information reg step
153
-                // force cookie expiration by setting time to last week
154
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
155
-                // and update the global
156
-                $_COOKIE['ee_registration_added'] = 0;
157
-            }
158
-        }
159
-    }
160
-
161
-
162
-    protected function _init_page_props()
163
-    {
164
-        $this->page_slug = REG_PG_SLUG;
165
-        $this->_admin_base_url = REG_ADMIN_URL;
166
-        $this->_admin_base_path = REG_ADMIN;
167
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
168
-        $this->_cpt_routes = array(
169
-            'add_new_attendee' => 'espresso_attendees',
170
-            'edit_attendee'    => 'espresso_attendees',
171
-            'insert_attendee'  => 'espresso_attendees',
172
-            'update_attendee'  => 'espresso_attendees',
173
-        );
174
-        $this->_cpt_model_names = array(
175
-            'add_new_attendee' => 'EEM_Attendee',
176
-            'edit_attendee'    => 'EEM_Attendee',
177
-        );
178
-        $this->_cpt_edit_routes = array(
179
-            'espresso_attendees' => 'edit_attendee',
180
-        );
181
-        $this->_pagenow_map = array(
182
-            'add_new_attendee' => 'post-new.php',
183
-            'edit_attendee'    => 'post.php',
184
-            'trash'            => 'post.php',
185
-        );
186
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
187
-        // add filters so that the comment urls don't take users to a confusing 404 page
188
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
189
-    }
190
-
191
-
192
-    public function clear_comment_link($link, $comment, $args)
193
-    {
194
-        // gotta make sure this only happens on this route
195
-        $post_type = get_post_type($comment->comment_post_ID);
196
-        if ($post_type === 'espresso_attendees') {
197
-            return '#commentsdiv';
198
-        }
199
-        return $link;
200
-    }
201
-
202
-
203
-    protected function _ajax_hooks()
204
-    {
205
-        // todo: all hooks for registrations ajax goes in here
206
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
207
-    }
208
-
209
-
210
-    protected function _define_page_props()
211
-    {
212
-        $this->_admin_page_title = $this->page_label;
213
-        $this->_labels = array(
214
-            'buttons'                      => array(
215
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
216
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
217
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
218
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
219
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
220
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
221
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
222
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
223
-            ),
224
-            'publishbox'                   => array(
225
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
226
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
227
-            ),
228
-            'hide_add_button_on_cpt_route' => array(
229
-                'edit_attendee' => true,
230
-            ),
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     *        grab url requests and route them
237
-     *
238
-     * @access private
239
-     * @return void
240
-     * @throws EE_Error
241
-     */
242
-    public function _set_page_routes()
243
-    {
244
-        $this->_get_registration_status_array();
245
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
246
-            ? $this->_req_data['_REG_ID'] : 0;
247
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
248
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
249
-            : $reg_id;
250
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
251
-            ? $this->_req_data['ATT_ID'] : 0;
252
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
253
-            ? $this->_req_data['post']
254
-            : $att_id;
255
-        $this->_page_routes = array(
256
-            'default'                             => array(
257
-                'func'       => '_registrations_overview_list_table',
258
-                'capability' => 'ee_read_registrations',
259
-            ),
260
-            'view_registration'                   => array(
261
-                'func'       => '_registration_details',
262
-                'capability' => 'ee_read_registration',
263
-                'obj_id'     => $reg_id,
264
-            ),
265
-            'edit_registration'                   => array(
266
-                'func'               => '_update_attendee_registration_form',
267
-                'noheader'           => true,
268
-                'headers_sent_route' => 'view_registration',
269
-                'capability'         => 'ee_edit_registration',
270
-                'obj_id'             => $reg_id,
271
-                '_REG_ID'            => $reg_id,
272
-            ),
273
-            'trash_registrations'                 => array(
274
-                'func'       => '_trash_or_restore_registrations',
275
-                'args'       => array('trash' => true),
276
-                'noheader'   => true,
277
-                'capability' => 'ee_delete_registrations',
278
-            ),
279
-            'restore_registrations'               => array(
280
-                'func'       => '_trash_or_restore_registrations',
281
-                'args'       => array('trash' => false),
282
-                'noheader'   => true,
283
-                'capability' => 'ee_delete_registrations',
284
-            ),
285
-            'delete_registrations'                => array(
286
-                'func'       => '_delete_registrations',
287
-                'noheader'   => true,
288
-                'capability' => 'ee_delete_registrations',
289
-            ),
290
-            'new_registration'                    => array(
291
-                'func'       => 'new_registration',
292
-                'capability' => 'ee_edit_registrations',
293
-            ),
294
-            'process_reg_step'                    => array(
295
-                'func'       => 'process_reg_step',
296
-                'noheader'   => true,
297
-                'capability' => 'ee_edit_registrations',
298
-            ),
299
-            'redirect_to_txn'                     => array(
300
-                'func'       => 'redirect_to_txn',
301
-                'noheader'   => true,
302
-                'capability' => 'ee_edit_registrations',
303
-            ),
304
-            'change_reg_status'                   => array(
305
-                'func'       => '_change_reg_status',
306
-                'noheader'   => true,
307
-                'capability' => 'ee_edit_registration',
308
-                'obj_id'     => $reg_id,
309
-            ),
310
-            'approve_registration'                => array(
311
-                'func'       => 'approve_registration',
312
-                'noheader'   => true,
313
-                'capability' => 'ee_edit_registration',
314
-                'obj_id'     => $reg_id,
315
-            ),
316
-            'approve_and_notify_registration'     => array(
317
-                'func'       => 'approve_registration',
318
-                'noheader'   => true,
319
-                'args'       => array(true),
320
-                'capability' => 'ee_edit_registration',
321
-                'obj_id'     => $reg_id,
322
-            ),
323
-            'approve_registrations'               => array(
324
-                'func'       => 'bulk_action_on_registrations',
325
-                'noheader'   => true,
326
-                'capability' => 'ee_edit_registrations',
327
-                'args'       => array('approve'),
328
-            ),
329
-            'approve_and_notify_registrations'    => array(
330
-                'func'       => 'bulk_action_on_registrations',
331
-                'noheader'   => true,
332
-                'capability' => 'ee_edit_registrations',
333
-                'args'       => array('approve', true),
334
-            ),
335
-            'decline_registration'                => array(
336
-                'func'       => 'decline_registration',
337
-                'noheader'   => true,
338
-                'capability' => 'ee_edit_registration',
339
-                'obj_id'     => $reg_id,
340
-            ),
341
-            'decline_and_notify_registration'     => array(
342
-                'func'       => 'decline_registration',
343
-                'noheader'   => true,
344
-                'args'       => array(true),
345
-                'capability' => 'ee_edit_registration',
346
-                'obj_id'     => $reg_id,
347
-            ),
348
-            'decline_registrations'               => array(
349
-                'func'       => 'bulk_action_on_registrations',
350
-                'noheader'   => true,
351
-                'capability' => 'ee_edit_registrations',
352
-                'args'       => array('decline'),
353
-            ),
354
-            'decline_and_notify_registrations'    => array(
355
-                'func'       => 'bulk_action_on_registrations',
356
-                'noheader'   => true,
357
-                'capability' => 'ee_edit_registrations',
358
-                'args'       => array('decline', true),
359
-            ),
360
-            'pending_registration'                => array(
361
-                'func'       => 'pending_registration',
362
-                'noheader'   => true,
363
-                'capability' => 'ee_edit_registration',
364
-                'obj_id'     => $reg_id,
365
-            ),
366
-            'pending_and_notify_registration'     => array(
367
-                'func'       => 'pending_registration',
368
-                'noheader'   => true,
369
-                'args'       => array(true),
370
-                'capability' => 'ee_edit_registration',
371
-                'obj_id'     => $reg_id,
372
-            ),
373
-            'pending_registrations'               => array(
374
-                'func'       => 'bulk_action_on_registrations',
375
-                'noheader'   => true,
376
-                'capability' => 'ee_edit_registrations',
377
-                'args'       => array('pending'),
378
-            ),
379
-            'pending_and_notify_registrations'    => array(
380
-                'func'       => 'bulk_action_on_registrations',
381
-                'noheader'   => true,
382
-                'capability' => 'ee_edit_registrations',
383
-                'args'       => array('pending', true),
384
-            ),
385
-            'no_approve_registration'             => array(
386
-                'func'       => 'not_approve_registration',
387
-                'noheader'   => true,
388
-                'capability' => 'ee_edit_registration',
389
-                'obj_id'     => $reg_id,
390
-            ),
391
-            'no_approve_and_notify_registration'  => array(
392
-                'func'       => 'not_approve_registration',
393
-                'noheader'   => true,
394
-                'args'       => array(true),
395
-                'capability' => 'ee_edit_registration',
396
-                'obj_id'     => $reg_id,
397
-            ),
398
-            'no_approve_registrations'            => array(
399
-                'func'       => 'bulk_action_on_registrations',
400
-                'noheader'   => true,
401
-                'capability' => 'ee_edit_registrations',
402
-                'args'       => array('not_approve'),
403
-            ),
404
-            'no_approve_and_notify_registrations' => array(
405
-                'func'       => 'bulk_action_on_registrations',
406
-                'noheader'   => true,
407
-                'capability' => 'ee_edit_registrations',
408
-                'args'       => array('not_approve', true),
409
-            ),
410
-            'cancel_registration'                 => array(
411
-                'func'       => 'cancel_registration',
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_registration',
414
-                'obj_id'     => $reg_id,
415
-            ),
416
-            'cancel_and_notify_registration'      => array(
417
-                'func'       => 'cancel_registration',
418
-                'noheader'   => true,
419
-                'args'       => array(true),
420
-                'capability' => 'ee_edit_registration',
421
-                'obj_id'     => $reg_id,
422
-            ),
423
-            'cancel_registrations'                => array(
424
-                'func'       => 'bulk_action_on_registrations',
425
-                'noheader'   => true,
426
-                'capability' => 'ee_edit_registrations',
427
-                'args'       => array('cancel'),
428
-            ),
429
-            'cancel_and_notify_registrations'     => array(
430
-                'func'       => 'bulk_action_on_registrations',
431
-                'noheader'   => true,
432
-                'capability' => 'ee_edit_registrations',
433
-                'args'       => array('cancel', true),
434
-            ),
435
-            'wait_list_registration'              => array(
436
-                'func'       => 'wait_list_registration',
437
-                'noheader'   => true,
438
-                'capability' => 'ee_edit_registration',
439
-                'obj_id'     => $reg_id,
440
-            ),
441
-            'wait_list_and_notify_registration'   => array(
442
-                'func'       => 'wait_list_registration',
443
-                'noheader'   => true,
444
-                'args'       => array(true),
445
-                'capability' => 'ee_edit_registration',
446
-                'obj_id'     => $reg_id,
447
-            ),
448
-            'contact_list'                        => array(
449
-                'func'       => '_attendee_contact_list_table',
450
-                'capability' => 'ee_read_contacts',
451
-            ),
452
-            'add_new_attendee'                    => array(
453
-                'func' => '_create_new_cpt_item',
454
-                'args' => array(
455
-                    'new_attendee' => true,
456
-                    'capability'   => 'ee_edit_contacts',
457
-                ),
458
-            ),
459
-            'edit_attendee'                       => array(
460
-                'func'       => '_edit_cpt_item',
461
-                'capability' => 'ee_edit_contacts',
462
-                'obj_id'     => $att_id,
463
-            ),
464
-            'duplicate_attendee'                  => array(
465
-                'func'       => '_duplicate_attendee',
466
-                'noheader'   => true,
467
-                'capability' => 'ee_edit_contacts',
468
-                'obj_id'     => $att_id,
469
-            ),
470
-            'insert_attendee'                     => array(
471
-                'func'       => '_insert_or_update_attendee',
472
-                'args'       => array(
473
-                    'new_attendee' => true,
474
-                ),
475
-                'noheader'   => true,
476
-                'capability' => 'ee_edit_contacts',
477
-            ),
478
-            'update_attendee'                     => array(
479
-                'func'       => '_insert_or_update_attendee',
480
-                'args'       => array(
481
-                    'new_attendee' => false,
482
-                ),
483
-                'noheader'   => true,
484
-                'capability' => 'ee_edit_contacts',
485
-                'obj_id'     => $att_id,
486
-            ),
487
-            'trash_attendees'                     => array(
488
-                'func'       => '_trash_or_restore_attendees',
489
-                'args'       => array(
490
-                    'trash' => 'true',
491
-                ),
492
-                'noheader'   => true,
493
-                'capability' => 'ee_delete_contacts',
494
-            ),
495
-            'trash_attendee'                      => array(
496
-                'func'       => '_trash_or_restore_attendees',
497
-                'args'       => array(
498
-                    'trash' => true,
499
-                ),
500
-                'noheader'   => true,
501
-                'capability' => 'ee_delete_contacts',
502
-                'obj_id'     => $att_id,
503
-            ),
504
-            'restore_attendees'                   => array(
505
-                'func'       => '_trash_or_restore_attendees',
506
-                'args'       => array(
507
-                    'trash' => false,
508
-                ),
509
-                'noheader'   => true,
510
-                'capability' => 'ee_delete_contacts',
511
-                'obj_id'     => $att_id,
512
-            ),
513
-            'resend_registration'                 => array(
514
-                'func'       => '_resend_registration',
515
-                'noheader'   => true,
516
-                'capability' => 'ee_send_message',
517
-            ),
518
-            'registrations_report'                => array(
519
-                'func'       => '_registrations_report',
520
-                'noheader'   => true,
521
-                'capability' => 'ee_read_registrations',
522
-            ),
523
-            'contact_list_export'                 => array(
524
-                'func'       => '_contact_list_export',
525
-                'noheader'   => true,
526
-                'capability' => 'export',
527
-            ),
528
-            'contact_list_report'                 => array(
529
-                'func'       => '_contact_list_report',
530
-                'noheader'   => true,
531
-                'capability' => 'ee_read_contacts',
532
-            ),
533
-        );
534
-    }
535
-
536
-
537
-    protected function _set_page_config()
538
-    {
539
-        $this->_page_config = array(
540
-            'default'           => array(
541
-                'nav'           => array(
542
-                    'label' => esc_html__('Overview', 'event_espresso'),
543
-                    'order' => 5,
544
-                ),
545
-                'help_tabs'     => array(
546
-                    'registrations_overview_help_tab'                       => array(
547
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
548
-                        'filename' => 'registrations_overview',
549
-                    ),
550
-                    'registrations_overview_table_column_headings_help_tab' => array(
551
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
552
-                        'filename' => 'registrations_overview_table_column_headings',
553
-                    ),
554
-                    'registrations_overview_filters_help_tab'               => array(
555
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
556
-                        'filename' => 'registrations_overview_filters',
557
-                    ),
558
-                    'registrations_overview_views_help_tab'                 => array(
559
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
560
-                        'filename' => 'registrations_overview_views',
561
-                    ),
562
-                    'registrations_regoverview_other_help_tab'              => array(
563
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
564
-                        'filename' => 'registrations_overview_other',
565
-                    ),
566
-                ),
567
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
-                // 'help_tour'     => array('Registration_Overview_Help_Tour'),
569
-                'qtips'         => array('Registration_List_Table_Tips'),
570
-                'list_table'    => 'EE_Registrations_List_Table',
571
-                'require_nonce' => false,
572
-            ),
573
-            'view_registration' => array(
574
-                'nav'           => array(
575
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
576
-                    'order'      => 15,
577
-                    'url'        => isset($this->_req_data['_REG_ID'])
578
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
579
-                        : $this->_admin_base_url,
580
-                    'persistent' => false,
581
-                ),
582
-                'help_tabs'     => array(
583
-                    'registrations_details_help_tab'                    => array(
584
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
585
-                        'filename' => 'registrations_details',
586
-                    ),
587
-                    'registrations_details_table_help_tab'              => array(
588
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
589
-                        'filename' => 'registrations_details_table',
590
-                    ),
591
-                    'registrations_details_form_answers_help_tab'       => array(
592
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
593
-                        'filename' => 'registrations_details_form_answers',
594
-                    ),
595
-                    'registrations_details_registrant_details_help_tab' => array(
596
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
597
-                        'filename' => 'registrations_details_registrant_details',
598
-                    ),
599
-                ),
600
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
601
-                // 'help_tour'     => array('Registration_Details_Help_Tour'),
602
-                'metaboxes'     => array_merge(
603
-                    $this->_default_espresso_metaboxes,
604
-                    array('_registration_details_metaboxes')
605
-                ),
606
-                'require_nonce' => false,
607
-            ),
608
-            'new_registration'  => array(
609
-                'nav'           => array(
610
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
-                    'url'        => '#',
612
-                    'order'      => 15,
613
-                    'persistent' => false,
614
-                ),
615
-                'metaboxes'     => $this->_default_espresso_metaboxes,
616
-                'labels'        => array(
617
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
-                ),
619
-                'require_nonce' => false,
620
-            ),
621
-            'add_new_attendee'  => array(
622
-                'nav'           => array(
623
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
624
-                    'order'      => 15,
625
-                    'persistent' => false,
626
-                ),
627
-                'metaboxes'     => array_merge(
628
-                    $this->_default_espresso_metaboxes,
629
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
630
-                ),
631
-                'require_nonce' => false,
632
-            ),
633
-            'edit_attendee'     => array(
634
-                'nav'           => array(
635
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
-                    'order'      => 15,
637
-                    'persistent' => false,
638
-                    'url'        => isset($this->_req_data['ATT_ID'])
639
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
640
-                        : $this->_admin_base_url,
641
-                ),
642
-                'metaboxes'     => array('attendee_editor_metaboxes'),
643
-                'require_nonce' => false,
644
-            ),
645
-            'contact_list'      => array(
646
-                'nav'           => array(
647
-                    'label' => esc_html__('Contact List', 'event_espresso'),
648
-                    'order' => 20,
649
-                ),
650
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
651
-                'help_tabs'     => array(
652
-                    'registrations_contact_list_help_tab'                       => array(
653
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
654
-                        'filename' => 'registrations_contact_list',
655
-                    ),
656
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
657
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
658
-                        'filename' => 'registrations_contact_list_table_column_headings',
659
-                    ),
660
-                    'registrations_contact_list_views_help_tab'                 => array(
661
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
662
-                        'filename' => 'registrations_contact_list_views',
663
-                    ),
664
-                    'registrations_contact_list_other_help_tab'                 => array(
665
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
666
-                        'filename' => 'registrations_contact_list_other',
667
-                    ),
668
-                ),
669
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
670
-                // 'help_tour'     => array('Contact_List_Help_Tour'),
671
-                'metaboxes'     => array(),
672
-                'require_nonce' => false,
673
-            ),
674
-            // override default cpt routes
675
-            'create_new'        => '',
676
-            'edit'              => '',
677
-        );
678
-    }
679
-
680
-
681
-    /**
682
-     * The below methods aren't used by this class currently
683
-     */
684
-    protected function _add_screen_options()
685
-    {
686
-    }
687
-
688
-
689
-    protected function _add_feature_pointers()
690
-    {
691
-    }
692
-
693
-
694
-    public function admin_init()
695
-    {
696
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
697
-            'click "Update Registration Questions" to save your changes',
698
-            'event_espresso'
699
-        );
700
-    }
701
-
702
-
703
-    public function admin_notices()
704
-    {
705
-    }
706
-
707
-
708
-    public function admin_footer_scripts()
709
-    {
710
-    }
711
-
712
-
713
-    /**
714
-     *        get list of registration statuses
715
-     *
716
-     * @access private
717
-     * @return void
718
-     * @throws EE_Error
719
-     */
720
-    private function _get_registration_status_array()
721
-    {
722
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
723
-    }
724
-
725
-
726
-    /**
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @since 4.10.2.p
731
-     */
732
-    protected function _add_screen_options_default()
733
-    {
734
-        $this->_per_page_screen_option();
735
-    }
736
-
737
-
738
-    /**
739
-     * @throws InvalidArgumentException
740
-     * @throws InvalidDataTypeException
741
-     * @throws InvalidInterfaceException
742
-     * @since 4.10.2.p
743
-     */
744
-    protected function _add_screen_options_contact_list()
745
-    {
746
-        $page_title = $this->_admin_page_title;
747
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
-        $this->_per_page_screen_option();
749
-        $this->_admin_page_title = $page_title;
750
-    }
751
-
752
-
753
-    public function load_scripts_styles()
754
-    {
755
-        // style
756
-        wp_register_style(
757
-            'espresso_reg',
758
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
-            array('ee-admin-css'),
760
-            EVENT_ESPRESSO_VERSION
761
-        );
762
-        wp_enqueue_style('espresso_reg');
763
-        // script
764
-        wp_register_script(
765
-            'espresso_reg',
766
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
768
-            EVENT_ESPRESSO_VERSION,
769
-            true
770
-        );
771
-        wp_enqueue_script('espresso_reg');
772
-    }
773
-
774
-
775
-    /**
776
-     * @throws EE_Error
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidDataTypeException
779
-     * @throws InvalidInterfaceException
780
-     * @throws ReflectionException
781
-     * @since 4.10.2.p
782
-     */
783
-    public function load_scripts_styles_edit_attendee()
784
-    {
785
-        // stuff to only show up on our attendee edit details page.
786
-        $attendee_details_translations = array(
787
-            'att_publish_text' => sprintf(
788
-                /* translators: The date and time */
789
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
-            ),
792
-        );
793
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
-        wp_enqueue_script('jquery-validate');
795
-    }
796
-
797
-
798
-    /**
799
-     * @throws EE_Error
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     * @throws ReflectionException
804
-     * @since 4.10.2.p
805
-     */
806
-    public function load_scripts_styles_view_registration()
807
-    {
808
-        // styles
809
-        wp_enqueue_style('espresso-ui-theme');
810
-        // scripts
811
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
812
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
813
-    }
814
-
815
-
816
-    public function load_scripts_styles_contact_list()
817
-    {
818
-        wp_dequeue_style('espresso_reg');
819
-        wp_register_style(
820
-            'espresso_att',
821
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
-            array('ee-admin-css'),
823
-            EVENT_ESPRESSO_VERSION
824
-        );
825
-        wp_enqueue_style('espresso_att');
826
-    }
827
-
828
-
829
-    public function load_scripts_styles_new_registration()
830
-    {
831
-        wp_register_script(
832
-            'ee-spco-for-admin',
833
-            REG_ASSETS_URL . 'spco_for_admin.js',
834
-            array('underscore', 'jquery'),
835
-            EVENT_ESPRESSO_VERSION,
836
-            true
837
-        );
838
-        wp_enqueue_script('ee-spco-for-admin');
839
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
-        EE_Form_Section_Proper::wp_enqueue_scripts();
841
-        EED_Ticket_Selector::load_tckt_slctr_assets();
842
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
843
-    }
844
-
845
-
846
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
-    {
848
-        add_filter('FHEE_load_EE_messages', '__return_true');
849
-    }
850
-
851
-
852
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
-    {
854
-        add_filter('FHEE_load_EE_messages', '__return_true');
855
-    }
856
-
857
-
858
-    /**
859
-     * @throws EE_Error
860
-     * @throws InvalidArgumentException
861
-     * @throws InvalidDataTypeException
862
-     * @throws InvalidInterfaceException
863
-     * @throws ReflectionException
864
-     * @since 4.10.2.p
865
-     */
866
-    protected function _set_list_table_views_default()
867
-    {
868
-        // for notification related bulk actions we need to make sure only active messengers have an option.
869
-        EED_Messages::set_autoloaders();
870
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
871
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
-        $active_mts = $message_resource_manager->list_of_active_message_types();
873
-        // key= bulk_action_slug, value= message type.
874
-        $match_array = array(
875
-            'approve_registrations'    => 'registration',
876
-            'decline_registrations'    => 'declined_registration',
877
-            'pending_registrations'    => 'pending_approval',
878
-            'no_approve_registrations' => 'not_approved_registration',
879
-            'cancel_registrations'     => 'cancelled_registration',
880
-        );
881
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
882
-            'ee_send_message',
883
-            'batch_send_messages'
884
-        );
885
-        /** setup reg status bulk actions **/
886
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
-                'Approve and Notify Registrations',
890
-                'event_espresso'
891
-            );
892
-        }
893
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
-                'Decline and Notify Registrations',
897
-                'event_espresso'
898
-            );
899
-        }
900
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
901
-            'Set Registrations to Pending Payment',
902
-            'event_espresso'
903
-        );
904
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
-                'Set Registrations to Pending Payment and Notify',
907
-                'event_espresso'
908
-            );
909
-        }
910
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
-            'Set Registrations to Not Approved',
912
-            'event_espresso'
913
-        );
914
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
-                'Set Registrations to Not Approved and Notify',
917
-                'event_espresso'
918
-            );
919
-        }
920
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
-                'Cancel Registrations and Notify',
924
-                'event_espresso'
925
-            );
926
-        }
927
-        $def_reg_status_actions = apply_filters(
928
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
-            $def_reg_status_actions,
930
-            $active_mts,
931
-            $can_send
932
-        );
933
-
934
-        $this->_views = array(
935
-            'all'   => array(
936
-                'slug'        => 'all',
937
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
-                'count'       => 0,
939
-                'bulk_action' => array_merge(
940
-                    $def_reg_status_actions,
941
-                    array(
942
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
-                    )
944
-                ),
945
-            ),
946
-            'month' => array(
947
-                'slug'        => 'month',
948
-                'label'       => esc_html__('This Month', 'event_espresso'),
949
-                'count'       => 0,
950
-                'bulk_action' => array_merge(
951
-                    $def_reg_status_actions,
952
-                    array(
953
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
-                    )
955
-                ),
956
-            ),
957
-            'today' => array(
958
-                'slug'        => 'today',
959
-                'label'       => sprintf(
960
-                    esc_html__('Today - %s', 'event_espresso'),
961
-                    date('M d, Y', current_time('timestamp'))
962
-                ),
963
-                'count'       => 0,
964
-                'bulk_action' => array_merge(
965
-                    $def_reg_status_actions,
966
-                    array(
967
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
-                    )
969
-                ),
970
-            ),
971
-        );
972
-        if (
973
-            EE_Registry::instance()->CAP->current_user_can(
974
-                'ee_delete_registrations',
975
-                'espresso_registrations_delete_registration'
976
-            )
977
-        ) {
978
-            $this->_views['incomplete'] = array(
979
-                'slug'        => 'incomplete',
980
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
981
-                'count'       => 0,
982
-                'bulk_action' => array(
983
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
-                ),
985
-            );
986
-            $this->_views['trash'] = array(
987
-                'slug'        => 'trash',
988
-                'label'       => esc_html__('Trash', 'event_espresso'),
989
-                'count'       => 0,
990
-                'bulk_action' => array(
991
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
-                ),
994
-            );
995
-        }
996
-    }
997
-
998
-
999
-    protected function _set_list_table_views_contact_list()
1000
-    {
1001
-        $this->_views = array(
1002
-            'in_use' => array(
1003
-                'slug'        => 'in_use',
1004
-                'label'       => esc_html__('In Use', 'event_espresso'),
1005
-                'count'       => 0,
1006
-                'bulk_action' => array(
1007
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
-                ),
1009
-            ),
1010
-        );
1011
-        if (
1012
-            EE_Registry::instance()->CAP->current_user_can(
1013
-                'ee_delete_contacts',
1014
-                'espresso_registrations_trash_attendees'
1015
-            )
1016
-        ) {
1017
-            $this->_views['trash'] = array(
1018
-                'slug'        => 'trash',
1019
-                'label'       => esc_html__('Trash', 'event_espresso'),
1020
-                'count'       => 0,
1021
-                'bulk_action' => array(
1022
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
-                ),
1024
-            );
1025
-        }
1026
-    }
1027
-
1028
-
1029
-    protected function _registration_legend_items()
1030
-    {
1031
-        $fc_items = array(
1032
-            'star-icon'        => array(
1033
-                'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1034
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1035
-            ),
1036
-            'view_details'     => array(
1037
-                'class' => 'dashicons dashicons-clipboard',
1038
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1039
-            ),
1040
-            'edit_attendee'    => array(
1041
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1042
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1043
-            ),
1044
-            'view_transaction' => array(
1045
-                'class' => 'dashicons dashicons-cart',
1046
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1047
-            ),
1048
-            'view_invoice'     => array(
1049
-                'class' => 'dashicons dashicons-media-spreadsheet',
1050
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1051
-            ),
1052
-        );
1053
-        if (
1054
-            EE_Registry::instance()->CAP->current_user_can(
1055
-                'ee_send_message',
1056
-                'espresso_registrations_resend_registration'
1057
-            )
1058
-        ) {
1059
-            $fc_items['resend_registration'] = array(
1060
-                'class' => 'dashicons dashicons-email-alt',
1061
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1062
-            );
1063
-        } else {
1064
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1065
-        }
1066
-        if (
1067
-            EE_Registry::instance()->CAP->current_user_can(
1068
-                'ee_read_global_messages',
1069
-                'view_filtered_messages'
1070
-            )
1071
-        ) {
1072
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1073
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1074
-                $fc_items['view_related_messages'] = array(
1075
-                    'class' => $related_for_icon['css_class'],
1076
-                    'desc'  => $related_for_icon['label'],
1077
-                );
1078
-            }
1079
-        }
1080
-        $sc_items = array(
1081
-            'approved_status'   => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1083
-                'desc'  => EEH_Template::pretty_status(
1084
-                    EEM_Registration::status_id_approved,
1085
-                    false,
1086
-                    'sentence'
1087
-                ),
1088
-            ),
1089
-            'pending_status'    => array(
1090
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1091
-                'desc'  => EEH_Template::pretty_status(
1092
-                    EEM_Registration::status_id_pending_payment,
1093
-                    false,
1094
-                    'sentence'
1095
-                ),
1096
-            ),
1097
-            'wait_list'         => array(
1098
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1099
-                'desc'  => EEH_Template::pretty_status(
1100
-                    EEM_Registration::status_id_wait_list,
1101
-                    false,
1102
-                    'sentence'
1103
-                ),
1104
-            ),
1105
-            'incomplete_status' => array(
1106
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1107
-                'desc'  => EEH_Template::pretty_status(
1108
-                    EEM_Registration::status_id_incomplete,
1109
-                    false,
1110
-                    'sentence'
1111
-                ),
1112
-            ),
1113
-            'not_approved'      => array(
1114
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1115
-                'desc'  => EEH_Template::pretty_status(
1116
-                    EEM_Registration::status_id_not_approved,
1117
-                    false,
1118
-                    'sentence'
1119
-                ),
1120
-            ),
1121
-            'declined_status'   => array(
1122
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1123
-                'desc'  => EEH_Template::pretty_status(
1124
-                    EEM_Registration::status_id_declined,
1125
-                    false,
1126
-                    'sentence'
1127
-                ),
1128
-            ),
1129
-            'cancelled_status'  => array(
1130
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1131
-                'desc'  => EEH_Template::pretty_status(
1132
-                    EEM_Registration::status_id_cancelled,
1133
-                    false,
1134
-                    'sentence'
1135
-                ),
1136
-            ),
1137
-        );
1138
-        return array_merge($fc_items, $sc_items);
1139
-    }
1140
-
1141
-
1142
-
1143
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * @throws DomainException
1149
-     * @throws EE_Error
1150
-     * @throws InvalidArgumentException
1151
-     * @throws InvalidDataTypeException
1152
-     * @throws InvalidInterfaceException
1153
-     * @throws ReflectionException
1154
-     */
1155
-    protected function _registrations_overview_list_table()
1156
-    {
1157
-        $this->appendAddNewRegistrationButtonToPageTitle();
1158
-        $header_text = '';
1159
-        $admin_page_header_decorators = [
1160
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
-        ];
1165
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1167
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1168
-        }
1169
-        $this->_template_args['admin_page_header'] = $header_text;
1170
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1171
-        $this->display_admin_list_table_page_with_no_sidebar();
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * @throws EE_Error
1177
-     * @throws InvalidArgumentException
1178
-     * @throws InvalidDataTypeException
1179
-     * @throws InvalidInterfaceException
1180
-     */
1181
-    private function appendAddNewRegistrationButtonToPageTitle()
1182
-    {
1183
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1184
-            ? absint($this->_req_data['event_id'])
1185
-            : 0;
1186
-        if (
1187
-            $EVT_ID
1188
-            && EE_Registry::instance()->CAP->current_user_can(
1189
-                'ee_edit_registrations',
1190
-                'espresso_registrations_new_registration',
1191
-                $EVT_ID
1192
-            )
1193
-        ) {
1194
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
-                'new_registration',
1196
-                'add-registrant',
1197
-                array('event_id' => $EVT_ID),
1198
-                'add-new-h2'
1199
-            );
1200
-        }
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * This sets the _registration property for the registration details screen
1206
-     *
1207
-     * @access private
1208
-     * @return bool
1209
-     * @throws EE_Error
1210
-     * @throws InvalidArgumentException
1211
-     * @throws InvalidDataTypeException
1212
-     * @throws InvalidInterfaceException
1213
-     */
1214
-    private function _set_registration_object()
1215
-    {
1216
-        // get out if we've already set the object
1217
-        if ($this->_registration instanceof EE_Registration) {
1218
-            return true;
1219
-        }
1220
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1221
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1222
-            return true;
1223
-        }
1224
-        $error_msg = sprintf(
1225
-            esc_html__(
1226
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1227
-                'event_espresso'
1228
-            ),
1229
-            $REG_ID
1230
-        );
1231
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1232
-        $this->_registration = null;
1233
-        return false;
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     * Used to retrieve registrations for the list table.
1239
-     *
1240
-     * @param int  $per_page
1241
-     * @param bool $count
1242
-     * @param bool $this_month
1243
-     * @param bool $today
1244
-     * @return EE_Registration[]|int
1245
-     * @throws EE_Error
1246
-     * @throws InvalidArgumentException
1247
-     * @throws InvalidDataTypeException
1248
-     * @throws InvalidInterfaceException
1249
-     */
1250
-    public function get_registrations(
1251
-        $per_page = 10,
1252
-        $count = false,
1253
-        $this_month = false,
1254
-        $today = false
1255
-    ) {
1256
-        if ($this_month) {
1257
-            $this->_req_data['status'] = 'month';
1258
-        }
1259
-        if ($today) {
1260
-            $this->_req_data['status'] = 'today';
1261
-        }
1262
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1263
-        /**
1264
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1265
-         *
1266
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1267
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1268
-         *                             or if you have the development copy of EE you can view this at the path:
1269
-         *                             /docs/G--Model-System/model-query-params.md
1270
-         */
1271
-        $query_params['group_by'] = '';
1272
-
1273
-        return $count
1274
-            ? $this->getRegistrationModel()->count($query_params)
1275
-            /** @type EE_Registration[] */
1276
-            : $this->getRegistrationModel()->get_all($query_params);
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1282
-     * Note: this listens to values on the request for some of the query parameters.
1283
-     *
1284
-     * @param array $request
1285
-     * @param int   $per_page
1286
-     * @param bool  $count
1287
-     * @return array
1288
-     * @throws EE_Error
1289
-     * @throws InvalidArgumentException
1290
-     * @throws InvalidDataTypeException
1291
-     * @throws InvalidInterfaceException
1292
-     */
1293
-    protected function _get_registration_query_parameters(
1294
-        $request = array(),
1295
-        $per_page = 10,
1296
-        $count = false
1297
-    ) {
1298
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1299
-        $list_table_query_builder = $this->loader->getNew(
1300
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1301
-            [ $request ]
1302
-        );
1303
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1304
-    }
1305
-
1306
-
1307
-    public function get_registration_status_array()
1308
-    {
1309
-        return self::$_reg_status;
1310
-    }
1311
-
1312
-
1313
-
1314
-
1315
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1316
-    /**
1317
-     *        generates HTML for the View Registration Details Admin page
1318
-     *
1319
-     * @access protected
1320
-     * @return void
1321
-     * @throws DomainException
1322
-     * @throws EE_Error
1323
-     * @throws InvalidArgumentException
1324
-     * @throws InvalidDataTypeException
1325
-     * @throws InvalidInterfaceException
1326
-     * @throws EntityNotFoundException
1327
-     * @throws ReflectionException
1328
-     */
1329
-    protected function _registration_details()
1330
-    {
1331
-        $this->_template_args = array();
1332
-        $this->_set_registration_object();
1333
-        if (is_object($this->_registration)) {
1334
-            $transaction = $this->_registration->transaction()
1335
-                ? $this->_registration->transaction()
1336
-                : EE_Transaction::new_instance();
1337
-            $this->_session = $transaction->session_data();
1338
-            $event_id = $this->_registration->event_ID();
1339
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1340
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1341
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1342
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1343
-            $this->_template_args['grand_total'] = $transaction->total();
1344
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1345
-            // link back to overview
1346
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1347
-            $this->_template_args['registration'] = $this->_registration;
1348
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1349
-                array(
1350
-                    'action'   => 'default',
1351
-                    'event_id' => $event_id,
1352
-                ),
1353
-                REG_ADMIN_URL
1354
-            );
1355
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1356
-                array(
1357
-                    'action' => 'default',
1358
-                    'EVT_ID' => $event_id,
1359
-                    'page'   => 'espresso_transactions',
1360
-                ),
1361
-                admin_url('admin.php')
1362
-            );
1363
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1364
-                array(
1365
-                    'page'   => 'espresso_events',
1366
-                    'action' => 'edit',
1367
-                    'post'   => $event_id,
1368
-                ),
1369
-                admin_url('admin.php')
1370
-            );
1371
-            // next and previous links
1372
-            $next_reg = $this->_registration->next(
1373
-                null,
1374
-                array(),
1375
-                'REG_ID'
1376
-            );
1377
-            $this->_template_args['next_registration'] = $next_reg
1378
-                ? $this->_next_link(
1379
-                    EE_Admin_Page::add_query_args_and_nonce(
1380
-                        array(
1381
-                            'action'  => 'view_registration',
1382
-                            '_REG_ID' => $next_reg['REG_ID'],
1383
-                        ),
1384
-                        REG_ADMIN_URL
1385
-                    ),
1386
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1387
-                )
1388
-                : '';
1389
-            $previous_reg = $this->_registration->previous(
1390
-                null,
1391
-                array(),
1392
-                'REG_ID'
1393
-            );
1394
-            $this->_template_args['previous_registration'] = $previous_reg
1395
-                ? $this->_previous_link(
1396
-                    EE_Admin_Page::add_query_args_and_nonce(
1397
-                        array(
1398
-                            'action'  => 'view_registration',
1399
-                            '_REG_ID' => $previous_reg['REG_ID'],
1400
-                        ),
1401
-                        REG_ADMIN_URL
1402
-                    ),
1403
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1404
-                )
1405
-                : '';
1406
-            // grab header
1407
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1408
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1409
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1410
-                $template_path,
1411
-                $this->_template_args,
1412
-                true
1413
-            );
1414
-        } else {
1415
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1416
-        }
1417
-        // the details template wrapper
1418
-        $this->display_admin_page_with_sidebar();
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * @throws EE_Error
1424
-     * @throws InvalidArgumentException
1425
-     * @throws InvalidDataTypeException
1426
-     * @throws InvalidInterfaceException
1427
-     * @throws ReflectionException
1428
-     * @since 4.10.2.p
1429
-     */
1430
-    protected function _registration_details_metaboxes()
1431
-    {
1432
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1433
-        $this->_set_registration_object();
1434
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1435
-        add_meta_box(
1436
-            'edit-reg-status-mbox',
1437
-            esc_html__('Registration Status', 'event_espresso'),
1438
-            array($this, 'set_reg_status_buttons_metabox'),
1439
-            $this->wp_page_slug,
1440
-            'normal',
1441
-            'high'
1442
-        );
1443
-        add_meta_box(
1444
-            'edit-reg-details-mbox',
1445
-            esc_html__('Registration Details', 'event_espresso'),
1446
-            array($this, '_reg_details_meta_box'),
1447
-            $this->wp_page_slug,
1448
-            'normal',
1449
-            'high'
1450
-        );
1451
-        if (
1452
-            $attendee instanceof EE_Attendee
1453
-            && EE_Registry::instance()->CAP->current_user_can(
1454
-                'ee_read_registration',
1455
-                'edit-reg-questions-mbox',
1456
-                $this->_registration->ID()
1457
-            )
1458
-        ) {
1459
-            add_meta_box(
1460
-                'edit-reg-questions-mbox',
1461
-                esc_html__('Registration Form Answers', 'event_espresso'),
1462
-                array($this, '_reg_questions_meta_box'),
1463
-                $this->wp_page_slug,
1464
-                'normal',
1465
-                'high'
1466
-            );
1467
-        }
1468
-        add_meta_box(
1469
-            'edit-reg-registrant-mbox',
1470
-            esc_html__('Contact Details', 'event_espresso'),
1471
-            array($this, '_reg_registrant_side_meta_box'),
1472
-            $this->wp_page_slug,
1473
-            'side',
1474
-            'high'
1475
-        );
1476
-        if ($this->_registration->group_size() > 1) {
1477
-            add_meta_box(
1478
-                'edit-reg-attendees-mbox',
1479
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1480
-                array($this, '_reg_attendees_meta_box'),
1481
-                $this->wp_page_slug,
1482
-                'normal',
1483
-                'high'
1484
-            );
1485
-        }
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * set_reg_status_buttons_metabox
1491
-     *
1492
-     * @access protected
1493
-     * @return string
1494
-     * @throws EE_Error
1495
-     * @throws EntityNotFoundException
1496
-     * @throws InvalidArgumentException
1497
-     * @throws InvalidDataTypeException
1498
-     * @throws InvalidInterfaceException
1499
-     * @throws ReflectionException
1500
-     */
1501
-    public function set_reg_status_buttons_metabox()
1502
-    {
1503
-        $this->_set_registration_object();
1504
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1505
-        echo $change_reg_status_form->form_open(
1506
-            self::add_query_args_and_nonce(
1507
-                array(
1508
-                    'action' => 'change_reg_status',
1509
-                ),
1510
-                REG_ADMIN_URL
1511
-            )
1512
-        );
1513
-        echo $change_reg_status_form->get_html();
1514
-        echo $change_reg_status_form->form_close();
1515
-    }
1516
-
1517
-
1518
-    /**
1519
-     * @return EE_Form_Section_Proper
1520
-     * @throws EE_Error
1521
-     * @throws InvalidArgumentException
1522
-     * @throws InvalidDataTypeException
1523
-     * @throws InvalidInterfaceException
1524
-     * @throws EntityNotFoundException
1525
-     * @throws ReflectionException
1526
-     */
1527
-    protected function _generate_reg_status_change_form()
1528
-    {
1529
-        $reg_status_change_form_array = array(
1530
-            'name'            => 'reg_status_change_form',
1531
-            'html_id'         => 'reg-status-change-form',
1532
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1533
-            'subsections'     => array(
1534
-                'return'             => new EE_Hidden_Input(
1535
-                    array(
1536
-                        'name'    => 'return',
1537
-                        'default' => 'view_registration',
1538
-                    )
1539
-                ),
1540
-                'REG_ID'             => new EE_Hidden_Input(
1541
-                    array(
1542
-                        'name'    => 'REG_ID',
1543
-                        'default' => $this->_registration->ID(),
1544
-                    )
1545
-                ),
1546
-                'current_status'     => new EE_Form_Section_HTML(
1547
-                    EEH_HTML::table(
1548
-                        EEH_HTML::tr(
1549
-                            EEH_HTML::th(
1550
-                                EEH_HTML::label(
1551
-                                    EEH_HTML::strong(
1552
-                                        esc_html__('Current Registration Status', 'event_espresso')
1553
-                                    )
1554
-                                )
1555
-                            )
1556
-                            . EEH_HTML::td(
1557
-                                EEH_HTML::strong(
1558
-                                    $this->_registration->pretty_status(),
1559
-                                    '',
1560
-                                    'status-' . $this->_registration->status_ID(),
1561
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1562
-                                )
1563
-                            )
1564
-                        )
1565
-                    )
1566
-                )
1567
-            )
1568
-        );
1569
-        if (
1570
-            EE_Registry::instance()->CAP->current_user_can(
1571
-                'ee_edit_registration',
1572
-                'toggle_registration_status',
1573
-                $this->_registration->ID()
1574
-            )
1575
-        ) {
1576
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1577
-                $this->_get_reg_statuses(),
1578
-                array(
1579
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1580
-                    'default'         => $this->_registration->status_ID(),
1581
-                )
1582
-            );
1583
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1584
-                array(
1585
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1586
-                    'default'         => false,
1587
-                    'html_help_text'  => esc_html__(
1588
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1589
-                        'event_espresso'
1590
-                    )
1591
-                )
1592
-            );
1593
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1594
-                array(
1595
-                    'html_class'      => 'button-primary',
1596
-                    'html_label_text' => '&nbsp;',
1597
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1598
-                )
1599
-            );
1600
-        }
1601
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1602
-    }
1603
-
1604
-
1605
-    /**
1606
-     * Returns an array of all the buttons for the various statuses and switch status actions
1607
-     *
1608
-     * @return array
1609
-     * @throws EE_Error
1610
-     * @throws InvalidArgumentException
1611
-     * @throws InvalidDataTypeException
1612
-     * @throws InvalidInterfaceException
1613
-     * @throws EntityNotFoundException
1614
-     */
1615
-    protected function _get_reg_statuses()
1616
-    {
1617
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1618
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1619
-        // get current reg status
1620
-        $current_status = $this->_registration->status_ID();
1621
-        // is registration for free event? This will determine whether to display the pending payment option
1622
-        if (
1623
-            $current_status !== EEM_Registration::status_id_pending_payment
1624
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1625
-        ) {
1626
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1627
-        }
1628
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1629
-    }
1630
-
1631
-
1632
-    /**
1633
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1634
-     *
1635
-     * @param bool $status REG status given for changing registrations to.
1636
-     * @param bool $notify Whether to send messages notifications or not.
1637
-     * @return array (array with reg_id(s) updated and whether update was successful.
1638
-     * @throws DomainException
1639
-     * @throws EE_Error
1640
-     * @throws EntityNotFoundException
1641
-     * @throws InvalidArgumentException
1642
-     * @throws InvalidDataTypeException
1643
-     * @throws InvalidInterfaceException
1644
-     * @throws ReflectionException
1645
-     * @throws RuntimeException
1646
-     */
1647
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1648
-    {
1649
-        if (isset($this->_req_data['reg_status_change_form'])) {
1650
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1651
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1652
-                : array();
1653
-        } else {
1654
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1655
-                ? (array) $this->_req_data['_REG_ID']
1656
-                : array();
1657
-        }
1658
-        // sanitize $REG_IDs
1659
-        $REG_IDs = array_map('absint', $REG_IDs);
1660
-        // and remove empty entries
1661
-        $REG_IDs = array_filter($REG_IDs);
1662
-
1663
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1664
-
1665
-        /**
1666
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1667
-         * Currently this value is used downstream by the _process_resend_registration method.
1668
-         *
1669
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1670
-         * @param bool                     $status           The status registrations were changed to.
1671
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1672
-         * @param Registrations_Admin_Page $admin_page_object
1673
-         */
1674
-        $this->_req_data['_REG_ID'] = apply_filters(
1675
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1676
-            $result['REG_ID'],
1677
-            $status,
1678
-            $result['success'],
1679
-            $this
1680
-        );
1681
-
1682
-        // notify?
1683
-        if (
1684
-            $notify
1685
-            && $result['success']
1686
-            && ! empty($this->_req_data['_REG_ID'])
1687
-            && EE_Registry::instance()->CAP->current_user_can(
1688
-                'ee_send_message',
1689
-                'espresso_registrations_resend_registration'
1690
-            )
1691
-        ) {
1692
-            $this->_process_resend_registration();
1693
-        }
1694
-        return $result;
1695
-    }
1696
-
1697
-
1698
-    /**
1699
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1700
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1701
-     *
1702
-     * @param array  $REG_IDs
1703
-     * @param string $status
1704
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1705
-     *                        slug sent with setting the registration status.
1706
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1707
-     * @throws EE_Error
1708
-     * @throws InvalidArgumentException
1709
-     * @throws InvalidDataTypeException
1710
-     * @throws InvalidInterfaceException
1711
-     * @throws ReflectionException
1712
-     * @throws RuntimeException
1713
-     * @throws EntityNotFoundException
1714
-     * @throws DomainException
1715
-     */
1716
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1717
-    {
1718
-        $success = false;
1719
-        // typecast $REG_IDs
1720
-        $REG_IDs = (array) $REG_IDs;
1721
-        if (! empty($REG_IDs)) {
1722
-            $success = true;
1723
-            // set default status if none is passed
1724
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1725
-            $status_context = $notify
1726
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1727
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1728
-            // loop through REG_ID's and change status
1729
-            foreach ($REG_IDs as $REG_ID) {
1730
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1731
-                if ($registration instanceof EE_Registration) {
1732
-                    $registration->set_status(
1733
-                        $status,
1734
-                        false,
1735
-                        new Context(
1736
-                            $status_context,
1737
-                            esc_html__(
1738
-                                'Manually triggered status change on a Registration Admin Page route.',
1739
-                                'event_espresso'
1740
-                            )
1741
-                        )
1742
-                    );
1743
-                    $result = $registration->save();
1744
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1745
-                    $success = $result !== false ? $success : false;
1746
-                }
1747
-            }
1748
-        }
1749
-
1750
-        // return $success and processed registrations
1751
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1752
-    }
1753
-
1754
-
1755
-    /**
1756
-     * Common logic for setting up success message and redirecting to appropriate route
1757
-     *
1758
-     * @param string $STS_ID status id for the registration changed to
1759
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1760
-     * @return void
1761
-     * @throws DomainException
1762
-     * @throws EE_Error
1763
-     * @throws EntityNotFoundException
1764
-     * @throws InvalidArgumentException
1765
-     * @throws InvalidDataTypeException
1766
-     * @throws InvalidInterfaceException
1767
-     * @throws ReflectionException
1768
-     * @throws RuntimeException
1769
-     */
1770
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1771
-    {
1772
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1773
-            : array('success' => false);
1774
-        $success = isset($result['success']) && $result['success'];
1775
-        // setup success message
1776
-        if ($success) {
1777
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1778
-                $msg = sprintf(
1779
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1780
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1781
-                );
1782
-            } else {
1783
-                $msg = sprintf(
1784
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1785
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1786
-                );
1787
-            }
1788
-            EE_Error::add_success($msg);
1789
-        } else {
1790
-            EE_Error::add_error(
1791
-                esc_html__(
1792
-                    'Something went wrong, and the status was not changed',
1793
-                    'event_espresso'
1794
-                ),
1795
-                __FILE__,
1796
-                __LINE__,
1797
-                __FUNCTION__
1798
-            );
1799
-        }
1800
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1801
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1802
-        } else {
1803
-            $route = array('action' => 'default');
1804
-        }
1805
-        $route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1806
-        $this->_redirect_after_action($success, '', '', $route, true);
1807
-    }
1808
-
1809
-
1810
-    /**
1811
-     * incoming reg status change from reg details page.
1812
-     *
1813
-     * @return void
1814
-     * @throws EE_Error
1815
-     * @throws EntityNotFoundException
1816
-     * @throws InvalidArgumentException
1817
-     * @throws InvalidDataTypeException
1818
-     * @throws InvalidInterfaceException
1819
-     * @throws ReflectionException
1820
-     * @throws RuntimeException
1821
-     * @throws DomainException
1822
-     */
1823
-    protected function _change_reg_status()
1824
-    {
1825
-        $this->_req_data['return'] = 'view_registration';
1826
-        // set notify based on whether the send notifications toggle is set or not
1827
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1828
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1829
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1830
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1831
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1832
-            case EEM_Registration::status_id_approved:
1833
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1834
-                $this->approve_registration($notify);
1835
-                break;
1836
-            case EEM_Registration::status_id_pending_payment:
1837
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1838
-                $this->pending_registration($notify);
1839
-                break;
1840
-            case EEM_Registration::status_id_not_approved:
1841
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1842
-                $this->not_approve_registration($notify);
1843
-                break;
1844
-            case EEM_Registration::status_id_declined:
1845
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1846
-                $this->decline_registration($notify);
1847
-                break;
1848
-            case EEM_Registration::status_id_cancelled:
1849
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1850
-                $this->cancel_registration($notify);
1851
-                break;
1852
-            case EEM_Registration::status_id_wait_list:
1853
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1854
-                $this->wait_list_registration($notify);
1855
-                break;
1856
-            case EEM_Registration::status_id_incomplete:
1857
-            default:
1858
-                $result['success'] = false;
1859
-                unset($this->_req_data['return']);
1860
-                $this->_reg_status_change_return('', false);
1861
-                break;
1862
-        }
1863
-    }
1864
-
1865
-
1866
-    /**
1867
-     * Callback for bulk action routes.
1868
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1869
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1870
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1871
-     * when an action is happening on just a single registration).
1872
-     *
1873
-     * @param      $action
1874
-     * @param bool $notify
1875
-     */
1876
-    protected function bulk_action_on_registrations($action, $notify = false)
1877
-    {
1878
-        do_action(
1879
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1880
-            $this,
1881
-            $action,
1882
-            $notify
1883
-        );
1884
-        $method = $action . '_registration';
1885
-        if (method_exists($this, $method)) {
1886
-            $this->$method($notify);
1887
-        }
1888
-    }
1889
-
1890
-
1891
-    /**
1892
-     * approve_registration
1893
-     *
1894
-     * @access protected
1895
-     * @param bool $notify whether or not to notify the registrant about their approval.
1896
-     * @return void
1897
-     * @throws EE_Error
1898
-     * @throws EntityNotFoundException
1899
-     * @throws InvalidArgumentException
1900
-     * @throws InvalidDataTypeException
1901
-     * @throws InvalidInterfaceException
1902
-     * @throws ReflectionException
1903
-     * @throws RuntimeException
1904
-     * @throws DomainException
1905
-     */
1906
-    protected function approve_registration($notify = false)
1907
-    {
1908
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1909
-    }
1910
-
1911
-
1912
-    /**
1913
-     *        decline_registration
1914
-     *
1915
-     * @access protected
1916
-     * @param bool $notify whether or not to notify the registrant about their status change.
1917
-     * @return void
1918
-     * @throws EE_Error
1919
-     * @throws EntityNotFoundException
1920
-     * @throws InvalidArgumentException
1921
-     * @throws InvalidDataTypeException
1922
-     * @throws InvalidInterfaceException
1923
-     * @throws ReflectionException
1924
-     * @throws RuntimeException
1925
-     * @throws DomainException
1926
-     */
1927
-    protected function decline_registration($notify = false)
1928
-    {
1929
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1930
-    }
1931
-
1932
-
1933
-    /**
1934
-     *        cancel_registration
1935
-     *
1936
-     * @access protected
1937
-     * @param bool $notify whether or not to notify the registrant about their status change.
1938
-     * @return void
1939
-     * @throws EE_Error
1940
-     * @throws EntityNotFoundException
1941
-     * @throws InvalidArgumentException
1942
-     * @throws InvalidDataTypeException
1943
-     * @throws InvalidInterfaceException
1944
-     * @throws ReflectionException
1945
-     * @throws RuntimeException
1946
-     * @throws DomainException
1947
-     */
1948
-    protected function cancel_registration($notify = false)
1949
-    {
1950
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1951
-    }
1952
-
1953
-
1954
-    /**
1955
-     *        not_approve_registration
1956
-     *
1957
-     * @access protected
1958
-     * @param bool $notify whether or not to notify the registrant about their status change.
1959
-     * @return void
1960
-     * @throws EE_Error
1961
-     * @throws EntityNotFoundException
1962
-     * @throws InvalidArgumentException
1963
-     * @throws InvalidDataTypeException
1964
-     * @throws InvalidInterfaceException
1965
-     * @throws ReflectionException
1966
-     * @throws RuntimeException
1967
-     * @throws DomainException
1968
-     */
1969
-    protected function not_approve_registration($notify = false)
1970
-    {
1971
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1972
-    }
1973
-
1974
-
1975
-    /**
1976
-     *        decline_registration
1977
-     *
1978
-     * @access protected
1979
-     * @param bool $notify whether or not to notify the registrant about their status change.
1980
-     * @return void
1981
-     * @throws EE_Error
1982
-     * @throws EntityNotFoundException
1983
-     * @throws InvalidArgumentException
1984
-     * @throws InvalidDataTypeException
1985
-     * @throws InvalidInterfaceException
1986
-     * @throws ReflectionException
1987
-     * @throws RuntimeException
1988
-     * @throws DomainException
1989
-     */
1990
-    protected function pending_registration($notify = false)
1991
-    {
1992
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * waitlist_registration
1998
-     *
1999
-     * @access protected
2000
-     * @param bool $notify whether or not to notify the registrant about their status change.
2001
-     * @return void
2002
-     * @throws EE_Error
2003
-     * @throws EntityNotFoundException
2004
-     * @throws InvalidArgumentException
2005
-     * @throws InvalidDataTypeException
2006
-     * @throws InvalidInterfaceException
2007
-     * @throws ReflectionException
2008
-     * @throws RuntimeException
2009
-     * @throws DomainException
2010
-     */
2011
-    protected function wait_list_registration($notify = false)
2012
-    {
2013
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2014
-    }
2015
-
2016
-
2017
-    /**
2018
-     *        generates HTML for the Registration main meta box
2019
-     *
2020
-     * @access public
2021
-     * @return void
2022
-     * @throws DomainException
2023
-     * @throws EE_Error
2024
-     * @throws InvalidArgumentException
2025
-     * @throws InvalidDataTypeException
2026
-     * @throws InvalidInterfaceException
2027
-     * @throws ReflectionException
2028
-     * @throws EntityNotFoundException
2029
-     */
2030
-    public function _reg_details_meta_box()
2031
-    {
2032
-        EEH_Autoloader::register_line_item_display_autoloaders();
2033
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2034
-        EE_Registry::instance()->load_helper('Line_Item');
2035
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2036
-            : EE_Transaction::new_instance();
2037
-        $this->_session = $transaction->session_data();
2038
-        $filters = new EE_Line_Item_Filter_Collection();
2039
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2040
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2041
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2042
-            $filters,
2043
-            $transaction->total_line_item()
2044
-        );
2045
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2046
-        $line_item_display = new EE_Line_Item_Display(
2047
-            'reg_admin_table',
2048
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2049
-        );
2050
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2051
-            $filtered_line_item_tree,
2052
-            array('EE_Registration' => $this->_registration)
2053
-        );
2054
-        $attendee = $this->_registration->attendee();
2055
-        if (
2056
-            EE_Registry::instance()->CAP->current_user_can(
2057
-                'ee_read_transaction',
2058
-                'espresso_transactions_view_transaction'
2059
-            )
2060
-        ) {
2061
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2062
-                EE_Admin_Page::add_query_args_and_nonce(
2063
-                    array(
2064
-                        'action' => 'view_transaction',
2065
-                        'TXN_ID' => $transaction->ID(),
2066
-                    ),
2067
-                    TXN_ADMIN_URL
2068
-                ),
2069
-                esc_html__(' View Transaction', 'event_espresso'),
2070
-                'button secondary-button right',
2071
-                'dashicons dashicons-cart'
2072
-            );
2073
-        } else {
2074
-            $this->_template_args['view_transaction_button'] = '';
2075
-        }
2076
-        if (
2077
-            $attendee instanceof EE_Attendee
2078
-            && EE_Registry::instance()->CAP->current_user_can(
2079
-                'ee_send_message',
2080
-                'espresso_registrations_resend_registration'
2081
-            )
2082
-        ) {
2083
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2084
-                EE_Admin_Page::add_query_args_and_nonce(
2085
-                    array(
2086
-                        'action'      => 'resend_registration',
2087
-                        '_REG_ID'     => $this->_registration->ID(),
2088
-                        'redirect_to' => 'view_registration',
2089
-                    ),
2090
-                    REG_ADMIN_URL
2091
-                ),
2092
-                esc_html__(' Resend Registration', 'event_espresso'),
2093
-                'button secondary-button right',
2094
-                'dashicons dashicons-email-alt'
2095
-            );
2096
-        } else {
2097
-            $this->_template_args['resend_registration_button'] = '';
2098
-        }
2099
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2100
-        $payment = $transaction->get_first_related('Payment');
2101
-        $payment = ! $payment instanceof EE_Payment
2102
-            ? EE_Payment::new_instance()
2103
-            : $payment;
2104
-        $payment_method = $payment->get_first_related('Payment_Method');
2105
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2106
-            ? EE_Payment_Method::new_instance()
2107
-            : $payment_method;
2108
-        $reg_details = array(
2109
-            'payment_method'       => $payment_method->name(),
2110
-            'response_msg'         => $payment->gateway_response(),
2111
-            'registration_id'      => $this->_registration->get('REG_code'),
2112
-            'registration_session' => $this->_registration->session_ID(),
2113
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2114
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2115
-        );
2116
-        if (isset($reg_details['registration_id'])) {
2117
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2118
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2119
-                'Registration ID',
2120
-                'event_espresso'
2121
-            );
2122
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2123
-        }
2124
-        if (isset($reg_details['payment_method'])) {
2125
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2126
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2127
-                'Most Recent Payment Method',
2128
-                'event_espresso'
2129
-            );
2130
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2131
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2132
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2133
-                'Payment method response',
2134
-                'event_espresso'
2135
-            );
2136
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2137
-        }
2138
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2139
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2140
-            'Registration Session',
2141
-            'event_espresso'
2142
-        );
2143
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2144
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2145
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2146
-            'Registration placed from IP',
2147
-            'event_espresso'
2148
-        );
2149
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2150
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2151
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2152
-            'Registrant User Agent',
2153
-            'event_espresso'
2154
-        );
2155
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2156
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2157
-            array(
2158
-                'action'   => 'default',
2159
-                'event_id' => $this->_registration->event_ID(),
2160
-            ),
2161
-            REG_ADMIN_URL
2162
-        );
2163
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2164
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2165
-        $template_path =
2166
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2167
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2168
-    }
2169
-
2170
-
2171
-    /**
2172
-     * generates HTML for the Registration Questions meta box.
2173
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2174
-     * otherwise uses new forms system
2175
-     *
2176
-     * @access public
2177
-     * @return void
2178
-     * @throws DomainException
2179
-     * @throws EE_Error
2180
-     * @throws InvalidArgumentException
2181
-     * @throws InvalidDataTypeException
2182
-     * @throws InvalidInterfaceException
2183
-     * @throws ReflectionException
2184
-     */
2185
-    public function _reg_questions_meta_box()
2186
-    {
2187
-        // allow someone to override this method entirely
2188
-        if (
2189
-            apply_filters(
2190
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2191
-                true,
2192
-                $this,
2193
-                $this->_registration
2194
-            )
2195
-        ) {
2196
-            $form = $this->_get_reg_custom_questions_form(
2197
-                $this->_registration->ID()
2198
-            );
2199
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2200
-                ? $form->get_html_and_js()
2201
-                : '';
2202
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2203
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2204
-            $template_path =
2205
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2206
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2207
-        }
2208
-    }
2209
-
2210
-
2211
-    /**
2212
-     * form_before_question_group
2213
-     *
2214
-     * @deprecated    as of 4.8.32.rc.000
2215
-     * @access        public
2216
-     * @param        string $output
2217
-     * @return        string
2218
-     */
2219
-    public function form_before_question_group($output)
2220
-    {
2221
-        EE_Error::doing_it_wrong(
2222
-            __CLASS__ . '::' . __FUNCTION__,
2223
-            esc_html__(
2224
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2225
-                'event_espresso'
2226
-            ),
2227
-            '4.8.32.rc.000'
2228
-        );
2229
-        return '
21
+	/**
22
+	 * @var EE_Registration
23
+	 */
24
+	private $_registration;
25
+
26
+	/**
27
+	 * @var EE_Event
28
+	 */
29
+	private $_reg_event;
30
+
31
+	/**
32
+	 * @var EE_Session
33
+	 */
34
+	private $_session;
35
+
36
+	private static $_reg_status;
37
+
38
+	/**
39
+	 * Form for displaying the custom questions for this registration.
40
+	 * This gets used a few times throughout the request so its best to cache it
41
+	 *
42
+	 * @var EE_Registration_Custom_Questions_Form
43
+	 */
44
+	protected $_reg_custom_questions_form;
45
+
46
+	/**
47
+	 * @var EEM_Registration $registration_model
48
+	 */
49
+	private $registration_model;
50
+
51
+	/**
52
+	 * @var EEM_Attendee $attendee_model
53
+	 */
54
+	private $attendee_model;
55
+
56
+	/**
57
+	 * @var EEM_Event $event_model
58
+	 */
59
+	private $event_model;
60
+
61
+	/**
62
+	 * @var EEM_Status $status_model
63
+	 */
64
+	private $status_model;
65
+
66
+
67
+	/**
68
+	 * @param bool $routing
69
+	 * @throws EE_Error
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws ReflectionException
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		parent::__construct($routing);
78
+		add_action('wp_loaded', array($this, 'wp_loaded'));
79
+	}
80
+
81
+	/**
82
+	 * @return EEM_Registration
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @since 4.10.2.p
87
+	 */
88
+	protected function getRegistrationModel()
89
+	{
90
+		if (! $this->registration_model instanceof EEM_Registration) {
91
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
92
+		}
93
+		return $this->registration_model;
94
+	}
95
+
96
+	/**
97
+	 * @return EEM_Attendee
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 * @since 4.10.2.p
102
+	 */
103
+	protected function getAttendeeModel()
104
+	{
105
+		if (! $this->attendee_model instanceof EEM_Attendee) {
106
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
107
+		}
108
+		return $this->attendee_model;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Event
114
+	 * @throws InvalidArgumentException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws InvalidInterfaceException
117
+	 * @since 4.10.2.p
118
+	 */
119
+	protected function getEventModel()
120
+	{
121
+		if (! $this->event_model instanceof EEM_Event) {
122
+			$this->event_model = $this->loader->getShared('EEM_Event');
123
+		}
124
+		return $this->event_model;
125
+	}
126
+
127
+	/**
128
+	 * @return EEM_Status
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidInterfaceException
132
+	 * @since 4.10.2.p
133
+	 */
134
+	protected function getStatusModel()
135
+	{
136
+		if (! $this->status_model instanceof EEM_Status) {
137
+			$this->status_model = $this->loader->getShared('EEM_Status');
138
+		}
139
+		return $this->status_model;
140
+	}
141
+
142
+
143
+	public function wp_loaded()
144
+	{
145
+		// when adding a new registration...
146
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
+			EE_System::do_not_cache();
148
+			if (
149
+				! isset($this->_req_data['processing_registration'])
150
+				|| absint($this->_req_data['processing_registration']) !== 1
151
+			) {
152
+				// and it's NOT the attendee information reg step
153
+				// force cookie expiration by setting time to last week
154
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
155
+				// and update the global
156
+				$_COOKIE['ee_registration_added'] = 0;
157
+			}
158
+		}
159
+	}
160
+
161
+
162
+	protected function _init_page_props()
163
+	{
164
+		$this->page_slug = REG_PG_SLUG;
165
+		$this->_admin_base_url = REG_ADMIN_URL;
166
+		$this->_admin_base_path = REG_ADMIN;
167
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
168
+		$this->_cpt_routes = array(
169
+			'add_new_attendee' => 'espresso_attendees',
170
+			'edit_attendee'    => 'espresso_attendees',
171
+			'insert_attendee'  => 'espresso_attendees',
172
+			'update_attendee'  => 'espresso_attendees',
173
+		);
174
+		$this->_cpt_model_names = array(
175
+			'add_new_attendee' => 'EEM_Attendee',
176
+			'edit_attendee'    => 'EEM_Attendee',
177
+		);
178
+		$this->_cpt_edit_routes = array(
179
+			'espresso_attendees' => 'edit_attendee',
180
+		);
181
+		$this->_pagenow_map = array(
182
+			'add_new_attendee' => 'post-new.php',
183
+			'edit_attendee'    => 'post.php',
184
+			'trash'            => 'post.php',
185
+		);
186
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
187
+		// add filters so that the comment urls don't take users to a confusing 404 page
188
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
189
+	}
190
+
191
+
192
+	public function clear_comment_link($link, $comment, $args)
193
+	{
194
+		// gotta make sure this only happens on this route
195
+		$post_type = get_post_type($comment->comment_post_ID);
196
+		if ($post_type === 'espresso_attendees') {
197
+			return '#commentsdiv';
198
+		}
199
+		return $link;
200
+	}
201
+
202
+
203
+	protected function _ajax_hooks()
204
+	{
205
+		// todo: all hooks for registrations ajax goes in here
206
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
207
+	}
208
+
209
+
210
+	protected function _define_page_props()
211
+	{
212
+		$this->_admin_page_title = $this->page_label;
213
+		$this->_labels = array(
214
+			'buttons'                      => array(
215
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
216
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
217
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
218
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
219
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
220
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
221
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
222
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
223
+			),
224
+			'publishbox'                   => array(
225
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
226
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
227
+			),
228
+			'hide_add_button_on_cpt_route' => array(
229
+				'edit_attendee' => true,
230
+			),
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 *        grab url requests and route them
237
+	 *
238
+	 * @access private
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 */
242
+	public function _set_page_routes()
243
+	{
244
+		$this->_get_registration_status_array();
245
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
246
+			? $this->_req_data['_REG_ID'] : 0;
247
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
248
+			? $this->_req_data['reg_status_change_form']['REG_ID']
249
+			: $reg_id;
250
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
251
+			? $this->_req_data['ATT_ID'] : 0;
252
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
253
+			? $this->_req_data['post']
254
+			: $att_id;
255
+		$this->_page_routes = array(
256
+			'default'                             => array(
257
+				'func'       => '_registrations_overview_list_table',
258
+				'capability' => 'ee_read_registrations',
259
+			),
260
+			'view_registration'                   => array(
261
+				'func'       => '_registration_details',
262
+				'capability' => 'ee_read_registration',
263
+				'obj_id'     => $reg_id,
264
+			),
265
+			'edit_registration'                   => array(
266
+				'func'               => '_update_attendee_registration_form',
267
+				'noheader'           => true,
268
+				'headers_sent_route' => 'view_registration',
269
+				'capability'         => 'ee_edit_registration',
270
+				'obj_id'             => $reg_id,
271
+				'_REG_ID'            => $reg_id,
272
+			),
273
+			'trash_registrations'                 => array(
274
+				'func'       => '_trash_or_restore_registrations',
275
+				'args'       => array('trash' => true),
276
+				'noheader'   => true,
277
+				'capability' => 'ee_delete_registrations',
278
+			),
279
+			'restore_registrations'               => array(
280
+				'func'       => '_trash_or_restore_registrations',
281
+				'args'       => array('trash' => false),
282
+				'noheader'   => true,
283
+				'capability' => 'ee_delete_registrations',
284
+			),
285
+			'delete_registrations'                => array(
286
+				'func'       => '_delete_registrations',
287
+				'noheader'   => true,
288
+				'capability' => 'ee_delete_registrations',
289
+			),
290
+			'new_registration'                    => array(
291
+				'func'       => 'new_registration',
292
+				'capability' => 'ee_edit_registrations',
293
+			),
294
+			'process_reg_step'                    => array(
295
+				'func'       => 'process_reg_step',
296
+				'noheader'   => true,
297
+				'capability' => 'ee_edit_registrations',
298
+			),
299
+			'redirect_to_txn'                     => array(
300
+				'func'       => 'redirect_to_txn',
301
+				'noheader'   => true,
302
+				'capability' => 'ee_edit_registrations',
303
+			),
304
+			'change_reg_status'                   => array(
305
+				'func'       => '_change_reg_status',
306
+				'noheader'   => true,
307
+				'capability' => 'ee_edit_registration',
308
+				'obj_id'     => $reg_id,
309
+			),
310
+			'approve_registration'                => array(
311
+				'func'       => 'approve_registration',
312
+				'noheader'   => true,
313
+				'capability' => 'ee_edit_registration',
314
+				'obj_id'     => $reg_id,
315
+			),
316
+			'approve_and_notify_registration'     => array(
317
+				'func'       => 'approve_registration',
318
+				'noheader'   => true,
319
+				'args'       => array(true),
320
+				'capability' => 'ee_edit_registration',
321
+				'obj_id'     => $reg_id,
322
+			),
323
+			'approve_registrations'               => array(
324
+				'func'       => 'bulk_action_on_registrations',
325
+				'noheader'   => true,
326
+				'capability' => 'ee_edit_registrations',
327
+				'args'       => array('approve'),
328
+			),
329
+			'approve_and_notify_registrations'    => array(
330
+				'func'       => 'bulk_action_on_registrations',
331
+				'noheader'   => true,
332
+				'capability' => 'ee_edit_registrations',
333
+				'args'       => array('approve', true),
334
+			),
335
+			'decline_registration'                => array(
336
+				'func'       => 'decline_registration',
337
+				'noheader'   => true,
338
+				'capability' => 'ee_edit_registration',
339
+				'obj_id'     => $reg_id,
340
+			),
341
+			'decline_and_notify_registration'     => array(
342
+				'func'       => 'decline_registration',
343
+				'noheader'   => true,
344
+				'args'       => array(true),
345
+				'capability' => 'ee_edit_registration',
346
+				'obj_id'     => $reg_id,
347
+			),
348
+			'decline_registrations'               => array(
349
+				'func'       => 'bulk_action_on_registrations',
350
+				'noheader'   => true,
351
+				'capability' => 'ee_edit_registrations',
352
+				'args'       => array('decline'),
353
+			),
354
+			'decline_and_notify_registrations'    => array(
355
+				'func'       => 'bulk_action_on_registrations',
356
+				'noheader'   => true,
357
+				'capability' => 'ee_edit_registrations',
358
+				'args'       => array('decline', true),
359
+			),
360
+			'pending_registration'                => array(
361
+				'func'       => 'pending_registration',
362
+				'noheader'   => true,
363
+				'capability' => 'ee_edit_registration',
364
+				'obj_id'     => $reg_id,
365
+			),
366
+			'pending_and_notify_registration'     => array(
367
+				'func'       => 'pending_registration',
368
+				'noheader'   => true,
369
+				'args'       => array(true),
370
+				'capability' => 'ee_edit_registration',
371
+				'obj_id'     => $reg_id,
372
+			),
373
+			'pending_registrations'               => array(
374
+				'func'       => 'bulk_action_on_registrations',
375
+				'noheader'   => true,
376
+				'capability' => 'ee_edit_registrations',
377
+				'args'       => array('pending'),
378
+			),
379
+			'pending_and_notify_registrations'    => array(
380
+				'func'       => 'bulk_action_on_registrations',
381
+				'noheader'   => true,
382
+				'capability' => 'ee_edit_registrations',
383
+				'args'       => array('pending', true),
384
+			),
385
+			'no_approve_registration'             => array(
386
+				'func'       => 'not_approve_registration',
387
+				'noheader'   => true,
388
+				'capability' => 'ee_edit_registration',
389
+				'obj_id'     => $reg_id,
390
+			),
391
+			'no_approve_and_notify_registration'  => array(
392
+				'func'       => 'not_approve_registration',
393
+				'noheader'   => true,
394
+				'args'       => array(true),
395
+				'capability' => 'ee_edit_registration',
396
+				'obj_id'     => $reg_id,
397
+			),
398
+			'no_approve_registrations'            => array(
399
+				'func'       => 'bulk_action_on_registrations',
400
+				'noheader'   => true,
401
+				'capability' => 'ee_edit_registrations',
402
+				'args'       => array('not_approve'),
403
+			),
404
+			'no_approve_and_notify_registrations' => array(
405
+				'func'       => 'bulk_action_on_registrations',
406
+				'noheader'   => true,
407
+				'capability' => 'ee_edit_registrations',
408
+				'args'       => array('not_approve', true),
409
+			),
410
+			'cancel_registration'                 => array(
411
+				'func'       => 'cancel_registration',
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_registration',
414
+				'obj_id'     => $reg_id,
415
+			),
416
+			'cancel_and_notify_registration'      => array(
417
+				'func'       => 'cancel_registration',
418
+				'noheader'   => true,
419
+				'args'       => array(true),
420
+				'capability' => 'ee_edit_registration',
421
+				'obj_id'     => $reg_id,
422
+			),
423
+			'cancel_registrations'                => array(
424
+				'func'       => 'bulk_action_on_registrations',
425
+				'noheader'   => true,
426
+				'capability' => 'ee_edit_registrations',
427
+				'args'       => array('cancel'),
428
+			),
429
+			'cancel_and_notify_registrations'     => array(
430
+				'func'       => 'bulk_action_on_registrations',
431
+				'noheader'   => true,
432
+				'capability' => 'ee_edit_registrations',
433
+				'args'       => array('cancel', true),
434
+			),
435
+			'wait_list_registration'              => array(
436
+				'func'       => 'wait_list_registration',
437
+				'noheader'   => true,
438
+				'capability' => 'ee_edit_registration',
439
+				'obj_id'     => $reg_id,
440
+			),
441
+			'wait_list_and_notify_registration'   => array(
442
+				'func'       => 'wait_list_registration',
443
+				'noheader'   => true,
444
+				'args'       => array(true),
445
+				'capability' => 'ee_edit_registration',
446
+				'obj_id'     => $reg_id,
447
+			),
448
+			'contact_list'                        => array(
449
+				'func'       => '_attendee_contact_list_table',
450
+				'capability' => 'ee_read_contacts',
451
+			),
452
+			'add_new_attendee'                    => array(
453
+				'func' => '_create_new_cpt_item',
454
+				'args' => array(
455
+					'new_attendee' => true,
456
+					'capability'   => 'ee_edit_contacts',
457
+				),
458
+			),
459
+			'edit_attendee'                       => array(
460
+				'func'       => '_edit_cpt_item',
461
+				'capability' => 'ee_edit_contacts',
462
+				'obj_id'     => $att_id,
463
+			),
464
+			'duplicate_attendee'                  => array(
465
+				'func'       => '_duplicate_attendee',
466
+				'noheader'   => true,
467
+				'capability' => 'ee_edit_contacts',
468
+				'obj_id'     => $att_id,
469
+			),
470
+			'insert_attendee'                     => array(
471
+				'func'       => '_insert_or_update_attendee',
472
+				'args'       => array(
473
+					'new_attendee' => true,
474
+				),
475
+				'noheader'   => true,
476
+				'capability' => 'ee_edit_contacts',
477
+			),
478
+			'update_attendee'                     => array(
479
+				'func'       => '_insert_or_update_attendee',
480
+				'args'       => array(
481
+					'new_attendee' => false,
482
+				),
483
+				'noheader'   => true,
484
+				'capability' => 'ee_edit_contacts',
485
+				'obj_id'     => $att_id,
486
+			),
487
+			'trash_attendees'                     => array(
488
+				'func'       => '_trash_or_restore_attendees',
489
+				'args'       => array(
490
+					'trash' => 'true',
491
+				),
492
+				'noheader'   => true,
493
+				'capability' => 'ee_delete_contacts',
494
+			),
495
+			'trash_attendee'                      => array(
496
+				'func'       => '_trash_or_restore_attendees',
497
+				'args'       => array(
498
+					'trash' => true,
499
+				),
500
+				'noheader'   => true,
501
+				'capability' => 'ee_delete_contacts',
502
+				'obj_id'     => $att_id,
503
+			),
504
+			'restore_attendees'                   => array(
505
+				'func'       => '_trash_or_restore_attendees',
506
+				'args'       => array(
507
+					'trash' => false,
508
+				),
509
+				'noheader'   => true,
510
+				'capability' => 'ee_delete_contacts',
511
+				'obj_id'     => $att_id,
512
+			),
513
+			'resend_registration'                 => array(
514
+				'func'       => '_resend_registration',
515
+				'noheader'   => true,
516
+				'capability' => 'ee_send_message',
517
+			),
518
+			'registrations_report'                => array(
519
+				'func'       => '_registrations_report',
520
+				'noheader'   => true,
521
+				'capability' => 'ee_read_registrations',
522
+			),
523
+			'contact_list_export'                 => array(
524
+				'func'       => '_contact_list_export',
525
+				'noheader'   => true,
526
+				'capability' => 'export',
527
+			),
528
+			'contact_list_report'                 => array(
529
+				'func'       => '_contact_list_report',
530
+				'noheader'   => true,
531
+				'capability' => 'ee_read_contacts',
532
+			),
533
+		);
534
+	}
535
+
536
+
537
+	protected function _set_page_config()
538
+	{
539
+		$this->_page_config = array(
540
+			'default'           => array(
541
+				'nav'           => array(
542
+					'label' => esc_html__('Overview', 'event_espresso'),
543
+					'order' => 5,
544
+				),
545
+				'help_tabs'     => array(
546
+					'registrations_overview_help_tab'                       => array(
547
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
548
+						'filename' => 'registrations_overview',
549
+					),
550
+					'registrations_overview_table_column_headings_help_tab' => array(
551
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
552
+						'filename' => 'registrations_overview_table_column_headings',
553
+					),
554
+					'registrations_overview_filters_help_tab'               => array(
555
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
556
+						'filename' => 'registrations_overview_filters',
557
+					),
558
+					'registrations_overview_views_help_tab'                 => array(
559
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
560
+						'filename' => 'registrations_overview_views',
561
+					),
562
+					'registrations_regoverview_other_help_tab'              => array(
563
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
564
+						'filename' => 'registrations_overview_other',
565
+					),
566
+				),
567
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
+				// 'help_tour'     => array('Registration_Overview_Help_Tour'),
569
+				'qtips'         => array('Registration_List_Table_Tips'),
570
+				'list_table'    => 'EE_Registrations_List_Table',
571
+				'require_nonce' => false,
572
+			),
573
+			'view_registration' => array(
574
+				'nav'           => array(
575
+					'label'      => esc_html__('REG Details', 'event_espresso'),
576
+					'order'      => 15,
577
+					'url'        => isset($this->_req_data['_REG_ID'])
578
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
579
+						: $this->_admin_base_url,
580
+					'persistent' => false,
581
+				),
582
+				'help_tabs'     => array(
583
+					'registrations_details_help_tab'                    => array(
584
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
585
+						'filename' => 'registrations_details',
586
+					),
587
+					'registrations_details_table_help_tab'              => array(
588
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
589
+						'filename' => 'registrations_details_table',
590
+					),
591
+					'registrations_details_form_answers_help_tab'       => array(
592
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
593
+						'filename' => 'registrations_details_form_answers',
594
+					),
595
+					'registrations_details_registrant_details_help_tab' => array(
596
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
597
+						'filename' => 'registrations_details_registrant_details',
598
+					),
599
+				),
600
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
601
+				// 'help_tour'     => array('Registration_Details_Help_Tour'),
602
+				'metaboxes'     => array_merge(
603
+					$this->_default_espresso_metaboxes,
604
+					array('_registration_details_metaboxes')
605
+				),
606
+				'require_nonce' => false,
607
+			),
608
+			'new_registration'  => array(
609
+				'nav'           => array(
610
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
+					'url'        => '#',
612
+					'order'      => 15,
613
+					'persistent' => false,
614
+				),
615
+				'metaboxes'     => $this->_default_espresso_metaboxes,
616
+				'labels'        => array(
617
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
+				),
619
+				'require_nonce' => false,
620
+			),
621
+			'add_new_attendee'  => array(
622
+				'nav'           => array(
623
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
624
+					'order'      => 15,
625
+					'persistent' => false,
626
+				),
627
+				'metaboxes'     => array_merge(
628
+					$this->_default_espresso_metaboxes,
629
+					array('_publish_post_box', 'attendee_editor_metaboxes')
630
+				),
631
+				'require_nonce' => false,
632
+			),
633
+			'edit_attendee'     => array(
634
+				'nav'           => array(
635
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
+					'order'      => 15,
637
+					'persistent' => false,
638
+					'url'        => isset($this->_req_data['ATT_ID'])
639
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
640
+						: $this->_admin_base_url,
641
+				),
642
+				'metaboxes'     => array('attendee_editor_metaboxes'),
643
+				'require_nonce' => false,
644
+			),
645
+			'contact_list'      => array(
646
+				'nav'           => array(
647
+					'label' => esc_html__('Contact List', 'event_espresso'),
648
+					'order' => 20,
649
+				),
650
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
651
+				'help_tabs'     => array(
652
+					'registrations_contact_list_help_tab'                       => array(
653
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
654
+						'filename' => 'registrations_contact_list',
655
+					),
656
+					'registrations_contact-list_table_column_headings_help_tab' => array(
657
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
658
+						'filename' => 'registrations_contact_list_table_column_headings',
659
+					),
660
+					'registrations_contact_list_views_help_tab'                 => array(
661
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
662
+						'filename' => 'registrations_contact_list_views',
663
+					),
664
+					'registrations_contact_list_other_help_tab'                 => array(
665
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
666
+						'filename' => 'registrations_contact_list_other',
667
+					),
668
+				),
669
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
670
+				// 'help_tour'     => array('Contact_List_Help_Tour'),
671
+				'metaboxes'     => array(),
672
+				'require_nonce' => false,
673
+			),
674
+			// override default cpt routes
675
+			'create_new'        => '',
676
+			'edit'              => '',
677
+		);
678
+	}
679
+
680
+
681
+	/**
682
+	 * The below methods aren't used by this class currently
683
+	 */
684
+	protected function _add_screen_options()
685
+	{
686
+	}
687
+
688
+
689
+	protected function _add_feature_pointers()
690
+	{
691
+	}
692
+
693
+
694
+	public function admin_init()
695
+	{
696
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
697
+			'click "Update Registration Questions" to save your changes',
698
+			'event_espresso'
699
+		);
700
+	}
701
+
702
+
703
+	public function admin_notices()
704
+	{
705
+	}
706
+
707
+
708
+	public function admin_footer_scripts()
709
+	{
710
+	}
711
+
712
+
713
+	/**
714
+	 *        get list of registration statuses
715
+	 *
716
+	 * @access private
717
+	 * @return void
718
+	 * @throws EE_Error
719
+	 */
720
+	private function _get_registration_status_array()
721
+	{
722
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
723
+	}
724
+
725
+
726
+	/**
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @since 4.10.2.p
731
+	 */
732
+	protected function _add_screen_options_default()
733
+	{
734
+		$this->_per_page_screen_option();
735
+	}
736
+
737
+
738
+	/**
739
+	 * @throws InvalidArgumentException
740
+	 * @throws InvalidDataTypeException
741
+	 * @throws InvalidInterfaceException
742
+	 * @since 4.10.2.p
743
+	 */
744
+	protected function _add_screen_options_contact_list()
745
+	{
746
+		$page_title = $this->_admin_page_title;
747
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
+		$this->_per_page_screen_option();
749
+		$this->_admin_page_title = $page_title;
750
+	}
751
+
752
+
753
+	public function load_scripts_styles()
754
+	{
755
+		// style
756
+		wp_register_style(
757
+			'espresso_reg',
758
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
+			array('ee-admin-css'),
760
+			EVENT_ESPRESSO_VERSION
761
+		);
762
+		wp_enqueue_style('espresso_reg');
763
+		// script
764
+		wp_register_script(
765
+			'espresso_reg',
766
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
768
+			EVENT_ESPRESSO_VERSION,
769
+			true
770
+		);
771
+		wp_enqueue_script('espresso_reg');
772
+	}
773
+
774
+
775
+	/**
776
+	 * @throws EE_Error
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidDataTypeException
779
+	 * @throws InvalidInterfaceException
780
+	 * @throws ReflectionException
781
+	 * @since 4.10.2.p
782
+	 */
783
+	public function load_scripts_styles_edit_attendee()
784
+	{
785
+		// stuff to only show up on our attendee edit details page.
786
+		$attendee_details_translations = array(
787
+			'att_publish_text' => sprintf(
788
+				/* translators: The date and time */
789
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
+			),
792
+		);
793
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
+		wp_enqueue_script('jquery-validate');
795
+	}
796
+
797
+
798
+	/**
799
+	 * @throws EE_Error
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 * @throws ReflectionException
804
+	 * @since 4.10.2.p
805
+	 */
806
+	public function load_scripts_styles_view_registration()
807
+	{
808
+		// styles
809
+		wp_enqueue_style('espresso-ui-theme');
810
+		// scripts
811
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
812
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
813
+	}
814
+
815
+
816
+	public function load_scripts_styles_contact_list()
817
+	{
818
+		wp_dequeue_style('espresso_reg');
819
+		wp_register_style(
820
+			'espresso_att',
821
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
+			array('ee-admin-css'),
823
+			EVENT_ESPRESSO_VERSION
824
+		);
825
+		wp_enqueue_style('espresso_att');
826
+	}
827
+
828
+
829
+	public function load_scripts_styles_new_registration()
830
+	{
831
+		wp_register_script(
832
+			'ee-spco-for-admin',
833
+			REG_ASSETS_URL . 'spco_for_admin.js',
834
+			array('underscore', 'jquery'),
835
+			EVENT_ESPRESSO_VERSION,
836
+			true
837
+		);
838
+		wp_enqueue_script('ee-spco-for-admin');
839
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
+		EE_Form_Section_Proper::wp_enqueue_scripts();
841
+		EED_Ticket_Selector::load_tckt_slctr_assets();
842
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
843
+	}
844
+
845
+
846
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
+	{
848
+		add_filter('FHEE_load_EE_messages', '__return_true');
849
+	}
850
+
851
+
852
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
+	{
854
+		add_filter('FHEE_load_EE_messages', '__return_true');
855
+	}
856
+
857
+
858
+	/**
859
+	 * @throws EE_Error
860
+	 * @throws InvalidArgumentException
861
+	 * @throws InvalidDataTypeException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws ReflectionException
864
+	 * @since 4.10.2.p
865
+	 */
866
+	protected function _set_list_table_views_default()
867
+	{
868
+		// for notification related bulk actions we need to make sure only active messengers have an option.
869
+		EED_Messages::set_autoloaders();
870
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
871
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
+		$active_mts = $message_resource_manager->list_of_active_message_types();
873
+		// key= bulk_action_slug, value= message type.
874
+		$match_array = array(
875
+			'approve_registrations'    => 'registration',
876
+			'decline_registrations'    => 'declined_registration',
877
+			'pending_registrations'    => 'pending_approval',
878
+			'no_approve_registrations' => 'not_approved_registration',
879
+			'cancel_registrations'     => 'cancelled_registration',
880
+		);
881
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
882
+			'ee_send_message',
883
+			'batch_send_messages'
884
+		);
885
+		/** setup reg status bulk actions **/
886
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
+				'Approve and Notify Registrations',
890
+				'event_espresso'
891
+			);
892
+		}
893
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
+				'Decline and Notify Registrations',
897
+				'event_espresso'
898
+			);
899
+		}
900
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
901
+			'Set Registrations to Pending Payment',
902
+			'event_espresso'
903
+		);
904
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
+				'Set Registrations to Pending Payment and Notify',
907
+				'event_espresso'
908
+			);
909
+		}
910
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
+			'Set Registrations to Not Approved',
912
+			'event_espresso'
913
+		);
914
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
+				'Set Registrations to Not Approved and Notify',
917
+				'event_espresso'
918
+			);
919
+		}
920
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
+				'Cancel Registrations and Notify',
924
+				'event_espresso'
925
+			);
926
+		}
927
+		$def_reg_status_actions = apply_filters(
928
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
+			$def_reg_status_actions,
930
+			$active_mts,
931
+			$can_send
932
+		);
933
+
934
+		$this->_views = array(
935
+			'all'   => array(
936
+				'slug'        => 'all',
937
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
+				'count'       => 0,
939
+				'bulk_action' => array_merge(
940
+					$def_reg_status_actions,
941
+					array(
942
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
+					)
944
+				),
945
+			),
946
+			'month' => array(
947
+				'slug'        => 'month',
948
+				'label'       => esc_html__('This Month', 'event_espresso'),
949
+				'count'       => 0,
950
+				'bulk_action' => array_merge(
951
+					$def_reg_status_actions,
952
+					array(
953
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
+					)
955
+				),
956
+			),
957
+			'today' => array(
958
+				'slug'        => 'today',
959
+				'label'       => sprintf(
960
+					esc_html__('Today - %s', 'event_espresso'),
961
+					date('M d, Y', current_time('timestamp'))
962
+				),
963
+				'count'       => 0,
964
+				'bulk_action' => array_merge(
965
+					$def_reg_status_actions,
966
+					array(
967
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
+					)
969
+				),
970
+			),
971
+		);
972
+		if (
973
+			EE_Registry::instance()->CAP->current_user_can(
974
+				'ee_delete_registrations',
975
+				'espresso_registrations_delete_registration'
976
+			)
977
+		) {
978
+			$this->_views['incomplete'] = array(
979
+				'slug'        => 'incomplete',
980
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
981
+				'count'       => 0,
982
+				'bulk_action' => array(
983
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
+				),
985
+			);
986
+			$this->_views['trash'] = array(
987
+				'slug'        => 'trash',
988
+				'label'       => esc_html__('Trash', 'event_espresso'),
989
+				'count'       => 0,
990
+				'bulk_action' => array(
991
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
+				),
994
+			);
995
+		}
996
+	}
997
+
998
+
999
+	protected function _set_list_table_views_contact_list()
1000
+	{
1001
+		$this->_views = array(
1002
+			'in_use' => array(
1003
+				'slug'        => 'in_use',
1004
+				'label'       => esc_html__('In Use', 'event_espresso'),
1005
+				'count'       => 0,
1006
+				'bulk_action' => array(
1007
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
+				),
1009
+			),
1010
+		);
1011
+		if (
1012
+			EE_Registry::instance()->CAP->current_user_can(
1013
+				'ee_delete_contacts',
1014
+				'espresso_registrations_trash_attendees'
1015
+			)
1016
+		) {
1017
+			$this->_views['trash'] = array(
1018
+				'slug'        => 'trash',
1019
+				'label'       => esc_html__('Trash', 'event_espresso'),
1020
+				'count'       => 0,
1021
+				'bulk_action' => array(
1022
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
+				),
1024
+			);
1025
+		}
1026
+	}
1027
+
1028
+
1029
+	protected function _registration_legend_items()
1030
+	{
1031
+		$fc_items = array(
1032
+			'star-icon'        => array(
1033
+				'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1034
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1035
+			),
1036
+			'view_details'     => array(
1037
+				'class' => 'dashicons dashicons-clipboard',
1038
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1039
+			),
1040
+			'edit_attendee'    => array(
1041
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1042
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1043
+			),
1044
+			'view_transaction' => array(
1045
+				'class' => 'dashicons dashicons-cart',
1046
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1047
+			),
1048
+			'view_invoice'     => array(
1049
+				'class' => 'dashicons dashicons-media-spreadsheet',
1050
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1051
+			),
1052
+		);
1053
+		if (
1054
+			EE_Registry::instance()->CAP->current_user_can(
1055
+				'ee_send_message',
1056
+				'espresso_registrations_resend_registration'
1057
+			)
1058
+		) {
1059
+			$fc_items['resend_registration'] = array(
1060
+				'class' => 'dashicons dashicons-email-alt',
1061
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1062
+			);
1063
+		} else {
1064
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1065
+		}
1066
+		if (
1067
+			EE_Registry::instance()->CAP->current_user_can(
1068
+				'ee_read_global_messages',
1069
+				'view_filtered_messages'
1070
+			)
1071
+		) {
1072
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1073
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1074
+				$fc_items['view_related_messages'] = array(
1075
+					'class' => $related_for_icon['css_class'],
1076
+					'desc'  => $related_for_icon['label'],
1077
+				);
1078
+			}
1079
+		}
1080
+		$sc_items = array(
1081
+			'approved_status'   => array(
1082
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1083
+				'desc'  => EEH_Template::pretty_status(
1084
+					EEM_Registration::status_id_approved,
1085
+					false,
1086
+					'sentence'
1087
+				),
1088
+			),
1089
+			'pending_status'    => array(
1090
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1091
+				'desc'  => EEH_Template::pretty_status(
1092
+					EEM_Registration::status_id_pending_payment,
1093
+					false,
1094
+					'sentence'
1095
+				),
1096
+			),
1097
+			'wait_list'         => array(
1098
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1099
+				'desc'  => EEH_Template::pretty_status(
1100
+					EEM_Registration::status_id_wait_list,
1101
+					false,
1102
+					'sentence'
1103
+				),
1104
+			),
1105
+			'incomplete_status' => array(
1106
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1107
+				'desc'  => EEH_Template::pretty_status(
1108
+					EEM_Registration::status_id_incomplete,
1109
+					false,
1110
+					'sentence'
1111
+				),
1112
+			),
1113
+			'not_approved'      => array(
1114
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1115
+				'desc'  => EEH_Template::pretty_status(
1116
+					EEM_Registration::status_id_not_approved,
1117
+					false,
1118
+					'sentence'
1119
+				),
1120
+			),
1121
+			'declined_status'   => array(
1122
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1123
+				'desc'  => EEH_Template::pretty_status(
1124
+					EEM_Registration::status_id_declined,
1125
+					false,
1126
+					'sentence'
1127
+				),
1128
+			),
1129
+			'cancelled_status'  => array(
1130
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1131
+				'desc'  => EEH_Template::pretty_status(
1132
+					EEM_Registration::status_id_cancelled,
1133
+					false,
1134
+					'sentence'
1135
+				),
1136
+			),
1137
+		);
1138
+		return array_merge($fc_items, $sc_items);
1139
+	}
1140
+
1141
+
1142
+
1143
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * @throws DomainException
1149
+	 * @throws EE_Error
1150
+	 * @throws InvalidArgumentException
1151
+	 * @throws InvalidDataTypeException
1152
+	 * @throws InvalidInterfaceException
1153
+	 * @throws ReflectionException
1154
+	 */
1155
+	protected function _registrations_overview_list_table()
1156
+	{
1157
+		$this->appendAddNewRegistrationButtonToPageTitle();
1158
+		$header_text = '';
1159
+		$admin_page_header_decorators = [
1160
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
+		];
1165
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1167
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1168
+		}
1169
+		$this->_template_args['admin_page_header'] = $header_text;
1170
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1171
+		$this->display_admin_list_table_page_with_no_sidebar();
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * @throws EE_Error
1177
+	 * @throws InvalidArgumentException
1178
+	 * @throws InvalidDataTypeException
1179
+	 * @throws InvalidInterfaceException
1180
+	 */
1181
+	private function appendAddNewRegistrationButtonToPageTitle()
1182
+	{
1183
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1184
+			? absint($this->_req_data['event_id'])
1185
+			: 0;
1186
+		if (
1187
+			$EVT_ID
1188
+			&& EE_Registry::instance()->CAP->current_user_can(
1189
+				'ee_edit_registrations',
1190
+				'espresso_registrations_new_registration',
1191
+				$EVT_ID
1192
+			)
1193
+		) {
1194
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
+				'new_registration',
1196
+				'add-registrant',
1197
+				array('event_id' => $EVT_ID),
1198
+				'add-new-h2'
1199
+			);
1200
+		}
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * This sets the _registration property for the registration details screen
1206
+	 *
1207
+	 * @access private
1208
+	 * @return bool
1209
+	 * @throws EE_Error
1210
+	 * @throws InvalidArgumentException
1211
+	 * @throws InvalidDataTypeException
1212
+	 * @throws InvalidInterfaceException
1213
+	 */
1214
+	private function _set_registration_object()
1215
+	{
1216
+		// get out if we've already set the object
1217
+		if ($this->_registration instanceof EE_Registration) {
1218
+			return true;
1219
+		}
1220
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1221
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1222
+			return true;
1223
+		}
1224
+		$error_msg = sprintf(
1225
+			esc_html__(
1226
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1227
+				'event_espresso'
1228
+			),
1229
+			$REG_ID
1230
+		);
1231
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1232
+		$this->_registration = null;
1233
+		return false;
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 * Used to retrieve registrations for the list table.
1239
+	 *
1240
+	 * @param int  $per_page
1241
+	 * @param bool $count
1242
+	 * @param bool $this_month
1243
+	 * @param bool $today
1244
+	 * @return EE_Registration[]|int
1245
+	 * @throws EE_Error
1246
+	 * @throws InvalidArgumentException
1247
+	 * @throws InvalidDataTypeException
1248
+	 * @throws InvalidInterfaceException
1249
+	 */
1250
+	public function get_registrations(
1251
+		$per_page = 10,
1252
+		$count = false,
1253
+		$this_month = false,
1254
+		$today = false
1255
+	) {
1256
+		if ($this_month) {
1257
+			$this->_req_data['status'] = 'month';
1258
+		}
1259
+		if ($today) {
1260
+			$this->_req_data['status'] = 'today';
1261
+		}
1262
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1263
+		/**
1264
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1265
+		 *
1266
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1267
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1268
+		 *                             or if you have the development copy of EE you can view this at the path:
1269
+		 *                             /docs/G--Model-System/model-query-params.md
1270
+		 */
1271
+		$query_params['group_by'] = '';
1272
+
1273
+		return $count
1274
+			? $this->getRegistrationModel()->count($query_params)
1275
+			/** @type EE_Registration[] */
1276
+			: $this->getRegistrationModel()->get_all($query_params);
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1282
+	 * Note: this listens to values on the request for some of the query parameters.
1283
+	 *
1284
+	 * @param array $request
1285
+	 * @param int   $per_page
1286
+	 * @param bool  $count
1287
+	 * @return array
1288
+	 * @throws EE_Error
1289
+	 * @throws InvalidArgumentException
1290
+	 * @throws InvalidDataTypeException
1291
+	 * @throws InvalidInterfaceException
1292
+	 */
1293
+	protected function _get_registration_query_parameters(
1294
+		$request = array(),
1295
+		$per_page = 10,
1296
+		$count = false
1297
+	) {
1298
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1299
+		$list_table_query_builder = $this->loader->getNew(
1300
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1301
+			[ $request ]
1302
+		);
1303
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1304
+	}
1305
+
1306
+
1307
+	public function get_registration_status_array()
1308
+	{
1309
+		return self::$_reg_status;
1310
+	}
1311
+
1312
+
1313
+
1314
+
1315
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1316
+	/**
1317
+	 *        generates HTML for the View Registration Details Admin page
1318
+	 *
1319
+	 * @access protected
1320
+	 * @return void
1321
+	 * @throws DomainException
1322
+	 * @throws EE_Error
1323
+	 * @throws InvalidArgumentException
1324
+	 * @throws InvalidDataTypeException
1325
+	 * @throws InvalidInterfaceException
1326
+	 * @throws EntityNotFoundException
1327
+	 * @throws ReflectionException
1328
+	 */
1329
+	protected function _registration_details()
1330
+	{
1331
+		$this->_template_args = array();
1332
+		$this->_set_registration_object();
1333
+		if (is_object($this->_registration)) {
1334
+			$transaction = $this->_registration->transaction()
1335
+				? $this->_registration->transaction()
1336
+				: EE_Transaction::new_instance();
1337
+			$this->_session = $transaction->session_data();
1338
+			$event_id = $this->_registration->event_ID();
1339
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1340
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1341
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1342
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1343
+			$this->_template_args['grand_total'] = $transaction->total();
1344
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1345
+			// link back to overview
1346
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1347
+			$this->_template_args['registration'] = $this->_registration;
1348
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1349
+				array(
1350
+					'action'   => 'default',
1351
+					'event_id' => $event_id,
1352
+				),
1353
+				REG_ADMIN_URL
1354
+			);
1355
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1356
+				array(
1357
+					'action' => 'default',
1358
+					'EVT_ID' => $event_id,
1359
+					'page'   => 'espresso_transactions',
1360
+				),
1361
+				admin_url('admin.php')
1362
+			);
1363
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1364
+				array(
1365
+					'page'   => 'espresso_events',
1366
+					'action' => 'edit',
1367
+					'post'   => $event_id,
1368
+				),
1369
+				admin_url('admin.php')
1370
+			);
1371
+			// next and previous links
1372
+			$next_reg = $this->_registration->next(
1373
+				null,
1374
+				array(),
1375
+				'REG_ID'
1376
+			);
1377
+			$this->_template_args['next_registration'] = $next_reg
1378
+				? $this->_next_link(
1379
+					EE_Admin_Page::add_query_args_and_nonce(
1380
+						array(
1381
+							'action'  => 'view_registration',
1382
+							'_REG_ID' => $next_reg['REG_ID'],
1383
+						),
1384
+						REG_ADMIN_URL
1385
+					),
1386
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1387
+				)
1388
+				: '';
1389
+			$previous_reg = $this->_registration->previous(
1390
+				null,
1391
+				array(),
1392
+				'REG_ID'
1393
+			);
1394
+			$this->_template_args['previous_registration'] = $previous_reg
1395
+				? $this->_previous_link(
1396
+					EE_Admin_Page::add_query_args_and_nonce(
1397
+						array(
1398
+							'action'  => 'view_registration',
1399
+							'_REG_ID' => $previous_reg['REG_ID'],
1400
+						),
1401
+						REG_ADMIN_URL
1402
+					),
1403
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1404
+				)
1405
+				: '';
1406
+			// grab header
1407
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1408
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1409
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1410
+				$template_path,
1411
+				$this->_template_args,
1412
+				true
1413
+			);
1414
+		} else {
1415
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1416
+		}
1417
+		// the details template wrapper
1418
+		$this->display_admin_page_with_sidebar();
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * @throws EE_Error
1424
+	 * @throws InvalidArgumentException
1425
+	 * @throws InvalidDataTypeException
1426
+	 * @throws InvalidInterfaceException
1427
+	 * @throws ReflectionException
1428
+	 * @since 4.10.2.p
1429
+	 */
1430
+	protected function _registration_details_metaboxes()
1431
+	{
1432
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1433
+		$this->_set_registration_object();
1434
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1435
+		add_meta_box(
1436
+			'edit-reg-status-mbox',
1437
+			esc_html__('Registration Status', 'event_espresso'),
1438
+			array($this, 'set_reg_status_buttons_metabox'),
1439
+			$this->wp_page_slug,
1440
+			'normal',
1441
+			'high'
1442
+		);
1443
+		add_meta_box(
1444
+			'edit-reg-details-mbox',
1445
+			esc_html__('Registration Details', 'event_espresso'),
1446
+			array($this, '_reg_details_meta_box'),
1447
+			$this->wp_page_slug,
1448
+			'normal',
1449
+			'high'
1450
+		);
1451
+		if (
1452
+			$attendee instanceof EE_Attendee
1453
+			&& EE_Registry::instance()->CAP->current_user_can(
1454
+				'ee_read_registration',
1455
+				'edit-reg-questions-mbox',
1456
+				$this->_registration->ID()
1457
+			)
1458
+		) {
1459
+			add_meta_box(
1460
+				'edit-reg-questions-mbox',
1461
+				esc_html__('Registration Form Answers', 'event_espresso'),
1462
+				array($this, '_reg_questions_meta_box'),
1463
+				$this->wp_page_slug,
1464
+				'normal',
1465
+				'high'
1466
+			);
1467
+		}
1468
+		add_meta_box(
1469
+			'edit-reg-registrant-mbox',
1470
+			esc_html__('Contact Details', 'event_espresso'),
1471
+			array($this, '_reg_registrant_side_meta_box'),
1472
+			$this->wp_page_slug,
1473
+			'side',
1474
+			'high'
1475
+		);
1476
+		if ($this->_registration->group_size() > 1) {
1477
+			add_meta_box(
1478
+				'edit-reg-attendees-mbox',
1479
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1480
+				array($this, '_reg_attendees_meta_box'),
1481
+				$this->wp_page_slug,
1482
+				'normal',
1483
+				'high'
1484
+			);
1485
+		}
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * set_reg_status_buttons_metabox
1491
+	 *
1492
+	 * @access protected
1493
+	 * @return string
1494
+	 * @throws EE_Error
1495
+	 * @throws EntityNotFoundException
1496
+	 * @throws InvalidArgumentException
1497
+	 * @throws InvalidDataTypeException
1498
+	 * @throws InvalidInterfaceException
1499
+	 * @throws ReflectionException
1500
+	 */
1501
+	public function set_reg_status_buttons_metabox()
1502
+	{
1503
+		$this->_set_registration_object();
1504
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1505
+		echo $change_reg_status_form->form_open(
1506
+			self::add_query_args_and_nonce(
1507
+				array(
1508
+					'action' => 'change_reg_status',
1509
+				),
1510
+				REG_ADMIN_URL
1511
+			)
1512
+		);
1513
+		echo $change_reg_status_form->get_html();
1514
+		echo $change_reg_status_form->form_close();
1515
+	}
1516
+
1517
+
1518
+	/**
1519
+	 * @return EE_Form_Section_Proper
1520
+	 * @throws EE_Error
1521
+	 * @throws InvalidArgumentException
1522
+	 * @throws InvalidDataTypeException
1523
+	 * @throws InvalidInterfaceException
1524
+	 * @throws EntityNotFoundException
1525
+	 * @throws ReflectionException
1526
+	 */
1527
+	protected function _generate_reg_status_change_form()
1528
+	{
1529
+		$reg_status_change_form_array = array(
1530
+			'name'            => 'reg_status_change_form',
1531
+			'html_id'         => 'reg-status-change-form',
1532
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1533
+			'subsections'     => array(
1534
+				'return'             => new EE_Hidden_Input(
1535
+					array(
1536
+						'name'    => 'return',
1537
+						'default' => 'view_registration',
1538
+					)
1539
+				),
1540
+				'REG_ID'             => new EE_Hidden_Input(
1541
+					array(
1542
+						'name'    => 'REG_ID',
1543
+						'default' => $this->_registration->ID(),
1544
+					)
1545
+				),
1546
+				'current_status'     => new EE_Form_Section_HTML(
1547
+					EEH_HTML::table(
1548
+						EEH_HTML::tr(
1549
+							EEH_HTML::th(
1550
+								EEH_HTML::label(
1551
+									EEH_HTML::strong(
1552
+										esc_html__('Current Registration Status', 'event_espresso')
1553
+									)
1554
+								)
1555
+							)
1556
+							. EEH_HTML::td(
1557
+								EEH_HTML::strong(
1558
+									$this->_registration->pretty_status(),
1559
+									'',
1560
+									'status-' . $this->_registration->status_ID(),
1561
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1562
+								)
1563
+							)
1564
+						)
1565
+					)
1566
+				)
1567
+			)
1568
+		);
1569
+		if (
1570
+			EE_Registry::instance()->CAP->current_user_can(
1571
+				'ee_edit_registration',
1572
+				'toggle_registration_status',
1573
+				$this->_registration->ID()
1574
+			)
1575
+		) {
1576
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1577
+				$this->_get_reg_statuses(),
1578
+				array(
1579
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1580
+					'default'         => $this->_registration->status_ID(),
1581
+				)
1582
+			);
1583
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1584
+				array(
1585
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1586
+					'default'         => false,
1587
+					'html_help_text'  => esc_html__(
1588
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1589
+						'event_espresso'
1590
+					)
1591
+				)
1592
+			);
1593
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1594
+				array(
1595
+					'html_class'      => 'button-primary',
1596
+					'html_label_text' => '&nbsp;',
1597
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1598
+				)
1599
+			);
1600
+		}
1601
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1602
+	}
1603
+
1604
+
1605
+	/**
1606
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1607
+	 *
1608
+	 * @return array
1609
+	 * @throws EE_Error
1610
+	 * @throws InvalidArgumentException
1611
+	 * @throws InvalidDataTypeException
1612
+	 * @throws InvalidInterfaceException
1613
+	 * @throws EntityNotFoundException
1614
+	 */
1615
+	protected function _get_reg_statuses()
1616
+	{
1617
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1618
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1619
+		// get current reg status
1620
+		$current_status = $this->_registration->status_ID();
1621
+		// is registration for free event? This will determine whether to display the pending payment option
1622
+		if (
1623
+			$current_status !== EEM_Registration::status_id_pending_payment
1624
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1625
+		) {
1626
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1627
+		}
1628
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1629
+	}
1630
+
1631
+
1632
+	/**
1633
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1634
+	 *
1635
+	 * @param bool $status REG status given for changing registrations to.
1636
+	 * @param bool $notify Whether to send messages notifications or not.
1637
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1638
+	 * @throws DomainException
1639
+	 * @throws EE_Error
1640
+	 * @throws EntityNotFoundException
1641
+	 * @throws InvalidArgumentException
1642
+	 * @throws InvalidDataTypeException
1643
+	 * @throws InvalidInterfaceException
1644
+	 * @throws ReflectionException
1645
+	 * @throws RuntimeException
1646
+	 */
1647
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1648
+	{
1649
+		if (isset($this->_req_data['reg_status_change_form'])) {
1650
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1651
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1652
+				: array();
1653
+		} else {
1654
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1655
+				? (array) $this->_req_data['_REG_ID']
1656
+				: array();
1657
+		}
1658
+		// sanitize $REG_IDs
1659
+		$REG_IDs = array_map('absint', $REG_IDs);
1660
+		// and remove empty entries
1661
+		$REG_IDs = array_filter($REG_IDs);
1662
+
1663
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1664
+
1665
+		/**
1666
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1667
+		 * Currently this value is used downstream by the _process_resend_registration method.
1668
+		 *
1669
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1670
+		 * @param bool                     $status           The status registrations were changed to.
1671
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1672
+		 * @param Registrations_Admin_Page $admin_page_object
1673
+		 */
1674
+		$this->_req_data['_REG_ID'] = apply_filters(
1675
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1676
+			$result['REG_ID'],
1677
+			$status,
1678
+			$result['success'],
1679
+			$this
1680
+		);
1681
+
1682
+		// notify?
1683
+		if (
1684
+			$notify
1685
+			&& $result['success']
1686
+			&& ! empty($this->_req_data['_REG_ID'])
1687
+			&& EE_Registry::instance()->CAP->current_user_can(
1688
+				'ee_send_message',
1689
+				'espresso_registrations_resend_registration'
1690
+			)
1691
+		) {
1692
+			$this->_process_resend_registration();
1693
+		}
1694
+		return $result;
1695
+	}
1696
+
1697
+
1698
+	/**
1699
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1700
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1701
+	 *
1702
+	 * @param array  $REG_IDs
1703
+	 * @param string $status
1704
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1705
+	 *                        slug sent with setting the registration status.
1706
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1707
+	 * @throws EE_Error
1708
+	 * @throws InvalidArgumentException
1709
+	 * @throws InvalidDataTypeException
1710
+	 * @throws InvalidInterfaceException
1711
+	 * @throws ReflectionException
1712
+	 * @throws RuntimeException
1713
+	 * @throws EntityNotFoundException
1714
+	 * @throws DomainException
1715
+	 */
1716
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1717
+	{
1718
+		$success = false;
1719
+		// typecast $REG_IDs
1720
+		$REG_IDs = (array) $REG_IDs;
1721
+		if (! empty($REG_IDs)) {
1722
+			$success = true;
1723
+			// set default status if none is passed
1724
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1725
+			$status_context = $notify
1726
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1727
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1728
+			// loop through REG_ID's and change status
1729
+			foreach ($REG_IDs as $REG_ID) {
1730
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1731
+				if ($registration instanceof EE_Registration) {
1732
+					$registration->set_status(
1733
+						$status,
1734
+						false,
1735
+						new Context(
1736
+							$status_context,
1737
+							esc_html__(
1738
+								'Manually triggered status change on a Registration Admin Page route.',
1739
+								'event_espresso'
1740
+							)
1741
+						)
1742
+					);
1743
+					$result = $registration->save();
1744
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1745
+					$success = $result !== false ? $success : false;
1746
+				}
1747
+			}
1748
+		}
1749
+
1750
+		// return $success and processed registrations
1751
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1752
+	}
1753
+
1754
+
1755
+	/**
1756
+	 * Common logic for setting up success message and redirecting to appropriate route
1757
+	 *
1758
+	 * @param string $STS_ID status id for the registration changed to
1759
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1760
+	 * @return void
1761
+	 * @throws DomainException
1762
+	 * @throws EE_Error
1763
+	 * @throws EntityNotFoundException
1764
+	 * @throws InvalidArgumentException
1765
+	 * @throws InvalidDataTypeException
1766
+	 * @throws InvalidInterfaceException
1767
+	 * @throws ReflectionException
1768
+	 * @throws RuntimeException
1769
+	 */
1770
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1771
+	{
1772
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1773
+			: array('success' => false);
1774
+		$success = isset($result['success']) && $result['success'];
1775
+		// setup success message
1776
+		if ($success) {
1777
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1778
+				$msg = sprintf(
1779
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1780
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1781
+				);
1782
+			} else {
1783
+				$msg = sprintf(
1784
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1785
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1786
+				);
1787
+			}
1788
+			EE_Error::add_success($msg);
1789
+		} else {
1790
+			EE_Error::add_error(
1791
+				esc_html__(
1792
+					'Something went wrong, and the status was not changed',
1793
+					'event_espresso'
1794
+				),
1795
+				__FILE__,
1796
+				__LINE__,
1797
+				__FUNCTION__
1798
+			);
1799
+		}
1800
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1801
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1802
+		} else {
1803
+			$route = array('action' => 'default');
1804
+		}
1805
+		$route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1806
+		$this->_redirect_after_action($success, '', '', $route, true);
1807
+	}
1808
+
1809
+
1810
+	/**
1811
+	 * incoming reg status change from reg details page.
1812
+	 *
1813
+	 * @return void
1814
+	 * @throws EE_Error
1815
+	 * @throws EntityNotFoundException
1816
+	 * @throws InvalidArgumentException
1817
+	 * @throws InvalidDataTypeException
1818
+	 * @throws InvalidInterfaceException
1819
+	 * @throws ReflectionException
1820
+	 * @throws RuntimeException
1821
+	 * @throws DomainException
1822
+	 */
1823
+	protected function _change_reg_status()
1824
+	{
1825
+		$this->_req_data['return'] = 'view_registration';
1826
+		// set notify based on whether the send notifications toggle is set or not
1827
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1828
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1829
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1830
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1831
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1832
+			case EEM_Registration::status_id_approved:
1833
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1834
+				$this->approve_registration($notify);
1835
+				break;
1836
+			case EEM_Registration::status_id_pending_payment:
1837
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1838
+				$this->pending_registration($notify);
1839
+				break;
1840
+			case EEM_Registration::status_id_not_approved:
1841
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1842
+				$this->not_approve_registration($notify);
1843
+				break;
1844
+			case EEM_Registration::status_id_declined:
1845
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1846
+				$this->decline_registration($notify);
1847
+				break;
1848
+			case EEM_Registration::status_id_cancelled:
1849
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1850
+				$this->cancel_registration($notify);
1851
+				break;
1852
+			case EEM_Registration::status_id_wait_list:
1853
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1854
+				$this->wait_list_registration($notify);
1855
+				break;
1856
+			case EEM_Registration::status_id_incomplete:
1857
+			default:
1858
+				$result['success'] = false;
1859
+				unset($this->_req_data['return']);
1860
+				$this->_reg_status_change_return('', false);
1861
+				break;
1862
+		}
1863
+	}
1864
+
1865
+
1866
+	/**
1867
+	 * Callback for bulk action routes.
1868
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1869
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1870
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1871
+	 * when an action is happening on just a single registration).
1872
+	 *
1873
+	 * @param      $action
1874
+	 * @param bool $notify
1875
+	 */
1876
+	protected function bulk_action_on_registrations($action, $notify = false)
1877
+	{
1878
+		do_action(
1879
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1880
+			$this,
1881
+			$action,
1882
+			$notify
1883
+		);
1884
+		$method = $action . '_registration';
1885
+		if (method_exists($this, $method)) {
1886
+			$this->$method($notify);
1887
+		}
1888
+	}
1889
+
1890
+
1891
+	/**
1892
+	 * approve_registration
1893
+	 *
1894
+	 * @access protected
1895
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1896
+	 * @return void
1897
+	 * @throws EE_Error
1898
+	 * @throws EntityNotFoundException
1899
+	 * @throws InvalidArgumentException
1900
+	 * @throws InvalidDataTypeException
1901
+	 * @throws InvalidInterfaceException
1902
+	 * @throws ReflectionException
1903
+	 * @throws RuntimeException
1904
+	 * @throws DomainException
1905
+	 */
1906
+	protected function approve_registration($notify = false)
1907
+	{
1908
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1909
+	}
1910
+
1911
+
1912
+	/**
1913
+	 *        decline_registration
1914
+	 *
1915
+	 * @access protected
1916
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1917
+	 * @return void
1918
+	 * @throws EE_Error
1919
+	 * @throws EntityNotFoundException
1920
+	 * @throws InvalidArgumentException
1921
+	 * @throws InvalidDataTypeException
1922
+	 * @throws InvalidInterfaceException
1923
+	 * @throws ReflectionException
1924
+	 * @throws RuntimeException
1925
+	 * @throws DomainException
1926
+	 */
1927
+	protected function decline_registration($notify = false)
1928
+	{
1929
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1930
+	}
1931
+
1932
+
1933
+	/**
1934
+	 *        cancel_registration
1935
+	 *
1936
+	 * @access protected
1937
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1938
+	 * @return void
1939
+	 * @throws EE_Error
1940
+	 * @throws EntityNotFoundException
1941
+	 * @throws InvalidArgumentException
1942
+	 * @throws InvalidDataTypeException
1943
+	 * @throws InvalidInterfaceException
1944
+	 * @throws ReflectionException
1945
+	 * @throws RuntimeException
1946
+	 * @throws DomainException
1947
+	 */
1948
+	protected function cancel_registration($notify = false)
1949
+	{
1950
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1951
+	}
1952
+
1953
+
1954
+	/**
1955
+	 *        not_approve_registration
1956
+	 *
1957
+	 * @access protected
1958
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1959
+	 * @return void
1960
+	 * @throws EE_Error
1961
+	 * @throws EntityNotFoundException
1962
+	 * @throws InvalidArgumentException
1963
+	 * @throws InvalidDataTypeException
1964
+	 * @throws InvalidInterfaceException
1965
+	 * @throws ReflectionException
1966
+	 * @throws RuntimeException
1967
+	 * @throws DomainException
1968
+	 */
1969
+	protected function not_approve_registration($notify = false)
1970
+	{
1971
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1972
+	}
1973
+
1974
+
1975
+	/**
1976
+	 *        decline_registration
1977
+	 *
1978
+	 * @access protected
1979
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1980
+	 * @return void
1981
+	 * @throws EE_Error
1982
+	 * @throws EntityNotFoundException
1983
+	 * @throws InvalidArgumentException
1984
+	 * @throws InvalidDataTypeException
1985
+	 * @throws InvalidInterfaceException
1986
+	 * @throws ReflectionException
1987
+	 * @throws RuntimeException
1988
+	 * @throws DomainException
1989
+	 */
1990
+	protected function pending_registration($notify = false)
1991
+	{
1992
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * waitlist_registration
1998
+	 *
1999
+	 * @access protected
2000
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2001
+	 * @return void
2002
+	 * @throws EE_Error
2003
+	 * @throws EntityNotFoundException
2004
+	 * @throws InvalidArgumentException
2005
+	 * @throws InvalidDataTypeException
2006
+	 * @throws InvalidInterfaceException
2007
+	 * @throws ReflectionException
2008
+	 * @throws RuntimeException
2009
+	 * @throws DomainException
2010
+	 */
2011
+	protected function wait_list_registration($notify = false)
2012
+	{
2013
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2014
+	}
2015
+
2016
+
2017
+	/**
2018
+	 *        generates HTML for the Registration main meta box
2019
+	 *
2020
+	 * @access public
2021
+	 * @return void
2022
+	 * @throws DomainException
2023
+	 * @throws EE_Error
2024
+	 * @throws InvalidArgumentException
2025
+	 * @throws InvalidDataTypeException
2026
+	 * @throws InvalidInterfaceException
2027
+	 * @throws ReflectionException
2028
+	 * @throws EntityNotFoundException
2029
+	 */
2030
+	public function _reg_details_meta_box()
2031
+	{
2032
+		EEH_Autoloader::register_line_item_display_autoloaders();
2033
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2034
+		EE_Registry::instance()->load_helper('Line_Item');
2035
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2036
+			: EE_Transaction::new_instance();
2037
+		$this->_session = $transaction->session_data();
2038
+		$filters = new EE_Line_Item_Filter_Collection();
2039
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2040
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2041
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2042
+			$filters,
2043
+			$transaction->total_line_item()
2044
+		);
2045
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2046
+		$line_item_display = new EE_Line_Item_Display(
2047
+			'reg_admin_table',
2048
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2049
+		);
2050
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2051
+			$filtered_line_item_tree,
2052
+			array('EE_Registration' => $this->_registration)
2053
+		);
2054
+		$attendee = $this->_registration->attendee();
2055
+		if (
2056
+			EE_Registry::instance()->CAP->current_user_can(
2057
+				'ee_read_transaction',
2058
+				'espresso_transactions_view_transaction'
2059
+			)
2060
+		) {
2061
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2062
+				EE_Admin_Page::add_query_args_and_nonce(
2063
+					array(
2064
+						'action' => 'view_transaction',
2065
+						'TXN_ID' => $transaction->ID(),
2066
+					),
2067
+					TXN_ADMIN_URL
2068
+				),
2069
+				esc_html__(' View Transaction', 'event_espresso'),
2070
+				'button secondary-button right',
2071
+				'dashicons dashicons-cart'
2072
+			);
2073
+		} else {
2074
+			$this->_template_args['view_transaction_button'] = '';
2075
+		}
2076
+		if (
2077
+			$attendee instanceof EE_Attendee
2078
+			&& EE_Registry::instance()->CAP->current_user_can(
2079
+				'ee_send_message',
2080
+				'espresso_registrations_resend_registration'
2081
+			)
2082
+		) {
2083
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2084
+				EE_Admin_Page::add_query_args_and_nonce(
2085
+					array(
2086
+						'action'      => 'resend_registration',
2087
+						'_REG_ID'     => $this->_registration->ID(),
2088
+						'redirect_to' => 'view_registration',
2089
+					),
2090
+					REG_ADMIN_URL
2091
+				),
2092
+				esc_html__(' Resend Registration', 'event_espresso'),
2093
+				'button secondary-button right',
2094
+				'dashicons dashicons-email-alt'
2095
+			);
2096
+		} else {
2097
+			$this->_template_args['resend_registration_button'] = '';
2098
+		}
2099
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2100
+		$payment = $transaction->get_first_related('Payment');
2101
+		$payment = ! $payment instanceof EE_Payment
2102
+			? EE_Payment::new_instance()
2103
+			: $payment;
2104
+		$payment_method = $payment->get_first_related('Payment_Method');
2105
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2106
+			? EE_Payment_Method::new_instance()
2107
+			: $payment_method;
2108
+		$reg_details = array(
2109
+			'payment_method'       => $payment_method->name(),
2110
+			'response_msg'         => $payment->gateway_response(),
2111
+			'registration_id'      => $this->_registration->get('REG_code'),
2112
+			'registration_session' => $this->_registration->session_ID(),
2113
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2114
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2115
+		);
2116
+		if (isset($reg_details['registration_id'])) {
2117
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2118
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2119
+				'Registration ID',
2120
+				'event_espresso'
2121
+			);
2122
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2123
+		}
2124
+		if (isset($reg_details['payment_method'])) {
2125
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2126
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2127
+				'Most Recent Payment Method',
2128
+				'event_espresso'
2129
+			);
2130
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2131
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2132
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2133
+				'Payment method response',
2134
+				'event_espresso'
2135
+			);
2136
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2137
+		}
2138
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2139
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2140
+			'Registration Session',
2141
+			'event_espresso'
2142
+		);
2143
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2144
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2145
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2146
+			'Registration placed from IP',
2147
+			'event_espresso'
2148
+		);
2149
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2150
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2151
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2152
+			'Registrant User Agent',
2153
+			'event_espresso'
2154
+		);
2155
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2156
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2157
+			array(
2158
+				'action'   => 'default',
2159
+				'event_id' => $this->_registration->event_ID(),
2160
+			),
2161
+			REG_ADMIN_URL
2162
+		);
2163
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2164
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2165
+		$template_path =
2166
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2167
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2168
+	}
2169
+
2170
+
2171
+	/**
2172
+	 * generates HTML for the Registration Questions meta box.
2173
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2174
+	 * otherwise uses new forms system
2175
+	 *
2176
+	 * @access public
2177
+	 * @return void
2178
+	 * @throws DomainException
2179
+	 * @throws EE_Error
2180
+	 * @throws InvalidArgumentException
2181
+	 * @throws InvalidDataTypeException
2182
+	 * @throws InvalidInterfaceException
2183
+	 * @throws ReflectionException
2184
+	 */
2185
+	public function _reg_questions_meta_box()
2186
+	{
2187
+		// allow someone to override this method entirely
2188
+		if (
2189
+			apply_filters(
2190
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2191
+				true,
2192
+				$this,
2193
+				$this->_registration
2194
+			)
2195
+		) {
2196
+			$form = $this->_get_reg_custom_questions_form(
2197
+				$this->_registration->ID()
2198
+			);
2199
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2200
+				? $form->get_html_and_js()
2201
+				: '';
2202
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2203
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2204
+			$template_path =
2205
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2206
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2207
+		}
2208
+	}
2209
+
2210
+
2211
+	/**
2212
+	 * form_before_question_group
2213
+	 *
2214
+	 * @deprecated    as of 4.8.32.rc.000
2215
+	 * @access        public
2216
+	 * @param        string $output
2217
+	 * @return        string
2218
+	 */
2219
+	public function form_before_question_group($output)
2220
+	{
2221
+		EE_Error::doing_it_wrong(
2222
+			__CLASS__ . '::' . __FUNCTION__,
2223
+			esc_html__(
2224
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2225
+				'event_espresso'
2226
+			),
2227
+			'4.8.32.rc.000'
2228
+		);
2229
+		return '
2230 2230
 	<table class="form-table ee-width-100">
2231 2231
 		<tbody>
2232 2232
 			';
2233
-    }
2234
-
2235
-
2236
-    /**
2237
-     * form_after_question_group
2238
-     *
2239
-     * @deprecated    as of 4.8.32.rc.000
2240
-     * @access        public
2241
-     * @param        string $output
2242
-     * @return        string
2243
-     */
2244
-    public function form_after_question_group($output)
2245
-    {
2246
-        EE_Error::doing_it_wrong(
2247
-            __CLASS__ . '::' . __FUNCTION__,
2248
-            esc_html__(
2249
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2250
-                'event_espresso'
2251
-            ),
2252
-            '4.8.32.rc.000'
2253
-        );
2254
-        return '
2233
+	}
2234
+
2235
+
2236
+	/**
2237
+	 * form_after_question_group
2238
+	 *
2239
+	 * @deprecated    as of 4.8.32.rc.000
2240
+	 * @access        public
2241
+	 * @param        string $output
2242
+	 * @return        string
2243
+	 */
2244
+	public function form_after_question_group($output)
2245
+	{
2246
+		EE_Error::doing_it_wrong(
2247
+			__CLASS__ . '::' . __FUNCTION__,
2248
+			esc_html__(
2249
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2250
+				'event_espresso'
2251
+			),
2252
+			'4.8.32.rc.000'
2253
+		);
2254
+		return '
2255 2255
 			<tr class="hide-if-no-js">
2256 2256
 				<th> </th>
2257 2257
 				<td class="reg-admin-edit-attendee-question-td">
2258 2258
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2259
-               . esc_attr__('click to edit question', 'event_espresso')
2260
-               . '">
2259
+			   . esc_attr__('click to edit question', 'event_espresso')
2260
+			   . '">
2261 2261
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2262
-               . esc_html__('edit the above question group', 'event_espresso')
2263
-               . '</span>
2262
+			   . esc_html__('edit the above question group', 'event_espresso')
2263
+			   . '</span>
2264 2264
 						<div class="dashicons dashicons-edit"></div>
2265 2265
 					</a>
2266 2266
 				</td>
@@ -2268,644 +2268,644 @@  discard block
 block discarded – undo
2268 2268
 		</tbody>
2269 2269
 	</table>
2270 2270
 ';
2271
-    }
2272
-
2273
-
2274
-    /**
2275
-     * form_form_field_label_wrap
2276
-     *
2277
-     * @deprecated    as of 4.8.32.rc.000
2278
-     * @access        public
2279
-     * @param        string $label
2280
-     * @return        string
2281
-     */
2282
-    public function form_form_field_label_wrap($label)
2283
-    {
2284
-        EE_Error::doing_it_wrong(
2285
-            __CLASS__ . '::' . __FUNCTION__,
2286
-            esc_html__(
2287
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2288
-                'event_espresso'
2289
-            ),
2290
-            '4.8.32.rc.000'
2291
-        );
2292
-        return '
2271
+	}
2272
+
2273
+
2274
+	/**
2275
+	 * form_form_field_label_wrap
2276
+	 *
2277
+	 * @deprecated    as of 4.8.32.rc.000
2278
+	 * @access        public
2279
+	 * @param        string $label
2280
+	 * @return        string
2281
+	 */
2282
+	public function form_form_field_label_wrap($label)
2283
+	{
2284
+		EE_Error::doing_it_wrong(
2285
+			__CLASS__ . '::' . __FUNCTION__,
2286
+			esc_html__(
2287
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2288
+				'event_espresso'
2289
+			),
2290
+			'4.8.32.rc.000'
2291
+		);
2292
+		return '
2293 2293
 			<tr>
2294 2294
 				<th>
2295 2295
 					' . $label . '
2296 2296
 				</th>';
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * form_form_field_input__wrap
2302
-     *
2303
-     * @deprecated    as of 4.8.32.rc.000
2304
-     * @access        public
2305
-     * @param        string $input
2306
-     * @return        string
2307
-     */
2308
-    public function form_form_field_input__wrap($input)
2309
-    {
2310
-        EE_Error::doing_it_wrong(
2311
-            __CLASS__ . '::' . __FUNCTION__,
2312
-            esc_html__(
2313
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314
-                'event_espresso'
2315
-            ),
2316
-            '4.8.32.rc.000'
2317
-        );
2318
-        return '
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * form_form_field_input__wrap
2302
+	 *
2303
+	 * @deprecated    as of 4.8.32.rc.000
2304
+	 * @access        public
2305
+	 * @param        string $input
2306
+	 * @return        string
2307
+	 */
2308
+	public function form_form_field_input__wrap($input)
2309
+	{
2310
+		EE_Error::doing_it_wrong(
2311
+			__CLASS__ . '::' . __FUNCTION__,
2312
+			esc_html__(
2313
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314
+				'event_espresso'
2315
+			),
2316
+			'4.8.32.rc.000'
2317
+		);
2318
+		return '
2319 2319
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2320 2320
 					' . $input . '
2321 2321
 				</td>
2322 2322
 			</tr>';
2323
-    }
2324
-
2325
-
2326
-    /**
2327
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2328
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2329
-     * to display the page
2330
-     *
2331
-     * @access protected
2332
-     * @return void
2333
-     * @throws EE_Error
2334
-     * @throws InvalidArgumentException
2335
-     * @throws InvalidDataTypeException
2336
-     * @throws InvalidInterfaceException
2337
-     * @throws ReflectionException
2338
-     */
2339
-    protected function _update_attendee_registration_form()
2340
-    {
2341
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2342
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2343
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2344
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2345
-            if ($success) {
2346
-                $what = esc_html__('Registration Form', 'event_espresso');
2347
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2348
-                    : array('action' => 'default');
2349
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2350
-            }
2351
-        }
2352
-    }
2353
-
2354
-
2355
-    /**
2356
-     * Gets the form for saving registrations custom questions (if done
2357
-     * previously retrieves the cached form object, which may have validation errors in it)
2358
-     *
2359
-     * @param int $REG_ID
2360
-     * @return EE_Registration_Custom_Questions_Form
2361
-     * @throws EE_Error
2362
-     * @throws InvalidArgumentException
2363
-     * @throws InvalidDataTypeException
2364
-     * @throws InvalidInterfaceException
2365
-     */
2366
-    protected function _get_reg_custom_questions_form($REG_ID)
2367
-    {
2368
-        if (! $this->_reg_custom_questions_form) {
2369
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2370
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2371
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2372
-            );
2373
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2374
-        }
2375
-        return $this->_reg_custom_questions_form;
2376
-    }
2377
-
2378
-
2379
-    /**
2380
-     * Saves
2381
-     *
2382
-     * @access private
2383
-     * @param bool $REG_ID
2384
-     * @return bool
2385
-     * @throws EE_Error
2386
-     * @throws InvalidArgumentException
2387
-     * @throws InvalidDataTypeException
2388
-     * @throws InvalidInterfaceException
2389
-     * @throws ReflectionException
2390
-     */
2391
-    private function _save_reg_custom_questions_form($REG_ID = false)
2392
-    {
2393
-        if (! $REG_ID) {
2394
-            EE_Error::add_error(
2395
-                esc_html__(
2396
-                    'An error occurred. No registration ID was received.',
2397
-                    'event_espresso'
2398
-                ),
2399
-                __FILE__,
2400
-                __FUNCTION__,
2401
-                __LINE__
2402
-            );
2403
-        }
2404
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2405
-        $form->receive_form_submission($this->_req_data);
2406
-        $success = false;
2407
-        if ($form->is_valid()) {
2408
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2409
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2410
-                    $where_conditions = array(
2411
-                        'QST_ID' => $question_id,
2412
-                        'REG_ID' => $REG_ID,
2413
-                    );
2414
-                    $possibly_new_values = array(
2415
-                        'ANS_value' => $input->normalized_value(),
2416
-                    );
2417
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2418
-                    if ($answer instanceof EE_Answer) {
2419
-                        $success = $answer->save($possibly_new_values);
2420
-                    } else {
2421
-                        // insert it then
2422
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2423
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2424
-                        $success = $answer->save();
2425
-                    }
2426
-                }
2427
-            }
2428
-        } else {
2429
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2430
-        }
2431
-        return $success;
2432
-    }
2433
-
2434
-
2435
-    /**
2436
-     *        generates HTML for the Registration main meta box
2437
-     *
2438
-     * @access public
2439
-     * @return void
2440
-     * @throws DomainException
2441
-     * @throws EE_Error
2442
-     * @throws InvalidArgumentException
2443
-     * @throws InvalidDataTypeException
2444
-     * @throws InvalidInterfaceException
2445
-     * @throws ReflectionException
2446
-     */
2447
-    public function _reg_attendees_meta_box()
2448
-    {
2449
-        $REG = $this->getRegistrationModel();
2450
-        // get all other registrations on this transaction, and cache
2451
-        // the attendees for them so we don't have to run another query using force_join
2452
-        $registrations = $REG->get_all(
2453
-            array(
2454
-                array(
2455
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2456
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2457
-                ),
2458
-                'force_join' => array('Attendee'),
2459
-                'default_where_conditions' => 'other_models_only',
2460
-            )
2461
-        );
2462
-        $this->_template_args['attendees'] = array();
2463
-        $this->_template_args['attendee_notice'] = '';
2464
-        if (
2465
-            empty($registrations)
2466
-            || (is_array($registrations)
2467
-                && ! EEH_Array::get_one_item_from_array($registrations))
2468
-        ) {
2469
-            EE_Error::add_error(
2470
-                esc_html__(
2471
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2472
-                    'event_espresso'
2473
-                ),
2474
-                __FILE__,
2475
-                __FUNCTION__,
2476
-                __LINE__
2477
-            );
2478
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2479
-        } else {
2480
-            $att_nmbr = 1;
2481
-            foreach ($registrations as $registration) {
2482
-                /* @var $registration EE_Registration */
2483
-                $attendee = $registration->attendee()
2484
-                    ? $registration->attendee()
2485
-                    : $this->getAttendeeModel()->create_default_object();
2486
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2487
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2488
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2489
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2490
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2491
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2492
-                    ', ',
2493
-                    $attendee->full_address_as_array()
2494
-                );
2495
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2496
-                    array(
2497
-                        'action' => 'edit_attendee',
2498
-                        'post'   => $attendee->ID(),
2499
-                    ),
2500
-                    REG_ADMIN_URL
2501
-                );
2502
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2503
-                    ? $registration->event_obj()->name()
2504
-                    : '';
2505
-                $att_nmbr++;
2506
-            }
2507
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2508
-        }
2509
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2510
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2511
-    }
2512
-
2513
-
2514
-    /**
2515
-     *        generates HTML for the Edit Registration side meta box
2516
-     *
2517
-     * @access public
2518
-     * @return void
2519
-     * @throws DomainException
2520
-     * @throws EE_Error
2521
-     * @throws InvalidArgumentException
2522
-     * @throws InvalidDataTypeException
2523
-     * @throws InvalidInterfaceException
2524
-     * @throws ReflectionException
2525
-     */
2526
-    public function _reg_registrant_side_meta_box()
2527
-    {
2528
-        /*@var $attendee EE_Attendee */
2529
-        $att_check = $this->_registration->attendee();
2530
-        $attendee = $att_check instanceof EE_Attendee
2531
-            ? $att_check
2532
-            : $this->getAttendeeModel()->create_default_object();
2533
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2534
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2535
-        // primary registration object (that way we know if we need to show create button or not)
2536
-        if (! $this->_registration->is_primary_registrant()) {
2537
-            $primary_registration = $this->_registration->get_primary_registration();
2538
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2539
-                : null;
2540
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2541
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2542
-                // custom attendee object so let's not worry about the primary reg.
2543
-                $primary_registration = null;
2544
-            }
2545
-        } else {
2546
-            $primary_registration = null;
2547
-        }
2548
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2549
-        $this->_template_args['fname'] = $attendee->fname();
2550
-        $this->_template_args['lname'] = $attendee->lname();
2551
-        $this->_template_args['email'] = $attendee->email();
2552
-        $this->_template_args['phone'] = $attendee->phone();
2553
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2554
-        // edit link
2555
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2556
-            array(
2557
-                'action' => 'edit_attendee',
2558
-                'post'   => $attendee->ID(),
2559
-            ),
2560
-            REG_ADMIN_URL
2561
-        );
2562
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2563
-        // create link
2564
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2565
-            ? EE_Admin_Page::add_query_args_and_nonce(
2566
-                array(
2567
-                    'action'  => 'duplicate_attendee',
2568
-                    '_REG_ID' => $this->_registration->ID(),
2569
-                ),
2570
-                REG_ADMIN_URL
2571
-            ) : '';
2572
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2573
-        $this->_template_args['att_check'] = $att_check;
2574
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2575
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2576
-    }
2577
-
2578
-
2579
-    /**
2580
-     * trash or restore registrations
2581
-     *
2582
-     * @param  boolean $trash whether to archive or restore
2583
-     * @return void
2584
-     * @throws EE_Error
2585
-     * @throws InvalidArgumentException
2586
-     * @throws InvalidDataTypeException
2587
-     * @throws InvalidInterfaceException
2588
-     * @throws RuntimeException
2589
-     * @access protected
2590
-     */
2591
-    protected function _trash_or_restore_registrations($trash = true)
2592
-    {
2593
-        // if empty _REG_ID then get out because there's nothing to do
2594
-        if (empty($this->_req_data['_REG_ID'])) {
2595
-            EE_Error::add_error(
2596
-                sprintf(
2597
-                    esc_html__(
2598
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2599
-                        'event_espresso'
2600
-                    ),
2601
-                    $trash ? 'trash' : 'restore'
2602
-                ),
2603
-                __FILE__,
2604
-                __LINE__,
2605
-                __FUNCTION__
2606
-            );
2607
-            $this->_redirect_after_action(false, '', '', array(), true);
2608
-        }
2609
-        $success = 0;
2610
-        $overwrite_msgs = false;
2611
-        // Checkboxes
2612
-        if (! is_array($this->_req_data['_REG_ID'])) {
2613
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2614
-        }
2615
-        $reg_count = count($this->_req_data['_REG_ID']);
2616
-        // cycle thru checkboxes
2617
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2618
-            /** @var EE_Registration $REG */
2619
-            $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2620
-            $payments = $REG->registration_payments();
2621
-            if (! empty($payments)) {
2622
-                $name = $REG->attendee() instanceof EE_Attendee
2623
-                    ? $REG->attendee()->full_name()
2624
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2625
-                $overwrite_msgs = true;
2626
-                EE_Error::add_error(
2627
-                    sprintf(
2628
-                        esc_html__(
2629
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2630
-                            'event_espresso'
2631
-                        ),
2632
-                        $name
2633
-                    ),
2634
-                    __FILE__,
2635
-                    __FUNCTION__,
2636
-                    __LINE__
2637
-                );
2638
-                // can't trash this registration because it has payments.
2639
-                continue;
2640
-            }
2641
-            $updated = $trash ? $REG->delete() : $REG->restore();
2642
-            if ($updated) {
2643
-                $success++;
2644
-            }
2645
-        }
2646
-        $this->_redirect_after_action(
2647
-            $success === $reg_count, // were ALL registrations affected?
2648
-            $success > 1
2649
-                ? esc_html__('Registrations', 'event_espresso')
2650
-                : esc_html__('Registration', 'event_espresso'),
2651
-            $trash
2652
-                ? esc_html__('moved to the trash', 'event_espresso')
2653
-                : esc_html__('restored', 'event_espresso'),
2654
-            $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2655
-            $overwrite_msgs
2656
-        );
2657
-    }
2658
-
2659
-
2660
-    /**
2661
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2662
-     * registration but also.
2663
-     * 1. Removing relations to EE_Attendee
2664
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2665
-     * ALSO trashed.
2666
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2667
-     * 4. Removing relationships between all tickets and the related registrations
2668
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2669
-     * 6. Deleting permanently any related Checkins.
2670
-     *
2671
-     * @return void
2672
-     * @throws EE_Error
2673
-     * @throws InvalidArgumentException
2674
-     * @throws InvalidDataTypeException
2675
-     * @throws InvalidInterfaceException
2676
-     * @throws ReflectionException
2677
-     */
2678
-    protected function _delete_registrations()
2679
-    {
2680
-        $REG_MDL = $this->getRegistrationModel();
2681
-        $success = 1;
2682
-        // Checkboxes
2683
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2684
-            // if array has more than one element than success message should be plural
2685
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2686
-            // cycle thru checkboxes
2687
-            foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2688
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2689
-                if (! $REG instanceof EE_Registration) {
2690
-                    continue;
2691
-                }
2692
-                $deleted = $this->_delete_registration($REG);
2693
-                if (! $deleted) {
2694
-                    $success = 0;
2695
-                }
2696
-            }
2697
-        } else {
2698
-            // grab single id and delete
2699
-            $REG_ID = $this->_req_data['_REG_ID'];
2700
-            /** @var EE_Registration $REG */
2701
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2702
-            $deleted = $this->_delete_registration($REG);
2703
-            if (! $deleted) {
2704
-                $success = 0;
2705
-            }
2706
-        }
2707
-        $what = $success > 1
2708
-            ? esc_html__('Registrations', 'event_espresso')
2709
-            : esc_html__('Registration', 'event_espresso');
2710
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2711
-        $this->_redirect_after_action(
2712
-            $success,
2713
-            $what,
2714
-            $action_desc,
2715
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2716
-            true
2717
-        );
2718
-    }
2719
-
2720
-
2721
-    /**
2722
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2723
-     * models get affected.
2724
-     *
2725
-     * @param EE_Registration $REG registration to be deleted permanently
2726
-     * @return bool true = successful deletion, false = fail.
2727
-     * @throws EE_Error
2728
-     * @throws InvalidArgumentException
2729
-     * @throws InvalidDataTypeException
2730
-     * @throws InvalidInterfaceException
2731
-     * @throws ReflectionException
2732
-     */
2733
-    protected function _delete_registration(EE_Registration $REG)
2734
-    {
2735
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2736
-        // registrations on the transaction that are NOT trashed.
2737
-        $TXN = $REG->get_first_related('Transaction');
2738
-        if (! $TXN instanceof EE_Transaction) {
2739
-            EE_Error::add_error(
2740
-                sprintf(
2741
-                    esc_html__(
2742
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2743
-                        'event_espresso'
2744
-                    ),
2745
-                    $REG->id()
2746
-                ),
2747
-                __FILE__,
2748
-                __FUNCTION__,
2749
-                __LINE__
2750
-            );
2751
-            return false;
2752
-        }
2753
-        $REGS = $TXN->get_many_related('Registration');
2754
-        $all_trashed = true;
2755
-        foreach ($REGS as $registration) {
2756
-            if (! $registration->get('REG_deleted')) {
2757
-                $all_trashed = false;
2758
-            }
2759
-        }
2760
-        if (! $all_trashed) {
2761
-            EE_Error::add_error(
2762
-                esc_html__(
2763
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2764
-                    'event_espresso'
2765
-                ),
2766
-                __FILE__,
2767
-                __FUNCTION__,
2768
-                __LINE__
2769
-            );
2770
-            return false;
2771
-        }
2772
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2773
-        // separately from THIS one).
2774
-        foreach ($REGS as $registration) {
2775
-            // delete related answers
2776
-            $registration->delete_related_permanently('Answer');
2777
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2778
-            $attendee = $registration->get_first_related('Attendee');
2779
-            if ($attendee instanceof EE_Attendee) {
2780
-                $registration->_remove_relation_to($attendee, 'Attendee');
2781
-            }
2782
-            // now remove relationships to tickets on this registration.
2783
-            $registration->_remove_relations('Ticket');
2784
-            // now delete permanently the checkins related to this registration.
2785
-            $registration->delete_related_permanently('Checkin');
2786
-            if ($registration->ID() === $REG->ID()) {
2787
-                continue;
2788
-            } //we don't want to delete permanently the existing registration just yet.
2789
-            // remove relation to transaction for these registrations if NOT the existing registrations
2790
-            $registration->_remove_relations('Transaction');
2791
-            // delete permanently any related messages.
2792
-            $registration->delete_related_permanently('Message');
2793
-            // now delete this registration permanently
2794
-            $registration->delete_permanently();
2795
-        }
2796
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2797
-        // (the transaction and line items should be all that's left).
2798
-        // delete the line items related to the transaction for this registration.
2799
-        $TXN->delete_related_permanently('Line_Item');
2800
-        // we need to remove all the relationships on the transaction
2801
-        $TXN->delete_related_permanently('Payment');
2802
-        $TXN->delete_related_permanently('Extra_Meta');
2803
-        $TXN->delete_related_permanently('Message');
2804
-        // now we can delete this REG permanently (and the transaction of course)
2805
-        $REG->delete_related_permanently('Transaction');
2806
-        return $REG->delete_permanently();
2807
-    }
2808
-
2809
-
2810
-    /**
2811
-     *    generates HTML for the Register New Attendee Admin page
2812
-     *
2813
-     * @access private
2814
-     * @throws DomainException
2815
-     * @throws EE_Error
2816
-     * @throws InvalidArgumentException
2817
-     * @throws InvalidDataTypeException
2818
-     * @throws InvalidInterfaceException
2819
-     * @throws ReflectionException
2820
-     */
2821
-    public function new_registration()
2822
-    {
2823
-        if (! $this->_set_reg_event()) {
2824
-            throw new EE_Error(
2825
-                esc_html__(
2826
-                    'Unable to continue with registering because there is no Event ID in the request',
2827
-                    'event_espresso'
2828
-                )
2829
-            );
2830
-        }
2831
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2832
-        // gotta start with a clean slate if we're not coming here via ajax
2833
-        if (
2834
-            ! defined('DOING_AJAX')
2835
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2836
-        ) {
2837
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2838
-        }
2839
-        $this->_template_args['event_name'] = '';
2840
-        // event name
2841
-        if ($this->_reg_event) {
2842
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2843
-            $edit_event_url = self::add_query_args_and_nonce(
2844
-                array(
2845
-                    'action' => 'edit',
2846
-                    'post'   => $this->_reg_event->ID(),
2847
-                ),
2848
-                EVENTS_ADMIN_URL
2849
-            );
2850
-            $edit_event_lnk = '<a href="'
2851
-                              . $edit_event_url
2852
-                              . '" title="'
2853
-                              . esc_attr__('Edit ', 'event_espresso')
2854
-                              . $this->_reg_event->name()
2855
-                              . '">'
2856
-                              . esc_html__('Edit Event', 'event_espresso')
2857
-                              . '</a>';
2858
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2859
-                                                   . $edit_event_lnk
2860
-                                                   . '</span>';
2861
-        }
2862
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2863
-        if (defined('DOING_AJAX')) {
2864
-            $this->_return_json();
2865
-        }
2866
-        // grab header
2867
-        $template_path =
2868
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2869
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
-            $template_path,
2871
-            $this->_template_args,
2872
-            true
2873
-        );
2874
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2875
-        // the details template wrapper
2876
-        $this->display_admin_page_with_sidebar();
2877
-    }
2878
-
2879
-
2880
-    /**
2881
-     * This returns the content for a registration step
2882
-     *
2883
-     * @access protected
2884
-     * @return string html
2885
-     * @throws DomainException
2886
-     * @throws EE_Error
2887
-     * @throws InvalidArgumentException
2888
-     * @throws InvalidDataTypeException
2889
-     * @throws InvalidInterfaceException
2890
-     */
2891
-    protected function _get_registration_step_content()
2892
-    {
2893
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2894
-            $warning_msg = sprintf(
2895
-                esc_html__(
2896
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2897
-                    'event_espresso'
2898
-                ),
2899
-                '<br />',
2900
-                '<h3 class="important-notice">',
2901
-                '</h3>',
2902
-                '<div class="float-right">',
2903
-                '<span id="redirect_timer" class="important-notice">30</span>',
2904
-                '</div>',
2905
-                '<b>',
2906
-                '</b>'
2907
-            );
2908
-            return '
2323
+	}
2324
+
2325
+
2326
+	/**
2327
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2328
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2329
+	 * to display the page
2330
+	 *
2331
+	 * @access protected
2332
+	 * @return void
2333
+	 * @throws EE_Error
2334
+	 * @throws InvalidArgumentException
2335
+	 * @throws InvalidDataTypeException
2336
+	 * @throws InvalidInterfaceException
2337
+	 * @throws ReflectionException
2338
+	 */
2339
+	protected function _update_attendee_registration_form()
2340
+	{
2341
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2342
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2343
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2344
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2345
+			if ($success) {
2346
+				$what = esc_html__('Registration Form', 'event_espresso');
2347
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2348
+					: array('action' => 'default');
2349
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2350
+			}
2351
+		}
2352
+	}
2353
+
2354
+
2355
+	/**
2356
+	 * Gets the form for saving registrations custom questions (if done
2357
+	 * previously retrieves the cached form object, which may have validation errors in it)
2358
+	 *
2359
+	 * @param int $REG_ID
2360
+	 * @return EE_Registration_Custom_Questions_Form
2361
+	 * @throws EE_Error
2362
+	 * @throws InvalidArgumentException
2363
+	 * @throws InvalidDataTypeException
2364
+	 * @throws InvalidInterfaceException
2365
+	 */
2366
+	protected function _get_reg_custom_questions_form($REG_ID)
2367
+	{
2368
+		if (! $this->_reg_custom_questions_form) {
2369
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2370
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2371
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2372
+			);
2373
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2374
+		}
2375
+		return $this->_reg_custom_questions_form;
2376
+	}
2377
+
2378
+
2379
+	/**
2380
+	 * Saves
2381
+	 *
2382
+	 * @access private
2383
+	 * @param bool $REG_ID
2384
+	 * @return bool
2385
+	 * @throws EE_Error
2386
+	 * @throws InvalidArgumentException
2387
+	 * @throws InvalidDataTypeException
2388
+	 * @throws InvalidInterfaceException
2389
+	 * @throws ReflectionException
2390
+	 */
2391
+	private function _save_reg_custom_questions_form($REG_ID = false)
2392
+	{
2393
+		if (! $REG_ID) {
2394
+			EE_Error::add_error(
2395
+				esc_html__(
2396
+					'An error occurred. No registration ID was received.',
2397
+					'event_espresso'
2398
+				),
2399
+				__FILE__,
2400
+				__FUNCTION__,
2401
+				__LINE__
2402
+			);
2403
+		}
2404
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2405
+		$form->receive_form_submission($this->_req_data);
2406
+		$success = false;
2407
+		if ($form->is_valid()) {
2408
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2409
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2410
+					$where_conditions = array(
2411
+						'QST_ID' => $question_id,
2412
+						'REG_ID' => $REG_ID,
2413
+					);
2414
+					$possibly_new_values = array(
2415
+						'ANS_value' => $input->normalized_value(),
2416
+					);
2417
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2418
+					if ($answer instanceof EE_Answer) {
2419
+						$success = $answer->save($possibly_new_values);
2420
+					} else {
2421
+						// insert it then
2422
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2423
+						$answer = EE_Answer::new_instance($cols_n_vals);
2424
+						$success = $answer->save();
2425
+					}
2426
+				}
2427
+			}
2428
+		} else {
2429
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2430
+		}
2431
+		return $success;
2432
+	}
2433
+
2434
+
2435
+	/**
2436
+	 *        generates HTML for the Registration main meta box
2437
+	 *
2438
+	 * @access public
2439
+	 * @return void
2440
+	 * @throws DomainException
2441
+	 * @throws EE_Error
2442
+	 * @throws InvalidArgumentException
2443
+	 * @throws InvalidDataTypeException
2444
+	 * @throws InvalidInterfaceException
2445
+	 * @throws ReflectionException
2446
+	 */
2447
+	public function _reg_attendees_meta_box()
2448
+	{
2449
+		$REG = $this->getRegistrationModel();
2450
+		// get all other registrations on this transaction, and cache
2451
+		// the attendees for them so we don't have to run another query using force_join
2452
+		$registrations = $REG->get_all(
2453
+			array(
2454
+				array(
2455
+					'TXN_ID' => $this->_registration->transaction_ID(),
2456
+					'REG_ID' => array('!=', $this->_registration->ID()),
2457
+				),
2458
+				'force_join' => array('Attendee'),
2459
+				'default_where_conditions' => 'other_models_only',
2460
+			)
2461
+		);
2462
+		$this->_template_args['attendees'] = array();
2463
+		$this->_template_args['attendee_notice'] = '';
2464
+		if (
2465
+			empty($registrations)
2466
+			|| (is_array($registrations)
2467
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2468
+		) {
2469
+			EE_Error::add_error(
2470
+				esc_html__(
2471
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2472
+					'event_espresso'
2473
+				),
2474
+				__FILE__,
2475
+				__FUNCTION__,
2476
+				__LINE__
2477
+			);
2478
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2479
+		} else {
2480
+			$att_nmbr = 1;
2481
+			foreach ($registrations as $registration) {
2482
+				/* @var $registration EE_Registration */
2483
+				$attendee = $registration->attendee()
2484
+					? $registration->attendee()
2485
+					: $this->getAttendeeModel()->create_default_object();
2486
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2487
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2488
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2489
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2490
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2491
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2492
+					', ',
2493
+					$attendee->full_address_as_array()
2494
+				);
2495
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2496
+					array(
2497
+						'action' => 'edit_attendee',
2498
+						'post'   => $attendee->ID(),
2499
+					),
2500
+					REG_ADMIN_URL
2501
+				);
2502
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2503
+					? $registration->event_obj()->name()
2504
+					: '';
2505
+				$att_nmbr++;
2506
+			}
2507
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2508
+		}
2509
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2510
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2511
+	}
2512
+
2513
+
2514
+	/**
2515
+	 *        generates HTML for the Edit Registration side meta box
2516
+	 *
2517
+	 * @access public
2518
+	 * @return void
2519
+	 * @throws DomainException
2520
+	 * @throws EE_Error
2521
+	 * @throws InvalidArgumentException
2522
+	 * @throws InvalidDataTypeException
2523
+	 * @throws InvalidInterfaceException
2524
+	 * @throws ReflectionException
2525
+	 */
2526
+	public function _reg_registrant_side_meta_box()
2527
+	{
2528
+		/*@var $attendee EE_Attendee */
2529
+		$att_check = $this->_registration->attendee();
2530
+		$attendee = $att_check instanceof EE_Attendee
2531
+			? $att_check
2532
+			: $this->getAttendeeModel()->create_default_object();
2533
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2534
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2535
+		// primary registration object (that way we know if we need to show create button or not)
2536
+		if (! $this->_registration->is_primary_registrant()) {
2537
+			$primary_registration = $this->_registration->get_primary_registration();
2538
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2539
+				: null;
2540
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2541
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2542
+				// custom attendee object so let's not worry about the primary reg.
2543
+				$primary_registration = null;
2544
+			}
2545
+		} else {
2546
+			$primary_registration = null;
2547
+		}
2548
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2549
+		$this->_template_args['fname'] = $attendee->fname();
2550
+		$this->_template_args['lname'] = $attendee->lname();
2551
+		$this->_template_args['email'] = $attendee->email();
2552
+		$this->_template_args['phone'] = $attendee->phone();
2553
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2554
+		// edit link
2555
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2556
+			array(
2557
+				'action' => 'edit_attendee',
2558
+				'post'   => $attendee->ID(),
2559
+			),
2560
+			REG_ADMIN_URL
2561
+		);
2562
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2563
+		// create link
2564
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2565
+			? EE_Admin_Page::add_query_args_and_nonce(
2566
+				array(
2567
+					'action'  => 'duplicate_attendee',
2568
+					'_REG_ID' => $this->_registration->ID(),
2569
+				),
2570
+				REG_ADMIN_URL
2571
+			) : '';
2572
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2573
+		$this->_template_args['att_check'] = $att_check;
2574
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2575
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2576
+	}
2577
+
2578
+
2579
+	/**
2580
+	 * trash or restore registrations
2581
+	 *
2582
+	 * @param  boolean $trash whether to archive or restore
2583
+	 * @return void
2584
+	 * @throws EE_Error
2585
+	 * @throws InvalidArgumentException
2586
+	 * @throws InvalidDataTypeException
2587
+	 * @throws InvalidInterfaceException
2588
+	 * @throws RuntimeException
2589
+	 * @access protected
2590
+	 */
2591
+	protected function _trash_or_restore_registrations($trash = true)
2592
+	{
2593
+		// if empty _REG_ID then get out because there's nothing to do
2594
+		if (empty($this->_req_data['_REG_ID'])) {
2595
+			EE_Error::add_error(
2596
+				sprintf(
2597
+					esc_html__(
2598
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2599
+						'event_espresso'
2600
+					),
2601
+					$trash ? 'trash' : 'restore'
2602
+				),
2603
+				__FILE__,
2604
+				__LINE__,
2605
+				__FUNCTION__
2606
+			);
2607
+			$this->_redirect_after_action(false, '', '', array(), true);
2608
+		}
2609
+		$success = 0;
2610
+		$overwrite_msgs = false;
2611
+		// Checkboxes
2612
+		if (! is_array($this->_req_data['_REG_ID'])) {
2613
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2614
+		}
2615
+		$reg_count = count($this->_req_data['_REG_ID']);
2616
+		// cycle thru checkboxes
2617
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2618
+			/** @var EE_Registration $REG */
2619
+			$REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2620
+			$payments = $REG->registration_payments();
2621
+			if (! empty($payments)) {
2622
+				$name = $REG->attendee() instanceof EE_Attendee
2623
+					? $REG->attendee()->full_name()
2624
+					: esc_html__('Unknown Attendee', 'event_espresso');
2625
+				$overwrite_msgs = true;
2626
+				EE_Error::add_error(
2627
+					sprintf(
2628
+						esc_html__(
2629
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2630
+							'event_espresso'
2631
+						),
2632
+						$name
2633
+					),
2634
+					__FILE__,
2635
+					__FUNCTION__,
2636
+					__LINE__
2637
+				);
2638
+				// can't trash this registration because it has payments.
2639
+				continue;
2640
+			}
2641
+			$updated = $trash ? $REG->delete() : $REG->restore();
2642
+			if ($updated) {
2643
+				$success++;
2644
+			}
2645
+		}
2646
+		$this->_redirect_after_action(
2647
+			$success === $reg_count, // were ALL registrations affected?
2648
+			$success > 1
2649
+				? esc_html__('Registrations', 'event_espresso')
2650
+				: esc_html__('Registration', 'event_espresso'),
2651
+			$trash
2652
+				? esc_html__('moved to the trash', 'event_espresso')
2653
+				: esc_html__('restored', 'event_espresso'),
2654
+			$this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2655
+			$overwrite_msgs
2656
+		);
2657
+	}
2658
+
2659
+
2660
+	/**
2661
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2662
+	 * registration but also.
2663
+	 * 1. Removing relations to EE_Attendee
2664
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2665
+	 * ALSO trashed.
2666
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2667
+	 * 4. Removing relationships between all tickets and the related registrations
2668
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2669
+	 * 6. Deleting permanently any related Checkins.
2670
+	 *
2671
+	 * @return void
2672
+	 * @throws EE_Error
2673
+	 * @throws InvalidArgumentException
2674
+	 * @throws InvalidDataTypeException
2675
+	 * @throws InvalidInterfaceException
2676
+	 * @throws ReflectionException
2677
+	 */
2678
+	protected function _delete_registrations()
2679
+	{
2680
+		$REG_MDL = $this->getRegistrationModel();
2681
+		$success = 1;
2682
+		// Checkboxes
2683
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2684
+			// if array has more than one element than success message should be plural
2685
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2686
+			// cycle thru checkboxes
2687
+			foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2688
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2689
+				if (! $REG instanceof EE_Registration) {
2690
+					continue;
2691
+				}
2692
+				$deleted = $this->_delete_registration($REG);
2693
+				if (! $deleted) {
2694
+					$success = 0;
2695
+				}
2696
+			}
2697
+		} else {
2698
+			// grab single id and delete
2699
+			$REG_ID = $this->_req_data['_REG_ID'];
2700
+			/** @var EE_Registration $REG */
2701
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2702
+			$deleted = $this->_delete_registration($REG);
2703
+			if (! $deleted) {
2704
+				$success = 0;
2705
+			}
2706
+		}
2707
+		$what = $success > 1
2708
+			? esc_html__('Registrations', 'event_espresso')
2709
+			: esc_html__('Registration', 'event_espresso');
2710
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2711
+		$this->_redirect_after_action(
2712
+			$success,
2713
+			$what,
2714
+			$action_desc,
2715
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2716
+			true
2717
+		);
2718
+	}
2719
+
2720
+
2721
+	/**
2722
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2723
+	 * models get affected.
2724
+	 *
2725
+	 * @param EE_Registration $REG registration to be deleted permanently
2726
+	 * @return bool true = successful deletion, false = fail.
2727
+	 * @throws EE_Error
2728
+	 * @throws InvalidArgumentException
2729
+	 * @throws InvalidDataTypeException
2730
+	 * @throws InvalidInterfaceException
2731
+	 * @throws ReflectionException
2732
+	 */
2733
+	protected function _delete_registration(EE_Registration $REG)
2734
+	{
2735
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2736
+		// registrations on the transaction that are NOT trashed.
2737
+		$TXN = $REG->get_first_related('Transaction');
2738
+		if (! $TXN instanceof EE_Transaction) {
2739
+			EE_Error::add_error(
2740
+				sprintf(
2741
+					esc_html__(
2742
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2743
+						'event_espresso'
2744
+					),
2745
+					$REG->id()
2746
+				),
2747
+				__FILE__,
2748
+				__FUNCTION__,
2749
+				__LINE__
2750
+			);
2751
+			return false;
2752
+		}
2753
+		$REGS = $TXN->get_many_related('Registration');
2754
+		$all_trashed = true;
2755
+		foreach ($REGS as $registration) {
2756
+			if (! $registration->get('REG_deleted')) {
2757
+				$all_trashed = false;
2758
+			}
2759
+		}
2760
+		if (! $all_trashed) {
2761
+			EE_Error::add_error(
2762
+				esc_html__(
2763
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2764
+					'event_espresso'
2765
+				),
2766
+				__FILE__,
2767
+				__FUNCTION__,
2768
+				__LINE__
2769
+			);
2770
+			return false;
2771
+		}
2772
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2773
+		// separately from THIS one).
2774
+		foreach ($REGS as $registration) {
2775
+			// delete related answers
2776
+			$registration->delete_related_permanently('Answer');
2777
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2778
+			$attendee = $registration->get_first_related('Attendee');
2779
+			if ($attendee instanceof EE_Attendee) {
2780
+				$registration->_remove_relation_to($attendee, 'Attendee');
2781
+			}
2782
+			// now remove relationships to tickets on this registration.
2783
+			$registration->_remove_relations('Ticket');
2784
+			// now delete permanently the checkins related to this registration.
2785
+			$registration->delete_related_permanently('Checkin');
2786
+			if ($registration->ID() === $REG->ID()) {
2787
+				continue;
2788
+			} //we don't want to delete permanently the existing registration just yet.
2789
+			// remove relation to transaction for these registrations if NOT the existing registrations
2790
+			$registration->_remove_relations('Transaction');
2791
+			// delete permanently any related messages.
2792
+			$registration->delete_related_permanently('Message');
2793
+			// now delete this registration permanently
2794
+			$registration->delete_permanently();
2795
+		}
2796
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2797
+		// (the transaction and line items should be all that's left).
2798
+		// delete the line items related to the transaction for this registration.
2799
+		$TXN->delete_related_permanently('Line_Item');
2800
+		// we need to remove all the relationships on the transaction
2801
+		$TXN->delete_related_permanently('Payment');
2802
+		$TXN->delete_related_permanently('Extra_Meta');
2803
+		$TXN->delete_related_permanently('Message');
2804
+		// now we can delete this REG permanently (and the transaction of course)
2805
+		$REG->delete_related_permanently('Transaction');
2806
+		return $REG->delete_permanently();
2807
+	}
2808
+
2809
+
2810
+	/**
2811
+	 *    generates HTML for the Register New Attendee Admin page
2812
+	 *
2813
+	 * @access private
2814
+	 * @throws DomainException
2815
+	 * @throws EE_Error
2816
+	 * @throws InvalidArgumentException
2817
+	 * @throws InvalidDataTypeException
2818
+	 * @throws InvalidInterfaceException
2819
+	 * @throws ReflectionException
2820
+	 */
2821
+	public function new_registration()
2822
+	{
2823
+		if (! $this->_set_reg_event()) {
2824
+			throw new EE_Error(
2825
+				esc_html__(
2826
+					'Unable to continue with registering because there is no Event ID in the request',
2827
+					'event_espresso'
2828
+				)
2829
+			);
2830
+		}
2831
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2832
+		// gotta start with a clean slate if we're not coming here via ajax
2833
+		if (
2834
+			! defined('DOING_AJAX')
2835
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2836
+		) {
2837
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2838
+		}
2839
+		$this->_template_args['event_name'] = '';
2840
+		// event name
2841
+		if ($this->_reg_event) {
2842
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2843
+			$edit_event_url = self::add_query_args_and_nonce(
2844
+				array(
2845
+					'action' => 'edit',
2846
+					'post'   => $this->_reg_event->ID(),
2847
+				),
2848
+				EVENTS_ADMIN_URL
2849
+			);
2850
+			$edit_event_lnk = '<a href="'
2851
+							  . $edit_event_url
2852
+							  . '" title="'
2853
+							  . esc_attr__('Edit ', 'event_espresso')
2854
+							  . $this->_reg_event->name()
2855
+							  . '">'
2856
+							  . esc_html__('Edit Event', 'event_espresso')
2857
+							  . '</a>';
2858
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2859
+												   . $edit_event_lnk
2860
+												   . '</span>';
2861
+		}
2862
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2863
+		if (defined('DOING_AJAX')) {
2864
+			$this->_return_json();
2865
+		}
2866
+		// grab header
2867
+		$template_path =
2868
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2869
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
+			$template_path,
2871
+			$this->_template_args,
2872
+			true
2873
+		);
2874
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2875
+		// the details template wrapper
2876
+		$this->display_admin_page_with_sidebar();
2877
+	}
2878
+
2879
+
2880
+	/**
2881
+	 * This returns the content for a registration step
2882
+	 *
2883
+	 * @access protected
2884
+	 * @return string html
2885
+	 * @throws DomainException
2886
+	 * @throws EE_Error
2887
+	 * @throws InvalidArgumentException
2888
+	 * @throws InvalidDataTypeException
2889
+	 * @throws InvalidInterfaceException
2890
+	 */
2891
+	protected function _get_registration_step_content()
2892
+	{
2893
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2894
+			$warning_msg = sprintf(
2895
+				esc_html__(
2896
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2897
+					'event_espresso'
2898
+				),
2899
+				'<br />',
2900
+				'<h3 class="important-notice">',
2901
+				'</h3>',
2902
+				'<div class="float-right">',
2903
+				'<span id="redirect_timer" class="important-notice">30</span>',
2904
+				'</div>',
2905
+				'<b>',
2906
+				'</b>'
2907
+			);
2908
+			return '
2909 2909
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2910 2910
 	<script >
2911 2911
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2918,869 +2918,869 @@  discard block
 block discarded – undo
2918 2918
 	        }
2919 2919
 	    }, 800 );
2920 2920
 	</script >';
2921
-        }
2922
-        $template_args = array(
2923
-            'title'                    => '',
2924
-            'content'                  => '',
2925
-            'step_button_text'         => '',
2926
-            'show_notification_toggle' => false,
2927
-        );
2928
-        // to indicate we're processing a new registration
2929
-        $hidden_fields = array(
2930
-            'processing_registration' => array(
2931
-                'type'  => 'hidden',
2932
-                'value' => 0,
2933
-            ),
2934
-            'event_id'                => array(
2935
-                'type'  => 'hidden',
2936
-                'value' => $this->_reg_event->ID(),
2937
-            ),
2938
-        );
2939
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
2940
-        $cart = EE_Registry::instance()->SSN->cart();
2941
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2942
-        switch ($step) {
2943
-            case 'ticket':
2944
-                $hidden_fields['processing_registration']['value'] = 1;
2945
-                $template_args['title'] = esc_html__(
2946
-                    'Step One: Select the Ticket for this registration',
2947
-                    'event_espresso'
2948
-                );
2949
-                $template_args['content'] =
2950
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2951
-                $template_args['content'] .= '</div>';
2952
-                $template_args['step_button_text'] = esc_html__(
2953
-                    'Add Tickets and Continue to Registrant Details',
2954
-                    'event_espresso'
2955
-                );
2956
-                $template_args['show_notification_toggle'] = false;
2957
-                break;
2958
-            case 'questions':
2959
-                $hidden_fields['processing_registration']['value'] = 2;
2960
-                $template_args['title'] = esc_html__(
2961
-                    'Step Two: Add Registrant Details for this Registration',
2962
-                    'event_espresso'
2963
-                );
2964
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2965
-                // properly by the first process_reg_step run.
2966
-                $template_args['content'] =
2967
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2968
-                $template_args['step_button_text'] = esc_html__(
2969
-                    'Save Registration and Continue to Details',
2970
-                    'event_espresso'
2971
-                );
2972
-                $template_args['show_notification_toggle'] = true;
2973
-                break;
2974
-        }
2975
-        // we come back to the process_registration_step route.
2976
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2977
-        return EEH_Template::display_template(
2978
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2979
-            $template_args,
2980
-            true
2981
-        );
2982
-    }
2983
-
2984
-
2985
-    /**
2986
-     *        set_reg_event
2987
-     *
2988
-     * @access private
2989
-     * @return bool
2990
-     * @throws EE_Error
2991
-     * @throws InvalidArgumentException
2992
-     * @throws InvalidDataTypeException
2993
-     * @throws InvalidInterfaceException
2994
-     */
2995
-    private function _set_reg_event()
2996
-    {
2997
-        if (is_object($this->_reg_event)) {
2998
-            return true;
2999
-        }
3000
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3001
-        if (! $EVT_ID) {
3002
-            return false;
3003
-        }
3004
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
3005
-        return true;
3006
-    }
3007
-
3008
-
3009
-    /**
3010
-     * process_reg_step
3011
-     *
3012
-     * @access        public
3013
-     * @return string
3014
-     * @throws DomainException
3015
-     * @throws EE_Error
3016
-     * @throws InvalidArgumentException
3017
-     * @throws InvalidDataTypeException
3018
-     * @throws InvalidInterfaceException
3019
-     * @throws ReflectionException
3020
-     * @throws RuntimeException
3021
-     */
3022
-    public function process_reg_step()
3023
-    {
3024
-        EE_System::do_not_cache();
3025
-        $this->_set_reg_event();
3026
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3027
-        EE_Registry::instance()->REQ->set('uts', time());
3028
-        // what step are we on?
3029
-        $cart = EE_Registry::instance()->SSN->cart();
3030
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3031
-        // if doing ajax then we need to verify the nonce
3032
-        if (defined('DOING_AJAX')) {
3033
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3034
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3035
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3036
-        }
3037
-        switch ($step) {
3038
-            case 'ticket':
3039
-                // process ticket selection
3040
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3041
-                if ($success) {
3042
-                    EE_Error::add_success(
3043
-                        esc_html__(
3044
-                            'Tickets Selected. Now complete the registration.',
3045
-                            'event_espresso'
3046
-                        )
3047
-                    );
3048
-                } else {
3049
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3050
-                }
3051
-                if (defined('DOING_AJAX')) {
3052
-                    $this->new_registration(); // display next step
3053
-                } else {
3054
-                    $query_args = array(
3055
-                        'action'                  => 'new_registration',
3056
-                        'processing_registration' => 1,
3057
-                        'event_id'                => $this->_reg_event->ID(),
3058
-                        'uts'                     => time(),
3059
-                    );
3060
-                    $this->_redirect_after_action(
3061
-                        false,
3062
-                        '',
3063
-                        '',
3064
-                        $query_args,
3065
-                        true
3066
-                    );
3067
-                }
3068
-                break;
3069
-            case 'questions':
3070
-                if (
3071
-                    ! isset(
3072
-                        $this->_req_data['txn_reg_status_change'],
3073
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
3074
-                    )
3075
-                ) {
3076
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3077
-                }
3078
-                // process registration
3079
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3080
-                if ($cart instanceof EE_Cart) {
3081
-                    $grand_total = $cart->get_cart_grand_total();
3082
-                    if ($grand_total instanceof EE_Line_Item) {
3083
-                        $grand_total->save_this_and_descendants_to_txn();
3084
-                    }
3085
-                }
3086
-                if (! $transaction instanceof EE_Transaction) {
3087
-                    $query_args = array(
3088
-                        'action'                  => 'new_registration',
3089
-                        'processing_registration' => 2,
3090
-                        'event_id'                => $this->_reg_event->ID(),
3091
-                        'uts'                     => time(),
3092
-                    );
3093
-                    if (defined('DOING_AJAX')) {
3094
-                        // display registration form again because there are errors (maybe validation?)
3095
-                        $this->new_registration();
3096
-                        return;
3097
-                    }
3098
-                    $this->_redirect_after_action(
3099
-                        false,
3100
-                        '',
3101
-                        '',
3102
-                        $query_args,
3103
-                        true
3104
-                    );
3105
-                    return;
3106
-                }
3107
-                // maybe update status, and make sure to save transaction if not done already
3108
-                if (! $transaction->update_status_based_on_total_paid()) {
3109
-                    $transaction->save();
3110
-                }
3111
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3112
-                $this->_req_data = array();
3113
-                $query_args = array(
3114
-                    'action'        => 'redirect_to_txn',
3115
-                    'TXN_ID'        => $transaction->ID(),
3116
-                    'EVT_ID'        => $this->_reg_event->ID(),
3117
-                    'event_name'    => urlencode($this->_reg_event->name()),
3118
-                    'redirect_from' => 'new_registration',
3119
-                );
3120
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3121
-                break;
3122
-        }
3123
-        // what are you looking here for?  Should be nothing to do at this point.
3124
-    }
3125
-
3126
-
3127
-    /**
3128
-     * redirect_to_txn
3129
-     *
3130
-     * @access public
3131
-     * @return void
3132
-     * @throws EE_Error
3133
-     * @throws InvalidArgumentException
3134
-     * @throws InvalidDataTypeException
3135
-     * @throws InvalidInterfaceException
3136
-     * @throws ReflectionException
3137
-     */
3138
-    public function redirect_to_txn()
3139
-    {
3140
-        EE_System::do_not_cache();
3141
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3142
-        $query_args = array(
3143
-            'action' => 'view_transaction',
3144
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3145
-            'page'   => 'espresso_transactions',
3146
-        );
3147
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3148
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3149
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3150
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3151
-        }
3152
-        EE_Error::add_success(
3153
-            esc_html__(
3154
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3155
-                'event_espresso'
3156
-            )
3157
-        );
3158
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3159
-    }
3160
-
3161
-
3162
-    /**
3163
-     *        generates HTML for the Attendee Contact List
3164
-     *
3165
-     * @access protected
3166
-     * @return void
3167
-     * @throws DomainException
3168
-     * @throws EE_Error
3169
-     */
3170
-    protected function _attendee_contact_list_table()
3171
-    {
3172
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3173
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3174
-        $this->display_admin_list_table_page_with_no_sidebar();
3175
-    }
3176
-
3177
-
3178
-    /**
3179
-     *        get_attendees
3180
-     *
3181
-     * @param      $per_page
3182
-     * @param bool $count whether to return count or data.
3183
-     * @param bool $trash
3184
-     * @return array
3185
-     * @throws EE_Error
3186
-     * @throws InvalidArgumentException
3187
-     * @throws InvalidDataTypeException
3188
-     * @throws InvalidInterfaceException
3189
-     * @access public
3190
-     */
3191
-    public function get_attendees($per_page, $count = false, $trash = false)
3192
-    {
3193
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3194
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3195
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3196
-        switch ($this->_req_data['orderby']) {
3197
-            case 'ATT_ID':
3198
-                $orderby = 'ATT_ID';
3199
-                break;
3200
-            case 'ATT_fname':
3201
-                $orderby = 'ATT_fname';
3202
-                break;
3203
-            case 'ATT_email':
3204
-                $orderby = 'ATT_email';
3205
-                break;
3206
-            case 'ATT_city':
3207
-                $orderby = 'ATT_city';
3208
-                break;
3209
-            case 'STA_ID':
3210
-                $orderby = 'STA_ID';
3211
-                break;
3212
-            case 'CNT_ID':
3213
-                $orderby = 'CNT_ID';
3214
-                break;
3215
-            case 'Registration_Count':
3216
-                $orderby = 'Registration_Count';
3217
-                break;
3218
-            default:
3219
-                $orderby = 'ATT_lname';
3220
-        }
3221
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3222
-            ? $this->_req_data['order']
3223
-            : 'ASC';
3224
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3225
-            ? $this->_req_data['paged']
3226
-            : 1;
3227
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3228
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3229
-            ? $this->_req_data['perpage']
3230
-            : $per_page;
3231
-        $_where = array();
3232
-        if (! empty($this->_req_data['s'])) {
3233
-            $sstr = '%' . $this->_req_data['s'] . '%';
3234
-            $_where['OR'] = array(
3235
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3236
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3237
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3238
-                'ATT_fname'                         => array('LIKE', $sstr),
3239
-                'ATT_lname'                         => array('LIKE', $sstr),
3240
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3241
-                'ATT_email'                         => array('LIKE', $sstr),
3242
-                'ATT_address'                       => array('LIKE', $sstr),
3243
-                'ATT_address2'                      => array('LIKE', $sstr),
3244
-                'ATT_city'                          => array('LIKE', $sstr),
3245
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3246
-                'State.STA_name'                    => array('LIKE', $sstr),
3247
-                'ATT_phone'                         => array('LIKE', $sstr),
3248
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3249
-                'Registration.REG_code'             => array('LIKE', $sstr),
3250
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3251
-            );
3252
-        }
3253
-        $offset = ($current_page - 1) * $per_page;
3254
-        $limit = $count ? null : array($offset, $per_page);
3255
-        $query_args = array(
3256
-            $_where,
3257
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3258
-            'limit'         => $limit,
3259
-        );
3260
-        if (! $count) {
3261
-            $query_args['order_by'] = array($orderby => $sort);
3262
-        }
3263
-        if ($trash) {
3264
-            $query_args[0]['status'] = array('!=', 'publish');
3265
-            $all_attendees = $count
3266
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3267
-                : $this->getAttendeeModel()->get_all($query_args);
3268
-        } else {
3269
-            $query_args[0]['status'] = array('IN', array('publish'));
3270
-            $all_attendees = $count
3271
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3272
-                : $this->getAttendeeModel()->get_all($query_args);
3273
-        }
3274
-        return $all_attendees;
3275
-    }
3276
-
3277
-
3278
-    /**
3279
-     * This is just taking care of resending the registration confirmation
3280
-     *
3281
-     * @access protected
3282
-     * @return void
3283
-     * @throws EE_Error
3284
-     * @throws InvalidArgumentException
3285
-     * @throws InvalidDataTypeException
3286
-     * @throws InvalidInterfaceException
3287
-     * @throws ReflectionException
3288
-     */
3289
-    protected function _resend_registration()
3290
-    {
3291
-        $this->_process_resend_registration();
3292
-        $query_args = isset($this->_req_data['redirect_to'])
3293
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3294
-            : array('action' => 'default');
3295
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3296
-    }
3297
-
3298
-    /**
3299
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3300
-     * to use when selecting registrations
3301
-     *
3302
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3303
-     *                                                     the query parameters from the request
3304
-     * @return void ends the request with a redirect or download
3305
-     */
3306
-    public function _registrations_report_base($method_name_for_getting_query_params)
3307
-    {
3308
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3309
-            wp_redirect(
3310
-                EE_Admin_Page::add_query_args_and_nonce(
3311
-                    array(
3312
-                        'page'        => 'espresso_batch',
3313
-                        'batch'       => 'file',
3314
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3315
-                        'filters'     => urlencode(
3316
-                            serialize(
3317
-                                $this->$method_name_for_getting_query_params(
3318
-                                    EEH_Array::is_set(
3319
-                                        $this->_req_data,
3320
-                                        'filters',
3321
-                                        array()
3322
-                                    )
3323
-                                )
3324
-                            )
3325
-                        ),
3326
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3327
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3328
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3329
-                    )
3330
-                )
3331
-            );
3332
-        } else {
3333
-            $new_request_args = array(
3334
-                'export' => 'report',
3335
-                'action' => 'registrations_report_for_event',
3336
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3337
-            );
3338
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3339
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3340
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3341
-                $EE_Export = EE_Export::instance($this->_req_data);
3342
-                $EE_Export->export();
3343
-            }
3344
-        }
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Creates a registration report using only query parameters in the request
3350
-     *
3351
-     * @return void
3352
-     */
3353
-    public function _registrations_report()
3354
-    {
3355
-        $this->_registrations_report_base('_get_registration_query_parameters');
3356
-    }
3357
-
3358
-
3359
-    public function _contact_list_export()
3360
-    {
3361
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3362
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3363
-            $EE_Export = EE_Export::instance($this->_req_data);
3364
-            $EE_Export->export_attendees();
3365
-        }
3366
-    }
3367
-
3368
-
3369
-    public function _contact_list_report()
3370
-    {
3371
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3372
-            wp_redirect(
3373
-                EE_Admin_Page::add_query_args_and_nonce(
3374
-                    array(
3375
-                        'page'        => 'espresso_batch',
3376
-                        'batch'       => 'file',
3377
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3378
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3379
-                    )
3380
-                )
3381
-            );
3382
-        } else {
3383
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3384
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3385
-                $EE_Export = EE_Export::instance($this->_req_data);
3386
-                $EE_Export->report_attendees();
3387
-            }
3388
-        }
3389
-    }
3390
-
3391
-
3392
-
3393
-
3394
-
3395
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3396
-    /**
3397
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3398
-     *
3399
-     * @return void
3400
-     * @throws EE_Error
3401
-     * @throws InvalidArgumentException
3402
-     * @throws InvalidDataTypeException
3403
-     * @throws InvalidInterfaceException
3404
-     * @throws ReflectionException
3405
-     */
3406
-    protected function _duplicate_attendee()
3407
-    {
3408
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3409
-        // verify we have necessary info
3410
-        if (empty($this->_req_data['_REG_ID'])) {
3411
-            EE_Error::add_error(
3412
-                esc_html__(
3413
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3414
-                    'event_espresso'
3415
-                ),
3416
-                __FILE__,
3417
-                __LINE__,
3418
-                __FUNCTION__
3419
-            );
3420
-            $query_args = array('action' => $action);
3421
-            $this->_redirect_after_action('', '', '', $query_args, true);
3422
-        }
3423
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3424
-        $registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3425
-        $attendee = $registration->attendee();
3426
-        // remove relation of existing attendee on registration
3427
-        $registration->_remove_relation_to($attendee, 'Attendee');
3428
-        // new attendee
3429
-        $new_attendee = clone $attendee;
3430
-        $new_attendee->set('ATT_ID', 0);
3431
-        $new_attendee->save();
3432
-        // add new attendee to reg
3433
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3434
-        EE_Error::add_success(
3435
-            esc_html__(
3436
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3437
-                'event_espresso'
3438
-            )
3439
-        );
3440
-        // redirect to edit page for attendee
3441
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3442
-        $this->_redirect_after_action('', '', '', $query_args, true);
3443
-    }
3444
-
3445
-
3446
-    /**
3447
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3448
-     *
3449
-     * @param int     $post_id
3450
-     * @param WP_POST $post
3451
-     * @throws DomainException
3452
-     * @throws EE_Error
3453
-     * @throws InvalidArgumentException
3454
-     * @throws InvalidDataTypeException
3455
-     * @throws InvalidInterfaceException
3456
-     * @throws LogicException
3457
-     * @throws InvalidFormSubmissionException
3458
-     * @throws ReflectionException
3459
-     */
3460
-    protected function _insert_update_cpt_item($post_id, $post)
3461
-    {
3462
-        $success = true;
3463
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3464
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3465
-            : null;
3466
-        // for attendee updates
3467
-        if ($attendee instanceof EE_Attendee) {
3468
-            // note we should only be UPDATING attendees at this point.
3469
-            $updated_fields = array(
3470
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3471
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3472
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3473
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3474
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3475
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3476
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3477
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3478
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3479
-            );
3480
-            foreach ($updated_fields as $field => $value) {
3481
-                $attendee->set($field, $value);
3482
-            }
3483
-
3484
-            // process contact details metabox form handler (which will also save the attendee)
3485
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3486
-            $success = $contact_details_form->process($this->_req_data);
3487
-
3488
-            $attendee_update_callbacks = apply_filters(
3489
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3490
-                array()
3491
-            );
3492
-            foreach ($attendee_update_callbacks as $a_callback) {
3493
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3494
-                    throw new EE_Error(
3495
-                        sprintf(
3496
-                            esc_html__(
3497
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3498
-                                'event_espresso'
3499
-                            ),
3500
-                            $a_callback
3501
-                        )
3502
-                    );
3503
-                }
3504
-            }
3505
-        }
3506
-
3507
-        if ($success === false) {
3508
-            EE_Error::add_error(
3509
-                esc_html__(
3510
-                    'Something went wrong with updating the meta table data for the registration.',
3511
-                    'event_espresso'
3512
-                ),
3513
-                __FILE__,
3514
-                __FUNCTION__,
3515
-                __LINE__
3516
-            );
3517
-        }
3518
-    }
3519
-
3520
-
3521
-    public function trash_cpt_item($post_id)
3522
-    {
3523
-    }
3524
-
3525
-
3526
-    public function delete_cpt_item($post_id)
3527
-    {
3528
-    }
3529
-
3530
-
3531
-    public function restore_cpt_item($post_id)
3532
-    {
3533
-    }
3534
-
3535
-
3536
-    protected function _restore_cpt_item($post_id, $revision_id)
3537
-    {
3538
-    }
3539
-
3540
-
3541
-    /**
3542
-     * @throws EE_Error
3543
-     * @since 4.10.2.p
3544
-     */
3545
-    public function attendee_editor_metaboxes()
3546
-    {
3547
-        $this->verify_cpt_object();
3548
-        remove_meta_box(
3549
-            'postexcerpt',
3550
-            $this->_cpt_routes[ $this->_req_action ],
3551
-            'normal'
3552
-        );
3553
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3554
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3555
-            add_meta_box(
3556
-                'postexcerpt',
3557
-                esc_html__('Short Biography', 'event_espresso'),
3558
-                'post_excerpt_meta_box',
3559
-                $this->_cpt_routes[ $this->_req_action ],
3560
-                'normal'
3561
-            );
3562
-        }
3563
-        if (post_type_supports('espresso_attendees', 'comments')) {
3564
-            add_meta_box(
3565
-                'commentsdiv',
3566
-                esc_html__('Notes on the Contact', 'event_espresso'),
3567
-                'post_comment_meta_box',
3568
-                $this->_cpt_routes[ $this->_req_action ],
3569
-                'normal',
3570
-                'core'
3571
-            );
3572
-        }
3573
-        add_meta_box(
3574
-            'attendee_contact_info',
3575
-            esc_html__('Contact Info', 'event_espresso'),
3576
-            array($this, 'attendee_contact_info'),
3577
-            $this->_cpt_routes[ $this->_req_action ],
3578
-            'side',
3579
-            'core'
3580
-        );
3581
-        add_meta_box(
3582
-            'attendee_details_address',
3583
-            esc_html__('Address Details', 'event_espresso'),
3584
-            array($this, 'attendee_address_details'),
3585
-            $this->_cpt_routes[ $this->_req_action ],
3586
-            'normal',
3587
-            'core'
3588
-        );
3589
-        add_meta_box(
3590
-            'attendee_registrations',
3591
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3592
-            array($this, 'attendee_registrations_meta_box'),
3593
-            $this->_cpt_routes[ $this->_req_action ],
3594
-            'normal',
3595
-            'high'
3596
-        );
3597
-    }
3598
-
3599
-
3600
-    /**
3601
-     * Metabox for attendee contact info
3602
-     *
3603
-     * @param  WP_Post $post wp post object
3604
-     * @return string attendee contact info ( and form )
3605
-     * @throws EE_Error
3606
-     * @throws InvalidArgumentException
3607
-     * @throws InvalidDataTypeException
3608
-     * @throws InvalidInterfaceException
3609
-     * @throws LogicException
3610
-     * @throws DomainException
3611
-     */
3612
-    public function attendee_contact_info($post)
3613
-    {
3614
-        // get attendee object ( should already have it )
3615
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3616
-        $form->enqueueStylesAndScripts();
3617
-        echo $form->display();
3618
-    }
3619
-
3620
-
3621
-    /**
3622
-     * Return form handler for the contact details metabox
3623
-     *
3624
-     * @param EE_Attendee $attendee
3625
-     * @return AttendeeContactDetailsMetaboxFormHandler
3626
-     * @throws DomainException
3627
-     * @throws InvalidArgumentException
3628
-     * @throws InvalidDataTypeException
3629
-     * @throws InvalidInterfaceException
3630
-     */
3631
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3632
-    {
3633
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3634
-    }
3635
-
3636
-
3637
-    /**
3638
-     * Metabox for attendee details
3639
-     *
3640
-     * @param  WP_Post $post wp post object
3641
-     * @throws DomainException
3642
-     */
3643
-    public function attendee_address_details($post)
3644
-    {
3645
-        // get attendee object (should already have it)
3646
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3647
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3648
-            new EE_Question_Form_Input(
3649
-                EE_Question::new_instance(
3650
-                    array(
3651
-                        'QST_ID'           => 0,
3652
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3653
-                        'QST_system'       => 'admin-state',
3654
-                    )
3655
-                ),
3656
-                EE_Answer::new_instance(
3657
-                    array(
3658
-                        'ANS_ID'    => 0,
3659
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3660
-                    )
3661
-                ),
3662
-                array(
3663
-                    'input_id'       => 'STA_ID',
3664
-                    'input_name'     => 'STA_ID',
3665
-                    'input_prefix'   => '',
3666
-                    'append_qstn_id' => false,
3667
-                )
3668
-            )
3669
-        );
3670
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3671
-            new EE_Question_Form_Input(
3672
-                EE_Question::new_instance(
3673
-                    array(
3674
-                        'QST_ID'           => 0,
3675
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3676
-                        'QST_system'       => 'admin-country',
3677
-                    )
3678
-                ),
3679
-                EE_Answer::new_instance(
3680
-                    array(
3681
-                        'ANS_ID'    => 0,
3682
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3683
-                    )
3684
-                ),
3685
-                array(
3686
-                    'input_id'       => 'CNT_ISO',
3687
-                    'input_name'     => 'CNT_ISO',
3688
-                    'input_prefix'   => '',
3689
-                    'append_qstn_id' => false,
3690
-                )
3691
-            )
3692
-        );
3693
-        $template =
3694
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3695
-        EEH_Template::display_template($template, $this->_template_args);
3696
-    }
3697
-
3698
-
3699
-    /**
3700
-     *        _attendee_details
3701
-     *
3702
-     * @access protected
3703
-     * @param $post
3704
-     * @return void
3705
-     * @throws DomainException
3706
-     * @throws EE_Error
3707
-     * @throws InvalidArgumentException
3708
-     * @throws InvalidDataTypeException
3709
-     * @throws InvalidInterfaceException
3710
-     * @throws ReflectionException
3711
-     */
3712
-    public function attendee_registrations_meta_box($post)
3713
-    {
3714
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3715
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3716
-        $template =
3717
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3718
-        EEH_Template::display_template($template, $this->_template_args);
3719
-    }
3720
-
3721
-
3722
-    /**
3723
-     * add in the form fields for the attendee edit
3724
-     *
3725
-     * @param  WP_Post $post wp post object
3726
-     * @return string html for new form.
3727
-     * @throws DomainException
3728
-     */
3729
-    public function after_title_form_fields($post)
3730
-    {
3731
-        if ($post->post_type === 'espresso_attendees') {
3732
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3733
-            $template_args['attendee'] = $this->_cpt_model_obj;
3734
-            EEH_Template::display_template($template, $template_args);
3735
-        }
3736
-    }
3737
-
3738
-
3739
-    /**
3740
-     *        _trash_or_restore_attendee
3741
-     *
3742
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3743
-     * @return void
3744
-     * @throws EE_Error
3745
-     * @throws InvalidArgumentException
3746
-     * @throws InvalidDataTypeException
3747
-     * @throws InvalidInterfaceException
3748
-     * @throws ReflectionException
3749
-     * @access protected
3750
-     */
3751
-    protected function _trash_or_restore_attendees($trash = true)
3752
-    {
3753
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3754
-        $success = 1;
3755
-        // Checkboxes
3756
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3757
-            // if array has more than one element than success message should be plural
3758
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3759
-            // cycle thru checkboxes
3760
-            foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3761
-                $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3762
-                    : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3763
-                if (! $updated) {
3764
-                    $success = 0;
3765
-                }
3766
-            }
3767
-        } else {
3768
-            // grab single id and delete
3769
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3770
-            // get attendee
3771
-            $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3772
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3773
-            $updated = $att->save() && $updated;
3774
-            if (! $updated) {
3775
-                $success = 0;
3776
-            }
3777
-        }
3778
-        $what = $success > 1
3779
-            ? esc_html__('Contacts', 'event_espresso')
3780
-            : esc_html__('Contact', 'event_espresso');
3781
-        $action_desc = $trash
3782
-            ? esc_html__('moved to the trash', 'event_espresso')
3783
-            : esc_html__('restored', 'event_espresso');
3784
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3785
-    }
2921
+		}
2922
+		$template_args = array(
2923
+			'title'                    => '',
2924
+			'content'                  => '',
2925
+			'step_button_text'         => '',
2926
+			'show_notification_toggle' => false,
2927
+		);
2928
+		// to indicate we're processing a new registration
2929
+		$hidden_fields = array(
2930
+			'processing_registration' => array(
2931
+				'type'  => 'hidden',
2932
+				'value' => 0,
2933
+			),
2934
+			'event_id'                => array(
2935
+				'type'  => 'hidden',
2936
+				'value' => $this->_reg_event->ID(),
2937
+			),
2938
+		);
2939
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
2940
+		$cart = EE_Registry::instance()->SSN->cart();
2941
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2942
+		switch ($step) {
2943
+			case 'ticket':
2944
+				$hidden_fields['processing_registration']['value'] = 1;
2945
+				$template_args['title'] = esc_html__(
2946
+					'Step One: Select the Ticket for this registration',
2947
+					'event_espresso'
2948
+				);
2949
+				$template_args['content'] =
2950
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2951
+				$template_args['content'] .= '</div>';
2952
+				$template_args['step_button_text'] = esc_html__(
2953
+					'Add Tickets and Continue to Registrant Details',
2954
+					'event_espresso'
2955
+				);
2956
+				$template_args['show_notification_toggle'] = false;
2957
+				break;
2958
+			case 'questions':
2959
+				$hidden_fields['processing_registration']['value'] = 2;
2960
+				$template_args['title'] = esc_html__(
2961
+					'Step Two: Add Registrant Details for this Registration',
2962
+					'event_espresso'
2963
+				);
2964
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2965
+				// properly by the first process_reg_step run.
2966
+				$template_args['content'] =
2967
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2968
+				$template_args['step_button_text'] = esc_html__(
2969
+					'Save Registration and Continue to Details',
2970
+					'event_espresso'
2971
+				);
2972
+				$template_args['show_notification_toggle'] = true;
2973
+				break;
2974
+		}
2975
+		// we come back to the process_registration_step route.
2976
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2977
+		return EEH_Template::display_template(
2978
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2979
+			$template_args,
2980
+			true
2981
+		);
2982
+	}
2983
+
2984
+
2985
+	/**
2986
+	 *        set_reg_event
2987
+	 *
2988
+	 * @access private
2989
+	 * @return bool
2990
+	 * @throws EE_Error
2991
+	 * @throws InvalidArgumentException
2992
+	 * @throws InvalidDataTypeException
2993
+	 * @throws InvalidInterfaceException
2994
+	 */
2995
+	private function _set_reg_event()
2996
+	{
2997
+		if (is_object($this->_reg_event)) {
2998
+			return true;
2999
+		}
3000
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3001
+		if (! $EVT_ID) {
3002
+			return false;
3003
+		}
3004
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
3005
+		return true;
3006
+	}
3007
+
3008
+
3009
+	/**
3010
+	 * process_reg_step
3011
+	 *
3012
+	 * @access        public
3013
+	 * @return string
3014
+	 * @throws DomainException
3015
+	 * @throws EE_Error
3016
+	 * @throws InvalidArgumentException
3017
+	 * @throws InvalidDataTypeException
3018
+	 * @throws InvalidInterfaceException
3019
+	 * @throws ReflectionException
3020
+	 * @throws RuntimeException
3021
+	 */
3022
+	public function process_reg_step()
3023
+	{
3024
+		EE_System::do_not_cache();
3025
+		$this->_set_reg_event();
3026
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3027
+		EE_Registry::instance()->REQ->set('uts', time());
3028
+		// what step are we on?
3029
+		$cart = EE_Registry::instance()->SSN->cart();
3030
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3031
+		// if doing ajax then we need to verify the nonce
3032
+		if (defined('DOING_AJAX')) {
3033
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3034
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3035
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3036
+		}
3037
+		switch ($step) {
3038
+			case 'ticket':
3039
+				// process ticket selection
3040
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3041
+				if ($success) {
3042
+					EE_Error::add_success(
3043
+						esc_html__(
3044
+							'Tickets Selected. Now complete the registration.',
3045
+							'event_espresso'
3046
+						)
3047
+					);
3048
+				} else {
3049
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3050
+				}
3051
+				if (defined('DOING_AJAX')) {
3052
+					$this->new_registration(); // display next step
3053
+				} else {
3054
+					$query_args = array(
3055
+						'action'                  => 'new_registration',
3056
+						'processing_registration' => 1,
3057
+						'event_id'                => $this->_reg_event->ID(),
3058
+						'uts'                     => time(),
3059
+					);
3060
+					$this->_redirect_after_action(
3061
+						false,
3062
+						'',
3063
+						'',
3064
+						$query_args,
3065
+						true
3066
+					);
3067
+				}
3068
+				break;
3069
+			case 'questions':
3070
+				if (
3071
+					! isset(
3072
+						$this->_req_data['txn_reg_status_change'],
3073
+						$this->_req_data['txn_reg_status_change']['send_notifications']
3074
+					)
3075
+				) {
3076
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3077
+				}
3078
+				// process registration
3079
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3080
+				if ($cart instanceof EE_Cart) {
3081
+					$grand_total = $cart->get_cart_grand_total();
3082
+					if ($grand_total instanceof EE_Line_Item) {
3083
+						$grand_total->save_this_and_descendants_to_txn();
3084
+					}
3085
+				}
3086
+				if (! $transaction instanceof EE_Transaction) {
3087
+					$query_args = array(
3088
+						'action'                  => 'new_registration',
3089
+						'processing_registration' => 2,
3090
+						'event_id'                => $this->_reg_event->ID(),
3091
+						'uts'                     => time(),
3092
+					);
3093
+					if (defined('DOING_AJAX')) {
3094
+						// display registration form again because there are errors (maybe validation?)
3095
+						$this->new_registration();
3096
+						return;
3097
+					}
3098
+					$this->_redirect_after_action(
3099
+						false,
3100
+						'',
3101
+						'',
3102
+						$query_args,
3103
+						true
3104
+					);
3105
+					return;
3106
+				}
3107
+				// maybe update status, and make sure to save transaction if not done already
3108
+				if (! $transaction->update_status_based_on_total_paid()) {
3109
+					$transaction->save();
3110
+				}
3111
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3112
+				$this->_req_data = array();
3113
+				$query_args = array(
3114
+					'action'        => 'redirect_to_txn',
3115
+					'TXN_ID'        => $transaction->ID(),
3116
+					'EVT_ID'        => $this->_reg_event->ID(),
3117
+					'event_name'    => urlencode($this->_reg_event->name()),
3118
+					'redirect_from' => 'new_registration',
3119
+				);
3120
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3121
+				break;
3122
+		}
3123
+		// what are you looking here for?  Should be nothing to do at this point.
3124
+	}
3125
+
3126
+
3127
+	/**
3128
+	 * redirect_to_txn
3129
+	 *
3130
+	 * @access public
3131
+	 * @return void
3132
+	 * @throws EE_Error
3133
+	 * @throws InvalidArgumentException
3134
+	 * @throws InvalidDataTypeException
3135
+	 * @throws InvalidInterfaceException
3136
+	 * @throws ReflectionException
3137
+	 */
3138
+	public function redirect_to_txn()
3139
+	{
3140
+		EE_System::do_not_cache();
3141
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3142
+		$query_args = array(
3143
+			'action' => 'view_transaction',
3144
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3145
+			'page'   => 'espresso_transactions',
3146
+		);
3147
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3148
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3149
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3150
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3151
+		}
3152
+		EE_Error::add_success(
3153
+			esc_html__(
3154
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3155
+				'event_espresso'
3156
+			)
3157
+		);
3158
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3159
+	}
3160
+
3161
+
3162
+	/**
3163
+	 *        generates HTML for the Attendee Contact List
3164
+	 *
3165
+	 * @access protected
3166
+	 * @return void
3167
+	 * @throws DomainException
3168
+	 * @throws EE_Error
3169
+	 */
3170
+	protected function _attendee_contact_list_table()
3171
+	{
3172
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3173
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3174
+		$this->display_admin_list_table_page_with_no_sidebar();
3175
+	}
3176
+
3177
+
3178
+	/**
3179
+	 *        get_attendees
3180
+	 *
3181
+	 * @param      $per_page
3182
+	 * @param bool $count whether to return count or data.
3183
+	 * @param bool $trash
3184
+	 * @return array
3185
+	 * @throws EE_Error
3186
+	 * @throws InvalidArgumentException
3187
+	 * @throws InvalidDataTypeException
3188
+	 * @throws InvalidInterfaceException
3189
+	 * @access public
3190
+	 */
3191
+	public function get_attendees($per_page, $count = false, $trash = false)
3192
+	{
3193
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3194
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3195
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3196
+		switch ($this->_req_data['orderby']) {
3197
+			case 'ATT_ID':
3198
+				$orderby = 'ATT_ID';
3199
+				break;
3200
+			case 'ATT_fname':
3201
+				$orderby = 'ATT_fname';
3202
+				break;
3203
+			case 'ATT_email':
3204
+				$orderby = 'ATT_email';
3205
+				break;
3206
+			case 'ATT_city':
3207
+				$orderby = 'ATT_city';
3208
+				break;
3209
+			case 'STA_ID':
3210
+				$orderby = 'STA_ID';
3211
+				break;
3212
+			case 'CNT_ID':
3213
+				$orderby = 'CNT_ID';
3214
+				break;
3215
+			case 'Registration_Count':
3216
+				$orderby = 'Registration_Count';
3217
+				break;
3218
+			default:
3219
+				$orderby = 'ATT_lname';
3220
+		}
3221
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3222
+			? $this->_req_data['order']
3223
+			: 'ASC';
3224
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3225
+			? $this->_req_data['paged']
3226
+			: 1;
3227
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3228
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3229
+			? $this->_req_data['perpage']
3230
+			: $per_page;
3231
+		$_where = array();
3232
+		if (! empty($this->_req_data['s'])) {
3233
+			$sstr = '%' . $this->_req_data['s'] . '%';
3234
+			$_where['OR'] = array(
3235
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3236
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3237
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3238
+				'ATT_fname'                         => array('LIKE', $sstr),
3239
+				'ATT_lname'                         => array('LIKE', $sstr),
3240
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3241
+				'ATT_email'                         => array('LIKE', $sstr),
3242
+				'ATT_address'                       => array('LIKE', $sstr),
3243
+				'ATT_address2'                      => array('LIKE', $sstr),
3244
+				'ATT_city'                          => array('LIKE', $sstr),
3245
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3246
+				'State.STA_name'                    => array('LIKE', $sstr),
3247
+				'ATT_phone'                         => array('LIKE', $sstr),
3248
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3249
+				'Registration.REG_code'             => array('LIKE', $sstr),
3250
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3251
+			);
3252
+		}
3253
+		$offset = ($current_page - 1) * $per_page;
3254
+		$limit = $count ? null : array($offset, $per_page);
3255
+		$query_args = array(
3256
+			$_where,
3257
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3258
+			'limit'         => $limit,
3259
+		);
3260
+		if (! $count) {
3261
+			$query_args['order_by'] = array($orderby => $sort);
3262
+		}
3263
+		if ($trash) {
3264
+			$query_args[0]['status'] = array('!=', 'publish');
3265
+			$all_attendees = $count
3266
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3267
+				: $this->getAttendeeModel()->get_all($query_args);
3268
+		} else {
3269
+			$query_args[0]['status'] = array('IN', array('publish'));
3270
+			$all_attendees = $count
3271
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3272
+				: $this->getAttendeeModel()->get_all($query_args);
3273
+		}
3274
+		return $all_attendees;
3275
+	}
3276
+
3277
+
3278
+	/**
3279
+	 * This is just taking care of resending the registration confirmation
3280
+	 *
3281
+	 * @access protected
3282
+	 * @return void
3283
+	 * @throws EE_Error
3284
+	 * @throws InvalidArgumentException
3285
+	 * @throws InvalidDataTypeException
3286
+	 * @throws InvalidInterfaceException
3287
+	 * @throws ReflectionException
3288
+	 */
3289
+	protected function _resend_registration()
3290
+	{
3291
+		$this->_process_resend_registration();
3292
+		$query_args = isset($this->_req_data['redirect_to'])
3293
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3294
+			: array('action' => 'default');
3295
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3296
+	}
3297
+
3298
+	/**
3299
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3300
+	 * to use when selecting registrations
3301
+	 *
3302
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3303
+	 *                                                     the query parameters from the request
3304
+	 * @return void ends the request with a redirect or download
3305
+	 */
3306
+	public function _registrations_report_base($method_name_for_getting_query_params)
3307
+	{
3308
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3309
+			wp_redirect(
3310
+				EE_Admin_Page::add_query_args_and_nonce(
3311
+					array(
3312
+						'page'        => 'espresso_batch',
3313
+						'batch'       => 'file',
3314
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3315
+						'filters'     => urlencode(
3316
+							serialize(
3317
+								$this->$method_name_for_getting_query_params(
3318
+									EEH_Array::is_set(
3319
+										$this->_req_data,
3320
+										'filters',
3321
+										array()
3322
+									)
3323
+								)
3324
+							)
3325
+						),
3326
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3327
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3328
+						'return_url'  => urlencode($this->_req_data['return_url']),
3329
+					)
3330
+				)
3331
+			);
3332
+		} else {
3333
+			$new_request_args = array(
3334
+				'export' => 'report',
3335
+				'action' => 'registrations_report_for_event',
3336
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3337
+			);
3338
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3339
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3340
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3341
+				$EE_Export = EE_Export::instance($this->_req_data);
3342
+				$EE_Export->export();
3343
+			}
3344
+		}
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Creates a registration report using only query parameters in the request
3350
+	 *
3351
+	 * @return void
3352
+	 */
3353
+	public function _registrations_report()
3354
+	{
3355
+		$this->_registrations_report_base('_get_registration_query_parameters');
3356
+	}
3357
+
3358
+
3359
+	public function _contact_list_export()
3360
+	{
3361
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3362
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3363
+			$EE_Export = EE_Export::instance($this->_req_data);
3364
+			$EE_Export->export_attendees();
3365
+		}
3366
+	}
3367
+
3368
+
3369
+	public function _contact_list_report()
3370
+	{
3371
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3372
+			wp_redirect(
3373
+				EE_Admin_Page::add_query_args_and_nonce(
3374
+					array(
3375
+						'page'        => 'espresso_batch',
3376
+						'batch'       => 'file',
3377
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3378
+						'return_url'  => urlencode($this->_req_data['return_url']),
3379
+					)
3380
+				)
3381
+			);
3382
+		} else {
3383
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3384
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3385
+				$EE_Export = EE_Export::instance($this->_req_data);
3386
+				$EE_Export->report_attendees();
3387
+			}
3388
+		}
3389
+	}
3390
+
3391
+
3392
+
3393
+
3394
+
3395
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3396
+	/**
3397
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3398
+	 *
3399
+	 * @return void
3400
+	 * @throws EE_Error
3401
+	 * @throws InvalidArgumentException
3402
+	 * @throws InvalidDataTypeException
3403
+	 * @throws InvalidInterfaceException
3404
+	 * @throws ReflectionException
3405
+	 */
3406
+	protected function _duplicate_attendee()
3407
+	{
3408
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3409
+		// verify we have necessary info
3410
+		if (empty($this->_req_data['_REG_ID'])) {
3411
+			EE_Error::add_error(
3412
+				esc_html__(
3413
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3414
+					'event_espresso'
3415
+				),
3416
+				__FILE__,
3417
+				__LINE__,
3418
+				__FUNCTION__
3419
+			);
3420
+			$query_args = array('action' => $action);
3421
+			$this->_redirect_after_action('', '', '', $query_args, true);
3422
+		}
3423
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3424
+		$registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3425
+		$attendee = $registration->attendee();
3426
+		// remove relation of existing attendee on registration
3427
+		$registration->_remove_relation_to($attendee, 'Attendee');
3428
+		// new attendee
3429
+		$new_attendee = clone $attendee;
3430
+		$new_attendee->set('ATT_ID', 0);
3431
+		$new_attendee->save();
3432
+		// add new attendee to reg
3433
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3434
+		EE_Error::add_success(
3435
+			esc_html__(
3436
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3437
+				'event_espresso'
3438
+			)
3439
+		);
3440
+		// redirect to edit page for attendee
3441
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3442
+		$this->_redirect_after_action('', '', '', $query_args, true);
3443
+	}
3444
+
3445
+
3446
+	/**
3447
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3448
+	 *
3449
+	 * @param int     $post_id
3450
+	 * @param WP_POST $post
3451
+	 * @throws DomainException
3452
+	 * @throws EE_Error
3453
+	 * @throws InvalidArgumentException
3454
+	 * @throws InvalidDataTypeException
3455
+	 * @throws InvalidInterfaceException
3456
+	 * @throws LogicException
3457
+	 * @throws InvalidFormSubmissionException
3458
+	 * @throws ReflectionException
3459
+	 */
3460
+	protected function _insert_update_cpt_item($post_id, $post)
3461
+	{
3462
+		$success = true;
3463
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3464
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3465
+			: null;
3466
+		// for attendee updates
3467
+		if ($attendee instanceof EE_Attendee) {
3468
+			// note we should only be UPDATING attendees at this point.
3469
+			$updated_fields = array(
3470
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3471
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3472
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3473
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3474
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3475
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3476
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3477
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3478
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3479
+			);
3480
+			foreach ($updated_fields as $field => $value) {
3481
+				$attendee->set($field, $value);
3482
+			}
3483
+
3484
+			// process contact details metabox form handler (which will also save the attendee)
3485
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3486
+			$success = $contact_details_form->process($this->_req_data);
3487
+
3488
+			$attendee_update_callbacks = apply_filters(
3489
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3490
+				array()
3491
+			);
3492
+			foreach ($attendee_update_callbacks as $a_callback) {
3493
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3494
+					throw new EE_Error(
3495
+						sprintf(
3496
+							esc_html__(
3497
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3498
+								'event_espresso'
3499
+							),
3500
+							$a_callback
3501
+						)
3502
+					);
3503
+				}
3504
+			}
3505
+		}
3506
+
3507
+		if ($success === false) {
3508
+			EE_Error::add_error(
3509
+				esc_html__(
3510
+					'Something went wrong with updating the meta table data for the registration.',
3511
+					'event_espresso'
3512
+				),
3513
+				__FILE__,
3514
+				__FUNCTION__,
3515
+				__LINE__
3516
+			);
3517
+		}
3518
+	}
3519
+
3520
+
3521
+	public function trash_cpt_item($post_id)
3522
+	{
3523
+	}
3524
+
3525
+
3526
+	public function delete_cpt_item($post_id)
3527
+	{
3528
+	}
3529
+
3530
+
3531
+	public function restore_cpt_item($post_id)
3532
+	{
3533
+	}
3534
+
3535
+
3536
+	protected function _restore_cpt_item($post_id, $revision_id)
3537
+	{
3538
+	}
3539
+
3540
+
3541
+	/**
3542
+	 * @throws EE_Error
3543
+	 * @since 4.10.2.p
3544
+	 */
3545
+	public function attendee_editor_metaboxes()
3546
+	{
3547
+		$this->verify_cpt_object();
3548
+		remove_meta_box(
3549
+			'postexcerpt',
3550
+			$this->_cpt_routes[ $this->_req_action ],
3551
+			'normal'
3552
+		);
3553
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3554
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3555
+			add_meta_box(
3556
+				'postexcerpt',
3557
+				esc_html__('Short Biography', 'event_espresso'),
3558
+				'post_excerpt_meta_box',
3559
+				$this->_cpt_routes[ $this->_req_action ],
3560
+				'normal'
3561
+			);
3562
+		}
3563
+		if (post_type_supports('espresso_attendees', 'comments')) {
3564
+			add_meta_box(
3565
+				'commentsdiv',
3566
+				esc_html__('Notes on the Contact', 'event_espresso'),
3567
+				'post_comment_meta_box',
3568
+				$this->_cpt_routes[ $this->_req_action ],
3569
+				'normal',
3570
+				'core'
3571
+			);
3572
+		}
3573
+		add_meta_box(
3574
+			'attendee_contact_info',
3575
+			esc_html__('Contact Info', 'event_espresso'),
3576
+			array($this, 'attendee_contact_info'),
3577
+			$this->_cpt_routes[ $this->_req_action ],
3578
+			'side',
3579
+			'core'
3580
+		);
3581
+		add_meta_box(
3582
+			'attendee_details_address',
3583
+			esc_html__('Address Details', 'event_espresso'),
3584
+			array($this, 'attendee_address_details'),
3585
+			$this->_cpt_routes[ $this->_req_action ],
3586
+			'normal',
3587
+			'core'
3588
+		);
3589
+		add_meta_box(
3590
+			'attendee_registrations',
3591
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3592
+			array($this, 'attendee_registrations_meta_box'),
3593
+			$this->_cpt_routes[ $this->_req_action ],
3594
+			'normal',
3595
+			'high'
3596
+		);
3597
+	}
3598
+
3599
+
3600
+	/**
3601
+	 * Metabox for attendee contact info
3602
+	 *
3603
+	 * @param  WP_Post $post wp post object
3604
+	 * @return string attendee contact info ( and form )
3605
+	 * @throws EE_Error
3606
+	 * @throws InvalidArgumentException
3607
+	 * @throws InvalidDataTypeException
3608
+	 * @throws InvalidInterfaceException
3609
+	 * @throws LogicException
3610
+	 * @throws DomainException
3611
+	 */
3612
+	public function attendee_contact_info($post)
3613
+	{
3614
+		// get attendee object ( should already have it )
3615
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3616
+		$form->enqueueStylesAndScripts();
3617
+		echo $form->display();
3618
+	}
3619
+
3620
+
3621
+	/**
3622
+	 * Return form handler for the contact details metabox
3623
+	 *
3624
+	 * @param EE_Attendee $attendee
3625
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3626
+	 * @throws DomainException
3627
+	 * @throws InvalidArgumentException
3628
+	 * @throws InvalidDataTypeException
3629
+	 * @throws InvalidInterfaceException
3630
+	 */
3631
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3632
+	{
3633
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3634
+	}
3635
+
3636
+
3637
+	/**
3638
+	 * Metabox for attendee details
3639
+	 *
3640
+	 * @param  WP_Post $post wp post object
3641
+	 * @throws DomainException
3642
+	 */
3643
+	public function attendee_address_details($post)
3644
+	{
3645
+		// get attendee object (should already have it)
3646
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3647
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3648
+			new EE_Question_Form_Input(
3649
+				EE_Question::new_instance(
3650
+					array(
3651
+						'QST_ID'           => 0,
3652
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3653
+						'QST_system'       => 'admin-state',
3654
+					)
3655
+				),
3656
+				EE_Answer::new_instance(
3657
+					array(
3658
+						'ANS_ID'    => 0,
3659
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3660
+					)
3661
+				),
3662
+				array(
3663
+					'input_id'       => 'STA_ID',
3664
+					'input_name'     => 'STA_ID',
3665
+					'input_prefix'   => '',
3666
+					'append_qstn_id' => false,
3667
+				)
3668
+			)
3669
+		);
3670
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3671
+			new EE_Question_Form_Input(
3672
+				EE_Question::new_instance(
3673
+					array(
3674
+						'QST_ID'           => 0,
3675
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3676
+						'QST_system'       => 'admin-country',
3677
+					)
3678
+				),
3679
+				EE_Answer::new_instance(
3680
+					array(
3681
+						'ANS_ID'    => 0,
3682
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3683
+					)
3684
+				),
3685
+				array(
3686
+					'input_id'       => 'CNT_ISO',
3687
+					'input_name'     => 'CNT_ISO',
3688
+					'input_prefix'   => '',
3689
+					'append_qstn_id' => false,
3690
+				)
3691
+			)
3692
+		);
3693
+		$template =
3694
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3695
+		EEH_Template::display_template($template, $this->_template_args);
3696
+	}
3697
+
3698
+
3699
+	/**
3700
+	 *        _attendee_details
3701
+	 *
3702
+	 * @access protected
3703
+	 * @param $post
3704
+	 * @return void
3705
+	 * @throws DomainException
3706
+	 * @throws EE_Error
3707
+	 * @throws InvalidArgumentException
3708
+	 * @throws InvalidDataTypeException
3709
+	 * @throws InvalidInterfaceException
3710
+	 * @throws ReflectionException
3711
+	 */
3712
+	public function attendee_registrations_meta_box($post)
3713
+	{
3714
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3715
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3716
+		$template =
3717
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3718
+		EEH_Template::display_template($template, $this->_template_args);
3719
+	}
3720
+
3721
+
3722
+	/**
3723
+	 * add in the form fields for the attendee edit
3724
+	 *
3725
+	 * @param  WP_Post $post wp post object
3726
+	 * @return string html for new form.
3727
+	 * @throws DomainException
3728
+	 */
3729
+	public function after_title_form_fields($post)
3730
+	{
3731
+		if ($post->post_type === 'espresso_attendees') {
3732
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3733
+			$template_args['attendee'] = $this->_cpt_model_obj;
3734
+			EEH_Template::display_template($template, $template_args);
3735
+		}
3736
+	}
3737
+
3738
+
3739
+	/**
3740
+	 *        _trash_or_restore_attendee
3741
+	 *
3742
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3743
+	 * @return void
3744
+	 * @throws EE_Error
3745
+	 * @throws InvalidArgumentException
3746
+	 * @throws InvalidDataTypeException
3747
+	 * @throws InvalidInterfaceException
3748
+	 * @throws ReflectionException
3749
+	 * @access protected
3750
+	 */
3751
+	protected function _trash_or_restore_attendees($trash = true)
3752
+	{
3753
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3754
+		$success = 1;
3755
+		// Checkboxes
3756
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3757
+			// if array has more than one element than success message should be plural
3758
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3759
+			// cycle thru checkboxes
3760
+			foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3761
+				$updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3762
+					: $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3763
+				if (! $updated) {
3764
+					$success = 0;
3765
+				}
3766
+			}
3767
+		} else {
3768
+			// grab single id and delete
3769
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3770
+			// get attendee
3771
+			$att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3772
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3773
+			$updated = $att->save() && $updated;
3774
+			if (! $updated) {
3775
+				$success = 0;
3776
+			}
3777
+		}
3778
+		$what = $success > 1
3779
+			? esc_html__('Contacts', 'event_espresso')
3780
+			: esc_html__('Contact', 'event_espresso');
3781
+		$action_desc = $trash
3782
+			? esc_html__('moved to the trash', 'event_espresso')
3783
+			: esc_html__('restored', 'event_espresso');
3784
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3785
+	}
3786 3786
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -15,566 +15,566 @@
 block discarded – undo
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Datetime
20
-     */
21
-    private $_dtt;
22
-
23
-
24
-    /**
25
-     * Initial setup of data properties for the list table.
26
-     */
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Set up of additional properties for the list table.
36
-     */
37
-    protected function _set_properties()
38
-    {
39
-        $this->_wp_list_args = array(
40
-            'singular' => esc_html__('event', 'event_espresso'),
41
-            'plural'   => esc_html__('events', 'event_espresso'),
42
-            'ajax'     => true, // for now
43
-            'screen'   => $this->_admin_page->get_current_screen()->id,
44
-        );
45
-        $this->_columns = array(
46
-            'cb'              => '<input type="checkbox" />',
47
-            'id'              => esc_html__('ID', 'event_espresso'),
48
-            'name'            => esc_html__('Name', 'event_espresso'),
49
-            'author'          => esc_html__('Author', 'event_espresso'),
50
-            'venue'           => esc_html__('Venue', 'event_espresso'),
51
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
-                                 . '<span class="screen-reader-text">'
55
-                                 . esc_html__('Approved Registrations', 'event_espresso')
56
-                                 . '</span>'
57
-                                 . '</span>',
58
-            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
-            'actions'         => esc_html__('Actions', 'event_espresso'),
60
-        );
61
-        $this->addConditionalColumns();
62
-        $this->_sortable_columns = array(
63
-            'id'              => array('EVT_ID' => true),
64
-            'name'            => array('EVT_name' => false),
65
-            'author'          => array('EVT_wp_user' => false),
66
-            'venue'           => array('Venue.VNU_name' => false),
67
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
-        );
70
-
71
-        $this->_primary_column = 'id';
72
-        $this->_hidden_columns = array('author', 'event_category');
73
-    }
74
-
75
-
76
-    /**
77
-     * @return array
78
-     */
79
-    protected function _get_table_filters()
80
-    {
81
-        return array(); // no filters with decaf
82
-    }
83
-
84
-
85
-    /**
86
-     * Setup of views properties.
87
-     *
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidArgumentException
91
-     */
92
-    protected function _add_view_counts()
93
-    {
94
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
95
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
-        if (
97
-            EE_Registry::instance()->CAP->current_user_can(
98
-                'ee_delete_events',
99
-                'espresso_events_trash_events'
100
-            )
101
-        ) {
102
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
103
-        }
104
-    }
105
-
106
-
107
-    /**
108
-     * @param EE_Event $item
109
-     * @return string
110
-     * @throws EE_Error
111
-     */
112
-    protected function _get_row_class($item)
113
-    {
114
-        $class = parent::_get_row_class($item);
115
-        // add status class
116
-        $class .= $item instanceof EE_Event
117
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
118
-            : '';
119
-        if ($this->_has_checkbox_column) {
120
-            $class .= ' has-checkbox-column';
121
-        }
122
-        return $class;
123
-    }
124
-
125
-
126
-    /**
127
-     * @param EE_Event $item
128
-     * @return string
129
-     * @throws EE_Error
130
-     */
131
-    public function column_status(EE_Event $item)
132
-    {
133
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
134
-               . $item->get_active_status()
135
-               . '"></span>';
136
-    }
137
-
138
-
139
-    /**
140
-     * @param  EE_Event $item
141
-     * @return string
142
-     * @throws EE_Error
143
-     */
144
-    public function column_cb($item)
145
-    {
146
-        if (! $item instanceof EE_Event) {
147
-            return '';
148
-        }
149
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
150
-        return sprintf(
151
-            '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
152
-            $item->ID()
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @param EE_Event $item
159
-     * @return mixed|string
160
-     * @throws EE_Error
161
-     */
162
-    public function column_id(EE_Event $item)
163
-    {
164
-        $content = $item->ID();
165
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
166
-        return $content;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param EE_Event $item
172
-     * @return string
173
-     * @throws EE_Error
174
-     * @throws InvalidArgumentException
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     */
178
-    public function column_name(EE_Event $item)
179
-    {
180
-        $edit_query_args = array(
181
-            'action' => 'edit',
182
-            'post'   => $item->ID(),
183
-        );
184
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
185
-        $actions = $this->_column_name_action_setup($item);
186
-        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
187
-        $content = '<strong><a class="row-title" href="'
188
-                   . $edit_link . '">'
189
-                   . $item->name()
190
-                   . '</a></strong>'
191
-                   . $status;
192
-        $content .= '<br><span class="ee-status-text-small">'
193
-                    . EEH_Template::pretty_status(
194
-                        $item->get_active_status(),
195
-                        false,
196
-                        'sentence'
197
-                    )
198
-                    . '</span>';
199
-        $content .= $this->row_actions($actions);
200
-        return $content;
201
-    }
202
-
203
-
204
-    /**
205
-     * Just a method for setting up the actions for the name column
206
-     *
207
-     * @param EE_Event $item
208
-     * @return array array of actions
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     */
214
-    protected function _column_name_action_setup(EE_Event $item)
215
-    {
216
-        // todo: remove when attendees is active
217
-        if (! defined('REG_ADMIN_URL')) {
218
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
219
-        }
220
-        $actions = array();
221
-        $restore_event_link = '';
222
-        $delete_event_link = '';
223
-        $trash_event_link = '';
224
-        if (
225
-            EE_Registry::instance()->CAP->current_user_can(
226
-                'ee_edit_event',
227
-                'espresso_events_edit',
228
-                $item->ID()
229
-            )
230
-        ) {
231
-            $edit_query_args = array(
232
-                'action' => 'edit',
233
-                'post'   => $item->ID(),
234
-            );
235
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
-            $actions['edit'] = '<a href="' . $edit_link . '"'
237
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
-                               . esc_html__('Edit', 'event_espresso')
239
-                               . '</a>';
240
-        }
241
-        if (
242
-            EE_Registry::instance()->CAP->current_user_can(
243
-                'ee_read_registrations',
244
-                'espresso_registrations_view_registration'
245
-            )
246
-            && EE_Registry::instance()->CAP->current_user_can(
247
-                'ee_read_event',
248
-                'espresso_registrations_view_registration',
249
-                $item->ID()
250
-            )
251
-        ) {
252
-            $attendees_query_args = array(
253
-                'action'   => 'default',
254
-                'event_id' => $item->ID(),
255
-            );
256
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
257
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
258
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
259
-                                    . esc_html__('Registrations', 'event_espresso')
260
-                                    . '</a>';
261
-        }
262
-        if (
263
-            EE_Registry::instance()->CAP->current_user_can(
264
-                'ee_delete_event',
265
-                'espresso_events_trash_event',
266
-                $item->ID()
267
-            )
268
-        ) {
269
-            $trash_event_query_args = array(
270
-                'action' => 'trash_event',
271
-                'EVT_ID' => $item->ID(),
272
-            );
273
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
274
-                $trash_event_query_args,
275
-                EVENTS_ADMIN_URL
276
-            );
277
-        }
278
-        if (
279
-            EE_Registry::instance()->CAP->current_user_can(
280
-                'ee_delete_event',
281
-                'espresso_events_restore_event',
282
-                $item->ID()
283
-            )
284
-        ) {
285
-            $restore_event_query_args = array(
286
-                'action' => 'restore_event',
287
-                'EVT_ID' => $item->ID(),
288
-            );
289
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
290
-                $restore_event_query_args,
291
-                EVENTS_ADMIN_URL
292
-            );
293
-        }
294
-        if (
295
-            EE_Registry::instance()->CAP->current_user_can(
296
-                'ee_delete_event',
297
-                'espresso_events_delete_event',
298
-                $item->ID()
299
-            )
300
-        ) {
301
-            $delete_event_query_args = array(
302
-                'action' => 'delete_event',
303
-                'EVT_ID' => $item->ID(),
304
-            );
305
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
306
-                $delete_event_query_args,
307
-                EVENTS_ADMIN_URL
308
-            );
309
-        }
310
-        $view_link = get_permalink($item->ID());
311
-        $actions['view'] = '<a href="' . $view_link . '"'
312
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
313
-                           . esc_html__('View', 'event_espresso')
314
-                           . '</a>';
315
-        if ($item->get('status') === 'trash') {
316
-            if (
317
-                EE_Registry::instance()->CAP->current_user_can(
318
-                    'ee_delete_event',
319
-                    'espresso_events_restore_event',
320
-                    $item->ID()
321
-                )
322
-            ) {
323
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
324
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
325
-                                                 . '">'
326
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
327
-                                                 . '</a>';
328
-            }
329
-            if (EE_Registry::instance()->CAP->current_user_can(
330
-                'ee_delete_event',
331
-                'espresso_events_delete_event',
332
-                $item->ID()
333
-            )
334
-            ) {
335
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
336
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
337
-                                     . esc_html__('Delete Permanently', 'event_espresso')
338
-                                     . '</a>';
339
-            }
340
-        } else {
341
-            if (
342
-                EE_Registry::instance()->CAP->current_user_can(
343
-                    'ee_delete_event',
344
-                    'espresso_events_trash_event',
345
-                    $item->ID()
346
-                )
347
-            ) {
348
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
349
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
350
-                                            . esc_html__('Trash', 'event_espresso')
351
-                                            . '</a>';
352
-            }
353
-        }
354
-        return $actions;
355
-    }
356
-
357
-
358
-    /**
359
-     * @param EE_Event $item
360
-     * @return string
361
-     * @throws EE_Error
362
-     */
363
-    public function column_author(EE_Event $item)
364
-    {
365
-        // user author info
366
-        $event_author = get_userdata($item->wp_user());
367
-        $gravatar = get_avatar($item->wp_user(), '15');
368
-        // filter link
369
-        $query_args = array(
370
-            'action'      => 'default',
371
-            'EVT_wp_user' => $item->wp_user(),
372
-        );
373
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
374
-        return $gravatar . '  <a href="' . $filter_url . '"'
375
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
376
-               . $event_author->display_name
377
-               . '</a>';
378
-    }
379
-
380
-
381
-    /**
382
-     * @param EE_Event $event
383
-     * @return string
384
-     * @throws EE_Error
385
-     */
386
-    public function column_event_category(EE_Event $event)
387
-    {
388
-        $event_categories = $event->get_all_event_categories();
389
-        return implode(
390
-            ', ',
391
-            array_map(
392
-                function (EE_Term $category) {
393
-                    return $category->name();
394
-                },
395
-                $event_categories
396
-            )
397
-        );
398
-    }
399
-
400
-
401
-    /**
402
-     * @param EE_Event $item
403
-     * @return string
404
-     * @throws EE_Error
405
-     */
406
-    public function column_venue(EE_Event $item)
407
-    {
408
-        $venue = $item->get_first_related('Venue');
409
-        return ! empty($venue)
410
-            ? $venue->name()
411
-            : '';
412
-    }
413
-
414
-
415
-    /**
416
-     * @param EE_Event $item
417
-     * @return string
418
-     * @throws EE_Error
419
-     */
420
-    public function column_start_date_time(EE_Event $item)
421
-    {
422
-        return $this->_dtt instanceof EE_Datetime
423
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
424
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
425
-    }
426
-
427
-
428
-    /**
429
-     * @param EE_Event $item
430
-     * @return string
431
-     * @throws EE_Error
432
-     */
433
-    public function column_reg_begins(EE_Event $item)
434
-    {
435
-        $reg_start = $item->get_ticket_with_earliest_start_time();
436
-        return $reg_start instanceof EE_Ticket
437
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
438
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
-    }
440
-
441
-
442
-    /**
443
-     * @param EE_Event $item
444
-     * @return int|string
445
-     * @throws EE_Error
446
-     * @throws InvalidArgumentException
447
-     * @throws InvalidDataTypeException
448
-     * @throws InvalidInterfaceException
449
-     */
450
-    public function column_attendees(EE_Event $item)
451
-    {
452
-        $attendees_query_args = array(
453
-            'action'   => 'default',
454
-            'event_id' => $item->ID(),
455
-        );
456
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
457
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
458
-        return EE_Registry::instance()->CAP->current_user_can(
459
-            'ee_read_event',
460
-            'espresso_registrations_view_registration',
461
-            $item->ID()
462
-        )
463
-               && EE_Registry::instance()->CAP->current_user_can(
464
-                   'ee_read_registrations',
465
-                   'espresso_registrations_view_registration'
466
-               )
467
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
468
-            : $registered_attendees;
469
-    }
470
-
471
-
472
-    /**
473
-     * @param EE_Event $item
474
-     * @return float
475
-     * @throws EE_Error
476
-     * @throws InvalidArgumentException
477
-     * @throws InvalidDataTypeException
478
-     * @throws InvalidInterfaceException
479
-     */
480
-    public function column_tkts_sold(EE_Event $item)
481
-    {
482
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
483
-    }
484
-
485
-
486
-    /**
487
-     * @param EE_Event $item
488
-     * @return string
489
-     * @throws EE_Error
490
-     * @throws InvalidArgumentException
491
-     * @throws InvalidDataTypeException
492
-     * @throws InvalidInterfaceException
493
-     */
494
-    public function column_actions(EE_Event $item)
495
-    {
496
-        // todo: remove when attendees is active
497
-        if (! defined('REG_ADMIN_URL')) {
498
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
499
-        }
500
-        $action_links = array();
501
-        $view_link = get_permalink($item->ID());
502
-        $action_links[] = '<a href="' . $view_link . '"'
503
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
504
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
505
-        if (
506
-            EE_Registry::instance()->CAP->current_user_can(
507
-                'ee_edit_event',
508
-                'espresso_events_edit',
509
-                $item->ID()
510
-            )
511
-        ) {
512
-            $edit_query_args = array(
513
-                'action' => 'edit',
514
-                'post'   => $item->ID(),
515
-            );
516
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
517
-            $action_links[] = '<a href="' . $edit_link . '"'
518
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
519
-                              . '<div class="ee-icon ee-icon-calendar-edit"></div>'
520
-                              . '</a>';
521
-        }
522
-        if (
523
-            EE_Registry::instance()->CAP->current_user_can(
524
-                'ee_read_registrations',
525
-                'espresso_registrations_view_registration'
526
-            ) && EE_Registry::instance()->CAP->current_user_can(
527
-                'ee_read_event',
528
-                'espresso_registrations_view_registration',
529
-                $item->ID()
530
-            )
531
-        ) {
532
-            $attendees_query_args = array(
533
-                'action'   => 'default',
534
-                'event_id' => $item->ID(),
535
-            );
536
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
537
-            $action_links[] = '<a href="' . $attendees_link . '"'
538
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
539
-                              . '<div class="dashicons dashicons-groups"></div>'
540
-                              . '</a>';
541
-        }
542
-        $action_links = apply_filters(
543
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
544
-            $action_links,
545
-            $item
546
-        );
547
-        return $this->_action_string(
548
-            implode("\n\t", $action_links),
549
-            $item,
550
-            'div'
551
-        );
552
-    }
553
-
554
-
555
-    /**
556
-     * Helper for adding columns conditionally
557
-     *
558
-     * @throws EE_Error
559
-     * @throws InvalidArgumentException
560
-     * @throws InvalidDataTypeException
561
-     * @throws InvalidInterfaceException
562
-     */
563
-    private function addConditionalColumns()
564
-    {
565
-        $event_category_count = EEM_Term::instance()->count(
566
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
567
-        );
568
-        if ($event_category_count === 0) {
569
-            return;
570
-        }
571
-        $column_array = [];
572
-        foreach ($this->_columns as $column => $column_label) {
573
-            $column_array[ $column ] = $column_label;
574
-            if ($column === 'venue') {
575
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
576
-            }
577
-        }
578
-        $this->_columns = $column_array;
579
-    }
18
+	/**
19
+	 * @var EE_Datetime
20
+	 */
21
+	private $_dtt;
22
+
23
+
24
+	/**
25
+	 * Initial setup of data properties for the list table.
26
+	 */
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Set up of additional properties for the list table.
36
+	 */
37
+	protected function _set_properties()
38
+	{
39
+		$this->_wp_list_args = array(
40
+			'singular' => esc_html__('event', 'event_espresso'),
41
+			'plural'   => esc_html__('events', 'event_espresso'),
42
+			'ajax'     => true, // for now
43
+			'screen'   => $this->_admin_page->get_current_screen()->id,
44
+		);
45
+		$this->_columns = array(
46
+			'cb'              => '<input type="checkbox" />',
47
+			'id'              => esc_html__('ID', 'event_espresso'),
48
+			'name'            => esc_html__('Name', 'event_espresso'),
49
+			'author'          => esc_html__('Author', 'event_espresso'),
50
+			'venue'           => esc_html__('Venue', 'event_espresso'),
51
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
+								 . '<span class="screen-reader-text">'
55
+								 . esc_html__('Approved Registrations', 'event_espresso')
56
+								 . '</span>'
57
+								 . '</span>',
58
+			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
+			'actions'         => esc_html__('Actions', 'event_espresso'),
60
+		);
61
+		$this->addConditionalColumns();
62
+		$this->_sortable_columns = array(
63
+			'id'              => array('EVT_ID' => true),
64
+			'name'            => array('EVT_name' => false),
65
+			'author'          => array('EVT_wp_user' => false),
66
+			'venue'           => array('Venue.VNU_name' => false),
67
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
+		);
70
+
71
+		$this->_primary_column = 'id';
72
+		$this->_hidden_columns = array('author', 'event_category');
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return array
78
+	 */
79
+	protected function _get_table_filters()
80
+	{
81
+		return array(); // no filters with decaf
82
+	}
83
+
84
+
85
+	/**
86
+	 * Setup of views properties.
87
+	 *
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidArgumentException
91
+	 */
92
+	protected function _add_view_counts()
93
+	{
94
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
95
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
+		if (
97
+			EE_Registry::instance()->CAP->current_user_can(
98
+				'ee_delete_events',
99
+				'espresso_events_trash_events'
100
+			)
101
+		) {
102
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
103
+		}
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param EE_Event $item
109
+	 * @return string
110
+	 * @throws EE_Error
111
+	 */
112
+	protected function _get_row_class($item)
113
+	{
114
+		$class = parent::_get_row_class($item);
115
+		// add status class
116
+		$class .= $item instanceof EE_Event
117
+			? ' ee-status-strip event-status-' . $item->get_active_status()
118
+			: '';
119
+		if ($this->_has_checkbox_column) {
120
+			$class .= ' has-checkbox-column';
121
+		}
122
+		return $class;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param EE_Event $item
128
+	 * @return string
129
+	 * @throws EE_Error
130
+	 */
131
+	public function column_status(EE_Event $item)
132
+	{
133
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
134
+			   . $item->get_active_status()
135
+			   . '"></span>';
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param  EE_Event $item
141
+	 * @return string
142
+	 * @throws EE_Error
143
+	 */
144
+	public function column_cb($item)
145
+	{
146
+		if (! $item instanceof EE_Event) {
147
+			return '';
148
+		}
149
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
150
+		return sprintf(
151
+			'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
152
+			$item->ID()
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param EE_Event $item
159
+	 * @return mixed|string
160
+	 * @throws EE_Error
161
+	 */
162
+	public function column_id(EE_Event $item)
163
+	{
164
+		$content = $item->ID();
165
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
166
+		return $content;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param EE_Event $item
172
+	 * @return string
173
+	 * @throws EE_Error
174
+	 * @throws InvalidArgumentException
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 */
178
+	public function column_name(EE_Event $item)
179
+	{
180
+		$edit_query_args = array(
181
+			'action' => 'edit',
182
+			'post'   => $item->ID(),
183
+		);
184
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
185
+		$actions = $this->_column_name_action_setup($item);
186
+		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
187
+		$content = '<strong><a class="row-title" href="'
188
+				   . $edit_link . '">'
189
+				   . $item->name()
190
+				   . '</a></strong>'
191
+				   . $status;
192
+		$content .= '<br><span class="ee-status-text-small">'
193
+					. EEH_Template::pretty_status(
194
+						$item->get_active_status(),
195
+						false,
196
+						'sentence'
197
+					)
198
+					. '</span>';
199
+		$content .= $this->row_actions($actions);
200
+		return $content;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Just a method for setting up the actions for the name column
206
+	 *
207
+	 * @param EE_Event $item
208
+	 * @return array array of actions
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 */
214
+	protected function _column_name_action_setup(EE_Event $item)
215
+	{
216
+		// todo: remove when attendees is active
217
+		if (! defined('REG_ADMIN_URL')) {
218
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
219
+		}
220
+		$actions = array();
221
+		$restore_event_link = '';
222
+		$delete_event_link = '';
223
+		$trash_event_link = '';
224
+		if (
225
+			EE_Registry::instance()->CAP->current_user_can(
226
+				'ee_edit_event',
227
+				'espresso_events_edit',
228
+				$item->ID()
229
+			)
230
+		) {
231
+			$edit_query_args = array(
232
+				'action' => 'edit',
233
+				'post'   => $item->ID(),
234
+			);
235
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
+			$actions['edit'] = '<a href="' . $edit_link . '"'
237
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
+							   . esc_html__('Edit', 'event_espresso')
239
+							   . '</a>';
240
+		}
241
+		if (
242
+			EE_Registry::instance()->CAP->current_user_can(
243
+				'ee_read_registrations',
244
+				'espresso_registrations_view_registration'
245
+			)
246
+			&& EE_Registry::instance()->CAP->current_user_can(
247
+				'ee_read_event',
248
+				'espresso_registrations_view_registration',
249
+				$item->ID()
250
+			)
251
+		) {
252
+			$attendees_query_args = array(
253
+				'action'   => 'default',
254
+				'event_id' => $item->ID(),
255
+			);
256
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
257
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
258
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
259
+									. esc_html__('Registrations', 'event_espresso')
260
+									. '</a>';
261
+		}
262
+		if (
263
+			EE_Registry::instance()->CAP->current_user_can(
264
+				'ee_delete_event',
265
+				'espresso_events_trash_event',
266
+				$item->ID()
267
+			)
268
+		) {
269
+			$trash_event_query_args = array(
270
+				'action' => 'trash_event',
271
+				'EVT_ID' => $item->ID(),
272
+			);
273
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
274
+				$trash_event_query_args,
275
+				EVENTS_ADMIN_URL
276
+			);
277
+		}
278
+		if (
279
+			EE_Registry::instance()->CAP->current_user_can(
280
+				'ee_delete_event',
281
+				'espresso_events_restore_event',
282
+				$item->ID()
283
+			)
284
+		) {
285
+			$restore_event_query_args = array(
286
+				'action' => 'restore_event',
287
+				'EVT_ID' => $item->ID(),
288
+			);
289
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
290
+				$restore_event_query_args,
291
+				EVENTS_ADMIN_URL
292
+			);
293
+		}
294
+		if (
295
+			EE_Registry::instance()->CAP->current_user_can(
296
+				'ee_delete_event',
297
+				'espresso_events_delete_event',
298
+				$item->ID()
299
+			)
300
+		) {
301
+			$delete_event_query_args = array(
302
+				'action' => 'delete_event',
303
+				'EVT_ID' => $item->ID(),
304
+			);
305
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
306
+				$delete_event_query_args,
307
+				EVENTS_ADMIN_URL
308
+			);
309
+		}
310
+		$view_link = get_permalink($item->ID());
311
+		$actions['view'] = '<a href="' . $view_link . '"'
312
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
313
+						   . esc_html__('View', 'event_espresso')
314
+						   . '</a>';
315
+		if ($item->get('status') === 'trash') {
316
+			if (
317
+				EE_Registry::instance()->CAP->current_user_can(
318
+					'ee_delete_event',
319
+					'espresso_events_restore_event',
320
+					$item->ID()
321
+				)
322
+			) {
323
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
324
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
325
+												 . '">'
326
+												 . esc_html__('Restore from Trash', 'event_espresso')
327
+												 . '</a>';
328
+			}
329
+			if (EE_Registry::instance()->CAP->current_user_can(
330
+				'ee_delete_event',
331
+				'espresso_events_delete_event',
332
+				$item->ID()
333
+			)
334
+			) {
335
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
336
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
337
+									 . esc_html__('Delete Permanently', 'event_espresso')
338
+									 . '</a>';
339
+			}
340
+		} else {
341
+			if (
342
+				EE_Registry::instance()->CAP->current_user_can(
343
+					'ee_delete_event',
344
+					'espresso_events_trash_event',
345
+					$item->ID()
346
+				)
347
+			) {
348
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
349
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
350
+											. esc_html__('Trash', 'event_espresso')
351
+											. '</a>';
352
+			}
353
+		}
354
+		return $actions;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @param EE_Event $item
360
+	 * @return string
361
+	 * @throws EE_Error
362
+	 */
363
+	public function column_author(EE_Event $item)
364
+	{
365
+		// user author info
366
+		$event_author = get_userdata($item->wp_user());
367
+		$gravatar = get_avatar($item->wp_user(), '15');
368
+		// filter link
369
+		$query_args = array(
370
+			'action'      => 'default',
371
+			'EVT_wp_user' => $item->wp_user(),
372
+		);
373
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
374
+		return $gravatar . '  <a href="' . $filter_url . '"'
375
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
376
+			   . $event_author->display_name
377
+			   . '</a>';
378
+	}
379
+
380
+
381
+	/**
382
+	 * @param EE_Event $event
383
+	 * @return string
384
+	 * @throws EE_Error
385
+	 */
386
+	public function column_event_category(EE_Event $event)
387
+	{
388
+		$event_categories = $event->get_all_event_categories();
389
+		return implode(
390
+			', ',
391
+			array_map(
392
+				function (EE_Term $category) {
393
+					return $category->name();
394
+				},
395
+				$event_categories
396
+			)
397
+		);
398
+	}
399
+
400
+
401
+	/**
402
+	 * @param EE_Event $item
403
+	 * @return string
404
+	 * @throws EE_Error
405
+	 */
406
+	public function column_venue(EE_Event $item)
407
+	{
408
+		$venue = $item->get_first_related('Venue');
409
+		return ! empty($venue)
410
+			? $venue->name()
411
+			: '';
412
+	}
413
+
414
+
415
+	/**
416
+	 * @param EE_Event $item
417
+	 * @return string
418
+	 * @throws EE_Error
419
+	 */
420
+	public function column_start_date_time(EE_Event $item)
421
+	{
422
+		return $this->_dtt instanceof EE_Datetime
423
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
424
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
425
+	}
426
+
427
+
428
+	/**
429
+	 * @param EE_Event $item
430
+	 * @return string
431
+	 * @throws EE_Error
432
+	 */
433
+	public function column_reg_begins(EE_Event $item)
434
+	{
435
+		$reg_start = $item->get_ticket_with_earliest_start_time();
436
+		return $reg_start instanceof EE_Ticket
437
+			? $reg_start->get_i18n_datetime('TKT_start_date')
438
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
+	}
440
+
441
+
442
+	/**
443
+	 * @param EE_Event $item
444
+	 * @return int|string
445
+	 * @throws EE_Error
446
+	 * @throws InvalidArgumentException
447
+	 * @throws InvalidDataTypeException
448
+	 * @throws InvalidInterfaceException
449
+	 */
450
+	public function column_attendees(EE_Event $item)
451
+	{
452
+		$attendees_query_args = array(
453
+			'action'   => 'default',
454
+			'event_id' => $item->ID(),
455
+		);
456
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
457
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
458
+		return EE_Registry::instance()->CAP->current_user_can(
459
+			'ee_read_event',
460
+			'espresso_registrations_view_registration',
461
+			$item->ID()
462
+		)
463
+			   && EE_Registry::instance()->CAP->current_user_can(
464
+				   'ee_read_registrations',
465
+				   'espresso_registrations_view_registration'
466
+			   )
467
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
468
+			: $registered_attendees;
469
+	}
470
+
471
+
472
+	/**
473
+	 * @param EE_Event $item
474
+	 * @return float
475
+	 * @throws EE_Error
476
+	 * @throws InvalidArgumentException
477
+	 * @throws InvalidDataTypeException
478
+	 * @throws InvalidInterfaceException
479
+	 */
480
+	public function column_tkts_sold(EE_Event $item)
481
+	{
482
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
483
+	}
484
+
485
+
486
+	/**
487
+	 * @param EE_Event $item
488
+	 * @return string
489
+	 * @throws EE_Error
490
+	 * @throws InvalidArgumentException
491
+	 * @throws InvalidDataTypeException
492
+	 * @throws InvalidInterfaceException
493
+	 */
494
+	public function column_actions(EE_Event $item)
495
+	{
496
+		// todo: remove when attendees is active
497
+		if (! defined('REG_ADMIN_URL')) {
498
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
499
+		}
500
+		$action_links = array();
501
+		$view_link = get_permalink($item->ID());
502
+		$action_links[] = '<a href="' . $view_link . '"'
503
+						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
504
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
505
+		if (
506
+			EE_Registry::instance()->CAP->current_user_can(
507
+				'ee_edit_event',
508
+				'espresso_events_edit',
509
+				$item->ID()
510
+			)
511
+		) {
512
+			$edit_query_args = array(
513
+				'action' => 'edit',
514
+				'post'   => $item->ID(),
515
+			);
516
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
517
+			$action_links[] = '<a href="' . $edit_link . '"'
518
+							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
519
+							  . '<div class="ee-icon ee-icon-calendar-edit"></div>'
520
+							  . '</a>';
521
+		}
522
+		if (
523
+			EE_Registry::instance()->CAP->current_user_can(
524
+				'ee_read_registrations',
525
+				'espresso_registrations_view_registration'
526
+			) && EE_Registry::instance()->CAP->current_user_can(
527
+				'ee_read_event',
528
+				'espresso_registrations_view_registration',
529
+				$item->ID()
530
+			)
531
+		) {
532
+			$attendees_query_args = array(
533
+				'action'   => 'default',
534
+				'event_id' => $item->ID(),
535
+			);
536
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
537
+			$action_links[] = '<a href="' . $attendees_link . '"'
538
+							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
539
+							  . '<div class="dashicons dashicons-groups"></div>'
540
+							  . '</a>';
541
+		}
542
+		$action_links = apply_filters(
543
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
544
+			$action_links,
545
+			$item
546
+		);
547
+		return $this->_action_string(
548
+			implode("\n\t", $action_links),
549
+			$item,
550
+			'div'
551
+		);
552
+	}
553
+
554
+
555
+	/**
556
+	 * Helper for adding columns conditionally
557
+	 *
558
+	 * @throws EE_Error
559
+	 * @throws InvalidArgumentException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws InvalidInterfaceException
562
+	 */
563
+	private function addConditionalColumns()
564
+	{
565
+		$event_category_count = EEM_Term::instance()->count(
566
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
567
+		);
568
+		if ($event_category_count === 0) {
569
+			return;
570
+		}
571
+		$column_array = [];
572
+		foreach ($this->_columns as $column => $column_label) {
573
+			$column_array[ $column ] = $column_label;
574
+			if ($column === 'venue') {
575
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
576
+			}
577
+		}
578
+		$this->_columns = $column_array;
579
+	}
580 580
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $class = parent::_get_row_class($item);
115 115
         // add status class
116 116
         $class .= $item instanceof EE_Event
117
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
117
+            ? ' ee-status-strip event-status-'.$item->get_active_status()
118 118
             : '';
119 119
         if ($this->_has_checkbox_column) {
120 120
             $class .= ' has-checkbox-column';
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function column_cb($item)
145 145
     {
146
-        if (! $item instanceof EE_Event) {
146
+        if ( ! $item instanceof EE_Event) {
147 147
             return '';
148 148
         }
149 149
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     public function column_id(EE_Event $item)
163 163
     {
164 164
         $content = $item->ID();
165
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
165
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->name().'</span>';
166 166
         return $content;
167 167
     }
168 168
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         $actions = $this->_column_name_action_setup($item);
186 186
         $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
187 187
         $content = '<strong><a class="row-title" href="'
188
-                   . $edit_link . '">'
188
+                   . $edit_link.'">'
189 189
                    . $item->name()
190 190
                    . '</a></strong>'
191 191
                    . $status;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     protected function _column_name_action_setup(EE_Event $item)
215 215
     {
216 216
         // todo: remove when attendees is active
217
-        if (! defined('REG_ADMIN_URL')) {
217
+        if ( ! defined('REG_ADMIN_URL')) {
218 218
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
219 219
         }
220 220
         $actions = array();
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
                 'post'   => $item->ID(),
234 234
             );
235 235
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
-            $actions['edit'] = '<a href="' . $edit_link . '"'
237
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
236
+            $actions['edit'] = '<a href="'.$edit_link.'"'
237
+                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
238 238
                                . esc_html__('Edit', 'event_espresso')
239 239
                                . '</a>';
240 240
         }
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
                 'event_id' => $item->ID(),
255 255
             );
256 256
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
257
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
258
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
257
+            $actions['attendees'] = '<a href="'.$attendees_link.'"'
258
+                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">'
259 259
                                     . esc_html__('Registrations', 'event_espresso')
260 260
                                     . '</a>';
261 261
         }
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
             );
309 309
         }
310 310
         $view_link = get_permalink($item->ID());
311
-        $actions['view'] = '<a href="' . $view_link . '"'
312
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
311
+        $actions['view'] = '<a href="'.$view_link.'"'
312
+                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">'
313 313
                            . esc_html__('View', 'event_espresso')
314 314
                            . '</a>';
315 315
         if ($item->get('status') === 'trash') {
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
                     $item->ID()
321 321
                 )
322 322
             ) {
323
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
324
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
323
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'
324
+                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso')
325 325
                                                  . '">'
326 326
                                                  . esc_html__('Restore from Trash', 'event_espresso')
327 327
                                                  . '</a>';
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
                 $item->ID()
333 333
             )
334 334
             ) {
335
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
336
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
335
+                $actions['delete'] = '<a href="'.$delete_event_link.'"'
336
+                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
337 337
                                      . esc_html__('Delete Permanently', 'event_espresso')
338 338
                                      . '</a>';
339 339
             }
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
                     $item->ID()
346 346
                 )
347 347
             ) {
348
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
349
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
348
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'"'
349
+                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">'
350 350
                                             . esc_html__('Trash', 'event_espresso')
351 351
                                             . '</a>';
352 352
             }
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
             'EVT_wp_user' => $item->wp_user(),
372 372
         );
373 373
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
374
-        return $gravatar . '  <a href="' . $filter_url . '"'
375
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
374
+        return $gravatar.'  <a href="'.$filter_url.'"'
375
+               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
376 376
                . $event_author->display_name
377 377
                . '</a>';
378 378
     }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
         return implode(
390 390
             ', ',
391 391
             array_map(
392
-                function (EE_Term $category) {
392
+                function(EE_Term $category) {
393 393
                     return $category->name();
394 394
                 },
395 395
                 $event_categories
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                    'ee_read_registrations',
465 465
                    'espresso_registrations_view_registration'
466 466
                )
467
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
467
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
468 468
             : $registered_attendees;
469 469
     }
470 470
 
@@ -494,13 +494,13 @@  discard block
 block discarded – undo
494 494
     public function column_actions(EE_Event $item)
495 495
     {
496 496
         // todo: remove when attendees is active
497
-        if (! defined('REG_ADMIN_URL')) {
497
+        if ( ! defined('REG_ADMIN_URL')) {
498 498
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
499 499
         }
500 500
         $action_links = array();
501 501
         $view_link = get_permalink($item->ID());
502
-        $action_links[] = '<a href="' . $view_link . '"'
503
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
502
+        $action_links[] = '<a href="'.$view_link.'"'
503
+                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">';
504 504
         $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
505 505
         if (
506 506
             EE_Registry::instance()->CAP->current_user_can(
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
                 'post'   => $item->ID(),
515 515
             );
516 516
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
517
-            $action_links[] = '<a href="' . $edit_link . '"'
518
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
517
+            $action_links[] = '<a href="'.$edit_link.'"'
518
+                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
519 519
                               . '<div class="ee-icon ee-icon-calendar-edit"></div>'
520 520
                               . '</a>';
521 521
         }
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
                 'event_id' => $item->ID(),
535 535
             );
536 536
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
537
-            $action_links[] = '<a href="' . $attendees_link . '"'
538
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
537
+            $action_links[] = '<a href="'.$attendees_link.'"'
538
+                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">'
539 539
                               . '<div class="dashicons dashicons-groups"></div>'
540 540
                               . '</a>';
541 541
         }
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         }
571 571
         $column_array = [];
572 572
         foreach ($this->_columns as $column => $column_label) {
573
-            $column_array[ $column ] = $column_label;
573
+            $column_array[$column] = $column_label;
574 574
             if ($column === 'venue') {
575 575
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
576 576
             }
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 1 patch
Indentation   +1399 added lines, -1399 removed lines patch added patch discarded remove patch
@@ -20,1414 +20,1414 @@
 block discarded – undo
20 20
 class General_Settings_Admin_Page extends EE_Admin_Page
21 21
 {
22 22
 
23
-    /**
24
-     * _question_group
25
-     * holds the specific question group object for the question group details screen
26
-     *
27
-     * @var object
28
-     */
29
-    protected $_question_group;
30
-
31
-
32
-    /**
33
-     * Initialize basic properties.
34
-     */
35
-    protected function _init_page_props()
36
-    {
37
-        $this->page_slug = GEN_SET_PG_SLUG;
38
-        $this->page_label = GEN_SET_LABEL;
39
-        $this->_admin_base_url = GEN_SET_ADMIN_URL;
40
-        $this->_admin_base_path = GEN_SET_ADMIN;
41
-    }
42
-
43
-
44
-    /**
45
-     * Set ajax hooks
46
-     */
47
-    protected function _ajax_hooks()
48
-    {
49
-        add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
50
-        add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
51
-        add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
52
-        add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
53
-    }
54
-
55
-
56
-    /**
57
-     * More page properties initialization.
58
-     */
59
-    protected function _define_page_props()
60
-    {
61
-        $this->_admin_page_title = GEN_SET_LABEL;
62
-        $this->_labels = array(
63
-            'publishbox' => esc_html__('Update Settings', 'event_espresso'),
64
-        );
65
-    }
66
-
67
-
68
-    /**
69
-     * Set page routes property.
70
-     */
71
-    protected function _set_page_routes()
72
-    {
73
-        $this->_page_routes = array(
74
-
75
-            'critical_pages'                => array(
76
-                'func'       => '_espresso_page_settings',
77
-                'capability' => 'manage_options',
78
-            ),
79
-            'update_espresso_page_settings' => array(
80
-                'func'       => '_update_espresso_page_settings',
81
-                'capability' => 'manage_options',
82
-                'noheader'   => true,
83
-            ),
84
-            'default'                       => array(
85
-                'func'       => '_your_organization_settings',
86
-                'capability' => 'manage_options',
87
-            ),
88
-
89
-            'update_your_organization_settings' => array(
90
-                'func'       => '_update_your_organization_settings',
91
-                'capability' => 'manage_options',
92
-                'noheader'   => true,
93
-            ),
94
-
95
-            'admin_option_settings' => array(
96
-                'func'       => '_admin_option_settings',
97
-                'capability' => 'manage_options',
98
-            ),
99
-
100
-            'update_admin_option_settings' => array(
101
-                'func'       => '_update_admin_option_settings',
102
-                'capability' => 'manage_options',
103
-                'noheader'   => true,
104
-            ),
105
-
106
-            'country_settings' => array(
107
-                'func'       => '_country_settings',
108
-                'capability' => 'manage_options',
109
-            ),
110
-
111
-            'update_country_settings' => array(
112
-                'func'       => '_update_country_settings',
113
-                'capability' => 'manage_options',
114
-                'noheader'   => true,
115
-            ),
116
-
117
-            'display_country_settings' => array(
118
-                'func'       => 'display_country_settings',
119
-                'capability' => 'manage_options',
120
-                'noheader'   => true,
121
-            ),
122
-
123
-            'add_new_state' => array(
124
-                'func'       => 'add_new_state',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-
129
-            'delete_state'            => array(
130
-                'func'       => 'delete_state',
131
-                'capability' => 'manage_options',
132
-                'noheader'   => true,
133
-            ),
134
-            'privacy_settings'        => array(
135
-                'func'       => 'privacySettings',
136
-                'capability' => 'manage_options',
137
-            ),
138
-            'update_privacy_settings' => array(
139
-                'func'               => 'updatePrivacySettings',
140
-                'capability'         => 'manage_options',
141
-                'noheader'           => true,
142
-                'headers_sent_route' => 'privacy_settings',
143
-            ),
144
-        );
145
-    }
146
-
147
-
148
-    /**
149
-     * Set page configuration property
150
-     */
151
-    protected function _set_page_config()
152
-    {
153
-        $this->_page_config = array(
154
-            'critical_pages'        => array(
155
-                'nav'           => array(
156
-                    'label' => esc_html__('Critical Pages', 'event_espresso'),
157
-                    'order' => 50,
158
-                ),
159
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
160
-                'help_tabs'     => array(
161
-                    'general_settings_critical_pages_help_tab' => array(
162
-                        'title'    => esc_html__('Critical Pages', 'event_espresso'),
163
-                        'filename' => 'general_settings_critical_pages',
164
-                    ),
165
-                ),
166
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
167
-                // 'help_tour'     => array('Critical_Pages_Help_Tour'),
168
-                'require_nonce' => false,
169
-            ),
170
-            'default'               => array(
171
-                'nav'           => array(
172
-                    'label' => esc_html__('Your Organization', 'event_espresso'),
173
-                    'order' => 20,
174
-                ),
175
-                'help_tabs'     => array(
176
-                    'general_settings_your_organization_help_tab' => array(
177
-                        'title'    => esc_html__('Your Organization', 'event_espresso'),
178
-                        'filename' => 'general_settings_your_organization',
179
-                    ),
180
-                ),
181
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
182
-                // 'help_tour'     => array('Your_Organization_Help_Tour'),
183
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
184
-                'require_nonce' => false,
185
-            ),
186
-            'admin_option_settings' => array(
187
-                'nav'           => array(
188
-                    'label' => esc_html__('Admin Options', 'event_espresso'),
189
-                    'order' => 60,
190
-                ),
191
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
192
-                'help_tabs'     => array(
193
-                    'general_settings_admin_options_help_tab' => array(
194
-                        'title'    => esc_html__('Admin Options', 'event_espresso'),
195
-                        'filename' => 'general_settings_admin_options',
196
-                    ),
197
-                ),
198
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
199
-                // 'help_tour'     => array('Admin_Options_Help_Tour'),
200
-                'require_nonce' => false,
201
-            ),
202
-            'country_settings'      => array(
203
-                'nav'           => array(
204
-                    'label' => esc_html__('Countries', 'event_espresso'),
205
-                    'order' => 70,
206
-                ),
207
-                'help_tabs'     => array(
208
-                    'general_settings_countries_help_tab' => array(
209
-                        'title'    => esc_html__('Countries', 'event_espresso'),
210
-                        'filename' => 'general_settings_countries',
211
-                    ),
212
-                ),
213
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
214
-                // 'help_tour'     => array('Countries_Help_Tour'),
215
-                'require_nonce' => false,
216
-            ),
217
-            'privacy_settings'      => array(
218
-                'nav'           => array(
219
-                    'label' => esc_html__('Privacy', 'event_espresso'),
220
-                    'order' => 80,
221
-                ),
222
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
223
-                'require_nonce' => false,
224
-            ),
225
-        );
226
-    }
227
-
228
-
229
-    protected function _add_screen_options()
230
-    {
231
-    }
232
-
233
-
234
-    protected function _add_feature_pointers()
235
-    {
236
-    }
237
-
238
-
239
-    /**
240
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
241
-     */
242
-    public function load_scripts_styles()
243
-    {
244
-        // styles
245
-        wp_enqueue_style('espresso-ui-theme');
246
-        // scripts
247
-        wp_enqueue_script('ee_admin_js');
248
-    }
249
-
250
-
251
-    /**
252
-     * Execute logic running on `admin_init`
253
-     */
254
-    public function admin_init()
255
-    {
256
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__(
257
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
258
-            'event_espresso'
259
-        ));
260
-        EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__(
261
-            'An error occurred! Please refresh the page and try again.',
262
-            'event_espresso'
263
-        ));
264
-        EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__(
265
-            'Are you sure you want to delete this State / Province?',
266
-            'event_espresso'
267
-        ));
268
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
269
-        EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
270
-            'admin-ajax.php?page=espresso_general_settings',
271
-            $protocol
272
-        );
273
-    }
274
-
275
-
276
-    public function admin_notices()
277
-    {
278
-    }
279
-
280
-
281
-    public function admin_footer_scripts()
282
-    {
283
-    }
284
-
285
-
286
-    /**
287
-     * Enqueue scripts and styles for the default route.
288
-     */
289
-    public function load_scripts_styles_default()
290
-    {
291
-        // styles
292
-        wp_enqueue_style('thickbox');
293
-        // scripts
294
-        wp_enqueue_script('media-upload');
295
-        wp_enqueue_script('thickbox');
296
-        wp_register_script(
297
-            'organization_settings',
298
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
299
-            array('jquery', 'media-upload', 'thickbox'),
300
-            EVENT_ESPRESSO_VERSION,
301
-            true
302
-        );
303
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
304
-        wp_enqueue_script('organization_settings');
305
-        wp_enqueue_style('organization-css');
306
-        $confirm_image_delete = array(
307
-            'text' => wp_strip_all_tags(
308
-                __(
309
-                    'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
310
-                    'event_espresso'
311
-                )
312
-            ),
313
-        );
314
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
315
-    }
316
-
317
-
318
-    /**
319
-     * Enqueue scripts and styles for the country settings route.
320
-     */
321
-    public function load_scripts_styles_country_settings()
322
-    {
323
-        // scripts
324
-        wp_register_script(
325
-            'gen_settings_countries',
326
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
327
-            array('ee_admin_js'),
328
-            EVENT_ESPRESSO_VERSION,
329
-            true
330
-        );
331
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
332
-        wp_enqueue_script('gen_settings_countries');
333
-        wp_enqueue_style('organization-css');
334
-    }
335
-
336
-
337
-    /*************        Espresso Pages        *************/
338
-    /**
339
-     * _espresso_page_settings
340
-     *
341
-     * @throws \EE_Error
342
-     * @throws DomainException
343
-     * @throws DomainException
344
-     * @throws InvalidDataTypeException
345
-     * @throws InvalidArgumentException
346
-     */
347
-    protected function _espresso_page_settings()
348
-    {
349
-        // Check to make sure all of the main pages are setup properly,
350
-        // if not create the default pages and display an admin notice
351
-        EEH_Activation::verify_default_pages_exist();
352
-        $this->_transient_garbage_collection();
353
-        $this->_template_args['values'] = $this->_yes_no_values;
354
-        $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
355
-            ? EE_Registry::instance()->CFG->core->reg_page_id
356
-            : null;
357
-        $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
358
-            ? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
359
-            : false;
360
-        $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
361
-            ? EE_Registry::instance()->CFG->core->txn_page_id
362
-            : null;
363
-        $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
364
-            ? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
365
-            : false;
366
-        $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
367
-            ? EE_Registry::instance()->CFG->core->thank_you_page_id
368
-            : null;
369
-        $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
370
-            ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
371
-            : false;
372
-        $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
373
-            ? EE_Registry::instance()->CFG->core->cancel_page_id
374
-            : null;
375
-        $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
376
-            ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
377
-            : false;
378
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
379
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
380
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
381
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
382
-            $this->_template_args,
383
-            true
384
-        );
385
-        $this->display_admin_page_with_sidebar();
386
-    }
387
-
388
-
389
-    /**
390
-     * Handler for updating espresso page settings.
391
-     *
392
-     * @throws EE_Error
393
-     */
394
-    protected function _update_espresso_page_settings()
395
-    {
396
-        // capture incoming request data && set page IDs
397
-        EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
398
-            ? absint($this->_req_data['reg_page_id'])
399
-            : EE_Registry::instance()->CFG->core->reg_page_id;
400
-        EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
401
-            ? absint($this->_req_data['txn_page_id'])
402
-            : EE_Registry::instance()->CFG->core->txn_page_id;
403
-        EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
404
-            ? absint($this->_req_data['thank_you_page_id'])
405
-            : EE_Registry::instance()->CFG->core->thank_you_page_id;
406
-        EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
407
-            ? absint($this->_req_data['cancel_page_id'])
408
-            : EE_Registry::instance()->CFG->core->cancel_page_id;
409
-
410
-        EE_Registry::instance()->CFG->core = apply_filters(
411
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
412
-            EE_Registry::instance()->CFG->core,
413
-            $this->_req_data
414
-        );
415
-        $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
-        $this->_redirect_after_action(
417
-            $this->_update_espresso_configuration(
418
-                $what,
419
-                EE_Registry::instance()->CFG->core,
420
-                __FILE__,
421
-                __FUNCTION__,
422
-                __LINE__
423
-            ),
424
-            $what,
425
-            '',
426
-            array(
427
-                'action' => 'critical_pages',
428
-            ),
429
-            true
430
-        );
431
-    }
432
-
433
-
434
-    /*************        Your Organization        *************/
435
-
436
-
437
-    /**
438
-     * @throws DomainException
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws InvalidDataTypeException
442
-     * @throws InvalidInterfaceException
443
-     */
444
-    protected function _your_organization_settings()
445
-    {
446
-        $this->_template_args['admin_page_content'] = '';
447
-        try {
448
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
449
-            $organization_settings_form = $this->loader->getShared(
450
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
451
-            );
452
-            $this->_template_args['admin_page_content'] = $organization_settings_form->display();
453
-        } catch (Exception $e) {
454
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
455
-        }
456
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
457
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
458
-        $this->display_admin_page_with_sidebar();
459
-    }
460
-
461
-
462
-    /**
463
-     * Handler for updating organization settings.
464
-     *
465
-     * @throws EE_Error
466
-     */
467
-    protected function _update_your_organization_settings()
468
-    {
469
-        try {
470
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
471
-            $organization_settings_form = $this->loader->getShared(
472
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
473
-            );
474
-            $success = $organization_settings_form->process($this->_req_data);
475
-            EE_Registry::instance()->CFG = apply_filters(
476
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
477
-                EE_Registry::instance()->CFG
478
-            );
479
-        } catch (Exception $e) {
480
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
481
-            $success = false;
482
-        }
483
-
484
-        if ($success) {
485
-            $success = $this->_update_espresso_configuration(
486
-                esc_html__('Your Organization Settings', 'event_espresso'),
487
-                EE_Registry::instance()->CFG,
488
-                __FILE__,
489
-                __FUNCTION__,
490
-                __LINE__
491
-            );
492
-        }
493
-
494
-        $this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
495
-    }
496
-
497
-
498
-
499
-    /*************        Admin Options        *************/
500
-
501
-
502
-    /**
503
-     * _admin_option_settings
504
-     *
505
-     * @throws \EE_Error
506
-     * @throws \LogicException
507
-     */
508
-    protected function _admin_option_settings()
509
-    {
510
-        $this->_template_args['admin_page_content'] = '';
511
-        try {
512
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
513
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
514
-            $this->_template_args['values'] = $this->_yes_no_values;
515
-            // also need to account for the do_action that was in the old template
516
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
517
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
518
-        } catch (Exception $e) {
519
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
-        }
521
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
522
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
523
-        $this->display_admin_page_with_sidebar();
524
-    }
525
-
526
-
527
-    /**
528
-     * _update_admin_option_settings
529
-     *
530
-     * @throws \EE_Error
531
-     * @throws InvalidDataTypeException
532
-     * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
533
-     * @throws \InvalidArgumentException
534
-     * @throws \LogicException
535
-     */
536
-    protected function _update_admin_option_settings()
537
-    {
538
-        try {
539
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
540
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
541
-            EE_Registry::instance()->CFG->admin = apply_filters(
542
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
543
-                EE_Registry::instance()->CFG->admin
544
-            );
545
-        } catch (Exception $e) {
546
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
547
-        }
548
-        $this->_redirect_after_action(
549
-            apply_filters(
550
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
551
-                $this->_update_espresso_configuration(
552
-                    'Admin Options',
553
-                    EE_Registry::instance()->CFG->admin,
554
-                    __FILE__,
555
-                    __FUNCTION__,
556
-                    __LINE__
557
-                )
558
-            ),
559
-            'Admin Options',
560
-            'updated',
561
-            array('action' => 'admin_option_settings')
562
-        );
563
-    }
564
-
565
-
566
-    /*************        Countries        *************/
567
-
568
-
569
-    /**
570
-     * @return string
571
-     */
572
-    protected function getCountryIsoForSite()
573
-    {
574
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
575
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
576
-            : 'US';
577
-    }
578
-
579
-
580
-    /**
581
-     * @param string          $CNT_ISO
582
-     * @param EE_Country|null $country
583
-     * @return EE_Base_Class|EE_Country
584
-     * @throws EE_Error
585
-     * @throws InvalidArgumentException
586
-     * @throws InvalidDataTypeException
587
-     * @throws InvalidInterfaceException
588
-     * @throws ReflectionException
589
-     */
590
-    protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
591
-    {
592
-        /** @var EE_Country $country */
593
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
594
-            ? $country
595
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
596
-    }
597
-
598
-
599
-    /**
600
-     * Output Country Settings view.
601
-     *
602
-     * @throws DomainException
603
-     * @throws EE_Error
604
-     * @throws InvalidArgumentException
605
-     * @throws InvalidDataTypeException
606
-     * @throws InvalidInterfaceException
607
-     * @throws ReflectionException
608
-     */
609
-    protected function _country_settings()
610
-    {
611
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
612
-        $CNT_ISO = isset($this->_req_data['country'])
613
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
614
-            : $CNT_ISO_for_site;
615
-
616
-        // load field generator helper
617
-
618
-        $this->_template_args['values'] = $this->_yes_no_values;
619
-
620
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
621
-            EE_Question::new_instance(
622
-                array(
623
-                    'QST_ID'           => 0,
624
-                    'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
625
-                    'QST_system'       => 'admin-country',
626
-                )
627
-            ),
628
-            EE_Answer::new_instance(
629
-                array(
630
-                    'ANS_ID'    => 0,
631
-                    'ANS_value' => $CNT_ISO,
632
-                )
633
-            ),
634
-            array(
635
-                'input_id'       => 'country',
636
-                'input_name'     => 'country',
637
-                'input_prefix'   => '',
638
-                'append_qstn_id' => false,
639
-            )
640
-        );
641
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
642
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
643
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
644
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
645
-            $country->ID(),
646
-            $country
647
-        );
648
-        $this->_template_args['country_states_settings'] = $this->display_country_states(
649
-            $country->ID(),
650
-            $country
651
-        );
652
-        $this->_template_args['CNT_name_for_site'] = $country->name();
653
-
654
-        $this->_set_add_edit_form_tags('update_country_settings');
655
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
656
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
657
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
658
-            $this->_template_args,
659
-            true
660
-        );
661
-        $this->display_admin_page_with_no_sidebar();
662
-    }
663
-
664
-
665
-    /**
666
-     *        display_country_settings
667
-     *
668
-     * @param string          $CNT_ISO
669
-     * @param EE_Country|null $country
670
-     * @return mixed string | array$country
671
-     * @throws DomainException
672
-     * @throws EE_Error
673
-     * @throws InvalidArgumentException
674
-     * @throws InvalidDataTypeException
675
-     * @throws InvalidInterfaceException
676
-     * @throws ReflectionException
677
-     */
678
-    public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
679
-    {
680
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
681
-
682
-        $CNT_ISO = isset($this->_req_data['country'])
683
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
684
-            : $CNT_ISO;
685
-        if (! $CNT_ISO) {
686
-            return '';
687
-        }
688
-
689
-        // for ajax
690
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
691
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
692
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
693
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
694
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
695
-        $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
696
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
697
-
698
-        $country_input_types = array(
699
-            'CNT_active'      => array(
700
-                'type'             => 'RADIO_BTN',
701
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
702
-                'class'            => '',
703
-                'options'          => $this->_yes_no_values,
704
-                'use_desc_4_label' => true,
705
-            ),
706
-            'CNT_ISO'         => array(
707
-                'type'       => 'TEXT',
708
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
709
-                'class'      => 'small-text',
710
-            ),
711
-            'CNT_ISO3'        => array(
712
-                'type'       => 'TEXT',
713
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
714
-                'class'      => 'small-text',
715
-            ),
716
-            'RGN_ID'          => array(
717
-                'type'       => 'TEXT',
718
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
719
-                'class'      => 'small-text',
720
-            ),
721
-            'CNT_name'        => array(
722
-                'type'       => 'TEXT',
723
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
724
-                'class'      => 'regular-text',
725
-            ),
726
-            'CNT_cur_code'    => array(
727
-                'type'       => 'TEXT',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
729
-                'class'      => 'small-text',
730
-                'disabled'   => $CNT_cur_disabled,
731
-            ),
732
-            'CNT_cur_single'  => array(
733
-                'type'       => 'TEXT',
734
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
735
-                'class'      => 'medium-text',
736
-                'disabled'   => $CNT_cur_disabled,
737
-            ),
738
-            'CNT_cur_plural'  => array(
739
-                'type'       => 'TEXT',
740
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
741
-                'class'      => 'medium-text',
742
-                'disabled'   => $CNT_cur_disabled,
743
-            ),
744
-            'CNT_cur_sign'    => array(
745
-                'type'         => 'TEXT',
746
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
747
-                'class'        => 'small-text',
748
-                'htmlentities' => false,
749
-                'disabled'     => $CNT_cur_disabled,
750
-            ),
751
-            'CNT_cur_sign_b4' => array(
752
-                'type'             => 'RADIO_BTN',
753
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
754
-                'class'            => '',
755
-                'options'          => $this->_yes_no_values,
756
-                'use_desc_4_label' => true,
757
-                'disabled'         => $CNT_cur_disabled,
758
-            ),
759
-            'CNT_cur_dec_plc' => array(
760
-                'type'       => 'RADIO_BTN',
761
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
762
-                'class'      => '',
763
-                'options'    => array(
764
-                    array('id' => 0, 'text' => ''),
765
-                    array('id' => 1, 'text' => ''),
766
-                    array('id' => 2, 'text' => ''),
767
-                    array('id' => 3, 'text' => ''),
768
-                ),
769
-                'disabled'   => $CNT_cur_disabled,
770
-            ),
771
-            'CNT_cur_dec_mrk' => array(
772
-                'type'             => 'RADIO_BTN',
773
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
-                'class'            => '',
775
-                'options'          => array(
776
-                    array(
777
-                        'id'   => ',',
778
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
779
-                    ),
780
-                    array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')),
781
-                ),
782
-                'use_desc_4_label' => true,
783
-                'disabled'         => $CNT_cur_disabled,
784
-            ),
785
-            'CNT_cur_thsnds'  => array(
786
-                'type'             => 'RADIO_BTN',
787
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
788
-                'class'            => '',
789
-                'options'          => array(
790
-                    array(
791
-                        'id'   => ',',
792
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
793
-                    ),
794
-                    array(
795
-                        'id' => '.',
796
-                        'text' => esc_html__('. (decimal)', 'event_espresso')
797
-                    ),
798
-                    array(
799
-                        'id' => '&nbsp;',
800
-                        'text' => esc_html__('(space)', 'event_espresso')
801
-                    )
802
-                ),
803
-                'use_desc_4_label' => true,
804
-                'disabled'         => $CNT_cur_disabled,
805
-            ),
806
-            'CNT_tel_code'    => array(
807
-                'type'       => 'TEXT',
808
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
809
-                'class'      => 'small-text',
810
-            ),
811
-            'CNT_is_EU'       => array(
812
-                'type'             => 'RADIO_BTN',
813
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
814
-                'class'            => '',
815
-                'options'          => $this->_yes_no_values,
816
-                'use_desc_4_label' => true,
817
-            ),
818
-        );
819
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
820
-            $country,
821
-            $country_input_types
822
-        );
823
-        $country_details_settings = EEH_Template::display_template(
824
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
825
-            $this->_template_args,
826
-            true
827
-        );
828
-
829
-        if (defined('DOING_AJAX')) {
830
-            $notices = EE_Error::get_notices(false, false, false);
831
-            echo wp_json_encode(
832
-                array(
833
-                    'return_data' => $country_details_settings,
834
-                    'success'     => $notices['success'],
835
-                    'errors'      => $notices['errors'],
836
-                )
837
-            );
838
-            die();
839
-        } else {
840
-            return $country_details_settings;
841
-        }
842
-    }
843
-
844
-
845
-    /**
846
-     * @param string          $CNT_ISO
847
-     * @param EE_Country|null $country
848
-     * @return string
849
-     * @throws DomainException
850
-     * @throws EE_Error
851
-     * @throws InvalidArgumentException
852
-     * @throws InvalidDataTypeException
853
-     * @throws InvalidInterfaceException
854
-     * @throws ReflectionException
855
-     */
856
-    public function display_country_states($CNT_ISO = '', EE_Country $country = null)
857
-    {
858
-
859
-        $CNT_ISO = isset($this->_req_data['country'])
860
-            ? sanitize_text_field($this->_req_data['country'])
861
-            : $CNT_ISO;
862
-        if (! $CNT_ISO) {
863
-            return '';
864
-        }
865
-        // for ajax
866
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
867
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
868
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
869
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
870
-        $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
871
-        if (empty($states)) {
872
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
873
-            $countrySubRegionDao = $this->loader->getShared(
874
-                'EventEspresso\core\services\address\CountrySubRegionDao'
875
-            );
876
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
877
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
878
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
879
-                    $states = EEM_State::instance()->get_all_states_for_these_countries(
880
-                        array($CNT_ISO => $CNT_ISO)
881
-                    );
882
-                }
883
-            }
884
-        }
885
-        if (is_array($states)) {
886
-            foreach ($states as $STA_ID => $state) {
887
-                if ($state instanceof EE_State) {
888
-                    // STA_abbrev    STA_name    STA_active
889
-                    $state_input_types = array(
890
-                        'STA_abbrev' => array(
891
-                            'type'       => 'TEXT',
892
-                            'input_name' => 'states[' . $STA_ID . ']',
893
-                            'class'      => 'mid-text',
894
-                        ),
895
-                        'STA_name'   => array(
896
-                            'type'       => 'TEXT',
897
-                            'input_name' => 'states[' . $STA_ID . ']',
898
-                            'class'      => 'regular-text',
899
-                        ),
900
-                        'STA_active' => array(
901
-                            'type'             => 'RADIO_BTN',
902
-                            'input_name'       => 'states[' . $STA_ID . ']',
903
-                            'options'          => $this->_yes_no_values,
904
-                            'use_desc_4_label' => true,
905
-                        ),
906
-                    );
907
-                    $this->_template_args['states'][ $STA_ID ]['inputs'] =
908
-                        EE_Question_Form_Input::generate_question_form_inputs_for_object(
909
-                            $state,
910
-                            $state_input_types
911
-                        );
912
-                    $query_args = array(
913
-                        'action'     => 'delete_state',
914
-                        'STA_ID'     => $STA_ID,
915
-                        'CNT_ISO'    => $CNT_ISO,
916
-                        'STA_abbrev' => $state->abbrev(),
917
-                    );
918
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
919
-                        EE_Admin_Page::add_query_args_and_nonce(
920
-                            $query_args,
921
-                            GEN_SET_ADMIN_URL
922
-                        );
923
-                }
924
-            }
925
-        } else {
926
-            $this->_template_args['states'] = false;
927
-        }
928
-
929
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
930
-            array('action' => 'add_new_state'),
931
-            GEN_SET_ADMIN_URL
932
-        );
933
-
934
-        $state_details_settings = EEH_Template::display_template(
935
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
936
-            $this->_template_args,
937
-            true
938
-        );
939
-
940
-        if (defined('DOING_AJAX')) {
941
-            $notices = EE_Error::get_notices(false, false, false);
942
-            echo wp_json_encode(
943
-                array(
944
-                    'return_data' => $state_details_settings,
945
-                    'success'     => $notices['success'],
946
-                    'errors'      => $notices['errors'],
947
-                )
948
-            );
949
-            die();
950
-        } else {
951
-            return $state_details_settings;
952
-        }
953
-    }
954
-
955
-
956
-    /**
957
-     *        add_new_state
958
-     *
959
-     * @access    public
960
-     * @return void
961
-     * @throws EE_Error
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidDataTypeException
964
-     * @throws InvalidInterfaceException
965
-     */
966
-    public function add_new_state()
967
-    {
968
-
969
-        $success = true;
970
-
971
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
972
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
973
-            : false;
974
-        if (! $CNT_ISO) {
975
-            EE_Error::add_error(
976
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
977
-                __FILE__,
978
-                __FUNCTION__,
979
-                __LINE__
980
-            );
981
-            $success = false;
982
-        }
983
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
984
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
985
-            : false;
986
-        if (! $STA_abbrev) {
987
-            EE_Error::add_error(
988
-                esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
989
-                __FILE__,
990
-                __FUNCTION__,
991
-                __LINE__
992
-            );
993
-            $success = false;
994
-        }
995
-        $STA_name = isset($this->_req_data['STA_name'])
996
-            ? sanitize_text_field($this->_req_data['STA_name'])
997
-            : false;
998
-        if (! $STA_name) {
999
-            EE_Error::add_error(
1000
-                esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1001
-                __FILE__,
1002
-                __FUNCTION__,
1003
-                __LINE__
1004
-            );
1005
-            $success = false;
1006
-        }
1007
-
1008
-        if ($success) {
1009
-            $cols_n_values = array(
1010
-                'CNT_ISO'    => $CNT_ISO,
1011
-                'STA_abbrev' => $STA_abbrev,
1012
-                'STA_name'   => $STA_name,
1013
-                'STA_active' => true,
1014
-            );
1015
-            $success = EEM_State::instance()->insert($cols_n_values);
1016
-            EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1017
-        }
1018
-
1019
-        if (defined('DOING_AJAX')) {
1020
-            $notices = EE_Error::get_notices(false, false, false);
1021
-            echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1022
-            die();
1023
-        } else {
1024
-            $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1025
-        }
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     *        delete_state
1031
-     *
1032
-     * @access    public
1033
-     * @return        boolean
1034
-     * @throws EE_Error
1035
-     * @throws InvalidArgumentException
1036
-     * @throws InvalidDataTypeException
1037
-     * @throws InvalidInterfaceException
1038
-     */
1039
-    public function delete_state()
1040
-    {
1041
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
1042
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1043
-            : false;
1044
-        $STA_ID = isset($this->_req_data['STA_ID'])
1045
-            ? sanitize_text_field($this->_req_data['STA_ID'])
1046
-            : false;
1047
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1048
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
1049
-            : false;
1050
-        if (! $STA_ID) {
1051
-            EE_Error::add_error(
1052
-                esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1053
-                __FILE__,
1054
-                __FUNCTION__,
1055
-                __LINE__
1056
-            );
1057
-            return false;
1058
-        }
1059
-
1060
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1061
-        if ($success !== false) {
1062
-            do_action(
1063
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1064
-                $CNT_ISO,
1065
-                $STA_ID,
1066
-                array('STA_abbrev' => $STA_abbrev)
1067
-            );
1068
-            EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1069
-        }
1070
-        if (defined('DOING_AJAX')) {
1071
-            $notices = EE_Error::get_notices(false, false);
1072
-            $notices['return_data'] = true;
1073
-            echo wp_json_encode($notices);
1074
-            die();
1075
-        } else {
1076
-            $this->_redirect_after_action(
1077
-                $success,
1078
-                'State',
1079
-                'deleted',
1080
-                array('action' => 'country_settings')
1081
-            );
1082
-        }
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     *        _update_country_settings
1088
-     *
1089
-     * @access    protected
1090
-     * @return void
1091
-     * @throws EE_Error
1092
-     * @throws InvalidArgumentException
1093
-     * @throws InvalidDataTypeException
1094
-     * @throws InvalidInterfaceException
1095
-     */
1096
-    protected function _update_country_settings()
1097
-    {
1098
-        // grab the country ISO code
1099
-        $CNT_ISO = isset($this->_req_data['country'])
1100
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
1101
-            : false;
1102
-        if (! $CNT_ISO) {
1103
-            EE_Error::add_error(
1104
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1105
-                __FILE__,
1106
-                __FUNCTION__,
1107
-                __LINE__
1108
-            );
1109
-
1110
-            return;
1111
-        }
1112
-        $cols_n_values = array();
1113
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1114
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1115
-            : false;
1116
-        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1117
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1118
-            : null;
1119
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1120
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1121
-            : null;
1122
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1123
-            $cols_n_values['CNT_cur_code'] = strtoupper(
1124
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1125
-            );
1126
-        }
1127
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1128
-            $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1129
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1130
-            );
1131
-        }
1132
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1133
-            $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1134
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1135
-            );
1136
-        }
1137
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1138
-            $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1139
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1140
-            );
1141
-        }
1142
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1143
-            $cols_n_values['CNT_cur_sign_b4'] = absint(
1144
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1145
-            );
1146
-        }
1147
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1148
-            $cols_n_values['CNT_cur_dec_plc'] = absint(
1149
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1150
-            );
1151
-        }
1152
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1153
-            $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1154
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1155
-            );
1156
-        }
1157
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1158
-            $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1159
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1160
-            );
1161
-        }
1162
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1163
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1164
-            : null;
1165
-        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1166
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1167
-            : false;
1168
-        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1169
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1170
-            : false;
1171
-        // allow filtering of country data
1172
-        $cols_n_values = apply_filters(
1173
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1174
-            $cols_n_values
1175
-        );
1176
-
1177
-        // where values
1178
-        $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1179
-        // run the update
1180
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1181
-
1182
-        if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1183
-            // allow filtering of states data
1184
-            $states = apply_filters(
1185
-                'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1186
-                $this->_req_data['states']
1187
-            );
1188
-
1189
-            // loop thru state data ( looks like : states[75][STA_name] )
1190
-            foreach ($states as $STA_ID => $state) {
1191
-                $cols_n_values = array(
1192
-                    'CNT_ISO'    => $CNT_ISO,
1193
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1194
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1195
-                    'STA_active' => (bool) absint($state['STA_active']),
1196
-                );
1197
-                // where values
1198
-                $where_cols_n_values = array(array('STA_ID' => $STA_ID));
1199
-                // run the update
1200
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1201
-                if ($success !== false) {
1202
-                    do_action(
1203
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1204
-                        $CNT_ISO,
1205
-                        $STA_ID,
1206
-                        $cols_n_values
1207
-                    );
1208
-                }
1209
-            }
1210
-        }
1211
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1212
-        if (
1213
-            isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1214
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1215
-        ) {
1216
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1217
-            EE_Registry::instance()->CFG->update_espresso_config();
1218
-        }
1219
-
1220
-        if ($success !== false) {
1221
-            EE_Error::add_success(
1222
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1223
-            );
1224
-        }
1225
-        $this->_redirect_after_action(
1226
-            $success,
1227
-            '',
1228
-            '',
1229
-            array('action' => 'country_settings', 'country' => $CNT_ISO),
1230
-            true
1231
-        );
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     *        form_form_field_label_wrap
1237
-     *
1238
-     * @access        public
1239
-     * @param        string $label
1240
-     * @return        string
1241
-     */
1242
-    public function country_form_field_label_wrap($label, $required_text)
1243
-    {
1244
-        return '
23
+	/**
24
+	 * _question_group
25
+	 * holds the specific question group object for the question group details screen
26
+	 *
27
+	 * @var object
28
+	 */
29
+	protected $_question_group;
30
+
31
+
32
+	/**
33
+	 * Initialize basic properties.
34
+	 */
35
+	protected function _init_page_props()
36
+	{
37
+		$this->page_slug = GEN_SET_PG_SLUG;
38
+		$this->page_label = GEN_SET_LABEL;
39
+		$this->_admin_base_url = GEN_SET_ADMIN_URL;
40
+		$this->_admin_base_path = GEN_SET_ADMIN;
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set ajax hooks
46
+	 */
47
+	protected function _ajax_hooks()
48
+	{
49
+		add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
50
+		add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
51
+		add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
52
+		add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
53
+	}
54
+
55
+
56
+	/**
57
+	 * More page properties initialization.
58
+	 */
59
+	protected function _define_page_props()
60
+	{
61
+		$this->_admin_page_title = GEN_SET_LABEL;
62
+		$this->_labels = array(
63
+			'publishbox' => esc_html__('Update Settings', 'event_espresso'),
64
+		);
65
+	}
66
+
67
+
68
+	/**
69
+	 * Set page routes property.
70
+	 */
71
+	protected function _set_page_routes()
72
+	{
73
+		$this->_page_routes = array(
74
+
75
+			'critical_pages'                => array(
76
+				'func'       => '_espresso_page_settings',
77
+				'capability' => 'manage_options',
78
+			),
79
+			'update_espresso_page_settings' => array(
80
+				'func'       => '_update_espresso_page_settings',
81
+				'capability' => 'manage_options',
82
+				'noheader'   => true,
83
+			),
84
+			'default'                       => array(
85
+				'func'       => '_your_organization_settings',
86
+				'capability' => 'manage_options',
87
+			),
88
+
89
+			'update_your_organization_settings' => array(
90
+				'func'       => '_update_your_organization_settings',
91
+				'capability' => 'manage_options',
92
+				'noheader'   => true,
93
+			),
94
+
95
+			'admin_option_settings' => array(
96
+				'func'       => '_admin_option_settings',
97
+				'capability' => 'manage_options',
98
+			),
99
+
100
+			'update_admin_option_settings' => array(
101
+				'func'       => '_update_admin_option_settings',
102
+				'capability' => 'manage_options',
103
+				'noheader'   => true,
104
+			),
105
+
106
+			'country_settings' => array(
107
+				'func'       => '_country_settings',
108
+				'capability' => 'manage_options',
109
+			),
110
+
111
+			'update_country_settings' => array(
112
+				'func'       => '_update_country_settings',
113
+				'capability' => 'manage_options',
114
+				'noheader'   => true,
115
+			),
116
+
117
+			'display_country_settings' => array(
118
+				'func'       => 'display_country_settings',
119
+				'capability' => 'manage_options',
120
+				'noheader'   => true,
121
+			),
122
+
123
+			'add_new_state' => array(
124
+				'func'       => 'add_new_state',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+
129
+			'delete_state'            => array(
130
+				'func'       => 'delete_state',
131
+				'capability' => 'manage_options',
132
+				'noheader'   => true,
133
+			),
134
+			'privacy_settings'        => array(
135
+				'func'       => 'privacySettings',
136
+				'capability' => 'manage_options',
137
+			),
138
+			'update_privacy_settings' => array(
139
+				'func'               => 'updatePrivacySettings',
140
+				'capability'         => 'manage_options',
141
+				'noheader'           => true,
142
+				'headers_sent_route' => 'privacy_settings',
143
+			),
144
+		);
145
+	}
146
+
147
+
148
+	/**
149
+	 * Set page configuration property
150
+	 */
151
+	protected function _set_page_config()
152
+	{
153
+		$this->_page_config = array(
154
+			'critical_pages'        => array(
155
+				'nav'           => array(
156
+					'label' => esc_html__('Critical Pages', 'event_espresso'),
157
+					'order' => 50,
158
+				),
159
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
160
+				'help_tabs'     => array(
161
+					'general_settings_critical_pages_help_tab' => array(
162
+						'title'    => esc_html__('Critical Pages', 'event_espresso'),
163
+						'filename' => 'general_settings_critical_pages',
164
+					),
165
+				),
166
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
167
+				// 'help_tour'     => array('Critical_Pages_Help_Tour'),
168
+				'require_nonce' => false,
169
+			),
170
+			'default'               => array(
171
+				'nav'           => array(
172
+					'label' => esc_html__('Your Organization', 'event_espresso'),
173
+					'order' => 20,
174
+				),
175
+				'help_tabs'     => array(
176
+					'general_settings_your_organization_help_tab' => array(
177
+						'title'    => esc_html__('Your Organization', 'event_espresso'),
178
+						'filename' => 'general_settings_your_organization',
179
+					),
180
+				),
181
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
182
+				// 'help_tour'     => array('Your_Organization_Help_Tour'),
183
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
184
+				'require_nonce' => false,
185
+			),
186
+			'admin_option_settings' => array(
187
+				'nav'           => array(
188
+					'label' => esc_html__('Admin Options', 'event_espresso'),
189
+					'order' => 60,
190
+				),
191
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
192
+				'help_tabs'     => array(
193
+					'general_settings_admin_options_help_tab' => array(
194
+						'title'    => esc_html__('Admin Options', 'event_espresso'),
195
+						'filename' => 'general_settings_admin_options',
196
+					),
197
+				),
198
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
199
+				// 'help_tour'     => array('Admin_Options_Help_Tour'),
200
+				'require_nonce' => false,
201
+			),
202
+			'country_settings'      => array(
203
+				'nav'           => array(
204
+					'label' => esc_html__('Countries', 'event_espresso'),
205
+					'order' => 70,
206
+				),
207
+				'help_tabs'     => array(
208
+					'general_settings_countries_help_tab' => array(
209
+						'title'    => esc_html__('Countries', 'event_espresso'),
210
+						'filename' => 'general_settings_countries',
211
+					),
212
+				),
213
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
214
+				// 'help_tour'     => array('Countries_Help_Tour'),
215
+				'require_nonce' => false,
216
+			),
217
+			'privacy_settings'      => array(
218
+				'nav'           => array(
219
+					'label' => esc_html__('Privacy', 'event_espresso'),
220
+					'order' => 80,
221
+				),
222
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
223
+				'require_nonce' => false,
224
+			),
225
+		);
226
+	}
227
+
228
+
229
+	protected function _add_screen_options()
230
+	{
231
+	}
232
+
233
+
234
+	protected function _add_feature_pointers()
235
+	{
236
+	}
237
+
238
+
239
+	/**
240
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
241
+	 */
242
+	public function load_scripts_styles()
243
+	{
244
+		// styles
245
+		wp_enqueue_style('espresso-ui-theme');
246
+		// scripts
247
+		wp_enqueue_script('ee_admin_js');
248
+	}
249
+
250
+
251
+	/**
252
+	 * Execute logic running on `admin_init`
253
+	 */
254
+	public function admin_init()
255
+	{
256
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__(
257
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
258
+			'event_espresso'
259
+		));
260
+		EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__(
261
+			'An error occurred! Please refresh the page and try again.',
262
+			'event_espresso'
263
+		));
264
+		EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__(
265
+			'Are you sure you want to delete this State / Province?',
266
+			'event_espresso'
267
+		));
268
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
269
+		EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
270
+			'admin-ajax.php?page=espresso_general_settings',
271
+			$protocol
272
+		);
273
+	}
274
+
275
+
276
+	public function admin_notices()
277
+	{
278
+	}
279
+
280
+
281
+	public function admin_footer_scripts()
282
+	{
283
+	}
284
+
285
+
286
+	/**
287
+	 * Enqueue scripts and styles for the default route.
288
+	 */
289
+	public function load_scripts_styles_default()
290
+	{
291
+		// styles
292
+		wp_enqueue_style('thickbox');
293
+		// scripts
294
+		wp_enqueue_script('media-upload');
295
+		wp_enqueue_script('thickbox');
296
+		wp_register_script(
297
+			'organization_settings',
298
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
299
+			array('jquery', 'media-upload', 'thickbox'),
300
+			EVENT_ESPRESSO_VERSION,
301
+			true
302
+		);
303
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
304
+		wp_enqueue_script('organization_settings');
305
+		wp_enqueue_style('organization-css');
306
+		$confirm_image_delete = array(
307
+			'text' => wp_strip_all_tags(
308
+				__(
309
+					'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
310
+					'event_espresso'
311
+				)
312
+			),
313
+		);
314
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Enqueue scripts and styles for the country settings route.
320
+	 */
321
+	public function load_scripts_styles_country_settings()
322
+	{
323
+		// scripts
324
+		wp_register_script(
325
+			'gen_settings_countries',
326
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
327
+			array('ee_admin_js'),
328
+			EVENT_ESPRESSO_VERSION,
329
+			true
330
+		);
331
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
332
+		wp_enqueue_script('gen_settings_countries');
333
+		wp_enqueue_style('organization-css');
334
+	}
335
+
336
+
337
+	/*************        Espresso Pages        *************/
338
+	/**
339
+	 * _espresso_page_settings
340
+	 *
341
+	 * @throws \EE_Error
342
+	 * @throws DomainException
343
+	 * @throws DomainException
344
+	 * @throws InvalidDataTypeException
345
+	 * @throws InvalidArgumentException
346
+	 */
347
+	protected function _espresso_page_settings()
348
+	{
349
+		// Check to make sure all of the main pages are setup properly,
350
+		// if not create the default pages and display an admin notice
351
+		EEH_Activation::verify_default_pages_exist();
352
+		$this->_transient_garbage_collection();
353
+		$this->_template_args['values'] = $this->_yes_no_values;
354
+		$this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
355
+			? EE_Registry::instance()->CFG->core->reg_page_id
356
+			: null;
357
+		$this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
358
+			? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
359
+			: false;
360
+		$this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
361
+			? EE_Registry::instance()->CFG->core->txn_page_id
362
+			: null;
363
+		$this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
364
+			? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
365
+			: false;
366
+		$this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
367
+			? EE_Registry::instance()->CFG->core->thank_you_page_id
368
+			: null;
369
+		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
370
+			? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
371
+			: false;
372
+		$this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
373
+			? EE_Registry::instance()->CFG->core->cancel_page_id
374
+			: null;
375
+		$this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
376
+			? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
377
+			: false;
378
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
379
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
380
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
381
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
382
+			$this->_template_args,
383
+			true
384
+		);
385
+		$this->display_admin_page_with_sidebar();
386
+	}
387
+
388
+
389
+	/**
390
+	 * Handler for updating espresso page settings.
391
+	 *
392
+	 * @throws EE_Error
393
+	 */
394
+	protected function _update_espresso_page_settings()
395
+	{
396
+		// capture incoming request data && set page IDs
397
+		EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
398
+			? absint($this->_req_data['reg_page_id'])
399
+			: EE_Registry::instance()->CFG->core->reg_page_id;
400
+		EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
401
+			? absint($this->_req_data['txn_page_id'])
402
+			: EE_Registry::instance()->CFG->core->txn_page_id;
403
+		EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
404
+			? absint($this->_req_data['thank_you_page_id'])
405
+			: EE_Registry::instance()->CFG->core->thank_you_page_id;
406
+		EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
407
+			? absint($this->_req_data['cancel_page_id'])
408
+			: EE_Registry::instance()->CFG->core->cancel_page_id;
409
+
410
+		EE_Registry::instance()->CFG->core = apply_filters(
411
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
412
+			EE_Registry::instance()->CFG->core,
413
+			$this->_req_data
414
+		);
415
+		$what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
+		$this->_redirect_after_action(
417
+			$this->_update_espresso_configuration(
418
+				$what,
419
+				EE_Registry::instance()->CFG->core,
420
+				__FILE__,
421
+				__FUNCTION__,
422
+				__LINE__
423
+			),
424
+			$what,
425
+			'',
426
+			array(
427
+				'action' => 'critical_pages',
428
+			),
429
+			true
430
+		);
431
+	}
432
+
433
+
434
+	/*************        Your Organization        *************/
435
+
436
+
437
+	/**
438
+	 * @throws DomainException
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws InvalidInterfaceException
443
+	 */
444
+	protected function _your_organization_settings()
445
+	{
446
+		$this->_template_args['admin_page_content'] = '';
447
+		try {
448
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
449
+			$organization_settings_form = $this->loader->getShared(
450
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
451
+			);
452
+			$this->_template_args['admin_page_content'] = $organization_settings_form->display();
453
+		} catch (Exception $e) {
454
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
455
+		}
456
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
457
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
458
+		$this->display_admin_page_with_sidebar();
459
+	}
460
+
461
+
462
+	/**
463
+	 * Handler for updating organization settings.
464
+	 *
465
+	 * @throws EE_Error
466
+	 */
467
+	protected function _update_your_organization_settings()
468
+	{
469
+		try {
470
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
471
+			$organization_settings_form = $this->loader->getShared(
472
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
473
+			);
474
+			$success = $organization_settings_form->process($this->_req_data);
475
+			EE_Registry::instance()->CFG = apply_filters(
476
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
477
+				EE_Registry::instance()->CFG
478
+			);
479
+		} catch (Exception $e) {
480
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
481
+			$success = false;
482
+		}
483
+
484
+		if ($success) {
485
+			$success = $this->_update_espresso_configuration(
486
+				esc_html__('Your Organization Settings', 'event_espresso'),
487
+				EE_Registry::instance()->CFG,
488
+				__FILE__,
489
+				__FUNCTION__,
490
+				__LINE__
491
+			);
492
+		}
493
+
494
+		$this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
495
+	}
496
+
497
+
498
+
499
+	/*************        Admin Options        *************/
500
+
501
+
502
+	/**
503
+	 * _admin_option_settings
504
+	 *
505
+	 * @throws \EE_Error
506
+	 * @throws \LogicException
507
+	 */
508
+	protected function _admin_option_settings()
509
+	{
510
+		$this->_template_args['admin_page_content'] = '';
511
+		try {
512
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
513
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
514
+			$this->_template_args['values'] = $this->_yes_no_values;
515
+			// also need to account for the do_action that was in the old template
516
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
517
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
518
+		} catch (Exception $e) {
519
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
+		}
521
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
522
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
523
+		$this->display_admin_page_with_sidebar();
524
+	}
525
+
526
+
527
+	/**
528
+	 * _update_admin_option_settings
529
+	 *
530
+	 * @throws \EE_Error
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
533
+	 * @throws \InvalidArgumentException
534
+	 * @throws \LogicException
535
+	 */
536
+	protected function _update_admin_option_settings()
537
+	{
538
+		try {
539
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
540
+			$admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
541
+			EE_Registry::instance()->CFG->admin = apply_filters(
542
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
543
+				EE_Registry::instance()->CFG->admin
544
+			);
545
+		} catch (Exception $e) {
546
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
547
+		}
548
+		$this->_redirect_after_action(
549
+			apply_filters(
550
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
551
+				$this->_update_espresso_configuration(
552
+					'Admin Options',
553
+					EE_Registry::instance()->CFG->admin,
554
+					__FILE__,
555
+					__FUNCTION__,
556
+					__LINE__
557
+				)
558
+			),
559
+			'Admin Options',
560
+			'updated',
561
+			array('action' => 'admin_option_settings')
562
+		);
563
+	}
564
+
565
+
566
+	/*************        Countries        *************/
567
+
568
+
569
+	/**
570
+	 * @return string
571
+	 */
572
+	protected function getCountryIsoForSite()
573
+	{
574
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
575
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
576
+			: 'US';
577
+	}
578
+
579
+
580
+	/**
581
+	 * @param string          $CNT_ISO
582
+	 * @param EE_Country|null $country
583
+	 * @return EE_Base_Class|EE_Country
584
+	 * @throws EE_Error
585
+	 * @throws InvalidArgumentException
586
+	 * @throws InvalidDataTypeException
587
+	 * @throws InvalidInterfaceException
588
+	 * @throws ReflectionException
589
+	 */
590
+	protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
591
+	{
592
+		/** @var EE_Country $country */
593
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
594
+			? $country
595
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
596
+	}
597
+
598
+
599
+	/**
600
+	 * Output Country Settings view.
601
+	 *
602
+	 * @throws DomainException
603
+	 * @throws EE_Error
604
+	 * @throws InvalidArgumentException
605
+	 * @throws InvalidDataTypeException
606
+	 * @throws InvalidInterfaceException
607
+	 * @throws ReflectionException
608
+	 */
609
+	protected function _country_settings()
610
+	{
611
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
612
+		$CNT_ISO = isset($this->_req_data['country'])
613
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
614
+			: $CNT_ISO_for_site;
615
+
616
+		// load field generator helper
617
+
618
+		$this->_template_args['values'] = $this->_yes_no_values;
619
+
620
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
621
+			EE_Question::new_instance(
622
+				array(
623
+					'QST_ID'           => 0,
624
+					'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
625
+					'QST_system'       => 'admin-country',
626
+				)
627
+			),
628
+			EE_Answer::new_instance(
629
+				array(
630
+					'ANS_ID'    => 0,
631
+					'ANS_value' => $CNT_ISO,
632
+				)
633
+			),
634
+			array(
635
+				'input_id'       => 'country',
636
+				'input_name'     => 'country',
637
+				'input_prefix'   => '',
638
+				'append_qstn_id' => false,
639
+			)
640
+		);
641
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
642
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
643
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
644
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
645
+			$country->ID(),
646
+			$country
647
+		);
648
+		$this->_template_args['country_states_settings'] = $this->display_country_states(
649
+			$country->ID(),
650
+			$country
651
+		);
652
+		$this->_template_args['CNT_name_for_site'] = $country->name();
653
+
654
+		$this->_set_add_edit_form_tags('update_country_settings');
655
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
656
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
657
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
658
+			$this->_template_args,
659
+			true
660
+		);
661
+		$this->display_admin_page_with_no_sidebar();
662
+	}
663
+
664
+
665
+	/**
666
+	 *        display_country_settings
667
+	 *
668
+	 * @param string          $CNT_ISO
669
+	 * @param EE_Country|null $country
670
+	 * @return mixed string | array$country
671
+	 * @throws DomainException
672
+	 * @throws EE_Error
673
+	 * @throws InvalidArgumentException
674
+	 * @throws InvalidDataTypeException
675
+	 * @throws InvalidInterfaceException
676
+	 * @throws ReflectionException
677
+	 */
678
+	public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
679
+	{
680
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
681
+
682
+		$CNT_ISO = isset($this->_req_data['country'])
683
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
684
+			: $CNT_ISO;
685
+		if (! $CNT_ISO) {
686
+			return '';
687
+		}
688
+
689
+		// for ajax
690
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
691
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
692
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
693
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
694
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
695
+		$CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
696
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
697
+
698
+		$country_input_types = array(
699
+			'CNT_active'      => array(
700
+				'type'             => 'RADIO_BTN',
701
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
702
+				'class'            => '',
703
+				'options'          => $this->_yes_no_values,
704
+				'use_desc_4_label' => true,
705
+			),
706
+			'CNT_ISO'         => array(
707
+				'type'       => 'TEXT',
708
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
709
+				'class'      => 'small-text',
710
+			),
711
+			'CNT_ISO3'        => array(
712
+				'type'       => 'TEXT',
713
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
714
+				'class'      => 'small-text',
715
+			),
716
+			'RGN_ID'          => array(
717
+				'type'       => 'TEXT',
718
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
719
+				'class'      => 'small-text',
720
+			),
721
+			'CNT_name'        => array(
722
+				'type'       => 'TEXT',
723
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
724
+				'class'      => 'regular-text',
725
+			),
726
+			'CNT_cur_code'    => array(
727
+				'type'       => 'TEXT',
728
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
729
+				'class'      => 'small-text',
730
+				'disabled'   => $CNT_cur_disabled,
731
+			),
732
+			'CNT_cur_single'  => array(
733
+				'type'       => 'TEXT',
734
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
735
+				'class'      => 'medium-text',
736
+				'disabled'   => $CNT_cur_disabled,
737
+			),
738
+			'CNT_cur_plural'  => array(
739
+				'type'       => 'TEXT',
740
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
741
+				'class'      => 'medium-text',
742
+				'disabled'   => $CNT_cur_disabled,
743
+			),
744
+			'CNT_cur_sign'    => array(
745
+				'type'         => 'TEXT',
746
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
747
+				'class'        => 'small-text',
748
+				'htmlentities' => false,
749
+				'disabled'     => $CNT_cur_disabled,
750
+			),
751
+			'CNT_cur_sign_b4' => array(
752
+				'type'             => 'RADIO_BTN',
753
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
754
+				'class'            => '',
755
+				'options'          => $this->_yes_no_values,
756
+				'use_desc_4_label' => true,
757
+				'disabled'         => $CNT_cur_disabled,
758
+			),
759
+			'CNT_cur_dec_plc' => array(
760
+				'type'       => 'RADIO_BTN',
761
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
762
+				'class'      => '',
763
+				'options'    => array(
764
+					array('id' => 0, 'text' => ''),
765
+					array('id' => 1, 'text' => ''),
766
+					array('id' => 2, 'text' => ''),
767
+					array('id' => 3, 'text' => ''),
768
+				),
769
+				'disabled'   => $CNT_cur_disabled,
770
+			),
771
+			'CNT_cur_dec_mrk' => array(
772
+				'type'             => 'RADIO_BTN',
773
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
+				'class'            => '',
775
+				'options'          => array(
776
+					array(
777
+						'id'   => ',',
778
+						'text' => esc_html__(', (comma)', 'event_espresso'),
779
+					),
780
+					array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')),
781
+				),
782
+				'use_desc_4_label' => true,
783
+				'disabled'         => $CNT_cur_disabled,
784
+			),
785
+			'CNT_cur_thsnds'  => array(
786
+				'type'             => 'RADIO_BTN',
787
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
788
+				'class'            => '',
789
+				'options'          => array(
790
+					array(
791
+						'id'   => ',',
792
+						'text' => esc_html__(', (comma)', 'event_espresso'),
793
+					),
794
+					array(
795
+						'id' => '.',
796
+						'text' => esc_html__('. (decimal)', 'event_espresso')
797
+					),
798
+					array(
799
+						'id' => '&nbsp;',
800
+						'text' => esc_html__('(space)', 'event_espresso')
801
+					)
802
+				),
803
+				'use_desc_4_label' => true,
804
+				'disabled'         => $CNT_cur_disabled,
805
+			),
806
+			'CNT_tel_code'    => array(
807
+				'type'       => 'TEXT',
808
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
809
+				'class'      => 'small-text',
810
+			),
811
+			'CNT_is_EU'       => array(
812
+				'type'             => 'RADIO_BTN',
813
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
814
+				'class'            => '',
815
+				'options'          => $this->_yes_no_values,
816
+				'use_desc_4_label' => true,
817
+			),
818
+		);
819
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
820
+			$country,
821
+			$country_input_types
822
+		);
823
+		$country_details_settings = EEH_Template::display_template(
824
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
825
+			$this->_template_args,
826
+			true
827
+		);
828
+
829
+		if (defined('DOING_AJAX')) {
830
+			$notices = EE_Error::get_notices(false, false, false);
831
+			echo wp_json_encode(
832
+				array(
833
+					'return_data' => $country_details_settings,
834
+					'success'     => $notices['success'],
835
+					'errors'      => $notices['errors'],
836
+				)
837
+			);
838
+			die();
839
+		} else {
840
+			return $country_details_settings;
841
+		}
842
+	}
843
+
844
+
845
+	/**
846
+	 * @param string          $CNT_ISO
847
+	 * @param EE_Country|null $country
848
+	 * @return string
849
+	 * @throws DomainException
850
+	 * @throws EE_Error
851
+	 * @throws InvalidArgumentException
852
+	 * @throws InvalidDataTypeException
853
+	 * @throws InvalidInterfaceException
854
+	 * @throws ReflectionException
855
+	 */
856
+	public function display_country_states($CNT_ISO = '', EE_Country $country = null)
857
+	{
858
+
859
+		$CNT_ISO = isset($this->_req_data['country'])
860
+			? sanitize_text_field($this->_req_data['country'])
861
+			: $CNT_ISO;
862
+		if (! $CNT_ISO) {
863
+			return '';
864
+		}
865
+		// for ajax
866
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
867
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
868
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
869
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
870
+		$states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
871
+		if (empty($states)) {
872
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
873
+			$countrySubRegionDao = $this->loader->getShared(
874
+				'EventEspresso\core\services\address\CountrySubRegionDao'
875
+			);
876
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
877
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
878
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
879
+					$states = EEM_State::instance()->get_all_states_for_these_countries(
880
+						array($CNT_ISO => $CNT_ISO)
881
+					);
882
+				}
883
+			}
884
+		}
885
+		if (is_array($states)) {
886
+			foreach ($states as $STA_ID => $state) {
887
+				if ($state instanceof EE_State) {
888
+					// STA_abbrev    STA_name    STA_active
889
+					$state_input_types = array(
890
+						'STA_abbrev' => array(
891
+							'type'       => 'TEXT',
892
+							'input_name' => 'states[' . $STA_ID . ']',
893
+							'class'      => 'mid-text',
894
+						),
895
+						'STA_name'   => array(
896
+							'type'       => 'TEXT',
897
+							'input_name' => 'states[' . $STA_ID . ']',
898
+							'class'      => 'regular-text',
899
+						),
900
+						'STA_active' => array(
901
+							'type'             => 'RADIO_BTN',
902
+							'input_name'       => 'states[' . $STA_ID . ']',
903
+							'options'          => $this->_yes_no_values,
904
+							'use_desc_4_label' => true,
905
+						),
906
+					);
907
+					$this->_template_args['states'][ $STA_ID ]['inputs'] =
908
+						EE_Question_Form_Input::generate_question_form_inputs_for_object(
909
+							$state,
910
+							$state_input_types
911
+						);
912
+					$query_args = array(
913
+						'action'     => 'delete_state',
914
+						'STA_ID'     => $STA_ID,
915
+						'CNT_ISO'    => $CNT_ISO,
916
+						'STA_abbrev' => $state->abbrev(),
917
+					);
918
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
919
+						EE_Admin_Page::add_query_args_and_nonce(
920
+							$query_args,
921
+							GEN_SET_ADMIN_URL
922
+						);
923
+				}
924
+			}
925
+		} else {
926
+			$this->_template_args['states'] = false;
927
+		}
928
+
929
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
930
+			array('action' => 'add_new_state'),
931
+			GEN_SET_ADMIN_URL
932
+		);
933
+
934
+		$state_details_settings = EEH_Template::display_template(
935
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
936
+			$this->_template_args,
937
+			true
938
+		);
939
+
940
+		if (defined('DOING_AJAX')) {
941
+			$notices = EE_Error::get_notices(false, false, false);
942
+			echo wp_json_encode(
943
+				array(
944
+					'return_data' => $state_details_settings,
945
+					'success'     => $notices['success'],
946
+					'errors'      => $notices['errors'],
947
+				)
948
+			);
949
+			die();
950
+		} else {
951
+			return $state_details_settings;
952
+		}
953
+	}
954
+
955
+
956
+	/**
957
+	 *        add_new_state
958
+	 *
959
+	 * @access    public
960
+	 * @return void
961
+	 * @throws EE_Error
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidDataTypeException
964
+	 * @throws InvalidInterfaceException
965
+	 */
966
+	public function add_new_state()
967
+	{
968
+
969
+		$success = true;
970
+
971
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
972
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
973
+			: false;
974
+		if (! $CNT_ISO) {
975
+			EE_Error::add_error(
976
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
977
+				__FILE__,
978
+				__FUNCTION__,
979
+				__LINE__
980
+			);
981
+			$success = false;
982
+		}
983
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
984
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
985
+			: false;
986
+		if (! $STA_abbrev) {
987
+			EE_Error::add_error(
988
+				esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
989
+				__FILE__,
990
+				__FUNCTION__,
991
+				__LINE__
992
+			);
993
+			$success = false;
994
+		}
995
+		$STA_name = isset($this->_req_data['STA_name'])
996
+			? sanitize_text_field($this->_req_data['STA_name'])
997
+			: false;
998
+		if (! $STA_name) {
999
+			EE_Error::add_error(
1000
+				esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1001
+				__FILE__,
1002
+				__FUNCTION__,
1003
+				__LINE__
1004
+			);
1005
+			$success = false;
1006
+		}
1007
+
1008
+		if ($success) {
1009
+			$cols_n_values = array(
1010
+				'CNT_ISO'    => $CNT_ISO,
1011
+				'STA_abbrev' => $STA_abbrev,
1012
+				'STA_name'   => $STA_name,
1013
+				'STA_active' => true,
1014
+			);
1015
+			$success = EEM_State::instance()->insert($cols_n_values);
1016
+			EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1017
+		}
1018
+
1019
+		if (defined('DOING_AJAX')) {
1020
+			$notices = EE_Error::get_notices(false, false, false);
1021
+			echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1022
+			die();
1023
+		} else {
1024
+			$this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1025
+		}
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 *        delete_state
1031
+	 *
1032
+	 * @access    public
1033
+	 * @return        boolean
1034
+	 * @throws EE_Error
1035
+	 * @throws InvalidArgumentException
1036
+	 * @throws InvalidDataTypeException
1037
+	 * @throws InvalidInterfaceException
1038
+	 */
1039
+	public function delete_state()
1040
+	{
1041
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
1042
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1043
+			: false;
1044
+		$STA_ID = isset($this->_req_data['STA_ID'])
1045
+			? sanitize_text_field($this->_req_data['STA_ID'])
1046
+			: false;
1047
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
1048
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
1049
+			: false;
1050
+		if (! $STA_ID) {
1051
+			EE_Error::add_error(
1052
+				esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1053
+				__FILE__,
1054
+				__FUNCTION__,
1055
+				__LINE__
1056
+			);
1057
+			return false;
1058
+		}
1059
+
1060
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1061
+		if ($success !== false) {
1062
+			do_action(
1063
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1064
+				$CNT_ISO,
1065
+				$STA_ID,
1066
+				array('STA_abbrev' => $STA_abbrev)
1067
+			);
1068
+			EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1069
+		}
1070
+		if (defined('DOING_AJAX')) {
1071
+			$notices = EE_Error::get_notices(false, false);
1072
+			$notices['return_data'] = true;
1073
+			echo wp_json_encode($notices);
1074
+			die();
1075
+		} else {
1076
+			$this->_redirect_after_action(
1077
+				$success,
1078
+				'State',
1079
+				'deleted',
1080
+				array('action' => 'country_settings')
1081
+			);
1082
+		}
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 *        _update_country_settings
1088
+	 *
1089
+	 * @access    protected
1090
+	 * @return void
1091
+	 * @throws EE_Error
1092
+	 * @throws InvalidArgumentException
1093
+	 * @throws InvalidDataTypeException
1094
+	 * @throws InvalidInterfaceException
1095
+	 */
1096
+	protected function _update_country_settings()
1097
+	{
1098
+		// grab the country ISO code
1099
+		$CNT_ISO = isset($this->_req_data['country'])
1100
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
1101
+			: false;
1102
+		if (! $CNT_ISO) {
1103
+			EE_Error::add_error(
1104
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1105
+				__FILE__,
1106
+				__FUNCTION__,
1107
+				__LINE__
1108
+			);
1109
+
1110
+			return;
1111
+		}
1112
+		$cols_n_values = array();
1113
+		$cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1114
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1115
+			: false;
1116
+		$cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1117
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1118
+			: null;
1119
+		$cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1120
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1121
+			: null;
1122
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1123
+			$cols_n_values['CNT_cur_code'] = strtoupper(
1124
+				sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1125
+			);
1126
+		}
1127
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1128
+			$cols_n_values['CNT_cur_single'] = sanitize_text_field(
1129
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1130
+			);
1131
+		}
1132
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1133
+			$cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1134
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1135
+			);
1136
+		}
1137
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1138
+			$cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1139
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1140
+			);
1141
+		}
1142
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1143
+			$cols_n_values['CNT_cur_sign_b4'] = absint(
1144
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1145
+			);
1146
+		}
1147
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1148
+			$cols_n_values['CNT_cur_dec_plc'] = absint(
1149
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1150
+			);
1151
+		}
1152
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1153
+			$cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1154
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1155
+			);
1156
+		}
1157
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1158
+			$cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1159
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1160
+			);
1161
+		}
1162
+		$cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1163
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1164
+			: null;
1165
+		$cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1166
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1167
+			: false;
1168
+		$cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1169
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1170
+			: false;
1171
+		// allow filtering of country data
1172
+		$cols_n_values = apply_filters(
1173
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1174
+			$cols_n_values
1175
+		);
1176
+
1177
+		// where values
1178
+		$where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1179
+		// run the update
1180
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1181
+
1182
+		if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1183
+			// allow filtering of states data
1184
+			$states = apply_filters(
1185
+				'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1186
+				$this->_req_data['states']
1187
+			);
1188
+
1189
+			// loop thru state data ( looks like : states[75][STA_name] )
1190
+			foreach ($states as $STA_ID => $state) {
1191
+				$cols_n_values = array(
1192
+					'CNT_ISO'    => $CNT_ISO,
1193
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1194
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1195
+					'STA_active' => (bool) absint($state['STA_active']),
1196
+				);
1197
+				// where values
1198
+				$where_cols_n_values = array(array('STA_ID' => $STA_ID));
1199
+				// run the update
1200
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1201
+				if ($success !== false) {
1202
+					do_action(
1203
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1204
+						$CNT_ISO,
1205
+						$STA_ID,
1206
+						$cols_n_values
1207
+					);
1208
+				}
1209
+			}
1210
+		}
1211
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1212
+		if (
1213
+			isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1214
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1215
+		) {
1216
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1217
+			EE_Registry::instance()->CFG->update_espresso_config();
1218
+		}
1219
+
1220
+		if ($success !== false) {
1221
+			EE_Error::add_success(
1222
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1223
+			);
1224
+		}
1225
+		$this->_redirect_after_action(
1226
+			$success,
1227
+			'',
1228
+			'',
1229
+			array('action' => 'country_settings', 'country' => $CNT_ISO),
1230
+			true
1231
+		);
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 *        form_form_field_label_wrap
1237
+	 *
1238
+	 * @access        public
1239
+	 * @param        string $label
1240
+	 * @return        string
1241
+	 */
1242
+	public function country_form_field_label_wrap($label, $required_text)
1243
+	{
1244
+		return '
1245 1245
 			<tr>
1246 1246
 				<th>
1247 1247
 					' . $label . '
1248 1248
 				</th>';
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     *        form_form_field_input__wrap
1254
-     *
1255
-     * @access        public
1256
-     * @param        string $label
1257
-     * @return        string
1258
-     */
1259
-    public function country_form_field_input__wrap($input, $label)
1260
-    {
1261
-        return '
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 *        form_form_field_input__wrap
1254
+	 *
1255
+	 * @access        public
1256
+	 * @param        string $label
1257
+	 * @return        string
1258
+	 */
1259
+	public function country_form_field_input__wrap($input, $label)
1260
+	{
1261
+		return '
1262 1262
 				<td class="general-settings-country-input-td">
1263 1263
 					' . $input . '
1264 1264
 				</td>
1265 1265
 			</tr>';
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     *        form_form_field_label_wrap
1271
-     *
1272
-     * @access        public
1273
-     * @param        string $label
1274
-     * @param        string $required_text
1275
-     * @return        string
1276
-     */
1277
-    public function state_form_field_label_wrap($label, $required_text)
1278
-    {
1279
-        return $required_text;
1280
-    }
1281
-
1282
-
1283
-    /**
1284
-     *        form_form_field_input__wrap
1285
-     *
1286
-     * @access        public
1287
-     * @param        string $label
1288
-     * @return        string
1289
-     */
1290
-    public function state_form_field_input__wrap($input, $label)
1291
-    {
1292
-        return '
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 *        form_form_field_label_wrap
1271
+	 *
1272
+	 * @access        public
1273
+	 * @param        string $label
1274
+	 * @param        string $required_text
1275
+	 * @return        string
1276
+	 */
1277
+	public function state_form_field_label_wrap($label, $required_text)
1278
+	{
1279
+		return $required_text;
1280
+	}
1281
+
1282
+
1283
+	/**
1284
+	 *        form_form_field_input__wrap
1285
+	 *
1286
+	 * @access        public
1287
+	 * @param        string $label
1288
+	 * @return        string
1289
+	 */
1290
+	public function state_form_field_input__wrap($input, $label)
1291
+	{
1292
+		return '
1293 1293
 				<td class="general-settings-country-state-input-td">
1294 1294
 					' . $input . '
1295 1295
 				</td>';
1296
-    }
1297
-
1298
-
1299
-    /***********/
1300
-
1301
-
1302
-    /**
1303
-     * displays edit and view links for critical EE pages
1304
-     *
1305
-     * @access public
1306
-     * @param int $ee_page_id
1307
-     * @return string
1308
-     */
1309
-    public static function edit_view_links($ee_page_id)
1310
-    {
1311
-        $links = '<a href="'
1312
-                 . add_query_arg(
1313
-                     array('post' => $ee_page_id, 'action' => 'edit'),
1314
-                     admin_url('post.php')
1315
-                 )
1316
-                 . '" >'
1317
-                 . esc_html__('Edit', 'event_espresso')
1318
-                 . '</a>';
1319
-        $links .= ' &nbsp;|&nbsp; ';
1320
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1321
-
1322
-        return $links;
1323
-    }
1324
-
1325
-
1326
-    /**
1327
-     * displays page and shortcode status for critical EE pages
1328
-     *
1329
-     * @param WP page object $ee_page
1330
-     * @return string
1331
-     */
1332
-    public static function page_and_shortcode_status($ee_page, $shortcode)
1333
-    {
1334
-
1335
-        // page status
1336
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1337
-            $pg_colour = 'green';
1338
-            $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1339
-        } else {
1340
-            $pg_colour = 'red';
1341
-            $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1342
-        }
1343
-
1344
-        // shortcode status
1345
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1346
-            $sc_colour = 'green';
1347
-            $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1348
-        } else {
1349
-            $sc_colour = 'red';
1350
-            $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1351
-        }
1352
-
1353
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1354
-               . $pg_status
1355
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * generates a dropdown of all parent pages - copied from WP core
1361
-     *
1362
-     * @param int $default
1363
-     * @param int $parent
1364
-     * @param int $level
1365
-     */
1366
-    public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1367
-    {
1368
-        global $wpdb;
1369
-        $items = $wpdb->get_results(
1370
-            $wpdb->prepare(
1371
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1372
-                $parent
1373
-            )
1374
-        );
1375
-
1376
-        if ($items) {
1377
-            foreach ($items as $item) {
1378
-                $pad = str_repeat('&nbsp;', $level * 3);
1379
-                if ($item->ID == $default) {
1380
-                    $current = ' selected="selected"';
1381
-                } else {
1382
-                    $current = '';
1383
-                }
1384
-
1385
-                echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1386
-                     . esc_html($item->post_title)
1387
-                     . "</option>";
1388
-                parent_dropdown($default, $item->ID, $level + 1);
1389
-            }
1390
-        }
1391
-    }
1392
-
1393
-
1394
-    /**
1395
-     * Loads the scripts for the privacy settings form
1396
-     */
1397
-    public function load_scripts_styles_privacy_settings()
1398
-    {
1399
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1400
-        $form_handler->enqueueStylesAndScripts();
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * display the privacy settings form
1406
-     */
1407
-    public function privacySettings()
1408
-    {
1409
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1410
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1411
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1412
-        $this->_template_args['admin_page_content'] = $form_handler->display();
1413
-        $this->display_admin_page_with_sidebar();
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * Update the privacy settings from form data
1419
-     *
1420
-     * @throws EE_Error
1421
-     */
1422
-    public function updatePrivacySettings()
1423
-    {
1424
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1425
-        $success = $form_handler->process($this->get_request_data());
1426
-        $this->_redirect_after_action(
1427
-            $success,
1428
-            esc_html__('Registration Form Options', 'event_espresso'),
1429
-            'updated',
1430
-            array('action' => 'privacy_settings')
1431
-        );
1432
-    }
1296
+	}
1297
+
1298
+
1299
+	/***********/
1300
+
1301
+
1302
+	/**
1303
+	 * displays edit and view links for critical EE pages
1304
+	 *
1305
+	 * @access public
1306
+	 * @param int $ee_page_id
1307
+	 * @return string
1308
+	 */
1309
+	public static function edit_view_links($ee_page_id)
1310
+	{
1311
+		$links = '<a href="'
1312
+				 . add_query_arg(
1313
+					 array('post' => $ee_page_id, 'action' => 'edit'),
1314
+					 admin_url('post.php')
1315
+				 )
1316
+				 . '" >'
1317
+				 . esc_html__('Edit', 'event_espresso')
1318
+				 . '</a>';
1319
+		$links .= ' &nbsp;|&nbsp; ';
1320
+		$links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1321
+
1322
+		return $links;
1323
+	}
1324
+
1325
+
1326
+	/**
1327
+	 * displays page and shortcode status for critical EE pages
1328
+	 *
1329
+	 * @param WP page object $ee_page
1330
+	 * @return string
1331
+	 */
1332
+	public static function page_and_shortcode_status($ee_page, $shortcode)
1333
+	{
1334
+
1335
+		// page status
1336
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1337
+			$pg_colour = 'green';
1338
+			$pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1339
+		} else {
1340
+			$pg_colour = 'red';
1341
+			$pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1342
+		}
1343
+
1344
+		// shortcode status
1345
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1346
+			$sc_colour = 'green';
1347
+			$sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1348
+		} else {
1349
+			$sc_colour = 'red';
1350
+			$sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1351
+		}
1352
+
1353
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1354
+			   . $pg_status
1355
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * generates a dropdown of all parent pages - copied from WP core
1361
+	 *
1362
+	 * @param int $default
1363
+	 * @param int $parent
1364
+	 * @param int $level
1365
+	 */
1366
+	public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1367
+	{
1368
+		global $wpdb;
1369
+		$items = $wpdb->get_results(
1370
+			$wpdb->prepare(
1371
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1372
+				$parent
1373
+			)
1374
+		);
1375
+
1376
+		if ($items) {
1377
+			foreach ($items as $item) {
1378
+				$pad = str_repeat('&nbsp;', $level * 3);
1379
+				if ($item->ID == $default) {
1380
+					$current = ' selected="selected"';
1381
+				} else {
1382
+					$current = '';
1383
+				}
1384
+
1385
+				echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1386
+					 . esc_html($item->post_title)
1387
+					 . "</option>";
1388
+				parent_dropdown($default, $item->ID, $level + 1);
1389
+			}
1390
+		}
1391
+	}
1392
+
1393
+
1394
+	/**
1395
+	 * Loads the scripts for the privacy settings form
1396
+	 */
1397
+	public function load_scripts_styles_privacy_settings()
1398
+	{
1399
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1400
+		$form_handler->enqueueStylesAndScripts();
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * display the privacy settings form
1406
+	 */
1407
+	public function privacySettings()
1408
+	{
1409
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1410
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1411
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1412
+		$this->_template_args['admin_page_content'] = $form_handler->display();
1413
+		$this->display_admin_page_with_sidebar();
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * Update the privacy settings from form data
1419
+	 *
1420
+	 * @throws EE_Error
1421
+	 */
1422
+	public function updatePrivacySettings()
1423
+	{
1424
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1425
+		$success = $form_handler->process($this->get_request_data());
1426
+		$this->_redirect_after_action(
1427
+			$success,
1428
+			esc_html__('Registration Form Options', 'event_espresso'),
1429
+			'updated',
1430
+			array('action' => 'privacy_settings')
1431
+		);
1432
+	}
1433 1433
 }
Please login to merge, or discard this patch.
admin_pages/general_settings/AdminOptionsSettings.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -26,220 +26,220 @@
 block discarded – undo
26 26
 class AdminOptionsSettings extends FormHandler
27 27
 {
28 28
 
29
-    protected $template_args = array();
29
+	protected $template_args = array();
30 30
 
31
-    /**
32
-     * Form constructor.
33
-     *
34
-     * @param \EE_Registry $registry
35
-     */
36
-    public function __construct(\EE_Registry $registry)
37
-    {
38
-        parent::__construct(
39
-            esc_html__('Admin Options', 'event_espresso'),
40
-            esc_html__('Admin Options', 'event_espresso'),
41
-            'admin_option_settings',
42
-            '',
43
-            FormHandler::DO_NOT_SETUP_FORM,
44
-            $registry
45
-        );
46
-    }
31
+	/**
32
+	 * Form constructor.
33
+	 *
34
+	 * @param \EE_Registry $registry
35
+	 */
36
+	public function __construct(\EE_Registry $registry)
37
+	{
38
+		parent::__construct(
39
+			esc_html__('Admin Options', 'event_espresso'),
40
+			esc_html__('Admin Options', 'event_espresso'),
41
+			'admin_option_settings',
42
+			'',
43
+			FormHandler::DO_NOT_SETUP_FORM,
44
+			$registry
45
+		);
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * @param array $template_args
51
-     */
52
-    public function setTemplateArgs(array $template_args)
53
-    {
54
-        $this->template_args = $template_args;
55
-    }
49
+	/**
50
+	 * @param array $template_args
51
+	 */
52
+	public function setTemplateArgs(array $template_args)
53
+	{
54
+		$this->template_args = $template_args;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * creates and returns the actual form
60
-     *
61
-     * @return EE_Form_Section_Proper
62
-     * @throws EE_Error
63
-     */
64
-    public function generate()
65
-    {
66
-        $form = new \EE_Form_Section_Proper(
67
-            array(
68
-                'name'            => 'admin_option_settings',
69
-                'html_id'         => 'admin_option_settings',
70
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
71
-                'subsections'     => array(
72
-                    // 'help_tour_activation_hdr' => new EE_Form_Section_HTML(
73
-                    //     EEH_HTML::h2(
74
-                    //         esc_html__('Help Tour Global Activation', 'event_espresso')
75
-                    //         . ' '
76
-                    //         . EEH_HTML::span(
77
-                    //             EEH_Template::get_help_tab_link('help_tour_activation_info'),
78
-                    //             'help_tour_activation'
79
-                    //         ),
80
-                    //         '',
81
-                    //         'ee-admin-settings-hdr'
82
-                    //     )
83
-                    // ),
84
-                    // 'help_tour_activation'     => new EE_Yes_No_Input(
85
-                    //     array(
86
-                    //         'html_label_text' => esc_html__('Activate Global Help Tours?', 'event_espresso'),
87
-                    //         'html_help_text'  => esc_html__(
88
-                    //             'This toggles whether the Event Espresso help tours are active globally or not.',
89
-                    //             'event_espresso'
90
-                    //         ),
91
-                    //         'default'         => isset($this->registry->CFG->admin->help_tour_activation)
92
-                    //             ? filter_var($this->registry->CFG->admin->help_tour_activation, FILTER_VALIDATE_BOOLEAN)
93
-                    //             : true,
94
-                    //         'required'        => false,
95
-                    //     )
96
-                    // ),
97
-                    'compatibility_hdr'        => new EE_Form_Section_HTML(
98
-                        EEH_HTML::h2(
99
-                            esc_html__('Compatibility Settings', 'event_espresso'),
100
-                            '',
101
-                            'ee-admin-settings-hdr'
102
-                        )
103
-                    ),
104
-                    'encode_session_data'      => new EE_Yes_No_Input(
105
-                        array(
106
-                            'html_label_text' => esc_html__('Encode Session Data?', 'event_espresso'),
107
-                            'html_help_text'  => sprintf(
108
-                                esc_html__(
109
-                                    'Some servers and database configurations can cause problems when saving the Event Espresso session data. Setting this option to "Yes" adds an extra layer of encoding to session data to prevent serialization errors, but can be incompatible with some server configurations.%1$sIf you receive "500 internal server" type errors during registration, try turning this option on.%1$sIf you get fatal PHP errors regarding missing base64 functions, then turn this option off.',
110
-                                    'event_espresso'
111
-                                ),
112
-                                '<br>'
113
-                            ),
114
-                            'default'         => $this->registry->CFG->admin->encode_session_data(),
115
-                            'required'        => false,
116
-                        )
117
-                    ),
118
-                ),
119
-            )
120
-        );
121
-        if (
122
-            $this->registry->CAP->current_user_can(
123
-                'manage_options',
124
-                'display_admin_settings_options_promote_and_affiliate'
125
-            )
126
-        ) {
127
-            $form->add_subsections(
128
-                array(
129
-                    'promote_ee_hdr'  => new EE_Form_Section_HTML(
130
-                        EEH_HTML::h2(
131
-                            esc_html__('Promote Event Espresso', 'event_espresso')
132
-                            . ' '
133
-                            . EEH_HTML::span(
134
-                                EEH_Template::get_help_tab_link('affiliate_info'),
135
-                                'affiliate_info'
136
-                            ),
137
-                            '',
138
-                            'ee-admin-settings-hdr'
139
-                        )
140
-                    ),
141
-                    'show_reg_footer' => new EE_Yes_No_Input(
142
-                        array(
143
-                            'html_label_text' => esc_html__(
144
-                                'Link to Event Espresso in your Registration Page?',
145
-                                'event_espresso'
146
-                            )
147
-                            . EEH_Template::get_help_tab_link('email_validation_info'),
148
-                            'html_help_text'  => esc_html__(
149
-                                'adds an unobtrusive link to Event Espresso\'s website in the footer of your registration form. Get an affiliate link (see below) and make money if people click the link and purchase Event Espresso.',
150
-                                'event_espresso'
151
-                            ),
152
-                            'default'         => filter_var($this->registry->CFG->admin->show_reg_footer, FILTER_VALIDATE_BOOLEAN),
153
-                            'required'        => false,
154
-                        )
155
-                    ),
156
-                    'affiliate_id'    => new EE_Text_Input(
157
-                        array(
158
-                            'html_label_text' => sprintf(
159
-                                esc_html__('Event Espresso %1$sAffiliate%2$s ID', 'event_espresso'),
160
-                                '<a href="http://eventespresso.com/affiliates/" target="_blank">',
161
-                                '</a>'
162
-                            ),
163
-                            'html_help_text'  => esc_html__(
164
-                                'Earn cash for promoting Event Espresso.',
165
-                                'event_espresso'
166
-                            ),
167
-                            'html_class'      => 'regular-text',
168
-                            'default'         => isset($this->registry->CFG->admin->affiliate_id)
169
-                                ? $this->registry->CFG->admin->get_pretty('affiliate_id')
170
-                                : '',
171
-                            'required'        => false,
172
-                        )
173
-                    ),
174
-                ),
175
-                // 'help_tour_activation_hdr'
176
-                'compatibility_hdr'
177
-            );
178
-        }
179
-        return $form;
180
-    }
58
+	/**
59
+	 * creates and returns the actual form
60
+	 *
61
+	 * @return EE_Form_Section_Proper
62
+	 * @throws EE_Error
63
+	 */
64
+	public function generate()
65
+	{
66
+		$form = new \EE_Form_Section_Proper(
67
+			array(
68
+				'name'            => 'admin_option_settings',
69
+				'html_id'         => 'admin_option_settings',
70
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
71
+				'subsections'     => array(
72
+					// 'help_tour_activation_hdr' => new EE_Form_Section_HTML(
73
+					//     EEH_HTML::h2(
74
+					//         esc_html__('Help Tour Global Activation', 'event_espresso')
75
+					//         . ' '
76
+					//         . EEH_HTML::span(
77
+					//             EEH_Template::get_help_tab_link('help_tour_activation_info'),
78
+					//             'help_tour_activation'
79
+					//         ),
80
+					//         '',
81
+					//         'ee-admin-settings-hdr'
82
+					//     )
83
+					// ),
84
+					// 'help_tour_activation'     => new EE_Yes_No_Input(
85
+					//     array(
86
+					//         'html_label_text' => esc_html__('Activate Global Help Tours?', 'event_espresso'),
87
+					//         'html_help_text'  => esc_html__(
88
+					//             'This toggles whether the Event Espresso help tours are active globally or not.',
89
+					//             'event_espresso'
90
+					//         ),
91
+					//         'default'         => isset($this->registry->CFG->admin->help_tour_activation)
92
+					//             ? filter_var($this->registry->CFG->admin->help_tour_activation, FILTER_VALIDATE_BOOLEAN)
93
+					//             : true,
94
+					//         'required'        => false,
95
+					//     )
96
+					// ),
97
+					'compatibility_hdr'        => new EE_Form_Section_HTML(
98
+						EEH_HTML::h2(
99
+							esc_html__('Compatibility Settings', 'event_espresso'),
100
+							'',
101
+							'ee-admin-settings-hdr'
102
+						)
103
+					),
104
+					'encode_session_data'      => new EE_Yes_No_Input(
105
+						array(
106
+							'html_label_text' => esc_html__('Encode Session Data?', 'event_espresso'),
107
+							'html_help_text'  => sprintf(
108
+								esc_html__(
109
+									'Some servers and database configurations can cause problems when saving the Event Espresso session data. Setting this option to "Yes" adds an extra layer of encoding to session data to prevent serialization errors, but can be incompatible with some server configurations.%1$sIf you receive "500 internal server" type errors during registration, try turning this option on.%1$sIf you get fatal PHP errors regarding missing base64 functions, then turn this option off.',
110
+									'event_espresso'
111
+								),
112
+								'<br>'
113
+							),
114
+							'default'         => $this->registry->CFG->admin->encode_session_data(),
115
+							'required'        => false,
116
+						)
117
+					),
118
+				),
119
+			)
120
+		);
121
+		if (
122
+			$this->registry->CAP->current_user_can(
123
+				'manage_options',
124
+				'display_admin_settings_options_promote_and_affiliate'
125
+			)
126
+		) {
127
+			$form->add_subsections(
128
+				array(
129
+					'promote_ee_hdr'  => new EE_Form_Section_HTML(
130
+						EEH_HTML::h2(
131
+							esc_html__('Promote Event Espresso', 'event_espresso')
132
+							. ' '
133
+							. EEH_HTML::span(
134
+								EEH_Template::get_help_tab_link('affiliate_info'),
135
+								'affiliate_info'
136
+							),
137
+							'',
138
+							'ee-admin-settings-hdr'
139
+						)
140
+					),
141
+					'show_reg_footer' => new EE_Yes_No_Input(
142
+						array(
143
+							'html_label_text' => esc_html__(
144
+								'Link to Event Espresso in your Registration Page?',
145
+								'event_espresso'
146
+							)
147
+							. EEH_Template::get_help_tab_link('email_validation_info'),
148
+							'html_help_text'  => esc_html__(
149
+								'adds an unobtrusive link to Event Espresso\'s website in the footer of your registration form. Get an affiliate link (see below) and make money if people click the link and purchase Event Espresso.',
150
+								'event_espresso'
151
+							),
152
+							'default'         => filter_var($this->registry->CFG->admin->show_reg_footer, FILTER_VALIDATE_BOOLEAN),
153
+							'required'        => false,
154
+						)
155
+					),
156
+					'affiliate_id'    => new EE_Text_Input(
157
+						array(
158
+							'html_label_text' => sprintf(
159
+								esc_html__('Event Espresso %1$sAffiliate%2$s ID', 'event_espresso'),
160
+								'<a href="http://eventespresso.com/affiliates/" target="_blank">',
161
+								'</a>'
162
+							),
163
+							'html_help_text'  => esc_html__(
164
+								'Earn cash for promoting Event Espresso.',
165
+								'event_espresso'
166
+							),
167
+							'html_class'      => 'regular-text',
168
+							'default'         => isset($this->registry->CFG->admin->affiliate_id)
169
+								? $this->registry->CFG->admin->get_pretty('affiliate_id')
170
+								: '',
171
+							'required'        => false,
172
+						)
173
+					),
174
+				),
175
+				// 'help_tour_activation_hdr'
176
+				'compatibility_hdr'
177
+			);
178
+		}
179
+		return $form;
180
+	}
181 181
 
182 182
 
183
-    /**
184
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
185
-     * returns a string of HTML that can be directly echoed in a template
186
-     *
187
-     * @return string
188
-     * @throws LogicException
189
-     * @throws \EE_Error
190
-     */
191
-    public function display()
192
-    {
193
-        add_filter(
194
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
195
-            array($this, 'handleOldAdminOptionsSettingsAction')
196
-        );
197
-        return parent::display();
198
-    }
183
+	/**
184
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
185
+	 * returns a string of HTML that can be directly echoed in a template
186
+	 *
187
+	 * @return string
188
+	 * @throws LogicException
189
+	 * @throws \EE_Error
190
+	 */
191
+	public function display()
192
+	{
193
+		add_filter(
194
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
195
+			array($this, 'handleOldAdminOptionsSettingsAction')
196
+		);
197
+		return parent::display();
198
+	}
199 199
 
200 200
 
201
-    /**
202
-     * @return string
203
-     */
204
-    public function handleOldAdminOptionsSettingsAction()
205
-    {
206
-        ob_start();
207
-        do_action('AHEE__admin_option_settings__template__before', $this->template_args);
208
-        return ob_get_clean();
209
-    }
201
+	/**
202
+	 * @return string
203
+	 */
204
+	public function handleOldAdminOptionsSettingsAction()
205
+	{
206
+		ob_start();
207
+		do_action('AHEE__admin_option_settings__template__before', $this->template_args);
208
+		return ob_get_clean();
209
+	}
210 210
 
211 211
 
212
-    /**
213
-     * handles processing the form submission
214
-     * returns true or false depending on whether the form was processed successfully or not
215
-     *
216
-     * @param array $form_data
217
-     * @return bool
218
-     * @throws InvalidFormSubmissionException
219
-     * @throws EE_Error
220
-     * @throws LogicException
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     */
224
-    public function process($form_data = array())
225
-    {
226
-        // process form
227
-        $valid_data = (array) parent::process($form_data);
228
-        if (empty($valid_data)) {
229
-            return false;
230
-        }
231
-        $this->registry->CFG->admin->show_reg_footer = isset($form_data['show_reg_footer'])
232
-            ? absint($form_data['show_reg_footer'])
233
-            : $this->registry->CFG->admin->show_reg_footer;
234
-        $this->registry->CFG->admin->affiliate_id = isset($form_data['affiliate_id'])
235
-            ? sanitize_text_field($form_data['affiliate_id'])
236
-            : $this->registry->CFG->admin->affiliate_id;
237
-        // $this->registry->CFG->admin->help_tour_activation = isset($form_data['help_tour_activation'])
238
-        //     ? absint($form_data['help_tour_activation'])
239
-        //     : $this->registry->CFG->admin->help_tour_activation;
240
-        if (isset($form_data['encode_session_data'])) {
241
-            $this->registry->CFG->admin->set_encode_session_data($form_data['encode_session_data']);
242
-        }
243
-        return false;
244
-    }
212
+	/**
213
+	 * handles processing the form submission
214
+	 * returns true or false depending on whether the form was processed successfully or not
215
+	 *
216
+	 * @param array $form_data
217
+	 * @return bool
218
+	 * @throws InvalidFormSubmissionException
219
+	 * @throws EE_Error
220
+	 * @throws LogicException
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 */
224
+	public function process($form_data = array())
225
+	{
226
+		// process form
227
+		$valid_data = (array) parent::process($form_data);
228
+		if (empty($valid_data)) {
229
+			return false;
230
+		}
231
+		$this->registry->CFG->admin->show_reg_footer = isset($form_data['show_reg_footer'])
232
+			? absint($form_data['show_reg_footer'])
233
+			: $this->registry->CFG->admin->show_reg_footer;
234
+		$this->registry->CFG->admin->affiliate_id = isset($form_data['affiliate_id'])
235
+			? sanitize_text_field($form_data['affiliate_id'])
236
+			: $this->registry->CFG->admin->affiliate_id;
237
+		// $this->registry->CFG->admin->help_tour_activation = isset($form_data['help_tour_activation'])
238
+		//     ? absint($form_data['help_tour_activation'])
239
+		//     : $this->registry->CFG->admin->help_tour_activation;
240
+		if (isset($form_data['encode_session_data'])) {
241
+			$this->registry->CFG->admin->set_encode_session_data($form_data['encode_session_data']);
242
+		}
243
+		return false;
244
+	}
245 245
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1477 added lines, -1477 removed lines patch added patch discarded remove patch
@@ -28,484 +28,484 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * This gets set in _setup_cpt
33
-     * It will contain the object for the custom post type.
34
-     *
35
-     * @var EE_CPT_Base
36
-     */
37
-    protected $_cpt_object;
38
-
39
-
40
-    /**
41
-     * a boolean flag to set whether the current route is a cpt route or not.
42
-     *
43
-     * @var bool
44
-     */
45
-    protected $_cpt_route = false;
46
-
47
-
48
-    /**
49
-     * This property allows cpt classes to define multiple routes as cpt routes.
50
-     * //in this array we define what the custom post type for this route is.
51
-     * array(
52
-     * 'route_name' => 'custom_post_type_slug'
53
-     * )
54
-     *
55
-     * @var array
56
-     */
57
-    protected $_cpt_routes = array();
58
-
59
-
60
-    /**
61
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
-     * in this format:
63
-     * array(
64
-     * 'post_type_slug' => 'edit_route'
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    protected $_cpt_edit_routes = array();
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-    /**
90
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
91
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
92
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
93
-     * Registration of containers should be done before load_page_dependencies() is run.
94
-     *
95
-     * @var array()
96
-     */
97
-    protected $_autosave_containers = array();
98
-    protected $_autosave_fields = array();
99
-
100
-    /**
101
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
102
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
103
-     *
104
-     * @var array
105
-     */
106
-    protected $_pagenow_map;
107
-
108
-
109
-
110
-    /**
111
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
112
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
113
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
114
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
115
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
116
-     *
117
-     * @access protected
118
-     * @abstract
119
-     * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
120
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
121
-     * @return void
122
-     */
123
-    abstract protected function _insert_update_cpt_item($post_id, $post);
124
-
125
-
126
-    /**
127
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
128
-     *
129
-     * @abstract
130
-     * @access public
131
-     * @param  string $post_id The ID of the cpt that was trashed
132
-     * @return void
133
-     */
134
-    abstract public function trash_cpt_item($post_id);
135
-
136
-
137
-    /**
138
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
139
-     *
140
-     * @param  string $post_id theID of the cpt that was untrashed
141
-     * @return void
142
-     */
143
-    abstract public function restore_cpt_item($post_id);
144
-
145
-
146
-    /**
147
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
148
-     * from the db
149
-     *
150
-     * @param  string $post_id the ID of the cpt that was deleted
151
-     * @return void
152
-     */
153
-    abstract public function delete_cpt_item($post_id);
154
-
155
-
156
-    /**
157
-     * @return LoaderInterface
158
-     * @throws InvalidArgumentException
159
-     * @throws InvalidDataTypeException
160
-     * @throws InvalidInterfaceException
161
-     */
162
-    protected function getLoader()
163
-    {
164
-        if (! $this->loader instanceof LoaderInterface) {
165
-            $this->loader = LoaderFactory::getLoader();
166
-        }
167
-        return $this->loader;
168
-    }
169
-
170
-
171
-    /**
172
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
173
-     *
174
-     * @access protected
175
-     * @return void
176
-     */
177
-    protected function _before_page_setup()
178
-    {
179
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
180
-        $this->_cpt_routes = array_merge(
181
-            array(
182
-                'create_new' => $this->page_slug,
183
-                'edit'       => $this->page_slug,
184
-                'trash'      => $this->page_slug,
185
-            ),
186
-            $this->_cpt_routes
187
-        );
188
-        // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
189
-        $this->_cpt_object = isset($this->_req_data['action'], $this->_cpt_routes[ $this->_req_data['action'] ])
190
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
191
-            : get_post_type_object($page);
192
-        // tweak pagenow for page loading.
193
-        if (! $this->_pagenow_map) {
194
-            $this->_pagenow_map = array(
195
-                'create_new' => 'post-new.php',
196
-                'edit'       => 'post.php',
197
-                'trash'      => 'post.php',
198
-            );
199
-        }
200
-        add_action('current_screen', array($this, 'modify_pagenow'));
201
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
202
-        // get current page from autosave
203
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
204
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
205
-            : null;
206
-        $this->_current_page = isset($this->_req_data['current_page'])
207
-            ? $this->_req_data['current_page']
208
-            : $current_page;
209
-        // autosave... make sure its only for the correct page
210
-        // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
211
-        // setup autosave ajax hook
212
-        // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
213
-        // }
214
-    }
215
-
216
-
217
-    /**
218
-     * Simply ensure that we simulate the correct post route for cpt screens
219
-     *
220
-     * @param WP_Screen $current_screen
221
-     * @return void
222
-     */
223
-    public function modify_pagenow($current_screen)
224
-    {
225
-        global $pagenow, $hook_suffix;
226
-        // possibly reset pagenow.
227
-        if (
228
-            ! empty($this->_req_data['page'])
229
-            && $this->_req_data['page'] === $this->page_slug
230
-            && ! empty($this->_req_data['action'])
231
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
232
-        ) {
233
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
234
-            $hook_suffix = $pagenow;
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * This method is used to register additional autosave containers to the _autosave_containers property.
241
-     *
242
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
243
-     *       automatically register the id for the post metabox as a container.
244
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
245
-     *                    you would send along the id of a metabox container.
246
-     * @return void
247
-     */
248
-    protected function _register_autosave_containers($ids)
249
-    {
250
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
251
-    }
252
-
253
-
254
-    /**
255
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
256
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
257
-     */
258
-    protected function _set_autosave_containers()
259
-    {
260
-        global $wp_meta_boxes;
261
-        $containers = array();
262
-        if (empty($wp_meta_boxes)) {
263
-            return;
264
-        }
265
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
266
-        foreach ($current_metaboxes as $box_context) {
267
-            foreach ($box_context as $box_details) {
268
-                foreach ($box_details as $box) {
269
-                    if (
270
-                        is_array($box) && is_array($box['callback'])
271
-                        && (
272
-                            $box['callback'][0] instanceof EE_Admin_Page
273
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
274
-                        )
275
-                    ) {
276
-                        $containers[] = $box['id'];
277
-                    }
278
-                }
279
-            }
280
-        }
281
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
282
-        // add hidden inputs container
283
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
284
-    }
285
-
286
-
287
-    protected function _load_autosave_scripts_styles()
288
-    {
289
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
31
+	/**
32
+	 * This gets set in _setup_cpt
33
+	 * It will contain the object for the custom post type.
34
+	 *
35
+	 * @var EE_CPT_Base
36
+	 */
37
+	protected $_cpt_object;
38
+
39
+
40
+	/**
41
+	 * a boolean flag to set whether the current route is a cpt route or not.
42
+	 *
43
+	 * @var bool
44
+	 */
45
+	protected $_cpt_route = false;
46
+
47
+
48
+	/**
49
+	 * This property allows cpt classes to define multiple routes as cpt routes.
50
+	 * //in this array we define what the custom post type for this route is.
51
+	 * array(
52
+	 * 'route_name' => 'custom_post_type_slug'
53
+	 * )
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected $_cpt_routes = array();
58
+
59
+
60
+	/**
61
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
+	 * in this format:
63
+	 * array(
64
+	 * 'post_type_slug' => 'edit_route'
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $_cpt_edit_routes = array();
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+	/**
90
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
91
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
92
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
93
+	 * Registration of containers should be done before load_page_dependencies() is run.
94
+	 *
95
+	 * @var array()
96
+	 */
97
+	protected $_autosave_containers = array();
98
+	protected $_autosave_fields = array();
99
+
100
+	/**
101
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
102
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
103
+	 *
104
+	 * @var array
105
+	 */
106
+	protected $_pagenow_map;
107
+
108
+
109
+
110
+	/**
111
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
112
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
113
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
114
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
115
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
116
+	 *
117
+	 * @access protected
118
+	 * @abstract
119
+	 * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
120
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
121
+	 * @return void
122
+	 */
123
+	abstract protected function _insert_update_cpt_item($post_id, $post);
124
+
125
+
126
+	/**
127
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
128
+	 *
129
+	 * @abstract
130
+	 * @access public
131
+	 * @param  string $post_id The ID of the cpt that was trashed
132
+	 * @return void
133
+	 */
134
+	abstract public function trash_cpt_item($post_id);
135
+
136
+
137
+	/**
138
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
139
+	 *
140
+	 * @param  string $post_id theID of the cpt that was untrashed
141
+	 * @return void
142
+	 */
143
+	abstract public function restore_cpt_item($post_id);
144
+
145
+
146
+	/**
147
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
148
+	 * from the db
149
+	 *
150
+	 * @param  string $post_id the ID of the cpt that was deleted
151
+	 * @return void
152
+	 */
153
+	abstract public function delete_cpt_item($post_id);
154
+
155
+
156
+	/**
157
+	 * @return LoaderInterface
158
+	 * @throws InvalidArgumentException
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws InvalidInterfaceException
161
+	 */
162
+	protected function getLoader()
163
+	{
164
+		if (! $this->loader instanceof LoaderInterface) {
165
+			$this->loader = LoaderFactory::getLoader();
166
+		}
167
+		return $this->loader;
168
+	}
169
+
170
+
171
+	/**
172
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
173
+	 *
174
+	 * @access protected
175
+	 * @return void
176
+	 */
177
+	protected function _before_page_setup()
178
+	{
179
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
180
+		$this->_cpt_routes = array_merge(
181
+			array(
182
+				'create_new' => $this->page_slug,
183
+				'edit'       => $this->page_slug,
184
+				'trash'      => $this->page_slug,
185
+			),
186
+			$this->_cpt_routes
187
+		);
188
+		// let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
189
+		$this->_cpt_object = isset($this->_req_data['action'], $this->_cpt_routes[ $this->_req_data['action'] ])
190
+			? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
191
+			: get_post_type_object($page);
192
+		// tweak pagenow for page loading.
193
+		if (! $this->_pagenow_map) {
194
+			$this->_pagenow_map = array(
195
+				'create_new' => 'post-new.php',
196
+				'edit'       => 'post.php',
197
+				'trash'      => 'post.php',
198
+			);
199
+		}
200
+		add_action('current_screen', array($this, 'modify_pagenow'));
201
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
202
+		// get current page from autosave
203
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
204
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
205
+			: null;
206
+		$this->_current_page = isset($this->_req_data['current_page'])
207
+			? $this->_req_data['current_page']
208
+			: $current_page;
209
+		// autosave... make sure its only for the correct page
210
+		// if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
211
+		// setup autosave ajax hook
212
+		// add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
213
+		// }
214
+	}
215
+
216
+
217
+	/**
218
+	 * Simply ensure that we simulate the correct post route for cpt screens
219
+	 *
220
+	 * @param WP_Screen $current_screen
221
+	 * @return void
222
+	 */
223
+	public function modify_pagenow($current_screen)
224
+	{
225
+		global $pagenow, $hook_suffix;
226
+		// possibly reset pagenow.
227
+		if (
228
+			! empty($this->_req_data['page'])
229
+			&& $this->_req_data['page'] === $this->page_slug
230
+			&& ! empty($this->_req_data['action'])
231
+			&& isset($this->_pagenow_map[ $this->_req_data['action'] ])
232
+		) {
233
+			$pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
234
+			$hook_suffix = $pagenow;
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
241
+	 *
242
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
243
+	 *       automatically register the id for the post metabox as a container.
244
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
245
+	 *                    you would send along the id of a metabox container.
246
+	 * @return void
247
+	 */
248
+	protected function _register_autosave_containers($ids)
249
+	{
250
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
251
+	}
252
+
253
+
254
+	/**
255
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
256
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
257
+	 */
258
+	protected function _set_autosave_containers()
259
+	{
260
+		global $wp_meta_boxes;
261
+		$containers = array();
262
+		if (empty($wp_meta_boxes)) {
263
+			return;
264
+		}
265
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
266
+		foreach ($current_metaboxes as $box_context) {
267
+			foreach ($box_context as $box_details) {
268
+				foreach ($box_details as $box) {
269
+					if (
270
+						is_array($box) && is_array($box['callback'])
271
+						&& (
272
+							$box['callback'][0] instanceof EE_Admin_Page
273
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
274
+						)
275
+					) {
276
+						$containers[] = $box['id'];
277
+					}
278
+				}
279
+			}
280
+		}
281
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
282
+		// add hidden inputs container
283
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
284
+	}
285
+
286
+
287
+	protected function _load_autosave_scripts_styles()
288
+	{
289
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
290 290
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
291 291
 
292
-        // filter _autosave_containers
293
-        $containers = apply_filters(
294
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
295
-            $this->_autosave_containers,
296
-            $this
297
-        );
298
-        $containers = apply_filters(
299
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
300
-            $containers,
301
-            $this
302
-        );
303
-
304
-        wp_localize_script(
305
-            'event_editor_js',
306
-            'EE_AUTOSAVE_IDS',
307
-            $containers
308
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
309
-
310
-        $unsaved_data_msg = array(
311
-            'eventmsg'     => sprintf(
312
-                __(
313
-                    'The changes you made to this %s will be lost if you navigate away from this page.',
314
-                    'event_espresso'
315
-                ),
316
-                $this->_cpt_object->labels->singular_name
317
-            ),
318
-            'inputChanged' => 0,
319
-        );
320
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
321
-    }
322
-
323
-
324
-    /**
325
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
326
-     *
327
-     * @access protected
328
-     * @return void
329
-     * @throws EE_Error
330
-     * @throws ReflectionException
331
-     */
332
-    protected function _load_page_dependencies()
333
-    {
334
-        // we only add stuff if this is a cpt_route!
335
-        if (! $this->_cpt_route) {
336
-            parent::_load_page_dependencies();
337
-            return;
338
-        }
339
-        // now let's do some automatic filters into the wp_system
340
-        // and we'll check to make sure the CHILD class
341
-        // automatically has the required methods in place.
342
-        // the following filters are for setting all the redirects
343
-        // on DEFAULT WP custom post type actions
344
-        // let's add a hidden input to the post-edit form
345
-        // so we know when we have to trigger our custom redirects!
346
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
347
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
348
-        // inject our Admin page nav tabs...
349
-        // let's make sure the nav tabs are set if they aren't already
350
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
351
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
352
-        // modify the post_updated messages array
353
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
354
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
355
-        // cpts use the same format for shortlinks as posts!
356
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
357
-        // This basically allows us to change the title of the "publish" metabox area
358
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
359
-        if (! empty($this->_labels['publishbox'])) {
360
-            $box_label = is_array($this->_labels['publishbox'])
361
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
362
-                ? $this->_labels['publishbox'][ $this->_req_action ]
363
-                : $this->_labels['publishbox'];
364
-            add_meta_box(
365
-                'submitdiv',
366
-                $box_label,
367
-                'post_submit_meta_box',
368
-                $this->_cpt_routes[ $this->_req_action ],
369
-                'side',
370
-                'core'
371
-            );
372
-        }
373
-        // let's add page_templates metabox if this cpt added support for it.
374
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
375
-            add_meta_box(
376
-                'page_templates',
377
-                __('Page Template', 'event_espresso'),
378
-                array($this, 'page_template_meta_box'),
379
-                $this->_cpt_routes[ $this->_req_action ],
380
-                'side',
381
-                'default'
382
-            );
383
-        }
384
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
385
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
386
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
387
-        }
388
-        // add preview button
389
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
390
-        // insert our own post_stati dropdown
391
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
392
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
393
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
394
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
395
-        }
396
-        // This allows for adding additional stuff after the title field on the wp post edit form.
397
-        // This is also before the wp_editor for post description field.
398
-        if (method_exists($this, 'edit_form_after_title')) {
399
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
400
-        }
401
-        /**
402
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
403
-         */
404
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
405
-        parent::_load_page_dependencies();
406
-        // notice we are ALSO going to load the pagenow hook set for this route
407
-        // (see _before_page_setup for the reset of the pagenow global ).
408
-        // This is for any plugins that are doing things properly
409
-        // and hooking into the load page hook for core wp cpt routes.
410
-        global $pagenow;
411
-        add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
412
-        do_action('load-' . $pagenow);
413
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
414
-        // we route REALLY early.
415
-        try {
416
-            $this->_route_admin_request();
417
-        } catch (EE_Error $e) {
418
-            $e->get_error();
419
-        }
420
-    }
421
-
422
-
423
-    /**
424
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
425
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
426
-     * route instead.
427
-     *
428
-     * @param string $good_protocol_url The escaped url.
429
-     * @param string $original_url      The original url.
430
-     * @param string $_context          The context sent to the esc_url method.
431
-     * @return string possibly a new url for our route.
432
-     */
433
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
434
-    {
435
-        $routes_to_match = array(
436
-            0 => array(
437
-                'edit.php?post_type=espresso_attendees',
438
-                'admin.php?page=espresso_registrations&action=contact_list',
439
-            ),
440
-            1 => array(
441
-                'edit.php?post_type=' . $this->_cpt_object->name,
442
-                'admin.php?page=' . $this->_cpt_object->name,
443
-            ),
444
-        );
445
-        foreach ($routes_to_match as $route_matches) {
446
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
447
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
448
-            }
449
-        }
450
-        return $good_protocol_url;
451
-    }
452
-
453
-
454
-    /**
455
-     * Determine whether the current cpt supports page templates or not.
456
-     *
457
-     * @since %VER%
458
-     * @param string $cpt_name The cpt slug we're checking on.
459
-     * @return bool True supported, false not.
460
-     * @throws InvalidArgumentException
461
-     * @throws InvalidDataTypeException
462
-     * @throws InvalidInterfaceException
463
-     */
464
-    private function _supports_page_templates($cpt_name)
465
-    {
466
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
467
-        $custom_post_types = $this->loader->getShared(
468
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
469
-        );
470
-        $cpt_args = $custom_post_types->getDefinitions();
471
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
472
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
473
-
474
-        // if the installed version of WP is > 4.7 we do some additional checks.
475
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
476
-            $post_templates = wp_get_theme()->get_post_templates();
477
-            // if there are $post_templates for this cpt, then we return false for this method because
478
-            // that means we aren't going to load our page template manager and leave that up to the native
479
-            // cpt template manager.
480
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
481
-        }
482
-
483
-        return $cpt_has_support;
484
-    }
485
-
486
-
487
-    /**
488
-     * Callback for the page_templates metabox selector.
489
-     *
490
-     * @since %VER%
491
-     * @return void
492
-     */
493
-    public function page_template_meta_box()
494
-    {
495
-        global $post;
496
-        $template = '';
497
-
498
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
499
-            $page_template_count = count(get_page_templates());
500
-        } else {
501
-            $page_template_count = count(get_page_templates($post));
502
-        }
503
-
504
-        if ($page_template_count) {
505
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
506
-            $template = ! empty($page_template) ? $page_template : '';
507
-        }
508
-        ?>
292
+		// filter _autosave_containers
293
+		$containers = apply_filters(
294
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
295
+			$this->_autosave_containers,
296
+			$this
297
+		);
298
+		$containers = apply_filters(
299
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
300
+			$containers,
301
+			$this
302
+		);
303
+
304
+		wp_localize_script(
305
+			'event_editor_js',
306
+			'EE_AUTOSAVE_IDS',
307
+			$containers
308
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
309
+
310
+		$unsaved_data_msg = array(
311
+			'eventmsg'     => sprintf(
312
+				__(
313
+					'The changes you made to this %s will be lost if you navigate away from this page.',
314
+					'event_espresso'
315
+				),
316
+				$this->_cpt_object->labels->singular_name
317
+			),
318
+			'inputChanged' => 0,
319
+		);
320
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
321
+	}
322
+
323
+
324
+	/**
325
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
326
+	 *
327
+	 * @access protected
328
+	 * @return void
329
+	 * @throws EE_Error
330
+	 * @throws ReflectionException
331
+	 */
332
+	protected function _load_page_dependencies()
333
+	{
334
+		// we only add stuff if this is a cpt_route!
335
+		if (! $this->_cpt_route) {
336
+			parent::_load_page_dependencies();
337
+			return;
338
+		}
339
+		// now let's do some automatic filters into the wp_system
340
+		// and we'll check to make sure the CHILD class
341
+		// automatically has the required methods in place.
342
+		// the following filters are for setting all the redirects
343
+		// on DEFAULT WP custom post type actions
344
+		// let's add a hidden input to the post-edit form
345
+		// so we know when we have to trigger our custom redirects!
346
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
347
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
348
+		// inject our Admin page nav tabs...
349
+		// let's make sure the nav tabs are set if they aren't already
350
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
351
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
352
+		// modify the post_updated messages array
353
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
354
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
355
+		// cpts use the same format for shortlinks as posts!
356
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
357
+		// This basically allows us to change the title of the "publish" metabox area
358
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
359
+		if (! empty($this->_labels['publishbox'])) {
360
+			$box_label = is_array($this->_labels['publishbox'])
361
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
362
+				? $this->_labels['publishbox'][ $this->_req_action ]
363
+				: $this->_labels['publishbox'];
364
+			add_meta_box(
365
+				'submitdiv',
366
+				$box_label,
367
+				'post_submit_meta_box',
368
+				$this->_cpt_routes[ $this->_req_action ],
369
+				'side',
370
+				'core'
371
+			);
372
+		}
373
+		// let's add page_templates metabox if this cpt added support for it.
374
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
375
+			add_meta_box(
376
+				'page_templates',
377
+				__('Page Template', 'event_espresso'),
378
+				array($this, 'page_template_meta_box'),
379
+				$this->_cpt_routes[ $this->_req_action ],
380
+				'side',
381
+				'default'
382
+			);
383
+		}
384
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
385
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
386
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
387
+		}
388
+		// add preview button
389
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
390
+		// insert our own post_stati dropdown
391
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
392
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
393
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
394
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
395
+		}
396
+		// This allows for adding additional stuff after the title field on the wp post edit form.
397
+		// This is also before the wp_editor for post description field.
398
+		if (method_exists($this, 'edit_form_after_title')) {
399
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
400
+		}
401
+		/**
402
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
403
+		 */
404
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
405
+		parent::_load_page_dependencies();
406
+		// notice we are ALSO going to load the pagenow hook set for this route
407
+		// (see _before_page_setup for the reset of the pagenow global ).
408
+		// This is for any plugins that are doing things properly
409
+		// and hooking into the load page hook for core wp cpt routes.
410
+		global $pagenow;
411
+		add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
412
+		do_action('load-' . $pagenow);
413
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
414
+		// we route REALLY early.
415
+		try {
416
+			$this->_route_admin_request();
417
+		} catch (EE_Error $e) {
418
+			$e->get_error();
419
+		}
420
+	}
421
+
422
+
423
+	/**
424
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
425
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
426
+	 * route instead.
427
+	 *
428
+	 * @param string $good_protocol_url The escaped url.
429
+	 * @param string $original_url      The original url.
430
+	 * @param string $_context          The context sent to the esc_url method.
431
+	 * @return string possibly a new url for our route.
432
+	 */
433
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
434
+	{
435
+		$routes_to_match = array(
436
+			0 => array(
437
+				'edit.php?post_type=espresso_attendees',
438
+				'admin.php?page=espresso_registrations&action=contact_list',
439
+			),
440
+			1 => array(
441
+				'edit.php?post_type=' . $this->_cpt_object->name,
442
+				'admin.php?page=' . $this->_cpt_object->name,
443
+			),
444
+		);
445
+		foreach ($routes_to_match as $route_matches) {
446
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
447
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
448
+			}
449
+		}
450
+		return $good_protocol_url;
451
+	}
452
+
453
+
454
+	/**
455
+	 * Determine whether the current cpt supports page templates or not.
456
+	 *
457
+	 * @since %VER%
458
+	 * @param string $cpt_name The cpt slug we're checking on.
459
+	 * @return bool True supported, false not.
460
+	 * @throws InvalidArgumentException
461
+	 * @throws InvalidDataTypeException
462
+	 * @throws InvalidInterfaceException
463
+	 */
464
+	private function _supports_page_templates($cpt_name)
465
+	{
466
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
467
+		$custom_post_types = $this->loader->getShared(
468
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
469
+		);
470
+		$cpt_args = $custom_post_types->getDefinitions();
471
+		$cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
472
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
473
+
474
+		// if the installed version of WP is > 4.7 we do some additional checks.
475
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
476
+			$post_templates = wp_get_theme()->get_post_templates();
477
+			// if there are $post_templates for this cpt, then we return false for this method because
478
+			// that means we aren't going to load our page template manager and leave that up to the native
479
+			// cpt template manager.
480
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
481
+		}
482
+
483
+		return $cpt_has_support;
484
+	}
485
+
486
+
487
+	/**
488
+	 * Callback for the page_templates metabox selector.
489
+	 *
490
+	 * @since %VER%
491
+	 * @return void
492
+	 */
493
+	public function page_template_meta_box()
494
+	{
495
+		global $post;
496
+		$template = '';
497
+
498
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
499
+			$page_template_count = count(get_page_templates());
500
+		} else {
501
+			$page_template_count = count(get_page_templates($post));
502
+		}
503
+
504
+		if ($page_template_count) {
505
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
506
+			$template = ! empty($page_template) ? $page_template : '';
507
+		}
508
+		?>
509 509
         <p><strong><?php _e('Template', 'event_espresso') ?></strong></p>
510 510
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select
511 511
         name="page_template" id="page_template">
@@ -513,481 +513,481 @@  discard block
 block discarded – undo
513 513
         <?php page_template_dropdown($template); ?>
514 514
     </select>
515 515
         <?php
516
-    }
517
-
518
-
519
-    /**
520
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
521
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
522
-     *
523
-     * @param  string $return    the current html
524
-     * @param  int    $id        the post id for the page
525
-     * @param  string $new_title What the title is
526
-     * @param  string $new_slug  what the slug is
527
-     * @return string            The new html string for the permalink area
528
-     */
529
-    public function preview_button_html($return, $id, $new_title, $new_slug)
530
-    {
531
-        $post = get_post($id);
532
-        if ('publish' !== get_post_status($post)) {
533
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
534
-                       . get_preview_post_link($id)
535
-                       . '" class="button button-small">'
536
-                       . __('Preview', 'event_espresso')
537
-                       . '</a></span>'
538
-                       . "\n";
539
-        }
540
-        return $return;
541
-    }
542
-
543
-
544
-    /**
545
-     * add our custom post stati dropdown on the wp post page for this cpt
546
-     *
547
-     * @return void
548
-     */
549
-    public function custom_post_stati_dropdown()
550
-    {
551
-
552
-        $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
553
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
554
-            ? $statuses[ $this->_cpt_model_obj->status() ]
555
-            : '';
556
-        $template_args = array(
557
-            'cur_status'            => $this->_cpt_model_obj->status(),
558
-            'statuses'              => $statuses,
559
-            'cur_status_label'      => $cur_status_label,
560
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
561
-        );
562
-        // we'll add a trash post status (WP doesn't add one for some reason)
563
-        if ($this->_cpt_model_obj->status() === 'trash') {
564
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
565
-            $statuses['trash'] = __('Trashed', 'event_espresso');
566
-            $template_args['statuses'] = $statuses;
567
-        }
568
-
569
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
570
-        EEH_Template::display_template($template, $template_args);
571
-    }
572
-
573
-
574
-    public function setup_autosave_hooks()
575
-    {
576
-        $this->_set_autosave_containers();
577
-        $this->_load_autosave_scripts_styles();
578
-    }
579
-
580
-
581
-    /**
582
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
583
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
584
-     * for the nonce in here, but then this method looks for two things:
585
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
586
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
587
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
588
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
589
-     * template args.
590
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
591
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
592
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
593
-     *    $this->_template_args['data']['items'] = array(
594
-     *        'event-datetime-ids' => '1,2,3';
595
-     *    );
596
-     *    Keep in mind the following things:
597
-     *    - "where" index is for the input with the id as that string.
598
-     *    - "what" index is what will be used for the value of that input.
599
-     *
600
-     * @return void
601
-     * @throws EE_Error
602
-     */
603
-    public function do_extra_autosave_stuff()
604
-    {
605
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
606
-        $nonce = isset($this->_req_data['autosavenonce'])
607
-            ? $this->_req_data['autosavenonce']
608
-            : null;
609
-        $this->_verify_nonce($nonce, 'autosave');
610
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
611
-        if (! defined('DOING_AUTOSAVE')) {
612
-            define('DOING_AUTOSAVE', true);
613
-        }
614
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
615
-        $autosave = "_ee_autosave_{$this->_current_view}";
616
-        if (method_exists($this, $autosave)) {
617
-            $this->$autosave();
618
-        } else {
619
-            $this->_template_args['success'] = true;
620
-        }
621
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
622
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
623
-        // now let's return json
624
-        $this->_return_json();
625
-    }
626
-
627
-
628
-    /**
629
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
630
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
631
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
632
-     *
633
-     * @access protected
634
-     * @return void
635
-     * @throws ReflectionException
636
-     * @throws EE_Error
637
-     */
638
-    protected function _extend_page_config_for_cpt()
639
-    {
640
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
641
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
642
-            return;
643
-        }
644
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
645
-        if (! empty($this->_cpt_object)) {
646
-            $this->_page_routes = array_merge(
647
-                array(
648
-                    'create_new' => '_create_new_cpt_item',
649
-                    'edit'       => '_edit_cpt_item',
650
-                ),
651
-                $this->_page_routes
652
-            );
653
-            $this->_page_config = array_merge(
654
-                array(
655
-                    'create_new' => array(
656
-                        'nav'           => array(
657
-                            'label' => $this->_cpt_object->labels->add_new_item,
658
-                            'order' => 5,
659
-                        ),
660
-                        'require_nonce' => false,
661
-                    ),
662
-                    'edit'       => array(
663
-                        'nav'           => array(
664
-                            'label'      => $this->_cpt_object->labels->edit_item,
665
-                            'order'      => 5,
666
-                            'persistent' => false,
667
-                            'url'        => '',
668
-                        ),
669
-                        'require_nonce' => false,
670
-                    ),
671
-                ),
672
-                $this->_page_config
673
-            );
674
-        }
675
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
676
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
677
-            return;
678
-        }
679
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
680
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
681
-        if (empty($this->_cpt_object)) {
682
-            $msg = sprintf(
683
-                __(
684
-                    'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
685
-                    'event_espresso'
686
-                ),
687
-                $this->page_slug,
688
-                $this->_req_action,
689
-                get_class($this)
690
-            );
691
-            throw new EE_Error($msg);
692
-        }
693
-        if ($this->_cpt_route) {
694
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
695
-            $this->_set_model_object($id);
696
-        }
697
-    }
698
-
699
-
700
-    /**
701
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
702
-     *
703
-     * @access protected
704
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
705
-     * @param bool   $ignore_route_check
706
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
707
-     * @throws EE_Error
708
-     * @throws InvalidArgumentException
709
-     * @throws InvalidDataTypeException
710
-     * @throws InvalidInterfaceException
711
-     * @throws ReflectionException
712
-     */
713
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
714
-    {
715
-        $model = null;
716
-        if (
717
-            empty($this->_cpt_model_names)
718
-            || (
719
-                ! $ignore_route_check
720
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
721
-            ) || (
722
-                $this->_cpt_model_obj instanceof EE_CPT_Base
723
-                && $this->_cpt_model_obj->ID() === $id
724
-            )
725
-        ) {
726
-            // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
727
-            return;
728
-        }
729
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
730
-        if ($ignore_route_check) {
731
-            $post_type = get_post_type($id);
732
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
733
-            $custom_post_types = $this->loader->getShared(
734
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
735
-            );
736
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
737
-            if (isset($model_names[ $post_type ])) {
738
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
739
-            }
740
-        } else {
741
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
742
-        }
743
-        if ($model instanceof EEM_Base) {
744
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
745
-        }
746
-        do_action(
747
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
748
-            $this->_cpt_model_obj,
749
-            $req_type
750
-        );
751
-    }
752
-
753
-
754
-    /**
755
-     * admin_init_global
756
-     * This runs all the code that we want executed within the WP admin_init hook.
757
-     * This method executes for ALL EE Admin pages.
758
-     *
759
-     * @access public
760
-     * @return void
761
-     */
762
-    public function admin_init_global()
763
-    {
764
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
765
-        // its possible this is a new save so let's catch that instead
766
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
767
-        $post_type = $post ? $post->post_type : false;
768
-        $current_route = isset($this->_req_data['current_route'])
769
-            ? $this->_req_data['current_route']
770
-            : 'shouldneverwork';
771
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
772
-            ? $this->_cpt_routes[ $current_route ]
773
-            : '';
774
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
775
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
776
-        if ($post_type === $route_to_check) {
777
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
778
-        }
779
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
780
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
781
-        if (! empty($revision)) {
782
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
783
-            // doing a restore?
784
-            if (! empty($action) && $action === 'restore') {
785
-                // get post for revision
786
-                $rev_post = get_post($revision);
787
-                $rev_parent = get_post($rev_post->post_parent);
788
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
789
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
790
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
791
-                    // restores of revisions
792
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
793
-                }
794
-            }
795
-        }
796
-        // NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
797
-        if ($post_type && $post_type === $route_to_check) {
798
-            // $post_id, $post
799
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
800
-            // $post_id
801
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
802
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
803
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
804
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
805
-        }
806
-    }
807
-
808
-
809
-    /**
810
-     * Callback for the WordPress trashed_post hook.
811
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
812
-     *
813
-     * @param int $post_id
814
-     * @throws EE_Error
815
-     * @throws ReflectionException
816
-     */
817
-    public function before_trash_cpt_item($post_id)
818
-    {
819
-        $this->_set_model_object($post_id, true, 'trash');
820
-        // if our cpt object isn't existent then get out immediately.
821
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
822
-            return;
823
-        }
824
-        $this->trash_cpt_item($post_id);
825
-    }
826
-
827
-
828
-    /**
829
-     * Callback for the WordPress untrashed_post hook.
830
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
831
-     *
832
-     * @param $post_id
833
-     * @throws EE_Error
834
-     * @throws ReflectionException
835
-     */
836
-    public function before_restore_cpt_item($post_id)
837
-    {
838
-        $this->_set_model_object($post_id, true, 'restore');
839
-        // if our cpt object isn't existent then get out immediately.
840
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
841
-            return;
842
-        }
843
-        $this->restore_cpt_item($post_id);
844
-    }
845
-
846
-
847
-    /**
848
-     * Callback for the WordPress after_delete_post hook.
849
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
850
-     *
851
-     * @param $post_id
852
-     * @throws EE_Error
853
-     * @throws ReflectionException
854
-     */
855
-    public function before_delete_cpt_item($post_id)
856
-    {
857
-        $this->_set_model_object($post_id, true, 'delete');
858
-        // if our cpt object isn't existent then get out immediately.
859
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
860
-            return;
861
-        }
862
-        $this->delete_cpt_item($post_id);
863
-    }
864
-
865
-
866
-    /**
867
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
868
-     * accordingly.
869
-     *
870
-     * @return void
871
-     * @throws EE_Error
872
-     * @throws InvalidArgumentException
873
-     * @throws InvalidDataTypeException
874
-     * @throws InvalidInterfaceException
875
-     * @throws ReflectionException
876
-     */
877
-    public function verify_cpt_object()
878
-    {
879
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
880
-        // verify event object
881
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
882
-            throw new EE_Error(
883
-                sprintf(
884
-                    __(
885
-                        'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
886
-                        'event_espresso'
887
-                    ),
888
-                    $label
889
-                )
890
-            );
891
-        }
892
-        // if auto-draft then throw an error
893
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
894
-            EE_Error::overwrite_errors();
895
-            EE_Error::add_error(
896
-                sprintf(
897
-                    __(
898
-                        'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
899
-                        'event_espresso'
900
-                    ),
901
-                    $label
902
-                ),
903
-                __FILE__,
904
-                __FUNCTION__,
905
-                __LINE__
906
-            );
907
-        }
908
-    }
909
-
910
-
911
-    /**
912
-     * admin_footer_scripts_global
913
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
914
-     * will apply on ALL EE_Admin pages.
915
-     *
916
-     * @access public
917
-     * @return void
918
-     */
919
-    public function admin_footer_scripts_global()
920
-    {
921
-        $this->_add_admin_page_ajax_loading_img();
922
-        $this->_add_admin_page_overlay();
923
-    }
924
-
925
-
926
-    /**
927
-     * add in any global scripts for cpt routes
928
-     *
929
-     * @return void
930
-     * @throws EE_Error
931
-     */
932
-    public function load_global_scripts_styles()
933
-    {
934
-        parent::load_global_scripts_styles();
935
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936
-            // setup custom post status object for localize script but only if we've got a cpt object
937
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
-            if (! empty($statuses)) {
939
-                // get ALL statuses!
940
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
941
-                // setup object
942
-                $ee_cpt_statuses = array();
943
-                foreach ($statuses as $status => $label) {
944
-                    $ee_cpt_statuses[ $status ] = array(
945
-                        'label'      => $label,
946
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
947
-                    );
948
-                }
949
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
950
-            }
951
-        }
952
-    }
953
-
954
-
955
-    /**
956
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
957
-     * insert/updates
958
-     *
959
-     * @param int     $post_id ID of post being updated
960
-     * @param WP_Post $post    Post object from WP
961
-     * @param bool    $update  Whether this is an update or a new save.
962
-     * @return void
963
-     * @throws EE_Error
964
-     * @throws ReflectionException
965
-     */
966
-    public function insert_update($post_id, $post, $update)
967
-    {
968
-        // make sure that if this is a revision OR trash action that we don't do any updates!
969
-        if (
970
-            isset($this->_req_data['action'])
971
-            && (
972
-                $this->_req_data['action'] === 'restore'
973
-                || $this->_req_data['action'] === 'trash'
974
-            )
975
-        ) {
976
-            return;
977
-        }
978
-        $this->_set_model_object($post_id, true, 'insert_update');
979
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
980
-        if (
981
-            $update
982
-            && (
983
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
984
-                || $this->_cpt_model_obj->ID() !== $post_id
985
-            )
986
-        ) {
987
-            return;
988
-        }
989
-        // check for autosave and update our req_data property accordingly.
990
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
516
+	}
517
+
518
+
519
+	/**
520
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
521
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
522
+	 *
523
+	 * @param  string $return    the current html
524
+	 * @param  int    $id        the post id for the page
525
+	 * @param  string $new_title What the title is
526
+	 * @param  string $new_slug  what the slug is
527
+	 * @return string            The new html string for the permalink area
528
+	 */
529
+	public function preview_button_html($return, $id, $new_title, $new_slug)
530
+	{
531
+		$post = get_post($id);
532
+		if ('publish' !== get_post_status($post)) {
533
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
534
+					   . get_preview_post_link($id)
535
+					   . '" class="button button-small">'
536
+					   . __('Preview', 'event_espresso')
537
+					   . '</a></span>'
538
+					   . "\n";
539
+		}
540
+		return $return;
541
+	}
542
+
543
+
544
+	/**
545
+	 * add our custom post stati dropdown on the wp post page for this cpt
546
+	 *
547
+	 * @return void
548
+	 */
549
+	public function custom_post_stati_dropdown()
550
+	{
551
+
552
+		$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
553
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
554
+			? $statuses[ $this->_cpt_model_obj->status() ]
555
+			: '';
556
+		$template_args = array(
557
+			'cur_status'            => $this->_cpt_model_obj->status(),
558
+			'statuses'              => $statuses,
559
+			'cur_status_label'      => $cur_status_label,
560
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
561
+		);
562
+		// we'll add a trash post status (WP doesn't add one for some reason)
563
+		if ($this->_cpt_model_obj->status() === 'trash') {
564
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
565
+			$statuses['trash'] = __('Trashed', 'event_espresso');
566
+			$template_args['statuses'] = $statuses;
567
+		}
568
+
569
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
570
+		EEH_Template::display_template($template, $template_args);
571
+	}
572
+
573
+
574
+	public function setup_autosave_hooks()
575
+	{
576
+		$this->_set_autosave_containers();
577
+		$this->_load_autosave_scripts_styles();
578
+	}
579
+
580
+
581
+	/**
582
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
583
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
584
+	 * for the nonce in here, but then this method looks for two things:
585
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
586
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
587
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
588
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
589
+	 * template args.
590
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
591
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
592
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
593
+	 *    $this->_template_args['data']['items'] = array(
594
+	 *        'event-datetime-ids' => '1,2,3';
595
+	 *    );
596
+	 *    Keep in mind the following things:
597
+	 *    - "where" index is for the input with the id as that string.
598
+	 *    - "what" index is what will be used for the value of that input.
599
+	 *
600
+	 * @return void
601
+	 * @throws EE_Error
602
+	 */
603
+	public function do_extra_autosave_stuff()
604
+	{
605
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
606
+		$nonce = isset($this->_req_data['autosavenonce'])
607
+			? $this->_req_data['autosavenonce']
608
+			: null;
609
+		$this->_verify_nonce($nonce, 'autosave');
610
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
611
+		if (! defined('DOING_AUTOSAVE')) {
612
+			define('DOING_AUTOSAVE', true);
613
+		}
614
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
615
+		$autosave = "_ee_autosave_{$this->_current_view}";
616
+		if (method_exists($this, $autosave)) {
617
+			$this->$autosave();
618
+		} else {
619
+			$this->_template_args['success'] = true;
620
+		}
621
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
622
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
623
+		// now let's return json
624
+		$this->_return_json();
625
+	}
626
+
627
+
628
+	/**
629
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
630
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
631
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
632
+	 *
633
+	 * @access protected
634
+	 * @return void
635
+	 * @throws ReflectionException
636
+	 * @throws EE_Error
637
+	 */
638
+	protected function _extend_page_config_for_cpt()
639
+	{
640
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
641
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
642
+			return;
643
+		}
644
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
645
+		if (! empty($this->_cpt_object)) {
646
+			$this->_page_routes = array_merge(
647
+				array(
648
+					'create_new' => '_create_new_cpt_item',
649
+					'edit'       => '_edit_cpt_item',
650
+				),
651
+				$this->_page_routes
652
+			);
653
+			$this->_page_config = array_merge(
654
+				array(
655
+					'create_new' => array(
656
+						'nav'           => array(
657
+							'label' => $this->_cpt_object->labels->add_new_item,
658
+							'order' => 5,
659
+						),
660
+						'require_nonce' => false,
661
+					),
662
+					'edit'       => array(
663
+						'nav'           => array(
664
+							'label'      => $this->_cpt_object->labels->edit_item,
665
+							'order'      => 5,
666
+							'persistent' => false,
667
+							'url'        => '',
668
+						),
669
+						'require_nonce' => false,
670
+					),
671
+				),
672
+				$this->_page_config
673
+			);
674
+		}
675
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
676
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
677
+			return;
678
+		}
679
+		$this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
680
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
681
+		if (empty($this->_cpt_object)) {
682
+			$msg = sprintf(
683
+				__(
684
+					'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
685
+					'event_espresso'
686
+				),
687
+				$this->page_slug,
688
+				$this->_req_action,
689
+				get_class($this)
690
+			);
691
+			throw new EE_Error($msg);
692
+		}
693
+		if ($this->_cpt_route) {
694
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
695
+			$this->_set_model_object($id);
696
+		}
697
+	}
698
+
699
+
700
+	/**
701
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
702
+	 *
703
+	 * @access protected
704
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
705
+	 * @param bool   $ignore_route_check
706
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
707
+	 * @throws EE_Error
708
+	 * @throws InvalidArgumentException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws InvalidInterfaceException
711
+	 * @throws ReflectionException
712
+	 */
713
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
714
+	{
715
+		$model = null;
716
+		if (
717
+			empty($this->_cpt_model_names)
718
+			|| (
719
+				! $ignore_route_check
720
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
721
+			) || (
722
+				$this->_cpt_model_obj instanceof EE_CPT_Base
723
+				&& $this->_cpt_model_obj->ID() === $id
724
+			)
725
+		) {
726
+			// get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
727
+			return;
728
+		}
729
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
730
+		if ($ignore_route_check) {
731
+			$post_type = get_post_type($id);
732
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
733
+			$custom_post_types = $this->loader->getShared(
734
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
735
+			);
736
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
737
+			if (isset($model_names[ $post_type ])) {
738
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
739
+			}
740
+		} else {
741
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
742
+		}
743
+		if ($model instanceof EEM_Base) {
744
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
745
+		}
746
+		do_action(
747
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
748
+			$this->_cpt_model_obj,
749
+			$req_type
750
+		);
751
+	}
752
+
753
+
754
+	/**
755
+	 * admin_init_global
756
+	 * This runs all the code that we want executed within the WP admin_init hook.
757
+	 * This method executes for ALL EE Admin pages.
758
+	 *
759
+	 * @access public
760
+	 * @return void
761
+	 */
762
+	public function admin_init_global()
763
+	{
764
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
765
+		// its possible this is a new save so let's catch that instead
766
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
767
+		$post_type = $post ? $post->post_type : false;
768
+		$current_route = isset($this->_req_data['current_route'])
769
+			? $this->_req_data['current_route']
770
+			: 'shouldneverwork';
771
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
772
+			? $this->_cpt_routes[ $current_route ]
773
+			: '';
774
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
775
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
776
+		if ($post_type === $route_to_check) {
777
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
778
+		}
779
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
780
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
781
+		if (! empty($revision)) {
782
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
783
+			// doing a restore?
784
+			if (! empty($action) && $action === 'restore') {
785
+				// get post for revision
786
+				$rev_post = get_post($revision);
787
+				$rev_parent = get_post($rev_post->post_parent);
788
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
789
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
790
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
791
+					// restores of revisions
792
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
793
+				}
794
+			}
795
+		}
796
+		// NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
797
+		if ($post_type && $post_type === $route_to_check) {
798
+			// $post_id, $post
799
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
800
+			// $post_id
801
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
802
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
803
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
804
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
805
+		}
806
+	}
807
+
808
+
809
+	/**
810
+	 * Callback for the WordPress trashed_post hook.
811
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
812
+	 *
813
+	 * @param int $post_id
814
+	 * @throws EE_Error
815
+	 * @throws ReflectionException
816
+	 */
817
+	public function before_trash_cpt_item($post_id)
818
+	{
819
+		$this->_set_model_object($post_id, true, 'trash');
820
+		// if our cpt object isn't existent then get out immediately.
821
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
822
+			return;
823
+		}
824
+		$this->trash_cpt_item($post_id);
825
+	}
826
+
827
+
828
+	/**
829
+	 * Callback for the WordPress untrashed_post hook.
830
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
831
+	 *
832
+	 * @param $post_id
833
+	 * @throws EE_Error
834
+	 * @throws ReflectionException
835
+	 */
836
+	public function before_restore_cpt_item($post_id)
837
+	{
838
+		$this->_set_model_object($post_id, true, 'restore');
839
+		// if our cpt object isn't existent then get out immediately.
840
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
841
+			return;
842
+		}
843
+		$this->restore_cpt_item($post_id);
844
+	}
845
+
846
+
847
+	/**
848
+	 * Callback for the WordPress after_delete_post hook.
849
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
850
+	 *
851
+	 * @param $post_id
852
+	 * @throws EE_Error
853
+	 * @throws ReflectionException
854
+	 */
855
+	public function before_delete_cpt_item($post_id)
856
+	{
857
+		$this->_set_model_object($post_id, true, 'delete');
858
+		// if our cpt object isn't existent then get out immediately.
859
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
860
+			return;
861
+		}
862
+		$this->delete_cpt_item($post_id);
863
+	}
864
+
865
+
866
+	/**
867
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
868
+	 * accordingly.
869
+	 *
870
+	 * @return void
871
+	 * @throws EE_Error
872
+	 * @throws InvalidArgumentException
873
+	 * @throws InvalidDataTypeException
874
+	 * @throws InvalidInterfaceException
875
+	 * @throws ReflectionException
876
+	 */
877
+	public function verify_cpt_object()
878
+	{
879
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
880
+		// verify event object
881
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
882
+			throw new EE_Error(
883
+				sprintf(
884
+					__(
885
+						'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
886
+						'event_espresso'
887
+					),
888
+					$label
889
+				)
890
+			);
891
+		}
892
+		// if auto-draft then throw an error
893
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
894
+			EE_Error::overwrite_errors();
895
+			EE_Error::add_error(
896
+				sprintf(
897
+					__(
898
+						'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
899
+						'event_espresso'
900
+					),
901
+					$label
902
+				),
903
+				__FILE__,
904
+				__FUNCTION__,
905
+				__LINE__
906
+			);
907
+		}
908
+	}
909
+
910
+
911
+	/**
912
+	 * admin_footer_scripts_global
913
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
914
+	 * will apply on ALL EE_Admin pages.
915
+	 *
916
+	 * @access public
917
+	 * @return void
918
+	 */
919
+	public function admin_footer_scripts_global()
920
+	{
921
+		$this->_add_admin_page_ajax_loading_img();
922
+		$this->_add_admin_page_overlay();
923
+	}
924
+
925
+
926
+	/**
927
+	 * add in any global scripts for cpt routes
928
+	 *
929
+	 * @return void
930
+	 * @throws EE_Error
931
+	 */
932
+	public function load_global_scripts_styles()
933
+	{
934
+		parent::load_global_scripts_styles();
935
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936
+			// setup custom post status object for localize script but only if we've got a cpt object
937
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
+			if (! empty($statuses)) {
939
+				// get ALL statuses!
940
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
941
+				// setup object
942
+				$ee_cpt_statuses = array();
943
+				foreach ($statuses as $status => $label) {
944
+					$ee_cpt_statuses[ $status ] = array(
945
+						'label'      => $label,
946
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
947
+					);
948
+				}
949
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
950
+			}
951
+		}
952
+	}
953
+
954
+
955
+	/**
956
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
957
+	 * insert/updates
958
+	 *
959
+	 * @param int     $post_id ID of post being updated
960
+	 * @param WP_Post $post    Post object from WP
961
+	 * @param bool    $update  Whether this is an update or a new save.
962
+	 * @return void
963
+	 * @throws EE_Error
964
+	 * @throws ReflectionException
965
+	 */
966
+	public function insert_update($post_id, $post, $update)
967
+	{
968
+		// make sure that if this is a revision OR trash action that we don't do any updates!
969
+		if (
970
+			isset($this->_req_data['action'])
971
+			&& (
972
+				$this->_req_data['action'] === 'restore'
973
+				|| $this->_req_data['action'] === 'trash'
974
+			)
975
+		) {
976
+			return;
977
+		}
978
+		$this->_set_model_object($post_id, true, 'insert_update');
979
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
980
+		if (
981
+			$update
982
+			&& (
983
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
984
+				|| $this->_cpt_model_obj->ID() !== $post_id
985
+			)
986
+		) {
987
+			return;
988
+		}
989
+		// check for autosave and update our req_data property accordingly.
990
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
991 991
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
992 992
 
993 993
                 foreach ( (array) $values as $key => $value ) {
@@ -997,540 +997,540 @@  discard block
 block discarded – undo
997 997
 
998 998
         }/**/ // TODO reactivate after autosave is implemented in 4.2
999 999
 
1000
-        // take care of updating any selected page_template IF this cpt supports it.
1001
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
-            // wp version aware.
1003
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
-                $page_templates = wp_get_theme()->get_page_templates();
1005
-            } else {
1006
-                $post->page_template = $this->_req_data['page_template'];
1007
-                $page_templates = wp_get_theme()->get_page_templates($post);
1008
-            }
1009
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1010
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011
-            } else {
1012
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1013
-            }
1014
-        }
1015
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1016
-            return;
1017
-        } //TODO we'll remove this after reimplementing autosave in 4.2
1018
-        $this->_insert_update_cpt_item($post_id, $post);
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1024
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1025
-     * so we don't have to check for our CPT.
1026
-     *
1027
-     * @param  int $post_id ID of the post
1028
-     * @return void
1029
-     */
1030
-    public function dont_permanently_delete_ee_cpts($post_id)
1031
-    {
1032
-        // only do this if we're actually processing one of our CPTs
1033
-        // if our cpt object isn't existent then get out immediately.
1034
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035
-            return;
1036
-        }
1037
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1038
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1039
-        // our cpts may have comments so let's take care of that too
1040
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1046
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1047
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1048
-     *
1049
-     * @param  int $post_id     ID of cpt item
1050
-     * @param  int $revision_id ID of revision being restored
1051
-     * @return void
1052
-     */
1053
-    public function restore_revision($post_id, $revision_id)
1054
-    {
1055
-        $this->_restore_cpt_item($post_id, $revision_id);
1056
-        // global action
1057
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058
-        // class specific action so you can limit hooking into a specific page.
1059
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * @see restore_revision() for details
1065
-     * @param  int $post_id     ID of cpt item
1066
-     * @param  int $revision_id ID of revision for item
1067
-     * @return void
1068
-     */
1069
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1070
-
1071
-
1072
-    /**
1073
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1074
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1075
-     * To fix we have to reset the current_screen using the page_slug
1076
-     * (which is identical - or should be - to our registered_post_type id.)
1077
-     * Also, since the core WP file loads the admin_header.php for WP
1078
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1079
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1080
-     *
1081
-     * @return void
1082
-     * @throws EE_Error
1083
-     */
1084
-    public function modify_current_screen()
1085
-    {
1086
-        // ONLY do this if the current page_route IS a cpt route
1087
-        if (! $this->_cpt_route) {
1088
-            return;
1089
-        }
1090
-        // routing things REALLY early b/c this is a cpt admin page
1091
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1092
-        $this->_current_screen = get_current_screen();
1093
-        $this->_current_screen->base = 'event-espresso';
1094
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1095
-        /*try {
1000
+		// take care of updating any selected page_template IF this cpt supports it.
1001
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
+			// wp version aware.
1003
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
+				$page_templates = wp_get_theme()->get_page_templates();
1005
+			} else {
1006
+				$post->page_template = $this->_req_data['page_template'];
1007
+				$page_templates = wp_get_theme()->get_page_templates($post);
1008
+			}
1009
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1010
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011
+			} else {
1012
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1013
+			}
1014
+		}
1015
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1016
+			return;
1017
+		} //TODO we'll remove this after reimplementing autosave in 4.2
1018
+		$this->_insert_update_cpt_item($post_id, $post);
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1024
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1025
+	 * so we don't have to check for our CPT.
1026
+	 *
1027
+	 * @param  int $post_id ID of the post
1028
+	 * @return void
1029
+	 */
1030
+	public function dont_permanently_delete_ee_cpts($post_id)
1031
+	{
1032
+		// only do this if we're actually processing one of our CPTs
1033
+		// if our cpt object isn't existent then get out immediately.
1034
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035
+			return;
1036
+		}
1037
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1038
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1039
+		// our cpts may have comments so let's take care of that too
1040
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1046
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1047
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1048
+	 *
1049
+	 * @param  int $post_id     ID of cpt item
1050
+	 * @param  int $revision_id ID of revision being restored
1051
+	 * @return void
1052
+	 */
1053
+	public function restore_revision($post_id, $revision_id)
1054
+	{
1055
+		$this->_restore_cpt_item($post_id, $revision_id);
1056
+		// global action
1057
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058
+		// class specific action so you can limit hooking into a specific page.
1059
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * @see restore_revision() for details
1065
+	 * @param  int $post_id     ID of cpt item
1066
+	 * @param  int $revision_id ID of revision for item
1067
+	 * @return void
1068
+	 */
1069
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1070
+
1071
+
1072
+	/**
1073
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1074
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1075
+	 * To fix we have to reset the current_screen using the page_slug
1076
+	 * (which is identical - or should be - to our registered_post_type id.)
1077
+	 * Also, since the core WP file loads the admin_header.php for WP
1078
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1079
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1080
+	 *
1081
+	 * @return void
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	public function modify_current_screen()
1085
+	{
1086
+		// ONLY do this if the current page_route IS a cpt route
1087
+		if (! $this->_cpt_route) {
1088
+			return;
1089
+		}
1090
+		// routing things REALLY early b/c this is a cpt admin page
1091
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1092
+		$this->_current_screen = get_current_screen();
1093
+		$this->_current_screen->base = 'event-espresso';
1094
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1095
+		/*try {
1096 1096
             $this->_route_admin_request();
1097 1097
         } catch ( EE_Error $e ) {
1098 1098
             $e->get_error();
1099 1099
         }/**/
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1105
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1106
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1107
-     * default to be.
1108
-     *
1109
-     * @param string $title The new title (or existing if there is no editor_title defined)
1110
-     * @return string
1111
-     */
1112
-    public function add_custom_editor_default_title($title)
1113
-    {
1114
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1115
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1116
-            : $title;
1117
-    }
1118
-
1119
-
1120
-    /**
1121
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1122
-     *
1123
-     * @param string $shortlink   The already generated shortlink
1124
-     * @param int    $id          Post ID for this item
1125
-     * @param string $context     The context for the link
1126
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1127
-     * @return string
1128
-     */
1129
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1130
-    {
1131
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1132
-            $post = get_post($id);
1133
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1134
-                $shortlink = home_url('?p=' . $post->ID);
1135
-            }
1136
-        }
1137
-        return $shortlink;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1143
-     * already run in modify_current_screen())
1144
-     *
1145
-     * @return void
1146
-     * @throws EE_Error
1147
-     * @throws ReflectionException
1148
-     */
1149
-    public function route_admin_request()
1150
-    {
1151
-        if ($this->_cpt_route) {
1152
-            return;
1153
-        }
1154
-        try {
1155
-            $this->_route_admin_request();
1156
-        } catch (EE_Error $e) {
1157
-            $e->get_error();
1158
-        }
1159
-    }
1160
-
1161
-
1162
-    /**
1163
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1164
-     *
1165
-     * @return void
1166
-     */
1167
-    public function cpt_post_form_hidden_input()
1168
-    {
1169
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1170
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1171
-        echo '<div id="ee-cpt-hidden-inputs">';
1172
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1173
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1174
-        echo '</div>';
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1180
-     *
1181
-     * @param string $location Original location url
1182
-     * @param int    $status   Status for http header
1183
-     * @return string           new (or original) url to redirect to.
1184
-     * @throws EE_Error
1185
-     */
1186
-    public function revision_redirect($location, $status)
1187
-    {
1188
-        // get revision
1189
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1190
-        // can't do anything without revision so let's get out if not present
1191
-        if (empty($rev_id)) {
1192
-            return $location;
1193
-        }
1194
-        // get rev_post_data
1195
-        $rev = get_post($rev_id);
1196
-        $admin_url = $this->_admin_base_url;
1197
-        $query_args = array(
1198
-            'action'   => 'edit',
1199
-            'post'     => $rev->post_parent,
1200
-            'revision' => $rev_id,
1201
-            'message'  => 5,
1202
-        );
1203
-        $this->_process_notices($query_args, true);
1204
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1205
-    }
1206
-
1207
-
1208
-    /**
1209
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1210
-     *
1211
-     * @param  string $link    the original generated link
1212
-     * @param  int    $id      post id
1213
-     * @param  string $context optional, defaults to display.  How to write the '&'
1214
-     * @return string          the link
1215
-     */
1216
-    public function modify_edit_post_link($link, $id, $context)
1217
-    {
1218
-        $post = get_post($id);
1219
-        if (
1220
-            ! isset($this->_req_data['action'])
1221
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1222
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1223
-        ) {
1224
-            return $link;
1225
-        }
1226
-        $query_args = array(
1227
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1228
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1229
-                : 'edit',
1230
-            'post'   => $id,
1231
-        );
1232
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1238
-     * our routes.
1239
-     *
1240
-     * @param string $delete_link  original delete link
1241
-     * @param int    $post_id      id of cpt object
1242
-     * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1243
-     * @return string new delete link
1244
-     * @throws EE_Error
1245
-     * @throws ReflectionException
1246
-     */
1247
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1248
-    {
1249
-        $post = get_post($post_id);
1250
-
1251
-        if (
1252
-            empty($this->_req_data['action'])
1253
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1254
-            || ! $post instanceof WP_Post
1255
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1256
-        ) {
1257
-            return $delete_link;
1258
-        }
1259
-        $this->_set_model_object($post->ID, true);
1260
-
1261
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1262
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1263
-
1264
-        return EE_Admin_Page::add_query_args_and_nonce(
1265
-            array(
1266
-                'page'   => $this->_req_data['page'],
1267
-                'action' => $action,
1268
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1269
-                         => $post->ID,
1270
-            ),
1271
-            admin_url()
1272
-        );
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1278
-     * so that we can hijack the default redirect locations for wp custom post types
1279
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1280
-     *
1281
-     * @param string $location This is the incoming currently set redirect location
1282
-     * @param string $post_id  This is the 'ID' value of the wp_posts table
1283
-     * @return string           the new location to redirect to
1284
-     * @throws EE_Error
1285
-     */
1286
-    public function cpt_post_location_redirect($location, $post_id)
1287
-    {
1288
-        // we DO have a match so let's setup the url
1289
-        // we have to get the post to determine our route
1290
-        $post = get_post($post_id);
1291
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1292
-        // shared query_args
1293
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1294
-        $admin_url = $this->_admin_base_url;
1295
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1296
-            $status = get_post_status($post_id);
1297
-            if (isset($this->_req_data['publish'])) {
1298
-                switch ($status) {
1299
-                    case 'pending':
1300
-                        $message = 8;
1301
-                        break;
1302
-                    case 'future':
1303
-                        $message = 9;
1304
-                        break;
1305
-                    default:
1306
-                        $message = 6;
1307
-                }
1308
-            } else {
1309
-                $message = 'draft' === $status ? 10 : 1;
1310
-            }
1311
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1312
-            $message = 2;
1313
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1314
-            $message = 3;
1315
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1316
-            $message = 7;
1317
-        } else {
1318
-            $message = 4;
1319
-        }
1320
-        // change the message if the post type is not viewable on the frontend
1321
-        $this->_cpt_object = get_post_type_object($post->post_type);
1322
-        $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1323
-        $query_args = array_merge(array('message' => $message), $query_args);
1324
-        $this->_process_notices($query_args, true);
1325
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     * This method is called to inject nav tabs on core WP cpt pages
1331
-     *
1332
-     * @access public
1333
-     * @return void
1334
-     * @throws EE_Error
1335
-     */
1336
-    public function inject_nav_tabs()
1337
-    {
1338
-        // can we hijack and insert the nav_tabs?
1339
-        $nav_tabs = $this->_get_main_nav_tabs();
1340
-        // first close off existing form tag
1341
-        $html = '>';
1342
-        $html .= $nav_tabs;
1343
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1344
-        $html .= '<span></span';
1345
-        echo $html;
1346
-    }
1347
-
1348
-
1349
-    /**
1350
-     * This just sets up the post update messages when an update form is loaded
1351
-     *
1352
-     * @access public
1353
-     * @param  array $messages the original messages array
1354
-     * @return array           the new messages array
1355
-     */
1356
-    public function post_update_messages($messages)
1357
-    {
1358
-        global $post;
1359
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1360
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1361
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1105
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1106
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1107
+	 * default to be.
1108
+	 *
1109
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1110
+	 * @return string
1111
+	 */
1112
+	public function add_custom_editor_default_title($title)
1113
+	{
1114
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1115
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1116
+			: $title;
1117
+	}
1118
+
1119
+
1120
+	/**
1121
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1122
+	 *
1123
+	 * @param string $shortlink   The already generated shortlink
1124
+	 * @param int    $id          Post ID for this item
1125
+	 * @param string $context     The context for the link
1126
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1127
+	 * @return string
1128
+	 */
1129
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1130
+	{
1131
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1132
+			$post = get_post($id);
1133
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1134
+				$shortlink = home_url('?p=' . $post->ID);
1135
+			}
1136
+		}
1137
+		return $shortlink;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1143
+	 * already run in modify_current_screen())
1144
+	 *
1145
+	 * @return void
1146
+	 * @throws EE_Error
1147
+	 * @throws ReflectionException
1148
+	 */
1149
+	public function route_admin_request()
1150
+	{
1151
+		if ($this->_cpt_route) {
1152
+			return;
1153
+		}
1154
+		try {
1155
+			$this->_route_admin_request();
1156
+		} catch (EE_Error $e) {
1157
+			$e->get_error();
1158
+		}
1159
+	}
1160
+
1161
+
1162
+	/**
1163
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1164
+	 *
1165
+	 * @return void
1166
+	 */
1167
+	public function cpt_post_form_hidden_input()
1168
+	{
1169
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1170
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1171
+		echo '<div id="ee-cpt-hidden-inputs">';
1172
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1173
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1174
+		echo '</div>';
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1180
+	 *
1181
+	 * @param string $location Original location url
1182
+	 * @param int    $status   Status for http header
1183
+	 * @return string           new (or original) url to redirect to.
1184
+	 * @throws EE_Error
1185
+	 */
1186
+	public function revision_redirect($location, $status)
1187
+	{
1188
+		// get revision
1189
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1190
+		// can't do anything without revision so let's get out if not present
1191
+		if (empty($rev_id)) {
1192
+			return $location;
1193
+		}
1194
+		// get rev_post_data
1195
+		$rev = get_post($rev_id);
1196
+		$admin_url = $this->_admin_base_url;
1197
+		$query_args = array(
1198
+			'action'   => 'edit',
1199
+			'post'     => $rev->post_parent,
1200
+			'revision' => $rev_id,
1201
+			'message'  => 5,
1202
+		);
1203
+		$this->_process_notices($query_args, true);
1204
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1205
+	}
1206
+
1207
+
1208
+	/**
1209
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1210
+	 *
1211
+	 * @param  string $link    the original generated link
1212
+	 * @param  int    $id      post id
1213
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1214
+	 * @return string          the link
1215
+	 */
1216
+	public function modify_edit_post_link($link, $id, $context)
1217
+	{
1218
+		$post = get_post($id);
1219
+		if (
1220
+			! isset($this->_req_data['action'])
1221
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1222
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1223
+		) {
1224
+			return $link;
1225
+		}
1226
+		$query_args = array(
1227
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1228
+				? $this->_cpt_edit_routes[ $post->post_type ]
1229
+				: 'edit',
1230
+			'post'   => $id,
1231
+		);
1232
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1238
+	 * our routes.
1239
+	 *
1240
+	 * @param string $delete_link  original delete link
1241
+	 * @param int    $post_id      id of cpt object
1242
+	 * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1243
+	 * @return string new delete link
1244
+	 * @throws EE_Error
1245
+	 * @throws ReflectionException
1246
+	 */
1247
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1248
+	{
1249
+		$post = get_post($post_id);
1250
+
1251
+		if (
1252
+			empty($this->_req_data['action'])
1253
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1254
+			|| ! $post instanceof WP_Post
1255
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1256
+		) {
1257
+			return $delete_link;
1258
+		}
1259
+		$this->_set_model_object($post->ID, true);
1260
+
1261
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1262
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1263
+
1264
+		return EE_Admin_Page::add_query_args_and_nonce(
1265
+			array(
1266
+				'page'   => $this->_req_data['page'],
1267
+				'action' => $action,
1268
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1269
+						 => $post->ID,
1270
+			),
1271
+			admin_url()
1272
+		);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1278
+	 * so that we can hijack the default redirect locations for wp custom post types
1279
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1280
+	 *
1281
+	 * @param string $location This is the incoming currently set redirect location
1282
+	 * @param string $post_id  This is the 'ID' value of the wp_posts table
1283
+	 * @return string           the new location to redirect to
1284
+	 * @throws EE_Error
1285
+	 */
1286
+	public function cpt_post_location_redirect($location, $post_id)
1287
+	{
1288
+		// we DO have a match so let's setup the url
1289
+		// we have to get the post to determine our route
1290
+		$post = get_post($post_id);
1291
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1292
+		// shared query_args
1293
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1294
+		$admin_url = $this->_admin_base_url;
1295
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1296
+			$status = get_post_status($post_id);
1297
+			if (isset($this->_req_data['publish'])) {
1298
+				switch ($status) {
1299
+					case 'pending':
1300
+						$message = 8;
1301
+						break;
1302
+					case 'future':
1303
+						$message = 9;
1304
+						break;
1305
+					default:
1306
+						$message = 6;
1307
+				}
1308
+			} else {
1309
+				$message = 'draft' === $status ? 10 : 1;
1310
+			}
1311
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1312
+			$message = 2;
1313
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1314
+			$message = 3;
1315
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1316
+			$message = 7;
1317
+		} else {
1318
+			$message = 4;
1319
+		}
1320
+		// change the message if the post type is not viewable on the frontend
1321
+		$this->_cpt_object = get_post_type_object($post->post_type);
1322
+		$message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1323
+		$query_args = array_merge(array('message' => $message), $query_args);
1324
+		$this->_process_notices($query_args, true);
1325
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 * This method is called to inject nav tabs on core WP cpt pages
1331
+	 *
1332
+	 * @access public
1333
+	 * @return void
1334
+	 * @throws EE_Error
1335
+	 */
1336
+	public function inject_nav_tabs()
1337
+	{
1338
+		// can we hijack and insert the nav_tabs?
1339
+		$nav_tabs = $this->_get_main_nav_tabs();
1340
+		// first close off existing form tag
1341
+		$html = '>';
1342
+		$html .= $nav_tabs;
1343
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1344
+		$html .= '<span></span';
1345
+		echo $html;
1346
+	}
1347
+
1348
+
1349
+	/**
1350
+	 * This just sets up the post update messages when an update form is loaded
1351
+	 *
1352
+	 * @access public
1353
+	 * @param  array $messages the original messages array
1354
+	 * @return array           the new messages array
1355
+	 */
1356
+	public function post_update_messages($messages)
1357
+	{
1358
+		global $post;
1359
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1360
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1361
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1362 1362
 
1363 1363
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1364
-        $messages[ $post->post_type ] = array(
1365
-            0  => '', // Unused. Messages start at index 1.
1366
-            1  => sprintf(
1367
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1368
-                $this->_cpt_object->labels->singular_name,
1369
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1370
-                '</a>'
1371
-            ),
1372
-            2  => __('Custom field updated', 'event_espresso'),
1373
-            3  => __('Custom field deleted.', 'event_espresso'),
1374
-            4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1375
-            5  => isset($_GET['revision']) ? sprintf(
1376
-                __('%s restored to revision from %s', 'event_espresso'),
1377
-                $this->_cpt_object->labels->singular_name,
1378
-                wp_post_revision_title((int) $_GET['revision'], false)
1379
-            )
1380
-                : false,
1381
-            6  => sprintf(
1382
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1383
-                $this->_cpt_object->labels->singular_name,
1384
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1385
-                '</a>'
1386
-            ),
1387
-            7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1388
-            8  => sprintf(
1389
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1390
-                $this->_cpt_object->labels->singular_name,
1391
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1392
-                '</a>'
1393
-            ),
1394
-            9  => sprintf(
1395
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1396
-                $this->_cpt_object->labels->singular_name,
1397
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1398
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1399
-                '</a>'
1400
-            ),
1401
-            10 => sprintf(
1402
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1403
-                $this->_cpt_object->labels->singular_name,
1404
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1405
-                '</a>'
1406
-            ),
1407
-        );
1408
-        return $messages;
1409
-    }
1410
-
1411
-
1412
-    /**
1413
-     * default method for the 'create_new' route for cpt admin pages.
1414
-     * For reference what to include in here, see wp-admin/post-new.php
1415
-     *
1416
-     * @access  protected
1417
-     * @return void
1418
-     */
1419
-    protected function _create_new_cpt_item()
1420
-    {
1421
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1422
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1423
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1424
-        $post_type_object = $this->_cpt_object;
1425
-        $title = $post_type_object->labels->add_new_item;
1426
-        $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1427
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1428
-        // modify the default editor title field with default title.
1429
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1430
-        $this->loadEditorTemplate(true);
1431
-    }
1432
-
1433
-
1434
-    /**
1435
-     * Enqueues auto-save and loads the editor template
1436
-     *
1437
-     * @param bool $creating
1438
-     */
1439
-    private function loadEditorTemplate($creating = true)
1440
-    {
1441
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1442
-        // these vars are used by the template
1443
-        $editing = true;
1444
-        $post_ID = $post->ID;
1445
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1446
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1447
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1448
-            if ($creating) {
1449
-                wp_enqueue_script('autosave');
1450
-            } elseif (
1451
-                isset($this->_cpt_routes[ $this->_req_data['action'] ])
1452
-                && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1453
-            ) {
1454
-                $create_new_action = apply_filters(
1455
-                    'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1456
-                    'create_new',
1457
-                    $this
1458
-                );
1459
-                $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1460
-                    array(
1461
-                        'action' => $create_new_action,
1462
-                        'page'   => $this->page_slug,
1463
-                    ),
1464
-                    'admin.php'
1465
-                );
1466
-            }
1467
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1468
-        }
1469
-    }
1470
-
1471
-
1472
-    public function add_new_admin_page_global()
1473
-    {
1474
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1475
-        ?>
1364
+		$messages[ $post->post_type ] = array(
1365
+			0  => '', // Unused. Messages start at index 1.
1366
+			1  => sprintf(
1367
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1368
+				$this->_cpt_object->labels->singular_name,
1369
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1370
+				'</a>'
1371
+			),
1372
+			2  => __('Custom field updated', 'event_espresso'),
1373
+			3  => __('Custom field deleted.', 'event_espresso'),
1374
+			4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1375
+			5  => isset($_GET['revision']) ? sprintf(
1376
+				__('%s restored to revision from %s', 'event_espresso'),
1377
+				$this->_cpt_object->labels->singular_name,
1378
+				wp_post_revision_title((int) $_GET['revision'], false)
1379
+			)
1380
+				: false,
1381
+			6  => sprintf(
1382
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1383
+				$this->_cpt_object->labels->singular_name,
1384
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1385
+				'</a>'
1386
+			),
1387
+			7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1388
+			8  => sprintf(
1389
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1390
+				$this->_cpt_object->labels->singular_name,
1391
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1392
+				'</a>'
1393
+			),
1394
+			9  => sprintf(
1395
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1396
+				$this->_cpt_object->labels->singular_name,
1397
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1398
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1399
+				'</a>'
1400
+			),
1401
+			10 => sprintf(
1402
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1403
+				$this->_cpt_object->labels->singular_name,
1404
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1405
+				'</a>'
1406
+			),
1407
+		);
1408
+		return $messages;
1409
+	}
1410
+
1411
+
1412
+	/**
1413
+	 * default method for the 'create_new' route for cpt admin pages.
1414
+	 * For reference what to include in here, see wp-admin/post-new.php
1415
+	 *
1416
+	 * @access  protected
1417
+	 * @return void
1418
+	 */
1419
+	protected function _create_new_cpt_item()
1420
+	{
1421
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1422
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1423
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1424
+		$post_type_object = $this->_cpt_object;
1425
+		$title = $post_type_object->labels->add_new_item;
1426
+		$post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1427
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1428
+		// modify the default editor title field with default title.
1429
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1430
+		$this->loadEditorTemplate(true);
1431
+	}
1432
+
1433
+
1434
+	/**
1435
+	 * Enqueues auto-save and loads the editor template
1436
+	 *
1437
+	 * @param bool $creating
1438
+	 */
1439
+	private function loadEditorTemplate($creating = true)
1440
+	{
1441
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1442
+		// these vars are used by the template
1443
+		$editing = true;
1444
+		$post_ID = $post->ID;
1445
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1446
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1447
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1448
+			if ($creating) {
1449
+				wp_enqueue_script('autosave');
1450
+			} elseif (
1451
+				isset($this->_cpt_routes[ $this->_req_data['action'] ])
1452
+				&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1453
+			) {
1454
+				$create_new_action = apply_filters(
1455
+					'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1456
+					'create_new',
1457
+					$this
1458
+				);
1459
+				$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1460
+					array(
1461
+						'action' => $create_new_action,
1462
+						'page'   => $this->page_slug,
1463
+					),
1464
+					'admin.php'
1465
+				);
1466
+			}
1467
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1468
+		}
1469
+	}
1470
+
1471
+
1472
+	public function add_new_admin_page_global()
1473
+	{
1474
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1475
+		?>
1476 1476
         <script type="text/javascript">
1477 1477
             adminpage = '<?php echo $admin_page; ?>';
1478 1478
         </script>
1479 1479
         <?php
1480
-    }
1481
-
1482
-
1483
-    /**
1484
-     * default method for the 'edit' route for cpt admin pages
1485
-     * For reference on what to put in here, refer to wp-admin/post.php
1486
-     *
1487
-     * @access protected
1488
-     * @return string   template for edit cpt form
1489
-     */
1490
-    protected function _edit_cpt_item()
1491
-    {
1492
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1493
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1494
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1495
-        if (empty($post)) {
1496
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1497
-        }
1498
-        if (! empty($_GET['get-post-lock'])) {
1499
-            wp_set_post_lock($post_id);
1500
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1501
-            exit();
1502
-        }
1503
-
1504
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1505
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1506
-        $post_type_object = $this->_cpt_object;
1507
-
1508
-        if (! wp_check_post_lock($post->ID)) {
1509
-            wp_set_post_lock($post->ID);
1510
-        }
1511
-        add_action('admin_footer', '_admin_notice_post_locked');
1512
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1513
-            wp_enqueue_script('admin-comments');
1514
-            enqueue_comment_hotkeys_js();
1515
-        }
1516
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1517
-        // modify the default editor title field with default title.
1518
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1519
-        $this->loadEditorTemplate(false);
1520
-    }
1521
-
1522
-
1523
-
1524
-    /**
1525
-     * some getters
1526
-     */
1527
-    /**
1528
-     * This returns the protected _cpt_model_obj property
1529
-     *
1530
-     * @return EE_CPT_Base
1531
-     */
1532
-    public function get_cpt_model_obj()
1533
-    {
1534
-        return $this->_cpt_model_obj;
1535
-    }
1480
+	}
1481
+
1482
+
1483
+	/**
1484
+	 * default method for the 'edit' route for cpt admin pages
1485
+	 * For reference on what to put in here, refer to wp-admin/post.php
1486
+	 *
1487
+	 * @access protected
1488
+	 * @return string   template for edit cpt form
1489
+	 */
1490
+	protected function _edit_cpt_item()
1491
+	{
1492
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1493
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1494
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1495
+		if (empty($post)) {
1496
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1497
+		}
1498
+		if (! empty($_GET['get-post-lock'])) {
1499
+			wp_set_post_lock($post_id);
1500
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1501
+			exit();
1502
+		}
1503
+
1504
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1505
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1506
+		$post_type_object = $this->_cpt_object;
1507
+
1508
+		if (! wp_check_post_lock($post->ID)) {
1509
+			wp_set_post_lock($post->ID);
1510
+		}
1511
+		add_action('admin_footer', '_admin_notice_post_locked');
1512
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1513
+			wp_enqueue_script('admin-comments');
1514
+			enqueue_comment_hotkeys_js();
1515
+		}
1516
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1517
+		// modify the default editor title field with default title.
1518
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1519
+		$this->loadEditorTemplate(false);
1520
+	}
1521
+
1522
+
1523
+
1524
+	/**
1525
+	 * some getters
1526
+	 */
1527
+	/**
1528
+	 * This returns the protected _cpt_model_obj property
1529
+	 *
1530
+	 * @return EE_CPT_Base
1531
+	 */
1532
+	public function get_cpt_model_obj()
1533
+	{
1534
+		return $this->_cpt_model_obj;
1535
+	}
1536 1536
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      */
162 162
     protected function getLoader()
163 163
     {
164
-        if (! $this->loader instanceof LoaderInterface) {
164
+        if ( ! $this->loader instanceof LoaderInterface) {
165 165
             $this->loader = LoaderFactory::getLoader();
166 166
         }
167 167
         return $this->loader;
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
             $this->_cpt_routes
187 187
         );
188 188
         // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
189
-        $this->_cpt_object = isset($this->_req_data['action'], $this->_cpt_routes[ $this->_req_data['action'] ])
190
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
189
+        $this->_cpt_object = isset($this->_req_data['action'], $this->_cpt_routes[$this->_req_data['action']])
190
+            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
191 191
             : get_post_type_object($page);
192 192
         // tweak pagenow for page loading.
193
-        if (! $this->_pagenow_map) {
193
+        if ( ! $this->_pagenow_map) {
194 194
             $this->_pagenow_map = array(
195 195
                 'create_new' => 'post-new.php',
196 196
                 'edit'       => 'post.php',
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
             ! empty($this->_req_data['page'])
229 229
             && $this->_req_data['page'] === $this->page_slug
230 230
             && ! empty($this->_req_data['action'])
231
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
231
+            && isset($this->_pagenow_map[$this->_req_data['action']])
232 232
         ) {
233
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
233
+            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
234 234
             $hook_suffix = $pagenow;
235 235
         }
236 236
     }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
         if (empty($wp_meta_boxes)) {
263 263
             return;
264 264
         }
265
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
265
+        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
266 266
         foreach ($current_metaboxes as $box_context) {
267 267
             foreach ($box_context as $box_details) {
268 268
                 foreach ($box_details as $box) {
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
             $this
297 297
         );
298 298
         $containers = apply_filters(
299
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
299
+            'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
300 300
             $containers,
301 301
             $this
302 302
         );
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
     protected function _load_page_dependencies()
333 333
     {
334 334
         // we only add stuff if this is a cpt_route!
335
-        if (! $this->_cpt_route) {
335
+        if ( ! $this->_cpt_route) {
336 336
             parent::_load_page_dependencies();
337 337
             return;
338 338
         }
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
         add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
357 357
         // This basically allows us to change the title of the "publish" metabox area
358 358
         // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
359
-        if (! empty($this->_labels['publishbox'])) {
359
+        if ( ! empty($this->_labels['publishbox'])) {
360 360
             $box_label = is_array($this->_labels['publishbox'])
361
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
362
-                ? $this->_labels['publishbox'][ $this->_req_action ]
361
+                         && isset($this->_labels['publishbox'][$this->_req_action])
362
+                ? $this->_labels['publishbox'][$this->_req_action]
363 363
                 : $this->_labels['publishbox'];
364 364
             add_meta_box(
365 365
                 'submitdiv',
366 366
                 $box_label,
367 367
                 'post_submit_meta_box',
368
-                $this->_cpt_routes[ $this->_req_action ],
368
+                $this->_cpt_routes[$this->_req_action],
369 369
                 'side',
370 370
                 'core'
371 371
             );
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
                 'page_templates',
377 377
                 __('Page Template', 'event_espresso'),
378 378
                 array($this, 'page_template_meta_box'),
379
-                $this->_cpt_routes[ $this->_req_action ],
379
+                $this->_cpt_routes[$this->_req_action],
380 380
                 'side',
381 381
                 'default'
382 382
             );
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
         // This is for any plugins that are doing things properly
409 409
         // and hooking into the load page hook for core wp cpt routes.
410 410
         global $pagenow;
411
-        add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
412
-        do_action('load-' . $pagenow);
411
+        add_action('load-'.$pagenow, array($this, 'modify_current_screen'), 20);
412
+        do_action('load-'.$pagenow);
413 413
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
414 414
         // we route REALLY early.
415 415
         try {
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
                 'admin.php?page=espresso_registrations&action=contact_list',
439 439
             ),
440 440
             1 => array(
441
-                'edit.php?post_type=' . $this->_cpt_object->name,
442
-                'admin.php?page=' . $this->_cpt_object->name,
441
+                'edit.php?post_type='.$this->_cpt_object->name,
442
+                'admin.php?page='.$this->_cpt_object->name,
443 443
             ),
444 444
         );
445 445
         foreach ($routes_to_match as $route_matches) {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
469 469
         );
470 470
         $cpt_args = $custom_post_types->getDefinitions();
471
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
471
+        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
472 472
         $cpt_has_support = ! empty($cpt_args['page_templates']);
473 473
 
474 474
         // if the installed version of WP is > 4.7 we do some additional checks.
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
             // if there are $post_templates for this cpt, then we return false for this method because
478 478
             // that means we aren't going to load our page template manager and leave that up to the native
479 479
             // cpt template manager.
480
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
480
+            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
481 481
         }
482 482
 
483 483
         return $cpt_has_support;
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 
552 552
         $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
553 553
         $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
554
-            ? $statuses[ $this->_cpt_model_obj->status() ]
554
+            ? $statuses[$this->_cpt_model_obj->status()]
555 555
             : '';
556 556
         $template_args = array(
557 557
             'cur_status'            => $this->_cpt_model_obj->status(),
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
             $template_args['statuses'] = $statuses;
567 567
         }
568 568
 
569
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
569
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
570 570
         EEH_Template::display_template($template, $template_args);
571 571
     }
572 572
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
             : null;
609 609
         $this->_verify_nonce($nonce, 'autosave');
610 610
         // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
611
-        if (! defined('DOING_AUTOSAVE')) {
611
+        if ( ! defined('DOING_AUTOSAVE')) {
612 612
             define('DOING_AUTOSAVE', true);
613 613
         }
614 614
         // if we made it here then the nonce checked out.  Let's run our methods and actions
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
             $this->_template_args['success'] = true;
620 620
         }
621 621
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
622
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
622
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
623 623
         // now let's return json
624 624
         $this->_return_json();
625 625
     }
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
             return;
643 643
         }
644 644
         // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
645
-        if (! empty($this->_cpt_object)) {
645
+        if ( ! empty($this->_cpt_object)) {
646 646
             $this->_page_routes = array_merge(
647 647
                 array(
648 648
                     'create_new' => '_create_new_cpt_item',
@@ -673,10 +673,10 @@  discard block
 block discarded – undo
673 673
             );
674 674
         }
675 675
         // load the next section only if this is a matching cpt route as set in the cpt routes array.
676
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
676
+        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
677 677
             return;
678 678
         }
679
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
679
+        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
680 680
         // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
681 681
         if (empty($this->_cpt_object)) {
682 682
             $msg = sprintf(
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             empty($this->_cpt_model_names)
718 718
             || (
719 719
                 ! $ignore_route_check
720
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
720
+                && ! isset($this->_cpt_routes[$this->_req_action])
721 721
             ) || (
722 722
                 $this->_cpt_model_obj instanceof EE_CPT_Base
723 723
                 && $this->_cpt_model_obj->ID() === $id
@@ -734,11 +734,11 @@  discard block
 block discarded – undo
734 734
                 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
735 735
             );
736 736
             $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
737
-            if (isset($model_names[ $post_type ])) {
738
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
737
+            if (isset($model_names[$post_type])) {
738
+                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
739 739
             }
740 740
         } else {
741
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
741
+            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
742 742
         }
743 743
         if ($model instanceof EEM_Base) {
744 744
             $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
@@ -768,8 +768,8 @@  discard block
 block discarded – undo
768 768
         $current_route = isset($this->_req_data['current_route'])
769 769
             ? $this->_req_data['current_route']
770 770
             : 'shouldneverwork';
771
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
772
-            ? $this->_cpt_routes[ $current_route ]
771
+        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
772
+            ? $this->_cpt_routes[$current_route]
773 773
             : '';
774 774
         add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
775 775
         add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
@@ -778,10 +778,10 @@  discard block
 block discarded – undo
778 778
         }
779 779
         // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
780 780
         $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
781
-        if (! empty($revision)) {
781
+        if ( ! empty($revision)) {
782 782
             $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
783 783
             // doing a restore?
784
-            if (! empty($action) && $action === 'restore') {
784
+            if ( ! empty($action) && $action === 'restore') {
785 785
                 // get post for revision
786 786
                 $rev_post = get_post($revision);
787 787
                 $rev_parent = get_post($rev_post->post_parent);
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
     {
819 819
         $this->_set_model_object($post_id, true, 'trash');
820 820
         // if our cpt object isn't existent then get out immediately.
821
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
821
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
822 822
             return;
823 823
         }
824 824
         $this->trash_cpt_item($post_id);
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     {
838 838
         $this->_set_model_object($post_id, true, 'restore');
839 839
         // if our cpt object isn't existent then get out immediately.
840
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
840
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
841 841
             return;
842 842
         }
843 843
         $this->restore_cpt_item($post_id);
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
     {
857 857
         $this->_set_model_object($post_id, true, 'delete');
858 858
         // if our cpt object isn't existent then get out immediately.
859
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
859
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
860 860
             return;
861 861
         }
862 862
         $this->delete_cpt_item($post_id);
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
     {
879 879
         $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
880 880
         // verify event object
881
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
881
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
882 882
             throw new EE_Error(
883 883
                 sprintf(
884 884
                     __(
@@ -935,13 +935,13 @@  discard block
 block discarded – undo
935 935
         if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936 936
             // setup custom post status object for localize script but only if we've got a cpt object
937 937
             $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
-            if (! empty($statuses)) {
938
+            if ( ! empty($statuses)) {
939 939
                 // get ALL statuses!
940 940
                 $statuses = $this->_cpt_model_obj->get_all_post_statuses();
941 941
                 // setup object
942 942
                 $ee_cpt_statuses = array();
943 943
                 foreach ($statuses as $status => $label) {
944
-                    $ee_cpt_statuses[ $status ] = array(
944
+                    $ee_cpt_statuses[$status] = array(
945 945
                         'label'      => $label,
946 946
                         'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
947 947
                     );
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
                 $post->page_template = $this->_req_data['page_template'];
1007 1007
                 $page_templates = wp_get_theme()->get_page_templates($post);
1008 1008
             }
1009
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1009
+            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
1010 1010
                 EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011 1011
             } else {
1012 1012
                 update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
     {
1032 1032
         // only do this if we're actually processing one of our CPTs
1033 1033
         // if our cpt object isn't existent then get out immediately.
1034
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1034
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035 1035
             return;
1036 1036
         }
1037 1037
         delete_post_meta($post_id, '_wp_trash_meta_status');
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
         // global action
1057 1057
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058 1058
         // class specific action so you can limit hooking into a specific page.
1059
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1059
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1060 1060
     }
1061 1061
 
1062 1062
 
@@ -1084,11 +1084,11 @@  discard block
 block discarded – undo
1084 1084
     public function modify_current_screen()
1085 1085
     {
1086 1086
         // ONLY do this if the current page_route IS a cpt route
1087
-        if (! $this->_cpt_route) {
1087
+        if ( ! $this->_cpt_route) {
1088 1088
             return;
1089 1089
         }
1090 1090
         // routing things REALLY early b/c this is a cpt admin page
1091
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1091
+        set_current_screen($this->_cpt_routes[$this->_req_action]);
1092 1092
         $this->_current_screen = get_current_screen();
1093 1093
         $this->_current_screen->base = 'event-espresso';
1094 1094
         $this->_add_help_tabs(); // we make sure we add any help tabs back in!
@@ -1111,8 +1111,8 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function add_custom_editor_default_title($title)
1113 1113
     {
1114
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1115
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1114
+        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1115
+            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1116 1116
             : $title;
1117 1117
     }
1118 1118
 
@@ -1128,10 +1128,10 @@  discard block
 block discarded – undo
1128 1128
      */
1129 1129
     public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1130 1130
     {
1131
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1131
+        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1132 1132
             $post = get_post($id);
1133 1133
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1134
-                $shortlink = home_url('?p=' . $post->ID);
1134
+                $shortlink = home_url('?p='.$post->ID);
1135 1135
             }
1136 1136
         }
1137 1137
         return $shortlink;
@@ -1166,11 +1166,11 @@  discard block
 block discarded – undo
1166 1166
      */
1167 1167
     public function cpt_post_form_hidden_input()
1168 1168
     {
1169
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1169
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1170 1170
         // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1171 1171
         echo '<div id="ee-cpt-hidden-inputs">';
1172
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1173
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1172
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1173
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1174 1174
         echo '</div>';
1175 1175
     }
1176 1176
 
@@ -1218,14 +1218,14 @@  discard block
 block discarded – undo
1218 1218
         $post = get_post($id);
1219 1219
         if (
1220 1220
             ! isset($this->_req_data['action'])
1221
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1222
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1221
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1222
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1223 1223
         ) {
1224 1224
             return $link;
1225 1225
         }
1226 1226
         $query_args = array(
1227
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1228
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1227
+            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1228
+                ? $this->_cpt_edit_routes[$post->post_type]
1229 1229
                 : 'edit',
1230 1230
             'post'   => $id,
1231 1231
         );
@@ -1250,16 +1250,16 @@  discard block
 block discarded – undo
1250 1250
 
1251 1251
         if (
1252 1252
             empty($this->_req_data['action'])
1253
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1253
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1254 1254
             || ! $post instanceof WP_Post
1255
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1255
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1256 1256
         ) {
1257 1257
             return $delete_link;
1258 1258
         }
1259 1259
         $this->_set_model_object($post->ID, true);
1260 1260
 
1261 1261
         // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1262
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1262
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1263 1263
 
1264 1264
         return EE_Admin_Page::add_query_args_and_nonce(
1265 1265
             array(
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
         // we DO have a match so let's setup the url
1289 1289
         // we have to get the post to determine our route
1290 1290
         $post = get_post($post_id);
1291
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1291
+        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1292 1292
         // shared query_args
1293 1293
         $query_args = array('action' => $edit_route, 'post' => $post_id);
1294 1294
         $admin_url = $this->_admin_base_url;
@@ -1361,12 +1361,12 @@  discard block
 block discarded – undo
1361 1361
         /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1362 1362
 
1363 1363
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1364
-        $messages[ $post->post_type ] = array(
1364
+        $messages[$post->post_type] = array(
1365 1365
             0  => '', // Unused. Messages start at index 1.
1366 1366
             1  => sprintf(
1367 1367
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1368 1368
                 $this->_cpt_object->labels->singular_name,
1369
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1369
+                '<a href="'.esc_url(get_permalink($id)).'">',
1370 1370
                 '</a>'
1371 1371
             ),
1372 1372
             2  => __('Custom field updated', 'event_espresso'),
@@ -1381,27 +1381,27 @@  discard block
 block discarded – undo
1381 1381
             6  => sprintf(
1382 1382
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1383 1383
                 $this->_cpt_object->labels->singular_name,
1384
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1384
+                '<a href="'.esc_url(get_permalink($id)).'">',
1385 1385
                 '</a>'
1386 1386
             ),
1387 1387
             7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1388 1388
             8  => sprintf(
1389 1389
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1390 1390
                 $this->_cpt_object->labels->singular_name,
1391
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1391
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1392 1392
                 '</a>'
1393 1393
             ),
1394 1394
             9  => sprintf(
1395 1395
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1396 1396
                 $this->_cpt_object->labels->singular_name,
1397
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1398
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1397
+                '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>',
1398
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1399 1399
                 '</a>'
1400 1400
             ),
1401 1401
             10 => sprintf(
1402 1402
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1403 1403
                 $this->_cpt_object->labels->singular_name,
1404
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1404
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1405 1405
                 '</a>'
1406 1406
             ),
1407 1407
         );
@@ -1420,10 +1420,10 @@  discard block
 block discarded – undo
1420 1420
     {
1421 1421
         // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1422 1422
         global $post, $title, $is_IE, $post_type, $post_type_object;
1423
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1423
+        $post_type = $this->_cpt_routes[$this->_req_action];
1424 1424
         $post_type_object = $this->_cpt_object;
1425 1425
         $title = $post_type_object->labels->add_new_item;
1426
-        $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1426
+        $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1427 1427
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1428 1428
         // modify the default editor title field with default title.
1429 1429
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
@@ -1448,8 +1448,8 @@  discard block
 block discarded – undo
1448 1448
             if ($creating) {
1449 1449
                 wp_enqueue_script('autosave');
1450 1450
             } elseif (
1451
-                isset($this->_cpt_routes[ $this->_req_data['action'] ])
1452
-                && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1451
+                isset($this->_cpt_routes[$this->_req_data['action']])
1452
+                && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1453 1453
             ) {
1454 1454
                 $create_new_action = apply_filters(
1455 1455
                     'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
                     'admin.php'
1465 1465
                 );
1466 1466
             }
1467
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1467
+            include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1468 1468
         }
1469 1469
     }
1470 1470
 
@@ -1495,21 +1495,21 @@  discard block
 block discarded – undo
1495 1495
         if (empty($post)) {
1496 1496
             wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1497 1497
         }
1498
-        if (! empty($_GET['get-post-lock'])) {
1498
+        if ( ! empty($_GET['get-post-lock'])) {
1499 1499
             wp_set_post_lock($post_id);
1500 1500
             wp_redirect(get_edit_post_link($post_id, 'url'));
1501 1501
             exit();
1502 1502
         }
1503 1503
 
1504 1504
         // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1505
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1505
+        $post_type = $this->_cpt_routes[$this->_req_action];
1506 1506
         $post_type_object = $this->_cpt_object;
1507 1507
 
1508
-        if (! wp_check_post_lock($post->ID)) {
1508
+        if ( ! wp_check_post_lock($post->ID)) {
1509 1509
             wp_set_post_lock($post->ID);
1510 1510
         }
1511 1511
         add_action('admin_footer', '_admin_notice_post_locked');
1512
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1512
+        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1513 1513
             wp_enqueue_script('admin-comments');
1514 1514
             enqueue_comment_hotkeys_js();
1515 1515
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +4083 added lines, -4083 removed lines patch added patch discarded remove patch
@@ -18,4152 +18,4152 @@
 block discarded – undo
18 18
  */
19 19
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
20 20
 {
21
-    /**
22
-     * @var EE_Admin_Config
23
-     */
24
-    protected $admin_config;
21
+	/**
22
+	 * @var EE_Admin_Config
23
+	 */
24
+	protected $admin_config;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    protected $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	protected $loader;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // nav tabs
52
-    protected $_nav_tabs;
51
+	// nav tabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    /**
57
-     * @var array $_help_tour
58
-     */
59
-    protected $_help_tour = array();
56
+	/**
57
+	 * @var array $_help_tour
58
+	 */
59
+	protected $_help_tour = array();
60 60
 
61 61
 
62
-    // template variables (used by templates)
63
-    protected $_template_path;
62
+	// template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    // boolean
80
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
79
+	// boolean
80
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    // list table args
85
-    protected $_view;
84
+	// list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    // action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	// action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    /**
94
-     * @var array $_page_config
95
-     */
96
-    protected $_page_config;
93
+	/**
94
+	 * @var array $_page_config
95
+	 */
96
+	protected $_page_config;
97 97
 
98
-    /**
99
-     * the current page route and route config
100
-     *
101
-     * @var string $_route
102
-     */
103
-    protected $_route;
98
+	/**
99
+	 * the current page route and route config
100
+	 *
101
+	 * @var string $_route
102
+	 */
103
+	protected $_route;
104 104
 
105
-    /**
106
-     * @var string $_cpt_route
107
-     */
108
-    protected $_cpt_route;
105
+	/**
106
+	 * @var string $_cpt_route
107
+	 */
108
+	protected $_cpt_route;
109 109
 
110
-    /**
111
-     * @var array $_route_config
112
-     */
113
-    protected $_route_config;
110
+	/**
111
+	 * @var array $_route_config
112
+	 */
113
+	protected $_route_config;
114 114
 
115
-    /**
116
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
-     * actions.
118
-     *
119
-     * @since 4.6.x
120
-     * @var array.
121
-     */
122
-    protected $_default_route_query_args;
123
-
124
-    // set via request page and action args.
125
-    protected $_current_page;
126
-
127
-    protected $_current_view;
128
-
129
-    protected $_current_page_view_url;
130
-
131
-    // sanitized request action (and nonce)
132
-
133
-    /**
134
-     * @var string $_req_action
135
-     */
136
-    protected $_req_action;
137
-
138
-    /**
139
-     * @var string $_req_nonce
140
-     */
141
-    protected $_req_nonce;
142
-
143
-    // search related
144
-    protected $_search_btn_label;
145
-
146
-    protected $_search_box_callback;
147
-
148
-    /**
149
-     * WP Current Screen object
150
-     *
151
-     * @var WP_Screen
152
-     */
153
-    protected $_current_screen;
154
-
155
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
-    protected $_hook_obj;
157
-
158
-    // for holding incoming request data
159
-    protected $_req_data;
160
-
161
-    // yes / no array for admin form fields
162
-    protected $_yes_no_values = array();
163
-
164
-    // some default things shared by all child classes
165
-    protected $_default_espresso_metaboxes;
166
-
167
-    /**
168
-     *    EE_Registry Object
169
-     *
170
-     * @var    EE_Registry
171
-     */
172
-    protected $EE;
173
-
174
-
175
-    /**
176
-     * This is just a property that flags whether the given route is a caffeinated route or not.
177
-     *
178
-     * @var boolean
179
-     */
180
-    protected $_is_caf = false;
181
-
182
-
183
-    /**
184
-     * @Constructor
185
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
186
-     * @throws InvalidArgumentException
187
-     * @throws InvalidDataTypeException
188
-     * @throws InvalidInterfaceException
189
-     * @throws ReflectionException
190
-     */
191
-    public function __construct($routing = true)
192
-    {
193
-        $this->loader = LoaderFactory::getLoader();
194
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
195
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
196
-            $this->_is_caf = true;
197
-        }
198
-        $this->_yes_no_values = array(
199
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
200
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
201
-        );
202
-        // set the _req_data property.
203
-        $this->_req_data = array_merge($_GET, $_POST);
204
-        // routing enabled?
205
-        $this->_routing = $routing;
206
-    }
207
-
208
-
209
-    /**
210
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
211
-     * for child classes that needed to set properties prior to these methods getting called,
212
-     * but also needed the parent class to have its construction completed as well.
213
-     * Bottom line is that constructors should ONLY be used for setting initial properties
214
-     * and any complex initialization logic should only run after instantiation is complete.
215
-     *
216
-     * This method gets called immediately after construction from within
217
-     *      EE_Admin_Page_Init::_initialize_admin_page()
218
-     *
219
-     * @throws EE_Error
220
-     * @throws InvalidArgumentException
221
-     * @throws InvalidDataTypeException
222
-     * @throws InvalidInterfaceException
223
-     * @throws ReflectionException
224
-     * @since $VID:$
225
-     */
226
-    public function initializePage()
227
-    {
228
-        // set initial page props (child method)
229
-        $this->_init_page_props();
230
-        // set global defaults
231
-        $this->_set_defaults();
232
-        // set early because incoming requests could be ajax related and we need to register those hooks.
233
-        $this->_global_ajax_hooks();
234
-        $this->_ajax_hooks();
235
-        // other_page_hooks have to be early too.
236
-        $this->_do_other_page_hooks();
237
-        // This just allows us to have extending classes do something specific
238
-        // before the parent constructor runs _page_setup().
239
-        if (method_exists($this, '_before_page_setup')) {
240
-            $this->_before_page_setup();
241
-        }
242
-        // set up page dependencies
243
-        $this->_page_setup();
244
-    }
245
-
246
-
247
-    /**
248
-     * _init_page_props
249
-     * Child classes use to set at least the following properties:
250
-     * $page_slug.
251
-     * $page_label.
252
-     *
253
-     * @abstract
254
-     * @return void
255
-     */
256
-    abstract protected function _init_page_props();
257
-
258
-
259
-    /**
260
-     * _ajax_hooks
261
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
262
-     * Note: within the ajax callback methods.
263
-     *
264
-     * @abstract
265
-     * @return void
266
-     */
267
-    abstract protected function _ajax_hooks();
268
-
269
-
270
-    /**
271
-     * _define_page_props
272
-     * child classes define page properties in here.  Must include at least:
273
-     * $_admin_base_url = base_url for all admin pages
274
-     * $_admin_page_title = default admin_page_title for admin pages
275
-     * $_labels = array of default labels for various automatically generated elements:
276
-     *    array(
277
-     *        'buttons' => array(
278
-     *            'add' => esc_html__('label for add new button'),
279
-     *            'edit' => esc_html__('label for edit button'),
280
-     *            'delete' => esc_html__('label for delete button')
281
-     *            )
282
-     *        )
283
-     *
284
-     * @abstract
285
-     * @return void
286
-     */
287
-    abstract protected function _define_page_props();
288
-
289
-
290
-    /**
291
-     * _set_page_routes
292
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
293
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
294
-     * have a 'default' route. Here's the format
295
-     * $this->_page_routes = array(
296
-     *        'default' => array(
297
-     *            'func' => '_default_method_handling_route',
298
-     *            'args' => array('array','of','args'),
299
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
300
-     *            ajax request, backend processing)
301
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
302
-     *            headers route after.  The string you enter here should match the defined route reference for a
303
-     *            headers sent route.
304
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
305
-     *            this route.
306
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
307
-     *            checks).
308
-     *        ),
309
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
310
-     *        handling method.
311
-     *        )
312
-     * )
313
-     *
314
-     * @abstract
315
-     * @return void
316
-     */
317
-    abstract protected function _set_page_routes();
318
-
319
-
320
-    /**
321
-     * _set_page_config
322
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
323
-     * array corresponds to the page_route for the loaded page. Format:
324
-     * $this->_page_config = array(
325
-     *        'default' => array(
326
-     *            'labels' => array(
327
-     *                'buttons' => array(
328
-     *                    'add' => esc_html__('label for adding item'),
329
-     *                    'edit' => esc_html__('label for editing item'),
330
-     *                    'delete' => esc_html__('label for deleting item')
331
-     *                ),
332
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
333
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
334
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
335
-     *            _define_page_props() method
336
-     *            'nav' => array(
337
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
338
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
339
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
340
-     *                'order' => 10, //required to indicate tab position.
341
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
342
-     *                displayed then add this parameter.
343
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
344
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
345
-     *            metaboxes set for eventespresso admin pages.
346
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
347
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
348
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
349
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
350
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
351
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
352
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
353
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
354
-     *            want to display.
355
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
356
-     *                'tab_id' => array(
357
-     *                    'title' => 'tab_title',
358
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
359
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
360
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
361
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
362
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
363
-     *                    attempt to use the callback which should match the name of a method in the class
364
-     *                    ),
365
-     *                'tab2_id' => array(
366
-     *                    'title' => 'tab2 title',
367
-     *                    'filename' => 'file_name_2'
368
-     *                    'callback' => 'callback_method_for_content',
369
-     *                 ),
370
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
371
-     *            help tab area on an admin page. @link
372
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
373
-     *            'help_tour' => array(
374
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
375
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
376
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
377
-     *            ),
378
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
379
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
380
-     *            just set
381
-     *            'require_nonce' to FALSE
382
-     *            )
383
-     * )
384
-     *
385
-     * @abstract
386
-     * @return void
387
-     */
388
-    abstract protected function _set_page_config();
389
-
390
-
391
-
392
-
393
-
394
-    /** end sample help_tour methods **/
395
-    /**
396
-     * _add_screen_options
397
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
398
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
399
-     * to a particular view.
400
-     *
401
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
402
-     *         see also WP_Screen object documents...
403
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
404
-     * @abstract
405
-     * @return void
406
-     */
407
-    abstract protected function _add_screen_options();
408
-
409
-
410
-    /**
411
-     * _add_feature_pointers
412
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
413
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
414
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
415
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
416
-     * extended) also see:
417
-     *
418
-     * @link   http://eamann.com/tech/wordpress-portland/
419
-     * @abstract
420
-     * @return void
421
-     */
422
-    abstract protected function _add_feature_pointers();
423
-
424
-
425
-    /**
426
-     * load_scripts_styles
427
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
428
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
429
-     * scripts/styles per view by putting them in a dynamic function in this format
430
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
431
-     *
432
-     * @abstract
433
-     * @return void
434
-     */
435
-    abstract public function load_scripts_styles();
436
-
437
-
438
-    /**
439
-     * admin_init
440
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
441
-     * all pages/views loaded by child class.
442
-     *
443
-     * @abstract
444
-     * @return void
445
-     */
446
-    abstract public function admin_init();
447
-
448
-
449
-    /**
450
-     * admin_notices
451
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
452
-     * all pages/views loaded by child class.
453
-     *
454
-     * @abstract
455
-     * @return void
456
-     */
457
-    abstract public function admin_notices();
458
-
459
-
460
-    /**
461
-     * admin_footer_scripts
462
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
463
-     * will apply to all pages/views loaded by child class.
464
-     *
465
-     * @return void
466
-     */
467
-    abstract public function admin_footer_scripts();
468
-
469
-
470
-    /**
471
-     * admin_footer
472
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
473
-     * apply to all pages/views loaded by child class.
474
-     *
475
-     * @return void
476
-     */
477
-    public function admin_footer()
478
-    {
479
-    }
480
-
481
-
482
-    /**
483
-     * _global_ajax_hooks
484
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
485
-     * Note: within the ajax callback methods.
486
-     *
487
-     * @abstract
488
-     * @return void
489
-     */
490
-    protected function _global_ajax_hooks()
491
-    {
492
-        // for lazy loading of metabox content
493
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
494
-
495
-        add_action(
496
-            'wp_ajax_espresso_hide_status_change_notice',
497
-            [$this, 'hideStatusChangeNotice']
498
-        );
499
-        add_action(
500
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
501
-            [$this, 'hideStatusChangeNotice']
502
-        );
503
-    }
504
-
505
-
506
-    public function ajax_metabox_content()
507
-    {
508
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
509
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
510
-        EE_Admin_Page::cached_rss_display($contentid, $url);
511
-        wp_die();
512
-    }
513
-
514
-
515
-    public function hideStatusChangeNotice()
516
-    {
517
-        $response = [];
518
-        try {
519
-            /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
520
-            $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
521
-            $response['success'] = $status_change_notice->dismiss() > -1;
522
-        } catch (Exception $exception) {
523
-            $response['errors'] = $exception->getMessage();
524
-        }
525
-        echo wp_json_encode($response);
526
-        exit();
527
-    }
528
-
529
-
530
-    /**
531
-     * _page_setup
532
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
533
-     * doesn't match the object.
534
-     *
535
-     * @final
536
-     * @return void
537
-     * @throws EE_Error
538
-     * @throws InvalidArgumentException
539
-     * @throws ReflectionException
540
-     * @throws InvalidDataTypeException
541
-     * @throws InvalidInterfaceException
542
-     */
543
-    final protected function _page_setup()
544
-    {
545
-        // requires?
546
-        // admin_init stuff - global - we're setting this REALLY early
547
-        // so if EE_Admin pages have to hook into other WP pages they can.
548
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
549
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
550
-        // next verify if we need to load anything...
551
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
552
-        $this->page_folder = strtolower(
553
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
554
-        );
555
-        global $ee_menu_slugs;
556
-        $ee_menu_slugs = (array) $ee_menu_slugs;
557
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
558
-            return;
559
-        }
560
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
561
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
562
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
563
-                ? $this->_req_data['action2']
564
-                : $this->_req_data['action'];
565
-        }
566
-        // then set blank or -1 action values to 'default'
567
-        $this->_req_action = isset($this->_req_data['action'])
568
-                             && ! empty($this->_req_data['action'])
569
-                             && $this->_req_data['action'] !== '-1'
570
-            ? sanitize_key($this->_req_data['action'])
571
-            : 'default';
572
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
573
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
574
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
575
-            ? $this->_req_data['route'] : $this->_req_action;
576
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
577
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
578
-            ? $this->_req_data['route']
579
-            : $this->_req_action;
580
-        $this->_current_view = $this->_req_action;
581
-        $this->_req_nonce = $this->_req_action . '_nonce';
582
-        $this->_define_page_props();
583
-        $this->_current_page_view_url = add_query_arg(
584
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
585
-            $this->_admin_base_url
586
-        );
587
-        // default things
588
-        $this->_default_espresso_metaboxes = array(
589
-            '_espresso_news_post_box',
590
-            '_espresso_links_post_box',
591
-            '_espresso_ratings_request',
592
-            '_espresso_sponsors_post_box',
593
-        );
594
-        // set page configs
595
-        $this->_set_page_routes();
596
-        $this->_set_page_config();
597
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
598
-        if (isset($this->_req_data['wp_referer'])) {
599
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
600
-        }
601
-        // for caffeinated and other extended functionality.
602
-        //  If there is a _extend_page_config method
603
-        // then let's run that to modify the all the various page configuration arrays
604
-        if (method_exists($this, '_extend_page_config')) {
605
-            $this->_extend_page_config();
606
-        }
607
-        // for CPT and other extended functionality.
608
-        // If there is an _extend_page_config_for_cpt
609
-        // then let's run that to modify all the various page configuration arrays.
610
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
611
-            $this->_extend_page_config_for_cpt();
612
-        }
613
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
614
-        $this->_page_routes = apply_filters(
615
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
616
-            $this->_page_routes,
617
-            $this
618
-        );
619
-        $this->_page_config = apply_filters(
620
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
621
-            $this->_page_config,
622
-            $this
623
-        );
624
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
625
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
626
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
627
-            add_action(
628
-                'AHEE__EE_Admin_Page__route_admin_request',
629
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
630
-                10,
631
-                2
632
-            );
633
-        }
634
-        // next route only if routing enabled
635
-        if ($this->_routing && ! defined('DOING_AJAX')) {
636
-            $this->_verify_routes();
637
-            // next let's just check user_access and kill if no access
638
-            $this->check_user_access();
639
-            if ($this->_is_UI_request) {
640
-                // admin_init stuff - global, all views for this page class, specific view
641
-                add_action('admin_init', array($this, 'admin_init'), 10);
642
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
643
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
644
-                }
645
-            } else {
646
-                // hijack regular WP loading and route admin request immediately
647
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
648
-                $this->route_admin_request();
649
-            }
650
-        }
651
-    }
652
-
653
-
654
-    /**
655
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
656
-     *
657
-     * @return void
658
-     * @throws EE_Error
659
-     */
660
-    private function _do_other_page_hooks()
661
-    {
662
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
663
-        foreach ($registered_pages as $page) {
664
-            // now let's setup the file name and class that should be present
665
-            $classname = str_replace('.class.php', '', $page);
666
-            // autoloaders should take care of loading file
667
-            if (! class_exists($classname)) {
668
-                $error_msg[] = sprintf(
669
-                    esc_html__(
670
-                        'Something went wrong with loading the %s admin hooks page.',
671
-                        'event_espresso'
672
-                    ),
673
-                    $page
674
-                );
675
-                $error_msg[] = $error_msg[0]
676
-                               . "\r\n"
677
-                               . sprintf(
678
-                                   esc_html__(
679
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
680
-                                       'event_espresso'
681
-                                   ),
682
-                                   $page,
683
-                                   '<br />',
684
-                                   '<strong>' . $classname . '</strong>'
685
-                               );
686
-                throw new EE_Error(implode('||', $error_msg));
687
-            }
688
-            // // notice we are passing the instance of this class to the hook object.
689
-            $this->loader->getShared($classname, [$this]);
690
-        }
691
-    }
692
-
693
-
694
-    /**
695
-     * @throws DomainException
696
-     * @throws EE_Error
697
-     * @throws InvalidArgumentException
698
-     * @throws InvalidDataTypeException
699
-     * @throws InvalidInterfaceException
700
-     * @throws ReflectionException
701
-     * @since $VID:$
702
-     */
703
-    public function load_page_dependencies()
704
-    {
705
-        try {
706
-            $this->_load_page_dependencies();
707
-        } catch (EE_Error $e) {
708
-            $e->get_error();
709
-        }
710
-    }
711
-
712
-
713
-    /**
714
-     * load_page_dependencies
715
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
716
-     *
717
-     * @return void
718
-     * @throws DomainException
719
-     * @throws EE_Error
720
-     * @throws InvalidArgumentException
721
-     * @throws InvalidDataTypeException
722
-     * @throws InvalidInterfaceException
723
-     * @throws ReflectionException
724
-     */
725
-    protected function _load_page_dependencies()
726
-    {
727
-        // let's set the current_screen and screen options to override what WP set
728
-        $this->_current_screen = get_current_screen();
729
-        // load admin_notices - global, page class, and view specific
730
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
731
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
732
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
733
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
734
-        }
735
-        // load network admin_notices - global, page class, and view specific
736
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
737
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
738
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
739
-        }
740
-        // this will save any per_page screen options if they are present
741
-        $this->_set_per_page_screen_options();
742
-        // setup list table properties
743
-        $this->_set_list_table();
744
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
745
-        // However in some cases the metaboxes will need to be added within a route handling callback.
746
-        $this->_add_registered_meta_boxes();
747
-        $this->_add_screen_columns();
748
-        // add screen options - global, page child class, and view specific
749
-        $this->_add_global_screen_options();
750
-        $this->_add_screen_options();
751
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
752
-        if (method_exists($this, $add_screen_options)) {
753
-            $this->{$add_screen_options}();
754
-        }
755
-        // add help tab(s) and tours- set via page_config and qtips.
756
-        // $this->_add_help_tour();
757
-        $this->_add_help_tabs();
758
-        $this->_add_qtips();
759
-        // add feature_pointers - global, page child class, and view specific
760
-        $this->_add_feature_pointers();
761
-        $this->_add_global_feature_pointers();
762
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
763
-        if (method_exists($this, $add_feature_pointer)) {
764
-            $this->{$add_feature_pointer}();
765
-        }
766
-        // enqueue scripts/styles - global, page class, and view specific
767
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
768
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
769
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
770
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
771
-        }
772
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
773
-        // admin_print_footer_scripts - global, page child class, and view specific.
774
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
775
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
776
-        // is a good use case. Notice the late priority we're giving these
777
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
778
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
779
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
780
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
781
-        }
782
-        // admin footer scripts
783
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
784
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
785
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
786
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
787
-        }
788
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
789
-        // targeted hook
790
-        do_action(
791
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
792
-        );
793
-    }
794
-
795
-
796
-    /**
797
-     * _set_defaults
798
-     * This sets some global defaults for class properties.
799
-     */
800
-    private function _set_defaults()
801
-    {
802
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
803
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
804
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
805
-        $this->_page_config = $this->_default_route_query_args = array();
806
-        $this->_default_nav_tab_name = 'overview';
807
-        // init template args
808
-        $this->_template_args = array(
809
-            'admin_page_header'  => '',
810
-            'admin_page_content' => '',
811
-            'post_body_content'  => '',
812
-            'before_list_table'  => '',
813
-            'after_list_table'   => '',
814
-        );
815
-    }
816
-
817
-
818
-    /**
819
-     * route_admin_request
820
-     *
821
-     * @see    _route_admin_request()
822
-     * @return exception|void error
823
-     * @throws InvalidArgumentException
824
-     * @throws InvalidInterfaceException
825
-     * @throws InvalidDataTypeException
826
-     * @throws EE_Error
827
-     * @throws ReflectionException
828
-     */
829
-    public function route_admin_request()
830
-    {
831
-        try {
832
-            $this->_route_admin_request();
833
-        } catch (EE_Error $e) {
834
-            $e->get_error();
835
-        }
836
-    }
837
-
838
-
839
-    public function set_wp_page_slug($wp_page_slug)
840
-    {
841
-        $this->_wp_page_slug = $wp_page_slug;
842
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
843
-        if (is_network_admin()) {
844
-            $this->_wp_page_slug .= '-network';
845
-        }
846
-    }
847
-
848
-
849
-    /**
850
-     * _verify_routes
851
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
852
-     * we know if we need to drop out.
853
-     *
854
-     * @return bool
855
-     * @throws EE_Error
856
-     */
857
-    protected function _verify_routes()
858
-    {
859
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
860
-            return false;
861
-        }
862
-        $this->_route = false;
863
-        // check that the page_routes array is not empty
864
-        if (empty($this->_page_routes)) {
865
-            // user error msg
866
-            $error_msg = sprintf(
867
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
868
-                $this->_admin_page_title
869
-            );
870
-            // developer error msg
871
-            $error_msg .= '||' . $error_msg
872
-                          . esc_html__(
873
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
874
-                              'event_espresso'
875
-                          );
876
-            throw new EE_Error($error_msg);
877
-        }
878
-        // and that the requested page route exists
879
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
880
-            $this->_route = $this->_page_routes[ $this->_req_action ];
881
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
882
-                ? $this->_page_config[ $this->_req_action ] : array();
883
-        } else {
884
-            // user error msg
885
-            $error_msg = sprintf(
886
-                esc_html__(
887
-                    'The requested page route does not exist for the %s admin page.',
888
-                    'event_espresso'
889
-                ),
890
-                $this->_admin_page_title
891
-            );
892
-            // developer error msg
893
-            $error_msg .= '||' . $error_msg
894
-                          . sprintf(
895
-                              esc_html__(
896
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
897
-                                  'event_espresso'
898
-                              ),
899
-                              $this->_req_action
900
-                          );
901
-            throw new EE_Error($error_msg);
902
-        }
903
-        // and that a default route exists
904
-        if (! array_key_exists('default', $this->_page_routes)) {
905
-            // user error msg
906
-            $error_msg = sprintf(
907
-                esc_html__(
908
-                    'A default page route has not been set for the % admin page.',
909
-                    'event_espresso'
910
-                ),
911
-                $this->_admin_page_title
912
-            );
913
-            // developer error msg
914
-            $error_msg .= '||' . $error_msg
915
-                          . esc_html__(
916
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
917
-                              'event_espresso'
918
-                          );
919
-            throw new EE_Error($error_msg);
920
-        }
921
-
922
-        // first lets' catch if the UI request has EVER been set.
923
-        if ($this->_is_UI_request === null) {
924
-            // lets set if this is a UI request or not.
925
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
926
-            // wait a minute... we might have a noheader in the route array
927
-            $this->_is_UI_request = is_array($this->_route)
928
-                                    && isset($this->_route['noheader'])
929
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
930
-        }
931
-        $this->_set_current_labels();
932
-        return true;
933
-    }
934
-
935
-
936
-    /**
937
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
938
-     *
939
-     * @param  string $route the route name we're verifying
940
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
941
-     * @throws EE_Error
942
-     */
943
-    protected function _verify_route($route)
944
-    {
945
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
946
-            return true;
947
-        }
948
-        // user error msg
949
-        $error_msg = sprintf(
950
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
951
-            $this->_admin_page_title
952
-        );
953
-        // developer error msg
954
-        $error_msg .= '||' . $error_msg
955
-                      . sprintf(
956
-                          esc_html__(
957
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
958
-                              'event_espresso'
959
-                          ),
960
-                          $route
961
-                      );
962
-        throw new EE_Error($error_msg);
963
-    }
964
-
965
-
966
-    /**
967
-     * perform nonce verification
968
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
969
-     * using this method (and save retyping!)
970
-     *
971
-     * @param string $nonce     The nonce sent
972
-     * @param string $nonce_ref The nonce reference string (name0)
973
-     * @return void
974
-     * @throws EE_Error
975
-     * @throws InvalidArgumentException
976
-     * @throws InvalidDataTypeException
977
-     * @throws InvalidInterfaceException
978
-     */
979
-    protected function _verify_nonce($nonce, $nonce_ref)
980
-    {
981
-        // verify nonce against expected value
982
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
983
-            // these are not the droids you are looking for !!!
984
-            $msg = sprintf(
985
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
986
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
987
-                '</a>'
988
-            );
989
-            if (WP_DEBUG) {
990
-                $msg .= "\n  "
991
-                        . sprintf(
992
-                            esc_html__(
993
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
994
-                                'event_espresso'
995
-                            ),
996
-                            EE_Admin_Page::class
997
-                        );
998
-            }
999
-            if (! defined('DOING_AJAX')) {
1000
-                wp_die($msg);
1001
-            } else {
1002
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1003
-                $this->_return_json();
1004
-            }
1005
-        }
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * _route_admin_request()
1011
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1012
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1013
-     * in the page routes and then will try to load the corresponding method.
1014
-     *
1015
-     * @return void
1016
-     * @throws EE_Error
1017
-     * @throws InvalidArgumentException
1018
-     * @throws InvalidDataTypeException
1019
-     * @throws InvalidInterfaceException
1020
-     * @throws ReflectionException
1021
-     */
1022
-    protected function _route_admin_request()
1023
-    {
1024
-        if (! $this->_is_UI_request) {
1025
-            $this->_verify_routes();
1026
-        }
1027
-        $nonce_check = isset($this->_route_config['require_nonce'])
1028
-            ? $this->_route_config['require_nonce']
1029
-            : true;
1030
-        if ($this->_req_action !== 'default' && $nonce_check) {
1031
-            // set nonce from post data
1032
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
1033
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1034
-                : '';
1035
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1036
-        }
1037
-        // set the nav_tabs array but ONLY if this is  UI_request
1038
-        if ($this->_is_UI_request) {
1039
-            $this->_set_nav_tabs();
1040
-        }
1041
-        // grab callback function
1042
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1043
-        // check if callback has args
1044
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1045
-        $error_msg = '';
1046
-        // action right before calling route
1047
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1048
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1049
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1050
-        }
1051
-        // right before calling the route, let's remove _wp_http_referer from the
1052
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1053
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1054
-            '_wp_http_referer',
1055
-            wp_unslash($_SERVER['REQUEST_URI'])
1056
-        );
1057
-        if (! empty($func)) {
1058
-            if (is_array($func)) {
1059
-                list($class, $method) = $func;
1060
-            } elseif (strpos($func, '::') !== false) {
1061
-                list($class, $method) = explode('::', $func);
1062
-            } else {
1063
-                $class = $this;
1064
-                $method = $func;
1065
-            }
1066
-            if (! (is_object($class) && $class === $this)) {
1067
-                // send along this admin page object for access by addons.
1068
-                $args['admin_page_object'] = $this;
1069
-            }
1070
-            // is it a method on a class that doesn't work?
1071
-            if (
1072
-                ((method_exists($class, $method)
1073
-                  && call_user_func_array(array($class, $method), $args) === false)
1074
-                 && (// is it a standalone function that doesn't work?
1075
-                     function_exists($method)
1076
-                     && call_user_func_array(
1077
-                         $func,
1078
-                         array_merge(array('admin_page_object' => $this), $args)
1079
-                     ) === false
1080
-                 )) || (// is it neither a class method NOR a standalone function?
1081
-                    ! function_exists($method)
1082
-                    && ! method_exists($class, $method)
1083
-                )
1084
-            ) {
1085
-                // user error msg
1086
-                $error_msg = esc_html__(
1087
-                    'An error occurred. The  requested page route could not be found.',
1088
-                    'event_espresso'
1089
-                );
1090
-                // developer error msg
1091
-                $error_msg .= '||';
1092
-                $error_msg .= sprintf(
1093
-                    esc_html__(
1094
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1095
-                        'event_espresso'
1096
-                    ),
1097
-                    $method
1098
-                );
1099
-            }
1100
-            if (! empty($error_msg)) {
1101
-                throw new EE_Error($error_msg);
1102
-            }
1103
-        }
1104
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1105
-        // then we need to reset the routing properties to the new route.
1106
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1107
-        if (
1108
-            $this->_is_UI_request === false
1109
-            && is_array($this->_route)
1110
-            && ! empty($this->_route['headers_sent_route'])
1111
-        ) {
1112
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1113
-        }
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * This method just allows the resetting of page properties in the case where a no headers
1119
-     * route redirects to a headers route in its route config.
1120
-     *
1121
-     * @since   4.3.0
1122
-     * @param  string $new_route New (non header) route to redirect to.
1123
-     * @return   void
1124
-     * @throws ReflectionException
1125
-     * @throws InvalidArgumentException
1126
-     * @throws InvalidInterfaceException
1127
-     * @throws InvalidDataTypeException
1128
-     * @throws EE_Error
1129
-     */
1130
-    protected function _reset_routing_properties($new_route)
1131
-    {
1132
-        $this->_is_UI_request = true;
1133
-        // now we set the current route to whatever the headers_sent_route is set at
1134
-        $this->_req_data['action'] = $new_route;
1135
-        // rerun page setup
1136
-        $this->_page_setup();
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * _add_query_arg
1142
-     * adds nonce to array of arguments then calls WP add_query_arg function
1143
-     *(internally just uses EEH_URL's function with the same name)
1144
-     *
1145
-     * @param array  $args
1146
-     * @param string $url
1147
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1148
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1149
-     *                                        Example usage: If the current page is:
1150
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1151
-     *                                        &action=default&event_id=20&month_range=March%202015
1152
-     *                                        &_wpnonce=5467821
1153
-     *                                        and you call:
1154
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1155
-     *                                        array(
1156
-     *                                        'action' => 'resend_something',
1157
-     *                                        'page=>espresso_registrations'
1158
-     *                                        ),
1159
-     *                                        $some_url,
1160
-     *                                        true
1161
-     *                                        );
1162
-     *                                        It will produce a url in this structure:
1163
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1164
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1165
-     *                                        month_range]=March%202015
1166
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1167
-     * @return string
1168
-     */
1169
-    public static function add_query_args_and_nonce(
1170
-        $args = array(),
1171
-        $url = '',
1172
-        $sticky = false,
1173
-        $exclude_nonce = false
1174
-    ) {
1175
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1176
-        if ($sticky) {
1177
-            $request = $_REQUEST;
1178
-            unset($request['_wp_http_referer'], $request['wp_referer']);
1179
-            foreach ($request as $key => $value) {
1180
-                // do not add nonces
1181
-                if (strpos($key, 'nonce') !== false) {
1182
-                    continue;
1183
-                }
1184
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1185
-            }
1186
-        }
1187
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1188
-    }
1189
-
1190
-
1191
-    /**
1192
-     * This returns a generated link that will load the related help tab.
1193
-     *
1194
-     * @param  string $help_tab_id the id for the connected help tab
1195
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1196
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1197
-     * @uses EEH_Template::get_help_tab_link()
1198
-     * @return string              generated link
1199
-     */
1200
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1201
-    {
1202
-        return EEH_Template::get_help_tab_link(
1203
-            $help_tab_id,
1204
-            $this->page_slug,
1205
-            $this->_req_action,
1206
-            $icon_style,
1207
-            $help_text
1208
-        );
1209
-    }
1210
-
1211
-
1212
-    /**
1213
-     * _add_help_tabs
1214
-     * Note child classes define their help tabs within the page_config array.
1215
-     *
1216
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1217
-     * @return void
1218
-     * @throws DomainException
1219
-     * @throws EE_Error
1220
-     * @throws ReflectionException
1221
-     */
1222
-    protected function _add_help_tabs()
1223
-    {
1224
-        $tour_buttons = '';
1225
-        if (isset($this->_page_config[ $this->_req_action ])) {
1226
-            $config = $this->_page_config[ $this->_req_action ];
1227
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1228
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1229
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1230
-            //     $tb = array();
1231
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1232
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1233
-            //         // if this is the end tour then we don't need to setup a button
1234
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1235
-            //             continue;
1236
-            //         }
1237
-            //         $tb[] = '<button id="trigger-tour-'
1238
-            //                 . $tour->get_slug()
1239
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1240
-            //                 . $tour->get_label()
1241
-            //                 . '</button>';
1242
-            //     }
1243
-            //     $tour_buttons .= implode('<br />', $tb);
1244
-            //     $tour_buttons .= '</div></div>';
1245
-            // }
1246
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1247
-            if (is_array($config) && isset($config['help_sidebar'])) {
1248
-                // check that the callback given is valid
1249
-                if (! method_exists($this, $config['help_sidebar'])) {
1250
-                    throw new EE_Error(
1251
-                        sprintf(
1252
-                            esc_html__(
1253
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1254
-                                'event_espresso'
1255
-                            ),
1256
-                            $config['help_sidebar'],
1257
-                            get_class($this)
1258
-                        )
1259
-                    );
1260
-                }
1261
-                $content = apply_filters(
1262
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1263
-                    $this->{$config['help_sidebar']}()
1264
-                );
1265
-                $content .= $tour_buttons; // add help tour buttons.
1266
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1267
-                $this->_current_screen->set_help_sidebar($content);
1268
-            }
1269
-            // if there ARE tour buttons...
1270
-            if (! empty($tour_buttons)) {
1271
-                // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1272
-                if (! isset($config['help_sidebar'])) {
1273
-                    $this->_current_screen->set_help_sidebar($tour_buttons);
1274
-                }
1275
-                // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1276
-                if (! isset($config['help_tabs'])) {
1277
-                    $_ht['id'] = $this->page_slug;
1278
-                    $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1279
-                    $_ht['content'] = '<p>'
1280
-                                      . esc_html__(
1281
-                                          'The buttons to the right allow you to start/restart any help tours available for this page',
1282
-                                          'event_espresso'
1283
-                                      ) . '</p>';
1284
-                    $this->_current_screen->add_help_tab($_ht);
1285
-                }
1286
-            }
1287
-            if (! isset($config['help_tabs'])) {
1288
-                return;
1289
-            } //no help tabs for this route
1290
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1291
-                // we're here so there ARE help tabs!
1292
-                // make sure we've got what we need
1293
-                if (! isset($cfg['title'])) {
1294
-                    throw new EE_Error(
1295
-                        esc_html__(
1296
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1297
-                            'event_espresso'
1298
-                        )
1299
-                    );
1300
-                }
1301
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1302
-                    throw new EE_Error(
1303
-                        esc_html__(
1304
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1305
-                            'event_espresso'
1306
-                        )
1307
-                    );
1308
-                }
1309
-                // first priority goes to content.
1310
-                if (! empty($cfg['content'])) {
1311
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1312
-                    // second priority goes to filename
1313
-                } elseif (! empty($cfg['filename'])) {
1314
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1315
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1316
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1317
-                                                             . basename($this->_get_dir())
1318
-                                                             . '/help_tabs/'
1319
-                                                             . $cfg['filename']
1320
-                                                             . '.help_tab.php' : $file_path;
1321
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1322
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1323
-                        EE_Error::add_error(
1324
-                            sprintf(
1325
-                                esc_html__(
1326
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1327
-                                    'event_espresso'
1328
-                                ),
1329
-                                $tab_id,
1330
-                                key($config),
1331
-                                $file_path
1332
-                            ),
1333
-                            __FILE__,
1334
-                            __FUNCTION__,
1335
-                            __LINE__
1336
-                        );
1337
-                        return;
1338
-                    }
1339
-                    $template_args['admin_page_obj'] = $this;
1340
-                    $content = EEH_Template::display_template(
1341
-                        $file_path,
1342
-                        $template_args,
1343
-                        true
1344
-                    );
1345
-                } else {
1346
-                    $content = '';
1347
-                }
1348
-                // check if callback is valid
1349
-                if (
1350
-                    empty($content) && (
1351
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1352
-                    )
1353
-                ) {
1354
-                    EE_Error::add_error(
1355
-                        sprintf(
1356
-                            esc_html__(
1357
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1358
-                                'event_espresso'
1359
-                            ),
1360
-                            $cfg['title']
1361
-                        ),
1362
-                        __FILE__,
1363
-                        __FUNCTION__,
1364
-                        __LINE__
1365
-                    );
1366
-                    return;
1367
-                }
1368
-                // setup config array for help tab method
1369
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1370
-                $_ht = array(
1371
-                    'id'       => $id,
1372
-                    'title'    => $cfg['title'],
1373
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1374
-                    'content'  => $content,
1375
-                );
1376
-                $this->_current_screen->add_help_tab($_ht);
1377
-            }
1378
-        }
1379
-    }
1380
-
1381
-
1382
-    /**
1383
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1384
-     * an array with properties for setting up usage of the joyride plugin
1385
-     *
1386
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1387
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1388
-     *         _set_page_config() comments
1389
-     * @return void
1390
-     * @throws EE_Error
1391
-     * @throws InvalidArgumentException
1392
-     * @throws InvalidDataTypeException
1393
-     * @throws InvalidInterfaceException
1394
-     * @throws ReflectionException
1395
-     */
1396
-    protected function _add_help_tour()
1397
-    {
1398
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1399
-        // $tours = array();
1400
-        // $this->_help_tour = array();
1401
-        // // exit early if help tours are turned off globally
1402
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1403
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1404
-        // ) {
1405
-        //     return;
1406
-        // }
1407
-        // // loop through _page_config to find any help_tour defined
1408
-        // foreach ($this->_page_config as $route => $config) {
1409
-        //     // we're only going to set things up for this route
1410
-        //     if ($route !== $this->_req_action) {
1411
-        //         continue;
1412
-        //     }
1413
-        //     if (isset($config['help_tour'])) {
1414
-        //         foreach ($config['help_tour'] as $tour) {
1415
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1416
-        //             // let's see if we can get that file...
1417
-        //             // if not its possible this is a decaf route not set in caffeinated
1418
-        //             // so lets try and get the caffeinated equivalent
1419
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1420
-        //                                                      . basename($this->_get_dir())
1421
-        //                                                      . '/help_tours/'
1422
-        //                                                      . $tour
1423
-        //                                                      . '.class.php' : $file_path;
1424
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1425
-        //             if (! is_readable($file_path)) {
1426
-        //                 EE_Error::add_error(
1427
-        //                     sprintf(
1428
-        //                         esc_html__(
1429
-        //                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1430
-        //                             'event_espresso'
1431
-        //                         ),
1432
-        //                         $file_path,
1433
-        //                         $tour
1434
-        //                     ),
1435
-        //                     __FILE__,
1436
-        //                     __FUNCTION__,
1437
-        //                     __LINE__
1438
-        //                 );
1439
-        //                 return;
1440
-        //             }
1441
-        //             require_once $file_path;
1442
-        //             if (! class_exists($tour)) {
1443
-        //                 $error_msg[] = sprintf(
1444
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1445
-        //                     $tour
1446
-        //                 );
1447
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1448
-        //                                . sprintf(
1449
-        //                                    esc_html__(
1450
-        //                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1451
-        //                                        'event_espresso'
1452
-        //                                    ),
1453
-        //                                    $tour,
1454
-        //                                    '<br />',
1455
-        //                                    $tour,
1456
-        //                                    $this->_req_action,
1457
-        //                                    get_class($this)
1458
-        //                                );
1459
-        //                 throw new EE_Error(implode('||', $error_msg));
1460
-        //             }
1461
-        //             $tour_obj = new $tour($this->_is_caf);
1462
-        //             $tours[] = $tour_obj;
1463
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1464
-        //         }
1465
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1466
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1467
-        //         $tours[] = $end_stop_tour;
1468
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1469
-        //     }
1470
-        // }
1471
-        //
1472
-        // if (! empty($tours)) {
1473
-        //     $this->_help_tour['tours'] = $tours;
1474
-        // }
1475
-        // // that's it!  Now that the $_help_tours property is set (or not)
1476
-        // // the scripts and html should be taken care of automatically.
1477
-        //
1478
-        // /**
1479
-        //  * Allow extending the help tours variable.
1480
-        //  *
1481
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1482
-        //  */
1483
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1484
-    }
1485
-
1486
-
1487
-    /**
1488
-     * This simply sets up any qtips that have been defined in the page config
1489
-     *
1490
-     * @return void
1491
-     * @throws ReflectionException
1492
-     * @throws EE_Error
1493
-     */
1494
-    protected function _add_qtips()
1495
-    {
1496
-        if (isset($this->_route_config['qtips'])) {
1497
-            $qtips = (array) $this->_route_config['qtips'];
1498
-            // load qtip loader
1499
-            $path = array(
1500
-                $this->_get_dir() . '/qtips/',
1501
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1502
-            );
1503
-            $qtip_loader = EEH_Qtip_Loader::instance();
1504
-            if ($qtip_loader instanceof EEH_Qtip_Loader) {
1505
-                $qtip_loader->register($qtips, $path);
1506
-            }
1507
-        }
1508
-    }
1509
-
1510
-
1511
-    /**
1512
-     * _set_nav_tabs
1513
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1514
-     * wish to add additional tabs or modify accordingly.
1515
-     *
1516
-     * @return void
1517
-     * @throws InvalidArgumentException
1518
-     * @throws InvalidInterfaceException
1519
-     * @throws InvalidDataTypeException
1520
-     */
1521
-    protected function _set_nav_tabs()
1522
-    {
1523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1524
-        $i = 0;
1525
-        foreach ($this->_page_config as $slug => $config) {
1526
-            if (
1527
-                ! is_array($config)
1528
-                || (
1529
-                    is_array($config)
1530
-                    && (
1531
-                        (isset($config['nav']) && ! $config['nav'])
1532
-                        || ! isset($config['nav'])
1533
-                    )
1534
-                )
1535
-            ) {
1536
-                continue;
1537
-            }
1538
-            // no nav tab for this config
1539
-            // check for persistent flag
1540
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1541
-                // nav tab is only to appear when route requested.
1542
-                continue;
1543
-            }
1544
-            if (! $this->check_user_access($slug, true)) {
1545
-                // no nav tab because current user does not have access.
1546
-                continue;
1547
-            }
1548
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1549
-            $this->_nav_tabs[ $slug ] = array(
1550
-                'url'       => isset($config['nav']['url'])
1551
-                    ? $config['nav']['url']
1552
-                    : EE_Admin_Page::add_query_args_and_nonce(
1553
-                        array('action' => $slug),
1554
-                        $this->_admin_base_url
1555
-                    ),
1556
-                'link_text' => isset($config['nav']['label'])
1557
-                    ? $config['nav']['label']
1558
-                    : ucwords(
1559
-                        str_replace('_', ' ', $slug)
1560
-                    ),
1561
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1562
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1563
-            );
1564
-            $i++;
1565
-        }
1566
-        // if $this->_nav_tabs is empty then lets set the default
1567
-        if (empty($this->_nav_tabs)) {
1568
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1569
-                'url'       => $this->_admin_base_url,
1570
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1571
-                'css_class' => 'nav-tab-active',
1572
-                'order'     => 10,
1573
-            );
1574
-        }
1575
-        // now let's sort the tabs according to order
1576
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1577
-    }
1578
-
1579
-
1580
-    /**
1581
-     * _set_current_labels
1582
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1583
-     * property array
1584
-     *
1585
-     * @return void
1586
-     */
1587
-    private function _set_current_labels()
1588
-    {
1589
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1590
-            foreach ($this->_route_config['labels'] as $label => $text) {
1591
-                if (is_array($text)) {
1592
-                    foreach ($text as $sublabel => $subtext) {
1593
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1594
-                    }
1595
-                } else {
1596
-                    $this->_labels[ $label ] = $text;
1597
-                }
1598
-            }
1599
-        }
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     *        verifies user access for this admin page
1605
-     *
1606
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1607
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1608
-     *                               return false if verify fail.
1609
-     * @return bool
1610
-     * @throws InvalidArgumentException
1611
-     * @throws InvalidDataTypeException
1612
-     * @throws InvalidInterfaceException
1613
-     */
1614
-    public function check_user_access($route_to_check = '', $verify_only = false)
1615
-    {
1616
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1617
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1618
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1619
-                      && is_array(
1620
-                          $this->_page_routes[ $route_to_check ]
1621
-                      )
1622
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1623
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1624
-        if (empty($capability) && empty($route_to_check)) {
1625
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1626
-                : $this->_route['capability'];
1627
-        } else {
1628
-            $capability = empty($capability) ? 'manage_options' : $capability;
1629
-        }
1630
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1631
-        if (
1632
-            ! defined('DOING_AJAX')
1633
-            && (
1634
-                ! function_exists('is_admin')
1635
-                || ! EE_Registry::instance()->CAP->current_user_can(
1636
-                    $capability,
1637
-                    $this->page_slug
1638
-                    . '_'
1639
-                    . $route_to_check,
1640
-                    $id
1641
-                )
1642
-            )
1643
-        ) {
1644
-            if ($verify_only) {
1645
-                return false;
1646
-            }
1647
-            if (is_user_logged_in()) {
1648
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1649
-            } else {
1650
-                return false;
1651
-            }
1652
-        }
1653
-        return true;
1654
-    }
1655
-
1656
-
1657
-    /**
1658
-     * admin_init_global
1659
-     * This runs all the code that we want executed within the WP admin_init hook.
1660
-     * This method executes for ALL EE Admin pages.
1661
-     *
1662
-     * @return void
1663
-     */
1664
-    public function admin_init_global()
1665
-    {
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     * wp_loaded_global
1671
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1672
-     * EE_Admin page and will execute on every EE Admin Page load
1673
-     *
1674
-     * @return void
1675
-     */
1676
-    public function wp_loaded()
1677
-    {
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * admin_notices
1683
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1684
-     * ALL EE_Admin pages.
1685
-     *
1686
-     * @return void
1687
-     */
1688
-    public function admin_notices_global()
1689
-    {
1690
-        $this->_display_no_javascript_warning();
1691
-        $this->_display_espresso_notices();
1692
-    }
1693
-
1694
-
1695
-    public function network_admin_notices_global()
1696
-    {
1697
-        $this->_display_no_javascript_warning();
1698
-        $this->_display_espresso_notices();
1699
-    }
1700
-
1701
-
1702
-    /**
1703
-     * admin_footer_scripts_global
1704
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1705
-     * will apply on ALL EE_Admin pages.
1706
-     *
1707
-     * @return void
1708
-     */
1709
-    public function admin_footer_scripts_global()
1710
-    {
1711
-        $this->_add_admin_page_ajax_loading_img();
1712
-        $this->_add_admin_page_overlay();
1713
-        // if metaboxes are present we need to add the nonce field
1714
-        if (
1715
-            isset($this->_route_config['metaboxes'])
1716
-            || isset($this->_route_config['list_table'])
1717
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1718
-        ) {
1719
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1720
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1721
-        }
1722
-    }
1723
-
1724
-
1725
-    /**
1726
-     * admin_footer_global
1727
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1728
-     * This particular method will apply on ALL EE_Admin Pages.
1729
-     *
1730
-     * @return void
1731
-     * @throws InvalidArgumentException
1732
-     * @throws InvalidDataTypeException
1733
-     * @throws InvalidInterfaceException
1734
-     */
1735
-    public function admin_footer_global()
1736
-    {
1737
-        // dialog container for dialog helper
1738
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1739
-        $d_cont .= '<div class="ee-notices"></div>';
1740
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1741
-        $d_cont .= '</div>';
1742
-        echo $d_cont;
1743
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1744
-        // help tour stuff?
1745
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1746
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1747
-        // }
1748
-        // current set timezone for timezone js
1749
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1750
-    }
1751
-
1752
-
1753
-    /**
1754
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1755
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1756
-     * help popups then in your templates or your content you set "triggers" for the content using the
1757
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1758
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1759
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1760
-     * for the
1761
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1762
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1763
-     *    'help_trigger_id' => array(
1764
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1765
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1766
-     *    )
1767
-     * );
1768
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1769
-     *
1770
-     * @param array $help_array
1771
-     * @param bool  $display
1772
-     * @return string content
1773
-     * @throws DomainException
1774
-     * @throws EE_Error
1775
-     */
1776
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1777
-    {
1778
-        $content = '';
1779
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1780
-        // loop through the array and setup content
1781
-        foreach ($help_array as $trigger => $help) {
1782
-            // make sure the array is setup properly
1783
-            if (! isset($help['title'], $help['content'])) {
1784
-                throw new EE_Error(
1785
-                    esc_html__(
1786
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1787
-                        'event_espresso'
1788
-                    )
1789
-                );
1790
-            }
1791
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1792
-            $template_args = array(
1793
-                'help_popup_id'      => $trigger,
1794
-                'help_popup_title'   => $help['title'],
1795
-                'help_popup_content' => $help['content'],
1796
-            );
1797
-            $content .= EEH_Template::display_template(
1798
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1799
-                $template_args,
1800
-                true
1801
-            );
1802
-        }
1803
-        if ($display) {
1804
-            echo $content;
1805
-            return '';
1806
-        }
1807
-        return $content;
1808
-    }
1809
-
1810
-
1811
-    /**
1812
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1813
-     *
1814
-     * @return array properly formatted array for help popup content
1815
-     * @throws EE_Error
1816
-     */
1817
-    private function _get_help_content()
1818
-    {
1819
-        // what is the method we're looking for?
1820
-        $method_name = '_help_popup_content_' . $this->_req_action;
1821
-        // if method doesn't exist let's get out.
1822
-        if (! method_exists($this, $method_name)) {
1823
-            return array();
1824
-        }
1825
-        // k we're good to go let's retrieve the help array
1826
-        $help_array = $this->{$method_name}();
1827
-        // make sure we've got an array!
1828
-        if (! is_array($help_array)) {
1829
-            throw new EE_Error(
1830
-                esc_html__(
1831
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1832
-                    'event_espresso'
1833
-                )
1834
-            );
1835
-        }
1836
-        return $help_array;
1837
-    }
1838
-
1839
-
1840
-    /**
1841
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1842
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1843
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1844
-     *
1845
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1846
-     * @param boolean $display    if false then we return the trigger string
1847
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1848
-     * @return string
1849
-     * @throws DomainException
1850
-     * @throws EE_Error
1851
-     */
1852
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1853
-    {
1854
-        if (defined('DOING_AJAX')) {
1855
-            return '';
1856
-        }
1857
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1858
-        $help_array = $this->_get_help_content();
1859
-        $help_content = '';
1860
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1861
-            $help_array[ $trigger_id ] = array(
1862
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1863
-                'content' => esc_html__(
1864
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1865
-                    'event_espresso'
1866
-                ),
1867
-            );
1868
-            $help_content = $this->_set_help_popup_content($help_array);
1869
-        }
1870
-        // let's setup the trigger
1871
-        $content = '<a class="ee-dialog" href="?height='
1872
-                   . $dimensions[0]
1873
-                   . '&width='
1874
-                   . $dimensions[1]
1875
-                   . '&inlineId='
1876
-                   . $trigger_id
1877
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1878
-        $content .= $help_content;
1879
-        if ($display) {
1880
-            echo $content;
1881
-            return '';
1882
-        }
1883
-        return $content;
1884
-    }
1885
-
1886
-
1887
-    /**
1888
-     * _add_global_screen_options
1889
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1890
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1891
-     *
1892
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1893
-     *         see also WP_Screen object documents...
1894
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1895
-     * @abstract
1896
-     * @return void
1897
-     */
1898
-    private function _add_global_screen_options()
1899
-    {
1900
-    }
1901
-
1902
-
1903
-    /**
1904
-     * _add_global_feature_pointers
1905
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1906
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1907
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1908
-     *
1909
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1910
-     *         extended) also see:
1911
-     * @link   http://eamann.com/tech/wordpress-portland/
1912
-     * @abstract
1913
-     * @return void
1914
-     */
1915
-    private function _add_global_feature_pointers()
1916
-    {
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * load_global_scripts_styles
1922
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1923
-     *
1924
-     * @return void
1925
-     * @throws EE_Error
1926
-     */
1927
-    public function load_global_scripts_styles()
1928
-    {
1929
-        // add debugging styles
1930
-        if (WP_DEBUG) {
1931
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1932
-        }
1933
-        // taking care of metaboxes
1934
-        if (
1935
-            empty($this->_cpt_route)
1936
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1937
-        ) {
1938
-            wp_enqueue_script('dashboard');
1939
-        }
1940
-
1941
-        // LOCALIZED DATA
1942
-        // localize script for ajax lazy loading
1943
-        wp_localize_script(
1944
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1945
-            'eeLazyLoadingContainers',
1946
-            apply_filters(
1947
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1948
-                ['espresso_news_post_box_content']
1949
-            )
1950
-        );
1951
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1952
-        // /**
1953
-        //  * help tour stuff
1954
-        //  */
1955
-        // if (! empty($this->_help_tour)) {
1956
-        //     // register the js for kicking things off
1957
-        //     wp_enqueue_script(
1958
-        //         'ee-help-tour',
1959
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1960
-        //         array('jquery-joyride'),
1961
-        //         EVENT_ESPRESSO_VERSION,
1962
-        //         true
1963
-        //     );
1964
-        //     $tours = array();
1965
-        //     // setup tours for the js tour object
1966
-        //     foreach ($this->_help_tour['tours'] as $tour) {
1967
-        //         if ($tour instanceof EE_Help_Tour) {
1968
-        //             $tours[] = array(
1969
-        //                 'id'      => $tour->get_slug(),
1970
-        //                 'options' => $tour->get_options(),
1971
-        //             );
1972
-        //         }
1973
-        //     }
1974
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1975
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1976
-        // }
1977
-    }
1978
-
1979
-
1980
-    /**
1981
-     *        admin_footer_scripts_eei18n_js_strings
1982
-     *
1983
-     * @return        void
1984
-     */
1985
-    public function admin_footer_scripts_eei18n_js_strings()
1986
-    {
1987
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1988
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
1989
-            'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1990
-            'event_espresso'
1991
-        );
1992
-        EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
1993
-        EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
1994
-        EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
1995
-        EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
1996
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
1997
-        EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
1998
-        EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
1999
-        EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2000
-        EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2001
-        EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2002
-        EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2003
-        EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2004
-        EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2005
-        EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2006
-        EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2007
-        EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2008
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2009
-        EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2010
-        EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2011
-        EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2012
-        EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2013
-        EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2014
-        EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2015
-        EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2016
-        EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2017
-        EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2018
-        EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2019
-        EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2020
-        EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2021
-        EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2022
-        EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2023
-        EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2024
-        EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2025
-        EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2026
-        EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2027
-        EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2028
-        EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2029
-        EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     *        load enhanced xdebug styles for ppl with failing eyesight
2035
-     *
2036
-     * @return        void
2037
-     */
2038
-    public function add_xdebug_style()
2039
-    {
2040
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2041
-    }
2042
-
2043
-
2044
-    /************************/
2045
-    /** LIST TABLE METHODS **/
2046
-    /************************/
2047
-    /**
2048
-     * this sets up the list table if the current view requires it.
2049
-     *
2050
-     * @return void
2051
-     * @throws EE_Error
2052
-     * @throws InvalidArgumentException
2053
-     * @throws InvalidDataTypeException
2054
-     * @throws InvalidInterfaceException
2055
-     */
2056
-    protected function _set_list_table()
2057
-    {
2058
-        // first is this a list_table view?
2059
-        if (! isset($this->_route_config['list_table'])) {
2060
-            return;
2061
-        } //not a list_table view so get out.
2062
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2063
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2064
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2065
-            // user error msg
2066
-            $error_msg = esc_html__(
2067
-                'An error occurred. The requested list table views could not be found.',
2068
-                'event_espresso'
2069
-            );
2070
-            // developer error msg
2071
-            $error_msg .= '||'
2072
-                          . sprintf(
2073
-                              esc_html__(
2074
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2075
-                                  'event_espresso'
2076
-                              ),
2077
-                              $this->_req_action,
2078
-                              $list_table_view
2079
-                          );
2080
-            throw new EE_Error($error_msg);
2081
-        }
2082
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2083
-        $this->_views = apply_filters(
2084
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2085
-            $this->_views
2086
-        );
2087
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2088
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2089
-        $this->_set_list_table_view();
2090
-        $this->_set_list_table_object();
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * set current view for List Table
2096
-     *
2097
-     * @return void
2098
-     */
2099
-    protected function _set_list_table_view()
2100
-    {
2101
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2102
-        // looking at active items or dumpster diving ?
2103
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2104
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2105
-        } else {
2106
-            $this->_view = sanitize_key($this->_req_data['status']);
2107
-        }
2108
-    }
2109
-
2110
-
2111
-    /**
2112
-     * _set_list_table_object
2113
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2114
-     *
2115
-     * @throws InvalidInterfaceException
2116
-     * @throws InvalidArgumentException
2117
-     * @throws InvalidDataTypeException
2118
-     * @throws EE_Error
2119
-     * @throws InvalidInterfaceException
2120
-     */
2121
-    protected function _set_list_table_object()
2122
-    {
2123
-        if (isset($this->_route_config['list_table'])) {
2124
-            if (! class_exists($this->_route_config['list_table'])) {
2125
-                throw new EE_Error(
2126
-                    sprintf(
2127
-                        esc_html__(
2128
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2129
-                            'event_espresso'
2130
-                        ),
2131
-                        $this->_route_config['list_table'],
2132
-                        get_class($this)
2133
-                    )
2134
-                );
2135
-            }
2136
-            $this->_list_table_object = $this->loader->getShared(
2137
-                $this->_route_config['list_table'],
2138
-                array($this)
2139
-            );
2140
-        }
2141
-    }
2142
-
2143
-
2144
-    /**
2145
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2146
-     *
2147
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2148
-     *                                                    urls.  The array should be indexed by the view it is being
2149
-     *                                                    added to.
2150
-     * @return array
2151
-     */
2152
-    public function get_list_table_view_RLs($extra_query_args = array())
2153
-    {
2154
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2155
-        if (empty($this->_views)) {
2156
-            $this->_views = array();
2157
-        }
2158
-        // cycle thru views
2159
-        foreach ($this->_views as $key => $view) {
2160
-            $query_args = array();
2161
-            // check for current view
2162
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2163
-            $query_args['action'] = $this->_req_action;
2164
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2165
-            $query_args['status'] = $view['slug'];
2166
-            // merge any other arguments sent in.
2167
-            if (isset($extra_query_args[ $view['slug'] ])) {
2168
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2169
-                    $query_args[] = $extra_query_arg;
2170
-                }
2171
-            }
2172
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2173
-        }
2174
-        return $this->_views;
2175
-    }
2176
-
2177
-
2178
-    /**
2179
-     * _entries_per_page_dropdown
2180
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2181
-     *
2182
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2183
-     *         WP does it.
2184
-     * @param int $max_entries total number of rows in the table
2185
-     * @return string
2186
-     */
2187
-    protected function _entries_per_page_dropdown($max_entries = 0)
2188
-    {
2189
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
-        $values = array(10, 25, 50, 100);
2191
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2192
-        if ($max_entries) {
2193
-            $values[] = $max_entries;
2194
-            sort($values);
2195
-        }
2196
-        $entries_per_page_dropdown = '
115
+	/**
116
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
+	 * actions.
118
+	 *
119
+	 * @since 4.6.x
120
+	 * @var array.
121
+	 */
122
+	protected $_default_route_query_args;
123
+
124
+	// set via request page and action args.
125
+	protected $_current_page;
126
+
127
+	protected $_current_view;
128
+
129
+	protected $_current_page_view_url;
130
+
131
+	// sanitized request action (and nonce)
132
+
133
+	/**
134
+	 * @var string $_req_action
135
+	 */
136
+	protected $_req_action;
137
+
138
+	/**
139
+	 * @var string $_req_nonce
140
+	 */
141
+	protected $_req_nonce;
142
+
143
+	// search related
144
+	protected $_search_btn_label;
145
+
146
+	protected $_search_box_callback;
147
+
148
+	/**
149
+	 * WP Current Screen object
150
+	 *
151
+	 * @var WP_Screen
152
+	 */
153
+	protected $_current_screen;
154
+
155
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
+	protected $_hook_obj;
157
+
158
+	// for holding incoming request data
159
+	protected $_req_data;
160
+
161
+	// yes / no array for admin form fields
162
+	protected $_yes_no_values = array();
163
+
164
+	// some default things shared by all child classes
165
+	protected $_default_espresso_metaboxes;
166
+
167
+	/**
168
+	 *    EE_Registry Object
169
+	 *
170
+	 * @var    EE_Registry
171
+	 */
172
+	protected $EE;
173
+
174
+
175
+	/**
176
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
177
+	 *
178
+	 * @var boolean
179
+	 */
180
+	protected $_is_caf = false;
181
+
182
+
183
+	/**
184
+	 * @Constructor
185
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
186
+	 * @throws InvalidArgumentException
187
+	 * @throws InvalidDataTypeException
188
+	 * @throws InvalidInterfaceException
189
+	 * @throws ReflectionException
190
+	 */
191
+	public function __construct($routing = true)
192
+	{
193
+		$this->loader = LoaderFactory::getLoader();
194
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
195
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
196
+			$this->_is_caf = true;
197
+		}
198
+		$this->_yes_no_values = array(
199
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
200
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
201
+		);
202
+		// set the _req_data property.
203
+		$this->_req_data = array_merge($_GET, $_POST);
204
+		// routing enabled?
205
+		$this->_routing = $routing;
206
+	}
207
+
208
+
209
+	/**
210
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
211
+	 * for child classes that needed to set properties prior to these methods getting called,
212
+	 * but also needed the parent class to have its construction completed as well.
213
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
214
+	 * and any complex initialization logic should only run after instantiation is complete.
215
+	 *
216
+	 * This method gets called immediately after construction from within
217
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
218
+	 *
219
+	 * @throws EE_Error
220
+	 * @throws InvalidArgumentException
221
+	 * @throws InvalidDataTypeException
222
+	 * @throws InvalidInterfaceException
223
+	 * @throws ReflectionException
224
+	 * @since $VID:$
225
+	 */
226
+	public function initializePage()
227
+	{
228
+		// set initial page props (child method)
229
+		$this->_init_page_props();
230
+		// set global defaults
231
+		$this->_set_defaults();
232
+		// set early because incoming requests could be ajax related and we need to register those hooks.
233
+		$this->_global_ajax_hooks();
234
+		$this->_ajax_hooks();
235
+		// other_page_hooks have to be early too.
236
+		$this->_do_other_page_hooks();
237
+		// This just allows us to have extending classes do something specific
238
+		// before the parent constructor runs _page_setup().
239
+		if (method_exists($this, '_before_page_setup')) {
240
+			$this->_before_page_setup();
241
+		}
242
+		// set up page dependencies
243
+		$this->_page_setup();
244
+	}
245
+
246
+
247
+	/**
248
+	 * _init_page_props
249
+	 * Child classes use to set at least the following properties:
250
+	 * $page_slug.
251
+	 * $page_label.
252
+	 *
253
+	 * @abstract
254
+	 * @return void
255
+	 */
256
+	abstract protected function _init_page_props();
257
+
258
+
259
+	/**
260
+	 * _ajax_hooks
261
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
262
+	 * Note: within the ajax callback methods.
263
+	 *
264
+	 * @abstract
265
+	 * @return void
266
+	 */
267
+	abstract protected function _ajax_hooks();
268
+
269
+
270
+	/**
271
+	 * _define_page_props
272
+	 * child classes define page properties in here.  Must include at least:
273
+	 * $_admin_base_url = base_url for all admin pages
274
+	 * $_admin_page_title = default admin_page_title for admin pages
275
+	 * $_labels = array of default labels for various automatically generated elements:
276
+	 *    array(
277
+	 *        'buttons' => array(
278
+	 *            'add' => esc_html__('label for add new button'),
279
+	 *            'edit' => esc_html__('label for edit button'),
280
+	 *            'delete' => esc_html__('label for delete button')
281
+	 *            )
282
+	 *        )
283
+	 *
284
+	 * @abstract
285
+	 * @return void
286
+	 */
287
+	abstract protected function _define_page_props();
288
+
289
+
290
+	/**
291
+	 * _set_page_routes
292
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
293
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
294
+	 * have a 'default' route. Here's the format
295
+	 * $this->_page_routes = array(
296
+	 *        'default' => array(
297
+	 *            'func' => '_default_method_handling_route',
298
+	 *            'args' => array('array','of','args'),
299
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
300
+	 *            ajax request, backend processing)
301
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
302
+	 *            headers route after.  The string you enter here should match the defined route reference for a
303
+	 *            headers sent route.
304
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
305
+	 *            this route.
306
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
307
+	 *            checks).
308
+	 *        ),
309
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
310
+	 *        handling method.
311
+	 *        )
312
+	 * )
313
+	 *
314
+	 * @abstract
315
+	 * @return void
316
+	 */
317
+	abstract protected function _set_page_routes();
318
+
319
+
320
+	/**
321
+	 * _set_page_config
322
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
323
+	 * array corresponds to the page_route for the loaded page. Format:
324
+	 * $this->_page_config = array(
325
+	 *        'default' => array(
326
+	 *            'labels' => array(
327
+	 *                'buttons' => array(
328
+	 *                    'add' => esc_html__('label for adding item'),
329
+	 *                    'edit' => esc_html__('label for editing item'),
330
+	 *                    'delete' => esc_html__('label for deleting item')
331
+	 *                ),
332
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
333
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
334
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
335
+	 *            _define_page_props() method
336
+	 *            'nav' => array(
337
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
338
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
339
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
340
+	 *                'order' => 10, //required to indicate tab position.
341
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
342
+	 *                displayed then add this parameter.
343
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
344
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
345
+	 *            metaboxes set for eventespresso admin pages.
346
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
347
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
348
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
349
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
350
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
351
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
352
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
353
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
354
+	 *            want to display.
355
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
356
+	 *                'tab_id' => array(
357
+	 *                    'title' => 'tab_title',
358
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
359
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
360
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
361
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
362
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
363
+	 *                    attempt to use the callback which should match the name of a method in the class
364
+	 *                    ),
365
+	 *                'tab2_id' => array(
366
+	 *                    'title' => 'tab2 title',
367
+	 *                    'filename' => 'file_name_2'
368
+	 *                    'callback' => 'callback_method_for_content',
369
+	 *                 ),
370
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
371
+	 *            help tab area on an admin page. @link
372
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
373
+	 *            'help_tour' => array(
374
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
375
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
376
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
377
+	 *            ),
378
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
379
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
380
+	 *            just set
381
+	 *            'require_nonce' to FALSE
382
+	 *            )
383
+	 * )
384
+	 *
385
+	 * @abstract
386
+	 * @return void
387
+	 */
388
+	abstract protected function _set_page_config();
389
+
390
+
391
+
392
+
393
+
394
+	/** end sample help_tour methods **/
395
+	/**
396
+	 * _add_screen_options
397
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
398
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
399
+	 * to a particular view.
400
+	 *
401
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
402
+	 *         see also WP_Screen object documents...
403
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
404
+	 * @abstract
405
+	 * @return void
406
+	 */
407
+	abstract protected function _add_screen_options();
408
+
409
+
410
+	/**
411
+	 * _add_feature_pointers
412
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
413
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
414
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
415
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
416
+	 * extended) also see:
417
+	 *
418
+	 * @link   http://eamann.com/tech/wordpress-portland/
419
+	 * @abstract
420
+	 * @return void
421
+	 */
422
+	abstract protected function _add_feature_pointers();
423
+
424
+
425
+	/**
426
+	 * load_scripts_styles
427
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
428
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
429
+	 * scripts/styles per view by putting them in a dynamic function in this format
430
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
431
+	 *
432
+	 * @abstract
433
+	 * @return void
434
+	 */
435
+	abstract public function load_scripts_styles();
436
+
437
+
438
+	/**
439
+	 * admin_init
440
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
441
+	 * all pages/views loaded by child class.
442
+	 *
443
+	 * @abstract
444
+	 * @return void
445
+	 */
446
+	abstract public function admin_init();
447
+
448
+
449
+	/**
450
+	 * admin_notices
451
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
452
+	 * all pages/views loaded by child class.
453
+	 *
454
+	 * @abstract
455
+	 * @return void
456
+	 */
457
+	abstract public function admin_notices();
458
+
459
+
460
+	/**
461
+	 * admin_footer_scripts
462
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
463
+	 * will apply to all pages/views loaded by child class.
464
+	 *
465
+	 * @return void
466
+	 */
467
+	abstract public function admin_footer_scripts();
468
+
469
+
470
+	/**
471
+	 * admin_footer
472
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
473
+	 * apply to all pages/views loaded by child class.
474
+	 *
475
+	 * @return void
476
+	 */
477
+	public function admin_footer()
478
+	{
479
+	}
480
+
481
+
482
+	/**
483
+	 * _global_ajax_hooks
484
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
485
+	 * Note: within the ajax callback methods.
486
+	 *
487
+	 * @abstract
488
+	 * @return void
489
+	 */
490
+	protected function _global_ajax_hooks()
491
+	{
492
+		// for lazy loading of metabox content
493
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
494
+
495
+		add_action(
496
+			'wp_ajax_espresso_hide_status_change_notice',
497
+			[$this, 'hideStatusChangeNotice']
498
+		);
499
+		add_action(
500
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
501
+			[$this, 'hideStatusChangeNotice']
502
+		);
503
+	}
504
+
505
+
506
+	public function ajax_metabox_content()
507
+	{
508
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
509
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
510
+		EE_Admin_Page::cached_rss_display($contentid, $url);
511
+		wp_die();
512
+	}
513
+
514
+
515
+	public function hideStatusChangeNotice()
516
+	{
517
+		$response = [];
518
+		try {
519
+			/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
520
+			$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
521
+			$response['success'] = $status_change_notice->dismiss() > -1;
522
+		} catch (Exception $exception) {
523
+			$response['errors'] = $exception->getMessage();
524
+		}
525
+		echo wp_json_encode($response);
526
+		exit();
527
+	}
528
+
529
+
530
+	/**
531
+	 * _page_setup
532
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
533
+	 * doesn't match the object.
534
+	 *
535
+	 * @final
536
+	 * @return void
537
+	 * @throws EE_Error
538
+	 * @throws InvalidArgumentException
539
+	 * @throws ReflectionException
540
+	 * @throws InvalidDataTypeException
541
+	 * @throws InvalidInterfaceException
542
+	 */
543
+	final protected function _page_setup()
544
+	{
545
+		// requires?
546
+		// admin_init stuff - global - we're setting this REALLY early
547
+		// so if EE_Admin pages have to hook into other WP pages they can.
548
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
549
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
550
+		// next verify if we need to load anything...
551
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
552
+		$this->page_folder = strtolower(
553
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
554
+		);
555
+		global $ee_menu_slugs;
556
+		$ee_menu_slugs = (array) $ee_menu_slugs;
557
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
558
+			return;
559
+		}
560
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
561
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
562
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
563
+				? $this->_req_data['action2']
564
+				: $this->_req_data['action'];
565
+		}
566
+		// then set blank or -1 action values to 'default'
567
+		$this->_req_action = isset($this->_req_data['action'])
568
+							 && ! empty($this->_req_data['action'])
569
+							 && $this->_req_data['action'] !== '-1'
570
+			? sanitize_key($this->_req_data['action'])
571
+			: 'default';
572
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
573
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
574
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
575
+			? $this->_req_data['route'] : $this->_req_action;
576
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
577
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
578
+			? $this->_req_data['route']
579
+			: $this->_req_action;
580
+		$this->_current_view = $this->_req_action;
581
+		$this->_req_nonce = $this->_req_action . '_nonce';
582
+		$this->_define_page_props();
583
+		$this->_current_page_view_url = add_query_arg(
584
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
585
+			$this->_admin_base_url
586
+		);
587
+		// default things
588
+		$this->_default_espresso_metaboxes = array(
589
+			'_espresso_news_post_box',
590
+			'_espresso_links_post_box',
591
+			'_espresso_ratings_request',
592
+			'_espresso_sponsors_post_box',
593
+		);
594
+		// set page configs
595
+		$this->_set_page_routes();
596
+		$this->_set_page_config();
597
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
598
+		if (isset($this->_req_data['wp_referer'])) {
599
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
600
+		}
601
+		// for caffeinated and other extended functionality.
602
+		//  If there is a _extend_page_config method
603
+		// then let's run that to modify the all the various page configuration arrays
604
+		if (method_exists($this, '_extend_page_config')) {
605
+			$this->_extend_page_config();
606
+		}
607
+		// for CPT and other extended functionality.
608
+		// If there is an _extend_page_config_for_cpt
609
+		// then let's run that to modify all the various page configuration arrays.
610
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
611
+			$this->_extend_page_config_for_cpt();
612
+		}
613
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
614
+		$this->_page_routes = apply_filters(
615
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
616
+			$this->_page_routes,
617
+			$this
618
+		);
619
+		$this->_page_config = apply_filters(
620
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
621
+			$this->_page_config,
622
+			$this
623
+		);
624
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
625
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
626
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
627
+			add_action(
628
+				'AHEE__EE_Admin_Page__route_admin_request',
629
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
630
+				10,
631
+				2
632
+			);
633
+		}
634
+		// next route only if routing enabled
635
+		if ($this->_routing && ! defined('DOING_AJAX')) {
636
+			$this->_verify_routes();
637
+			// next let's just check user_access and kill if no access
638
+			$this->check_user_access();
639
+			if ($this->_is_UI_request) {
640
+				// admin_init stuff - global, all views for this page class, specific view
641
+				add_action('admin_init', array($this, 'admin_init'), 10);
642
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
643
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
644
+				}
645
+			} else {
646
+				// hijack regular WP loading and route admin request immediately
647
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
648
+				$this->route_admin_request();
649
+			}
650
+		}
651
+	}
652
+
653
+
654
+	/**
655
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
656
+	 *
657
+	 * @return void
658
+	 * @throws EE_Error
659
+	 */
660
+	private function _do_other_page_hooks()
661
+	{
662
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
663
+		foreach ($registered_pages as $page) {
664
+			// now let's setup the file name and class that should be present
665
+			$classname = str_replace('.class.php', '', $page);
666
+			// autoloaders should take care of loading file
667
+			if (! class_exists($classname)) {
668
+				$error_msg[] = sprintf(
669
+					esc_html__(
670
+						'Something went wrong with loading the %s admin hooks page.',
671
+						'event_espresso'
672
+					),
673
+					$page
674
+				);
675
+				$error_msg[] = $error_msg[0]
676
+							   . "\r\n"
677
+							   . sprintf(
678
+								   esc_html__(
679
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
680
+									   'event_espresso'
681
+								   ),
682
+								   $page,
683
+								   '<br />',
684
+								   '<strong>' . $classname . '</strong>'
685
+							   );
686
+				throw new EE_Error(implode('||', $error_msg));
687
+			}
688
+			// // notice we are passing the instance of this class to the hook object.
689
+			$this->loader->getShared($classname, [$this]);
690
+		}
691
+	}
692
+
693
+
694
+	/**
695
+	 * @throws DomainException
696
+	 * @throws EE_Error
697
+	 * @throws InvalidArgumentException
698
+	 * @throws InvalidDataTypeException
699
+	 * @throws InvalidInterfaceException
700
+	 * @throws ReflectionException
701
+	 * @since $VID:$
702
+	 */
703
+	public function load_page_dependencies()
704
+	{
705
+		try {
706
+			$this->_load_page_dependencies();
707
+		} catch (EE_Error $e) {
708
+			$e->get_error();
709
+		}
710
+	}
711
+
712
+
713
+	/**
714
+	 * load_page_dependencies
715
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
716
+	 *
717
+	 * @return void
718
+	 * @throws DomainException
719
+	 * @throws EE_Error
720
+	 * @throws InvalidArgumentException
721
+	 * @throws InvalidDataTypeException
722
+	 * @throws InvalidInterfaceException
723
+	 * @throws ReflectionException
724
+	 */
725
+	protected function _load_page_dependencies()
726
+	{
727
+		// let's set the current_screen and screen options to override what WP set
728
+		$this->_current_screen = get_current_screen();
729
+		// load admin_notices - global, page class, and view specific
730
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
731
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
732
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
733
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
734
+		}
735
+		// load network admin_notices - global, page class, and view specific
736
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
737
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
738
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
739
+		}
740
+		// this will save any per_page screen options if they are present
741
+		$this->_set_per_page_screen_options();
742
+		// setup list table properties
743
+		$this->_set_list_table();
744
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
745
+		// However in some cases the metaboxes will need to be added within a route handling callback.
746
+		$this->_add_registered_meta_boxes();
747
+		$this->_add_screen_columns();
748
+		// add screen options - global, page child class, and view specific
749
+		$this->_add_global_screen_options();
750
+		$this->_add_screen_options();
751
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
752
+		if (method_exists($this, $add_screen_options)) {
753
+			$this->{$add_screen_options}();
754
+		}
755
+		// add help tab(s) and tours- set via page_config and qtips.
756
+		// $this->_add_help_tour();
757
+		$this->_add_help_tabs();
758
+		$this->_add_qtips();
759
+		// add feature_pointers - global, page child class, and view specific
760
+		$this->_add_feature_pointers();
761
+		$this->_add_global_feature_pointers();
762
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
763
+		if (method_exists($this, $add_feature_pointer)) {
764
+			$this->{$add_feature_pointer}();
765
+		}
766
+		// enqueue scripts/styles - global, page class, and view specific
767
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
768
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
769
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
770
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
771
+		}
772
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
773
+		// admin_print_footer_scripts - global, page child class, and view specific.
774
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
775
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
776
+		// is a good use case. Notice the late priority we're giving these
777
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
778
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
779
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
780
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
781
+		}
782
+		// admin footer scripts
783
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
784
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
785
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
786
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
787
+		}
788
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
789
+		// targeted hook
790
+		do_action(
791
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
792
+		);
793
+	}
794
+
795
+
796
+	/**
797
+	 * _set_defaults
798
+	 * This sets some global defaults for class properties.
799
+	 */
800
+	private function _set_defaults()
801
+	{
802
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
803
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
804
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
805
+		$this->_page_config = $this->_default_route_query_args = array();
806
+		$this->_default_nav_tab_name = 'overview';
807
+		// init template args
808
+		$this->_template_args = array(
809
+			'admin_page_header'  => '',
810
+			'admin_page_content' => '',
811
+			'post_body_content'  => '',
812
+			'before_list_table'  => '',
813
+			'after_list_table'   => '',
814
+		);
815
+	}
816
+
817
+
818
+	/**
819
+	 * route_admin_request
820
+	 *
821
+	 * @see    _route_admin_request()
822
+	 * @return exception|void error
823
+	 * @throws InvalidArgumentException
824
+	 * @throws InvalidInterfaceException
825
+	 * @throws InvalidDataTypeException
826
+	 * @throws EE_Error
827
+	 * @throws ReflectionException
828
+	 */
829
+	public function route_admin_request()
830
+	{
831
+		try {
832
+			$this->_route_admin_request();
833
+		} catch (EE_Error $e) {
834
+			$e->get_error();
835
+		}
836
+	}
837
+
838
+
839
+	public function set_wp_page_slug($wp_page_slug)
840
+	{
841
+		$this->_wp_page_slug = $wp_page_slug;
842
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
843
+		if (is_network_admin()) {
844
+			$this->_wp_page_slug .= '-network';
845
+		}
846
+	}
847
+
848
+
849
+	/**
850
+	 * _verify_routes
851
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
852
+	 * we know if we need to drop out.
853
+	 *
854
+	 * @return bool
855
+	 * @throws EE_Error
856
+	 */
857
+	protected function _verify_routes()
858
+	{
859
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
860
+			return false;
861
+		}
862
+		$this->_route = false;
863
+		// check that the page_routes array is not empty
864
+		if (empty($this->_page_routes)) {
865
+			// user error msg
866
+			$error_msg = sprintf(
867
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
868
+				$this->_admin_page_title
869
+			);
870
+			// developer error msg
871
+			$error_msg .= '||' . $error_msg
872
+						  . esc_html__(
873
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
874
+							  'event_espresso'
875
+						  );
876
+			throw new EE_Error($error_msg);
877
+		}
878
+		// and that the requested page route exists
879
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
880
+			$this->_route = $this->_page_routes[ $this->_req_action ];
881
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
882
+				? $this->_page_config[ $this->_req_action ] : array();
883
+		} else {
884
+			// user error msg
885
+			$error_msg = sprintf(
886
+				esc_html__(
887
+					'The requested page route does not exist for the %s admin page.',
888
+					'event_espresso'
889
+				),
890
+				$this->_admin_page_title
891
+			);
892
+			// developer error msg
893
+			$error_msg .= '||' . $error_msg
894
+						  . sprintf(
895
+							  esc_html__(
896
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
897
+								  'event_espresso'
898
+							  ),
899
+							  $this->_req_action
900
+						  );
901
+			throw new EE_Error($error_msg);
902
+		}
903
+		// and that a default route exists
904
+		if (! array_key_exists('default', $this->_page_routes)) {
905
+			// user error msg
906
+			$error_msg = sprintf(
907
+				esc_html__(
908
+					'A default page route has not been set for the % admin page.',
909
+					'event_espresso'
910
+				),
911
+				$this->_admin_page_title
912
+			);
913
+			// developer error msg
914
+			$error_msg .= '||' . $error_msg
915
+						  . esc_html__(
916
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
917
+							  'event_espresso'
918
+						  );
919
+			throw new EE_Error($error_msg);
920
+		}
921
+
922
+		// first lets' catch if the UI request has EVER been set.
923
+		if ($this->_is_UI_request === null) {
924
+			// lets set if this is a UI request or not.
925
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
926
+			// wait a minute... we might have a noheader in the route array
927
+			$this->_is_UI_request = is_array($this->_route)
928
+									&& isset($this->_route['noheader'])
929
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
930
+		}
931
+		$this->_set_current_labels();
932
+		return true;
933
+	}
934
+
935
+
936
+	/**
937
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
938
+	 *
939
+	 * @param  string $route the route name we're verifying
940
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
941
+	 * @throws EE_Error
942
+	 */
943
+	protected function _verify_route($route)
944
+	{
945
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
946
+			return true;
947
+		}
948
+		// user error msg
949
+		$error_msg = sprintf(
950
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
951
+			$this->_admin_page_title
952
+		);
953
+		// developer error msg
954
+		$error_msg .= '||' . $error_msg
955
+					  . sprintf(
956
+						  esc_html__(
957
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
958
+							  'event_espresso'
959
+						  ),
960
+						  $route
961
+					  );
962
+		throw new EE_Error($error_msg);
963
+	}
964
+
965
+
966
+	/**
967
+	 * perform nonce verification
968
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
969
+	 * using this method (and save retyping!)
970
+	 *
971
+	 * @param string $nonce     The nonce sent
972
+	 * @param string $nonce_ref The nonce reference string (name0)
973
+	 * @return void
974
+	 * @throws EE_Error
975
+	 * @throws InvalidArgumentException
976
+	 * @throws InvalidDataTypeException
977
+	 * @throws InvalidInterfaceException
978
+	 */
979
+	protected function _verify_nonce($nonce, $nonce_ref)
980
+	{
981
+		// verify nonce against expected value
982
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
983
+			// these are not the droids you are looking for !!!
984
+			$msg = sprintf(
985
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
986
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
987
+				'</a>'
988
+			);
989
+			if (WP_DEBUG) {
990
+				$msg .= "\n  "
991
+						. sprintf(
992
+							esc_html__(
993
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
994
+								'event_espresso'
995
+							),
996
+							EE_Admin_Page::class
997
+						);
998
+			}
999
+			if (! defined('DOING_AJAX')) {
1000
+				wp_die($msg);
1001
+			} else {
1002
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1003
+				$this->_return_json();
1004
+			}
1005
+		}
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * _route_admin_request()
1011
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1012
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1013
+	 * in the page routes and then will try to load the corresponding method.
1014
+	 *
1015
+	 * @return void
1016
+	 * @throws EE_Error
1017
+	 * @throws InvalidArgumentException
1018
+	 * @throws InvalidDataTypeException
1019
+	 * @throws InvalidInterfaceException
1020
+	 * @throws ReflectionException
1021
+	 */
1022
+	protected function _route_admin_request()
1023
+	{
1024
+		if (! $this->_is_UI_request) {
1025
+			$this->_verify_routes();
1026
+		}
1027
+		$nonce_check = isset($this->_route_config['require_nonce'])
1028
+			? $this->_route_config['require_nonce']
1029
+			: true;
1030
+		if ($this->_req_action !== 'default' && $nonce_check) {
1031
+			// set nonce from post data
1032
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
1033
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1034
+				: '';
1035
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1036
+		}
1037
+		// set the nav_tabs array but ONLY if this is  UI_request
1038
+		if ($this->_is_UI_request) {
1039
+			$this->_set_nav_tabs();
1040
+		}
1041
+		// grab callback function
1042
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1043
+		// check if callback has args
1044
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1045
+		$error_msg = '';
1046
+		// action right before calling route
1047
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1048
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1049
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1050
+		}
1051
+		// right before calling the route, let's remove _wp_http_referer from the
1052
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1053
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1054
+			'_wp_http_referer',
1055
+			wp_unslash($_SERVER['REQUEST_URI'])
1056
+		);
1057
+		if (! empty($func)) {
1058
+			if (is_array($func)) {
1059
+				list($class, $method) = $func;
1060
+			} elseif (strpos($func, '::') !== false) {
1061
+				list($class, $method) = explode('::', $func);
1062
+			} else {
1063
+				$class = $this;
1064
+				$method = $func;
1065
+			}
1066
+			if (! (is_object($class) && $class === $this)) {
1067
+				// send along this admin page object for access by addons.
1068
+				$args['admin_page_object'] = $this;
1069
+			}
1070
+			// is it a method on a class that doesn't work?
1071
+			if (
1072
+				((method_exists($class, $method)
1073
+				  && call_user_func_array(array($class, $method), $args) === false)
1074
+				 && (// is it a standalone function that doesn't work?
1075
+					 function_exists($method)
1076
+					 && call_user_func_array(
1077
+						 $func,
1078
+						 array_merge(array('admin_page_object' => $this), $args)
1079
+					 ) === false
1080
+				 )) || (// is it neither a class method NOR a standalone function?
1081
+					! function_exists($method)
1082
+					&& ! method_exists($class, $method)
1083
+				)
1084
+			) {
1085
+				// user error msg
1086
+				$error_msg = esc_html__(
1087
+					'An error occurred. The  requested page route could not be found.',
1088
+					'event_espresso'
1089
+				);
1090
+				// developer error msg
1091
+				$error_msg .= '||';
1092
+				$error_msg .= sprintf(
1093
+					esc_html__(
1094
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1095
+						'event_espresso'
1096
+					),
1097
+					$method
1098
+				);
1099
+			}
1100
+			if (! empty($error_msg)) {
1101
+				throw new EE_Error($error_msg);
1102
+			}
1103
+		}
1104
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1105
+		// then we need to reset the routing properties to the new route.
1106
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1107
+		if (
1108
+			$this->_is_UI_request === false
1109
+			&& is_array($this->_route)
1110
+			&& ! empty($this->_route['headers_sent_route'])
1111
+		) {
1112
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1113
+		}
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * This method just allows the resetting of page properties in the case where a no headers
1119
+	 * route redirects to a headers route in its route config.
1120
+	 *
1121
+	 * @since   4.3.0
1122
+	 * @param  string $new_route New (non header) route to redirect to.
1123
+	 * @return   void
1124
+	 * @throws ReflectionException
1125
+	 * @throws InvalidArgumentException
1126
+	 * @throws InvalidInterfaceException
1127
+	 * @throws InvalidDataTypeException
1128
+	 * @throws EE_Error
1129
+	 */
1130
+	protected function _reset_routing_properties($new_route)
1131
+	{
1132
+		$this->_is_UI_request = true;
1133
+		// now we set the current route to whatever the headers_sent_route is set at
1134
+		$this->_req_data['action'] = $new_route;
1135
+		// rerun page setup
1136
+		$this->_page_setup();
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * _add_query_arg
1142
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1143
+	 *(internally just uses EEH_URL's function with the same name)
1144
+	 *
1145
+	 * @param array  $args
1146
+	 * @param string $url
1147
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1148
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1149
+	 *                                        Example usage: If the current page is:
1150
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1151
+	 *                                        &action=default&event_id=20&month_range=March%202015
1152
+	 *                                        &_wpnonce=5467821
1153
+	 *                                        and you call:
1154
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1155
+	 *                                        array(
1156
+	 *                                        'action' => 'resend_something',
1157
+	 *                                        'page=>espresso_registrations'
1158
+	 *                                        ),
1159
+	 *                                        $some_url,
1160
+	 *                                        true
1161
+	 *                                        );
1162
+	 *                                        It will produce a url in this structure:
1163
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1164
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1165
+	 *                                        month_range]=March%202015
1166
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1167
+	 * @return string
1168
+	 */
1169
+	public static function add_query_args_and_nonce(
1170
+		$args = array(),
1171
+		$url = '',
1172
+		$sticky = false,
1173
+		$exclude_nonce = false
1174
+	) {
1175
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1176
+		if ($sticky) {
1177
+			$request = $_REQUEST;
1178
+			unset($request['_wp_http_referer'], $request['wp_referer']);
1179
+			foreach ($request as $key => $value) {
1180
+				// do not add nonces
1181
+				if (strpos($key, 'nonce') !== false) {
1182
+					continue;
1183
+				}
1184
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1185
+			}
1186
+		}
1187
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1188
+	}
1189
+
1190
+
1191
+	/**
1192
+	 * This returns a generated link that will load the related help tab.
1193
+	 *
1194
+	 * @param  string $help_tab_id the id for the connected help tab
1195
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1196
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1197
+	 * @uses EEH_Template::get_help_tab_link()
1198
+	 * @return string              generated link
1199
+	 */
1200
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1201
+	{
1202
+		return EEH_Template::get_help_tab_link(
1203
+			$help_tab_id,
1204
+			$this->page_slug,
1205
+			$this->_req_action,
1206
+			$icon_style,
1207
+			$help_text
1208
+		);
1209
+	}
1210
+
1211
+
1212
+	/**
1213
+	 * _add_help_tabs
1214
+	 * Note child classes define their help tabs within the page_config array.
1215
+	 *
1216
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1217
+	 * @return void
1218
+	 * @throws DomainException
1219
+	 * @throws EE_Error
1220
+	 * @throws ReflectionException
1221
+	 */
1222
+	protected function _add_help_tabs()
1223
+	{
1224
+		$tour_buttons = '';
1225
+		if (isset($this->_page_config[ $this->_req_action ])) {
1226
+			$config = $this->_page_config[ $this->_req_action ];
1227
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1228
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1229
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1230
+			//     $tb = array();
1231
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1232
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1233
+			//         // if this is the end tour then we don't need to setup a button
1234
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1235
+			//             continue;
1236
+			//         }
1237
+			//         $tb[] = '<button id="trigger-tour-'
1238
+			//                 . $tour->get_slug()
1239
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1240
+			//                 . $tour->get_label()
1241
+			//                 . '</button>';
1242
+			//     }
1243
+			//     $tour_buttons .= implode('<br />', $tb);
1244
+			//     $tour_buttons .= '</div></div>';
1245
+			// }
1246
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1247
+			if (is_array($config) && isset($config['help_sidebar'])) {
1248
+				// check that the callback given is valid
1249
+				if (! method_exists($this, $config['help_sidebar'])) {
1250
+					throw new EE_Error(
1251
+						sprintf(
1252
+							esc_html__(
1253
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1254
+								'event_espresso'
1255
+							),
1256
+							$config['help_sidebar'],
1257
+							get_class($this)
1258
+						)
1259
+					);
1260
+				}
1261
+				$content = apply_filters(
1262
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1263
+					$this->{$config['help_sidebar']}()
1264
+				);
1265
+				$content .= $tour_buttons; // add help tour buttons.
1266
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1267
+				$this->_current_screen->set_help_sidebar($content);
1268
+			}
1269
+			// if there ARE tour buttons...
1270
+			if (! empty($tour_buttons)) {
1271
+				// if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1272
+				if (! isset($config['help_sidebar'])) {
1273
+					$this->_current_screen->set_help_sidebar($tour_buttons);
1274
+				}
1275
+				// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1276
+				if (! isset($config['help_tabs'])) {
1277
+					$_ht['id'] = $this->page_slug;
1278
+					$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1279
+					$_ht['content'] = '<p>'
1280
+									  . esc_html__(
1281
+										  'The buttons to the right allow you to start/restart any help tours available for this page',
1282
+										  'event_espresso'
1283
+									  ) . '</p>';
1284
+					$this->_current_screen->add_help_tab($_ht);
1285
+				}
1286
+			}
1287
+			if (! isset($config['help_tabs'])) {
1288
+				return;
1289
+			} //no help tabs for this route
1290
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1291
+				// we're here so there ARE help tabs!
1292
+				// make sure we've got what we need
1293
+				if (! isset($cfg['title'])) {
1294
+					throw new EE_Error(
1295
+						esc_html__(
1296
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1297
+							'event_espresso'
1298
+						)
1299
+					);
1300
+				}
1301
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1302
+					throw new EE_Error(
1303
+						esc_html__(
1304
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1305
+							'event_espresso'
1306
+						)
1307
+					);
1308
+				}
1309
+				// first priority goes to content.
1310
+				if (! empty($cfg['content'])) {
1311
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1312
+					// second priority goes to filename
1313
+				} elseif (! empty($cfg['filename'])) {
1314
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1315
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1316
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1317
+															 . basename($this->_get_dir())
1318
+															 . '/help_tabs/'
1319
+															 . $cfg['filename']
1320
+															 . '.help_tab.php' : $file_path;
1321
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1322
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1323
+						EE_Error::add_error(
1324
+							sprintf(
1325
+								esc_html__(
1326
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1327
+									'event_espresso'
1328
+								),
1329
+								$tab_id,
1330
+								key($config),
1331
+								$file_path
1332
+							),
1333
+							__FILE__,
1334
+							__FUNCTION__,
1335
+							__LINE__
1336
+						);
1337
+						return;
1338
+					}
1339
+					$template_args['admin_page_obj'] = $this;
1340
+					$content = EEH_Template::display_template(
1341
+						$file_path,
1342
+						$template_args,
1343
+						true
1344
+					);
1345
+				} else {
1346
+					$content = '';
1347
+				}
1348
+				// check if callback is valid
1349
+				if (
1350
+					empty($content) && (
1351
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1352
+					)
1353
+				) {
1354
+					EE_Error::add_error(
1355
+						sprintf(
1356
+							esc_html__(
1357
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1358
+								'event_espresso'
1359
+							),
1360
+							$cfg['title']
1361
+						),
1362
+						__FILE__,
1363
+						__FUNCTION__,
1364
+						__LINE__
1365
+					);
1366
+					return;
1367
+				}
1368
+				// setup config array for help tab method
1369
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1370
+				$_ht = array(
1371
+					'id'       => $id,
1372
+					'title'    => $cfg['title'],
1373
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1374
+					'content'  => $content,
1375
+				);
1376
+				$this->_current_screen->add_help_tab($_ht);
1377
+			}
1378
+		}
1379
+	}
1380
+
1381
+
1382
+	/**
1383
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1384
+	 * an array with properties for setting up usage of the joyride plugin
1385
+	 *
1386
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1387
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1388
+	 *         _set_page_config() comments
1389
+	 * @return void
1390
+	 * @throws EE_Error
1391
+	 * @throws InvalidArgumentException
1392
+	 * @throws InvalidDataTypeException
1393
+	 * @throws InvalidInterfaceException
1394
+	 * @throws ReflectionException
1395
+	 */
1396
+	protected function _add_help_tour()
1397
+	{
1398
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1399
+		// $tours = array();
1400
+		// $this->_help_tour = array();
1401
+		// // exit early if help tours are turned off globally
1402
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1403
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1404
+		// ) {
1405
+		//     return;
1406
+		// }
1407
+		// // loop through _page_config to find any help_tour defined
1408
+		// foreach ($this->_page_config as $route => $config) {
1409
+		//     // we're only going to set things up for this route
1410
+		//     if ($route !== $this->_req_action) {
1411
+		//         continue;
1412
+		//     }
1413
+		//     if (isset($config['help_tour'])) {
1414
+		//         foreach ($config['help_tour'] as $tour) {
1415
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1416
+		//             // let's see if we can get that file...
1417
+		//             // if not its possible this is a decaf route not set in caffeinated
1418
+		//             // so lets try and get the caffeinated equivalent
1419
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1420
+		//                                                      . basename($this->_get_dir())
1421
+		//                                                      . '/help_tours/'
1422
+		//                                                      . $tour
1423
+		//                                                      . '.class.php' : $file_path;
1424
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1425
+		//             if (! is_readable($file_path)) {
1426
+		//                 EE_Error::add_error(
1427
+		//                     sprintf(
1428
+		//                         esc_html__(
1429
+		//                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1430
+		//                             'event_espresso'
1431
+		//                         ),
1432
+		//                         $file_path,
1433
+		//                         $tour
1434
+		//                     ),
1435
+		//                     __FILE__,
1436
+		//                     __FUNCTION__,
1437
+		//                     __LINE__
1438
+		//                 );
1439
+		//                 return;
1440
+		//             }
1441
+		//             require_once $file_path;
1442
+		//             if (! class_exists($tour)) {
1443
+		//                 $error_msg[] = sprintf(
1444
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1445
+		//                     $tour
1446
+		//                 );
1447
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1448
+		//                                . sprintf(
1449
+		//                                    esc_html__(
1450
+		//                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1451
+		//                                        'event_espresso'
1452
+		//                                    ),
1453
+		//                                    $tour,
1454
+		//                                    '<br />',
1455
+		//                                    $tour,
1456
+		//                                    $this->_req_action,
1457
+		//                                    get_class($this)
1458
+		//                                );
1459
+		//                 throw new EE_Error(implode('||', $error_msg));
1460
+		//             }
1461
+		//             $tour_obj = new $tour($this->_is_caf);
1462
+		//             $tours[] = $tour_obj;
1463
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1464
+		//         }
1465
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1466
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1467
+		//         $tours[] = $end_stop_tour;
1468
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1469
+		//     }
1470
+		// }
1471
+		//
1472
+		// if (! empty($tours)) {
1473
+		//     $this->_help_tour['tours'] = $tours;
1474
+		// }
1475
+		// // that's it!  Now that the $_help_tours property is set (or not)
1476
+		// // the scripts and html should be taken care of automatically.
1477
+		//
1478
+		// /**
1479
+		//  * Allow extending the help tours variable.
1480
+		//  *
1481
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1482
+		//  */
1483
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1484
+	}
1485
+
1486
+
1487
+	/**
1488
+	 * This simply sets up any qtips that have been defined in the page config
1489
+	 *
1490
+	 * @return void
1491
+	 * @throws ReflectionException
1492
+	 * @throws EE_Error
1493
+	 */
1494
+	protected function _add_qtips()
1495
+	{
1496
+		if (isset($this->_route_config['qtips'])) {
1497
+			$qtips = (array) $this->_route_config['qtips'];
1498
+			// load qtip loader
1499
+			$path = array(
1500
+				$this->_get_dir() . '/qtips/',
1501
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1502
+			);
1503
+			$qtip_loader = EEH_Qtip_Loader::instance();
1504
+			if ($qtip_loader instanceof EEH_Qtip_Loader) {
1505
+				$qtip_loader->register($qtips, $path);
1506
+			}
1507
+		}
1508
+	}
1509
+
1510
+
1511
+	/**
1512
+	 * _set_nav_tabs
1513
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1514
+	 * wish to add additional tabs or modify accordingly.
1515
+	 *
1516
+	 * @return void
1517
+	 * @throws InvalidArgumentException
1518
+	 * @throws InvalidInterfaceException
1519
+	 * @throws InvalidDataTypeException
1520
+	 */
1521
+	protected function _set_nav_tabs()
1522
+	{
1523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1524
+		$i = 0;
1525
+		foreach ($this->_page_config as $slug => $config) {
1526
+			if (
1527
+				! is_array($config)
1528
+				|| (
1529
+					is_array($config)
1530
+					&& (
1531
+						(isset($config['nav']) && ! $config['nav'])
1532
+						|| ! isset($config['nav'])
1533
+					)
1534
+				)
1535
+			) {
1536
+				continue;
1537
+			}
1538
+			// no nav tab for this config
1539
+			// check for persistent flag
1540
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1541
+				// nav tab is only to appear when route requested.
1542
+				continue;
1543
+			}
1544
+			if (! $this->check_user_access($slug, true)) {
1545
+				// no nav tab because current user does not have access.
1546
+				continue;
1547
+			}
1548
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1549
+			$this->_nav_tabs[ $slug ] = array(
1550
+				'url'       => isset($config['nav']['url'])
1551
+					? $config['nav']['url']
1552
+					: EE_Admin_Page::add_query_args_and_nonce(
1553
+						array('action' => $slug),
1554
+						$this->_admin_base_url
1555
+					),
1556
+				'link_text' => isset($config['nav']['label'])
1557
+					? $config['nav']['label']
1558
+					: ucwords(
1559
+						str_replace('_', ' ', $slug)
1560
+					),
1561
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1562
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1563
+			);
1564
+			$i++;
1565
+		}
1566
+		// if $this->_nav_tabs is empty then lets set the default
1567
+		if (empty($this->_nav_tabs)) {
1568
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1569
+				'url'       => $this->_admin_base_url,
1570
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1571
+				'css_class' => 'nav-tab-active',
1572
+				'order'     => 10,
1573
+			);
1574
+		}
1575
+		// now let's sort the tabs according to order
1576
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1577
+	}
1578
+
1579
+
1580
+	/**
1581
+	 * _set_current_labels
1582
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1583
+	 * property array
1584
+	 *
1585
+	 * @return void
1586
+	 */
1587
+	private function _set_current_labels()
1588
+	{
1589
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1590
+			foreach ($this->_route_config['labels'] as $label => $text) {
1591
+				if (is_array($text)) {
1592
+					foreach ($text as $sublabel => $subtext) {
1593
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1594
+					}
1595
+				} else {
1596
+					$this->_labels[ $label ] = $text;
1597
+				}
1598
+			}
1599
+		}
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 *        verifies user access for this admin page
1605
+	 *
1606
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1607
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1608
+	 *                               return false if verify fail.
1609
+	 * @return bool
1610
+	 * @throws InvalidArgumentException
1611
+	 * @throws InvalidDataTypeException
1612
+	 * @throws InvalidInterfaceException
1613
+	 */
1614
+	public function check_user_access($route_to_check = '', $verify_only = false)
1615
+	{
1616
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1617
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1618
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1619
+					  && is_array(
1620
+						  $this->_page_routes[ $route_to_check ]
1621
+					  )
1622
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1623
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1624
+		if (empty($capability) && empty($route_to_check)) {
1625
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1626
+				: $this->_route['capability'];
1627
+		} else {
1628
+			$capability = empty($capability) ? 'manage_options' : $capability;
1629
+		}
1630
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1631
+		if (
1632
+			! defined('DOING_AJAX')
1633
+			&& (
1634
+				! function_exists('is_admin')
1635
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1636
+					$capability,
1637
+					$this->page_slug
1638
+					. '_'
1639
+					. $route_to_check,
1640
+					$id
1641
+				)
1642
+			)
1643
+		) {
1644
+			if ($verify_only) {
1645
+				return false;
1646
+			}
1647
+			if (is_user_logged_in()) {
1648
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1649
+			} else {
1650
+				return false;
1651
+			}
1652
+		}
1653
+		return true;
1654
+	}
1655
+
1656
+
1657
+	/**
1658
+	 * admin_init_global
1659
+	 * This runs all the code that we want executed within the WP admin_init hook.
1660
+	 * This method executes for ALL EE Admin pages.
1661
+	 *
1662
+	 * @return void
1663
+	 */
1664
+	public function admin_init_global()
1665
+	{
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 * wp_loaded_global
1671
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1672
+	 * EE_Admin page and will execute on every EE Admin Page load
1673
+	 *
1674
+	 * @return void
1675
+	 */
1676
+	public function wp_loaded()
1677
+	{
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * admin_notices
1683
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1684
+	 * ALL EE_Admin pages.
1685
+	 *
1686
+	 * @return void
1687
+	 */
1688
+	public function admin_notices_global()
1689
+	{
1690
+		$this->_display_no_javascript_warning();
1691
+		$this->_display_espresso_notices();
1692
+	}
1693
+
1694
+
1695
+	public function network_admin_notices_global()
1696
+	{
1697
+		$this->_display_no_javascript_warning();
1698
+		$this->_display_espresso_notices();
1699
+	}
1700
+
1701
+
1702
+	/**
1703
+	 * admin_footer_scripts_global
1704
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1705
+	 * will apply on ALL EE_Admin pages.
1706
+	 *
1707
+	 * @return void
1708
+	 */
1709
+	public function admin_footer_scripts_global()
1710
+	{
1711
+		$this->_add_admin_page_ajax_loading_img();
1712
+		$this->_add_admin_page_overlay();
1713
+		// if metaboxes are present we need to add the nonce field
1714
+		if (
1715
+			isset($this->_route_config['metaboxes'])
1716
+			|| isset($this->_route_config['list_table'])
1717
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1718
+		) {
1719
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1720
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1721
+		}
1722
+	}
1723
+
1724
+
1725
+	/**
1726
+	 * admin_footer_global
1727
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1728
+	 * This particular method will apply on ALL EE_Admin Pages.
1729
+	 *
1730
+	 * @return void
1731
+	 * @throws InvalidArgumentException
1732
+	 * @throws InvalidDataTypeException
1733
+	 * @throws InvalidInterfaceException
1734
+	 */
1735
+	public function admin_footer_global()
1736
+	{
1737
+		// dialog container for dialog helper
1738
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1739
+		$d_cont .= '<div class="ee-notices"></div>';
1740
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1741
+		$d_cont .= '</div>';
1742
+		echo $d_cont;
1743
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1744
+		// help tour stuff?
1745
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1746
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1747
+		// }
1748
+		// current set timezone for timezone js
1749
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1750
+	}
1751
+
1752
+
1753
+	/**
1754
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1755
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1756
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1757
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1758
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1759
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1760
+	 * for the
1761
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1762
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1763
+	 *    'help_trigger_id' => array(
1764
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1765
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1766
+	 *    )
1767
+	 * );
1768
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1769
+	 *
1770
+	 * @param array $help_array
1771
+	 * @param bool  $display
1772
+	 * @return string content
1773
+	 * @throws DomainException
1774
+	 * @throws EE_Error
1775
+	 */
1776
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1777
+	{
1778
+		$content = '';
1779
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1780
+		// loop through the array and setup content
1781
+		foreach ($help_array as $trigger => $help) {
1782
+			// make sure the array is setup properly
1783
+			if (! isset($help['title'], $help['content'])) {
1784
+				throw new EE_Error(
1785
+					esc_html__(
1786
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1787
+						'event_espresso'
1788
+					)
1789
+				);
1790
+			}
1791
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1792
+			$template_args = array(
1793
+				'help_popup_id'      => $trigger,
1794
+				'help_popup_title'   => $help['title'],
1795
+				'help_popup_content' => $help['content'],
1796
+			);
1797
+			$content .= EEH_Template::display_template(
1798
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1799
+				$template_args,
1800
+				true
1801
+			);
1802
+		}
1803
+		if ($display) {
1804
+			echo $content;
1805
+			return '';
1806
+		}
1807
+		return $content;
1808
+	}
1809
+
1810
+
1811
+	/**
1812
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1813
+	 *
1814
+	 * @return array properly formatted array for help popup content
1815
+	 * @throws EE_Error
1816
+	 */
1817
+	private function _get_help_content()
1818
+	{
1819
+		// what is the method we're looking for?
1820
+		$method_name = '_help_popup_content_' . $this->_req_action;
1821
+		// if method doesn't exist let's get out.
1822
+		if (! method_exists($this, $method_name)) {
1823
+			return array();
1824
+		}
1825
+		// k we're good to go let's retrieve the help array
1826
+		$help_array = $this->{$method_name}();
1827
+		// make sure we've got an array!
1828
+		if (! is_array($help_array)) {
1829
+			throw new EE_Error(
1830
+				esc_html__(
1831
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1832
+					'event_espresso'
1833
+				)
1834
+			);
1835
+		}
1836
+		return $help_array;
1837
+	}
1838
+
1839
+
1840
+	/**
1841
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1842
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1843
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1844
+	 *
1845
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1846
+	 * @param boolean $display    if false then we return the trigger string
1847
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1848
+	 * @return string
1849
+	 * @throws DomainException
1850
+	 * @throws EE_Error
1851
+	 */
1852
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1853
+	{
1854
+		if (defined('DOING_AJAX')) {
1855
+			return '';
1856
+		}
1857
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1858
+		$help_array = $this->_get_help_content();
1859
+		$help_content = '';
1860
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1861
+			$help_array[ $trigger_id ] = array(
1862
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1863
+				'content' => esc_html__(
1864
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1865
+					'event_espresso'
1866
+				),
1867
+			);
1868
+			$help_content = $this->_set_help_popup_content($help_array);
1869
+		}
1870
+		// let's setup the trigger
1871
+		$content = '<a class="ee-dialog" href="?height='
1872
+				   . $dimensions[0]
1873
+				   . '&width='
1874
+				   . $dimensions[1]
1875
+				   . '&inlineId='
1876
+				   . $trigger_id
1877
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1878
+		$content .= $help_content;
1879
+		if ($display) {
1880
+			echo $content;
1881
+			return '';
1882
+		}
1883
+		return $content;
1884
+	}
1885
+
1886
+
1887
+	/**
1888
+	 * _add_global_screen_options
1889
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1890
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1891
+	 *
1892
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1893
+	 *         see also WP_Screen object documents...
1894
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1895
+	 * @abstract
1896
+	 * @return void
1897
+	 */
1898
+	private function _add_global_screen_options()
1899
+	{
1900
+	}
1901
+
1902
+
1903
+	/**
1904
+	 * _add_global_feature_pointers
1905
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1906
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1907
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1908
+	 *
1909
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1910
+	 *         extended) also see:
1911
+	 * @link   http://eamann.com/tech/wordpress-portland/
1912
+	 * @abstract
1913
+	 * @return void
1914
+	 */
1915
+	private function _add_global_feature_pointers()
1916
+	{
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * load_global_scripts_styles
1922
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1923
+	 *
1924
+	 * @return void
1925
+	 * @throws EE_Error
1926
+	 */
1927
+	public function load_global_scripts_styles()
1928
+	{
1929
+		// add debugging styles
1930
+		if (WP_DEBUG) {
1931
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1932
+		}
1933
+		// taking care of metaboxes
1934
+		if (
1935
+			empty($this->_cpt_route)
1936
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1937
+		) {
1938
+			wp_enqueue_script('dashboard');
1939
+		}
1940
+
1941
+		// LOCALIZED DATA
1942
+		// localize script for ajax lazy loading
1943
+		wp_localize_script(
1944
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1945
+			'eeLazyLoadingContainers',
1946
+			apply_filters(
1947
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1948
+				['espresso_news_post_box_content']
1949
+			)
1950
+		);
1951
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1952
+		// /**
1953
+		//  * help tour stuff
1954
+		//  */
1955
+		// if (! empty($this->_help_tour)) {
1956
+		//     // register the js for kicking things off
1957
+		//     wp_enqueue_script(
1958
+		//         'ee-help-tour',
1959
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1960
+		//         array('jquery-joyride'),
1961
+		//         EVENT_ESPRESSO_VERSION,
1962
+		//         true
1963
+		//     );
1964
+		//     $tours = array();
1965
+		//     // setup tours for the js tour object
1966
+		//     foreach ($this->_help_tour['tours'] as $tour) {
1967
+		//         if ($tour instanceof EE_Help_Tour) {
1968
+		//             $tours[] = array(
1969
+		//                 'id'      => $tour->get_slug(),
1970
+		//                 'options' => $tour->get_options(),
1971
+		//             );
1972
+		//         }
1973
+		//     }
1974
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1975
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1976
+		// }
1977
+	}
1978
+
1979
+
1980
+	/**
1981
+	 *        admin_footer_scripts_eei18n_js_strings
1982
+	 *
1983
+	 * @return        void
1984
+	 */
1985
+	public function admin_footer_scripts_eei18n_js_strings()
1986
+	{
1987
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1988
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
1989
+			'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1990
+			'event_espresso'
1991
+		);
1992
+		EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
1993
+		EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
1994
+		EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
1995
+		EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
1996
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
1997
+		EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
1998
+		EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
1999
+		EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2000
+		EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2001
+		EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2002
+		EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2003
+		EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2004
+		EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2005
+		EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2006
+		EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2007
+		EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2008
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2009
+		EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2010
+		EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2011
+		EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2012
+		EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2013
+		EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2014
+		EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2015
+		EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2016
+		EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2017
+		EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2018
+		EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2019
+		EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2020
+		EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2021
+		EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2022
+		EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2023
+		EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2024
+		EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2025
+		EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2026
+		EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2027
+		EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2028
+		EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2029
+		EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2035
+	 *
2036
+	 * @return        void
2037
+	 */
2038
+	public function add_xdebug_style()
2039
+	{
2040
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2041
+	}
2042
+
2043
+
2044
+	/************************/
2045
+	/** LIST TABLE METHODS **/
2046
+	/************************/
2047
+	/**
2048
+	 * this sets up the list table if the current view requires it.
2049
+	 *
2050
+	 * @return void
2051
+	 * @throws EE_Error
2052
+	 * @throws InvalidArgumentException
2053
+	 * @throws InvalidDataTypeException
2054
+	 * @throws InvalidInterfaceException
2055
+	 */
2056
+	protected function _set_list_table()
2057
+	{
2058
+		// first is this a list_table view?
2059
+		if (! isset($this->_route_config['list_table'])) {
2060
+			return;
2061
+		} //not a list_table view so get out.
2062
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2063
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2064
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2065
+			// user error msg
2066
+			$error_msg = esc_html__(
2067
+				'An error occurred. The requested list table views could not be found.',
2068
+				'event_espresso'
2069
+			);
2070
+			// developer error msg
2071
+			$error_msg .= '||'
2072
+						  . sprintf(
2073
+							  esc_html__(
2074
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2075
+								  'event_espresso'
2076
+							  ),
2077
+							  $this->_req_action,
2078
+							  $list_table_view
2079
+						  );
2080
+			throw new EE_Error($error_msg);
2081
+		}
2082
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2083
+		$this->_views = apply_filters(
2084
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2085
+			$this->_views
2086
+		);
2087
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2088
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2089
+		$this->_set_list_table_view();
2090
+		$this->_set_list_table_object();
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * set current view for List Table
2096
+	 *
2097
+	 * @return void
2098
+	 */
2099
+	protected function _set_list_table_view()
2100
+	{
2101
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2102
+		// looking at active items or dumpster diving ?
2103
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2104
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2105
+		} else {
2106
+			$this->_view = sanitize_key($this->_req_data['status']);
2107
+		}
2108
+	}
2109
+
2110
+
2111
+	/**
2112
+	 * _set_list_table_object
2113
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2114
+	 *
2115
+	 * @throws InvalidInterfaceException
2116
+	 * @throws InvalidArgumentException
2117
+	 * @throws InvalidDataTypeException
2118
+	 * @throws EE_Error
2119
+	 * @throws InvalidInterfaceException
2120
+	 */
2121
+	protected function _set_list_table_object()
2122
+	{
2123
+		if (isset($this->_route_config['list_table'])) {
2124
+			if (! class_exists($this->_route_config['list_table'])) {
2125
+				throw new EE_Error(
2126
+					sprintf(
2127
+						esc_html__(
2128
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2129
+							'event_espresso'
2130
+						),
2131
+						$this->_route_config['list_table'],
2132
+						get_class($this)
2133
+					)
2134
+				);
2135
+			}
2136
+			$this->_list_table_object = $this->loader->getShared(
2137
+				$this->_route_config['list_table'],
2138
+				array($this)
2139
+			);
2140
+		}
2141
+	}
2142
+
2143
+
2144
+	/**
2145
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2146
+	 *
2147
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2148
+	 *                                                    urls.  The array should be indexed by the view it is being
2149
+	 *                                                    added to.
2150
+	 * @return array
2151
+	 */
2152
+	public function get_list_table_view_RLs($extra_query_args = array())
2153
+	{
2154
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2155
+		if (empty($this->_views)) {
2156
+			$this->_views = array();
2157
+		}
2158
+		// cycle thru views
2159
+		foreach ($this->_views as $key => $view) {
2160
+			$query_args = array();
2161
+			// check for current view
2162
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2163
+			$query_args['action'] = $this->_req_action;
2164
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2165
+			$query_args['status'] = $view['slug'];
2166
+			// merge any other arguments sent in.
2167
+			if (isset($extra_query_args[ $view['slug'] ])) {
2168
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2169
+					$query_args[] = $extra_query_arg;
2170
+				}
2171
+			}
2172
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2173
+		}
2174
+		return $this->_views;
2175
+	}
2176
+
2177
+
2178
+	/**
2179
+	 * _entries_per_page_dropdown
2180
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2181
+	 *
2182
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2183
+	 *         WP does it.
2184
+	 * @param int $max_entries total number of rows in the table
2185
+	 * @return string
2186
+	 */
2187
+	protected function _entries_per_page_dropdown($max_entries = 0)
2188
+	{
2189
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
+		$values = array(10, 25, 50, 100);
2191
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2192
+		if ($max_entries) {
2193
+			$values[] = $max_entries;
2194
+			sort($values);
2195
+		}
2196
+		$entries_per_page_dropdown = '
2197 2197
 			<div id="entries-per-page-dv" class="alignleft actions">
2198 2198
 				<label class="hide-if-no-js">
2199 2199
 					Show
2200 2200
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2201
-        foreach ($values as $value) {
2202
-            if ($value < $max_entries) {
2203
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2204
-                $entries_per_page_dropdown .= '
2201
+		foreach ($values as $value) {
2202
+			if ($value < $max_entries) {
2203
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2204
+				$entries_per_page_dropdown .= '
2205 2205
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2206
-            }
2207
-        }
2208
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2209
-        $entries_per_page_dropdown .= '
2206
+			}
2207
+		}
2208
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2209
+		$entries_per_page_dropdown .= '
2210 2210
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2211
-        $entries_per_page_dropdown .= '
2211
+		$entries_per_page_dropdown .= '
2212 2212
 					</select>
2213 2213
 					entries
2214 2214
 				</label>
2215 2215
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2216 2216
 			</div>
2217 2217
 		';
2218
-        return $entries_per_page_dropdown;
2219
-    }
2220
-
2221
-
2222
-    /**
2223
-     *        _set_search_attributes
2224
-     *
2225
-     * @return        void
2226
-     */
2227
-    public function _set_search_attributes()
2228
-    {
2229
-        $this->_template_args['search']['btn_label'] = sprintf(
2230
-            esc_html__('Search %s', 'event_espresso'),
2231
-            empty($this->_search_btn_label) ? $this->page_label
2232
-                : $this->_search_btn_label
2233
-        );
2234
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2235
-    }
2236
-
2237
-
2238
-
2239
-    /*** END LIST TABLE METHODS **/
2240
-
2241
-
2242
-    /**
2243
-     * _add_registered_metaboxes
2244
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2245
-     *
2246
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2247
-     * @return void
2248
-     * @throws EE_Error
2249
-     */
2250
-    private function _add_registered_meta_boxes()
2251
-    {
2252
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2253
-        // we only add meta boxes if the page_route calls for it
2254
-        if (
2255
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2256
-            && is_array(
2257
-                $this->_route_config['metaboxes']
2258
-            )
2259
-        ) {
2260
-            // this simply loops through the callbacks provided
2261
-            // and checks if there is a corresponding callback registered by the child
2262
-            // if there is then we go ahead and process the metabox loader.
2263
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2264
-                // first check for Closures
2265
-                if ($metabox_callback instanceof Closure) {
2266
-                    $result = $metabox_callback();
2267
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2268
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2269
-                } else {
2270
-                    $result = $this->{$metabox_callback}();
2271
-                }
2272
-                if ($result === false) {
2273
-                    // user error msg
2274
-                    $error_msg = esc_html__(
2275
-                        'An error occurred. The  requested metabox could not be found.',
2276
-                        'event_espresso'
2277
-                    );
2278
-                    // developer error msg
2279
-                    $error_msg .= '||'
2280
-                                  . sprintf(
2281
-                                      esc_html__(
2282
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2283
-                                          'event_espresso'
2284
-                                      ),
2285
-                                      $metabox_callback
2286
-                                  );
2287
-                    throw new EE_Error($error_msg);
2288
-                }
2289
-            }
2290
-        }
2291
-    }
2292
-
2293
-
2294
-    /**
2295
-     * _add_screen_columns
2296
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2297
-     * the dynamic column template and we'll setup the column options for the page.
2298
-     *
2299
-     * @return void
2300
-     */
2301
-    private function _add_screen_columns()
2302
-    {
2303
-        if (
2304
-            is_array($this->_route_config)
2305
-            && isset($this->_route_config['columns'])
2306
-            && is_array($this->_route_config['columns'])
2307
-            && count($this->_route_config['columns']) === 2
2308
-        ) {
2309
-            add_screen_option(
2310
-                'layout_columns',
2311
-                array(
2312
-                    'max'     => (int) $this->_route_config['columns'][0],
2313
-                    'default' => (int) $this->_route_config['columns'][1],
2314
-                )
2315
-            );
2316
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2317
-            $screen_id = $this->_current_screen->id;
2318
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2319
-            $total_columns = ! empty($screen_columns)
2320
-                ? $screen_columns
2321
-                : $this->_route_config['columns'][1];
2322
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2323
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2324
-            $this->_template_args['screen'] = $this->_current_screen;
2325
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2326
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2327
-            // finally if we don't have has_metaboxes set in the route config
2328
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2329
-            $this->_route_config['has_metaboxes'] = true;
2330
-        }
2331
-    }
2332
-
2333
-
2334
-
2335
-    /** GLOBALLY AVAILABLE METABOXES **/
2336
-
2337
-
2338
-    /**
2339
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2340
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2341
-     * these get loaded on.
2342
-     */
2343
-    private function _espresso_news_post_box()
2344
-    {
2345
-        $news_box_title = apply_filters(
2346
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2347
-            esc_html__('New @ Event Espresso', 'event_espresso')
2348
-        );
2349
-        add_meta_box(
2350
-            'espresso_news_post_box',
2351
-            $news_box_title,
2352
-            array(
2353
-                $this,
2354
-                'espresso_news_post_box',
2355
-            ),
2356
-            $this->_wp_page_slug,
2357
-            'side'
2358
-        );
2359
-    }
2360
-
2361
-
2362
-    /**
2363
-     * Code for setting up espresso ratings request metabox.
2364
-     */
2365
-    protected function _espresso_ratings_request()
2366
-    {
2367
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2368
-            return;
2369
-        }
2370
-        $ratings_box_title = apply_filters(
2371
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2372
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2373
-        );
2374
-        add_meta_box(
2375
-            'espresso_ratings_request',
2376
-            $ratings_box_title,
2377
-            array(
2378
-                $this,
2379
-                'espresso_ratings_request',
2380
-            ),
2381
-            $this->_wp_page_slug,
2382
-            'side'
2383
-        );
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * Code for setting up espresso ratings request metabox content.
2389
-     *
2390
-     * @throws DomainException
2391
-     */
2392
-    public function espresso_ratings_request()
2393
-    {
2394
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2395
-    }
2396
-
2397
-
2398
-    public static function cached_rss_display($rss_id, $url)
2399
-    {
2400
-        $loading = '<p class="widget-loading hide-if-no-js">'
2401
-                   . __('Loading&#8230;', 'event_espresso')
2402
-                   . '</p><p class="hide-if-js">'
2403
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2404
-                   . '</p>';
2405
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2406
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2407
-        $post = '</div>' . "\n";
2408
-        $cache_key = 'ee_rss_' . md5($rss_id);
2409
-        $output = get_transient($cache_key);
2410
-        if ($output !== false) {
2411
-            echo $pre . $output . $post;
2412
-            return true;
2413
-        }
2414
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2415
-            echo $pre . $loading . $post;
2416
-            return false;
2417
-        }
2418
-        ob_start();
2419
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2420
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2421
-        return true;
2422
-    }
2423
-
2424
-
2425
-    public function espresso_news_post_box()
2426
-    {
2427
-        ?>
2218
+		return $entries_per_page_dropdown;
2219
+	}
2220
+
2221
+
2222
+	/**
2223
+	 *        _set_search_attributes
2224
+	 *
2225
+	 * @return        void
2226
+	 */
2227
+	public function _set_search_attributes()
2228
+	{
2229
+		$this->_template_args['search']['btn_label'] = sprintf(
2230
+			esc_html__('Search %s', 'event_espresso'),
2231
+			empty($this->_search_btn_label) ? $this->page_label
2232
+				: $this->_search_btn_label
2233
+		);
2234
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2235
+	}
2236
+
2237
+
2238
+
2239
+	/*** END LIST TABLE METHODS **/
2240
+
2241
+
2242
+	/**
2243
+	 * _add_registered_metaboxes
2244
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2245
+	 *
2246
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2247
+	 * @return void
2248
+	 * @throws EE_Error
2249
+	 */
2250
+	private function _add_registered_meta_boxes()
2251
+	{
2252
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2253
+		// we only add meta boxes if the page_route calls for it
2254
+		if (
2255
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2256
+			&& is_array(
2257
+				$this->_route_config['metaboxes']
2258
+			)
2259
+		) {
2260
+			// this simply loops through the callbacks provided
2261
+			// and checks if there is a corresponding callback registered by the child
2262
+			// if there is then we go ahead and process the metabox loader.
2263
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2264
+				// first check for Closures
2265
+				if ($metabox_callback instanceof Closure) {
2266
+					$result = $metabox_callback();
2267
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2268
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2269
+				} else {
2270
+					$result = $this->{$metabox_callback}();
2271
+				}
2272
+				if ($result === false) {
2273
+					// user error msg
2274
+					$error_msg = esc_html__(
2275
+						'An error occurred. The  requested metabox could not be found.',
2276
+						'event_espresso'
2277
+					);
2278
+					// developer error msg
2279
+					$error_msg .= '||'
2280
+								  . sprintf(
2281
+									  esc_html__(
2282
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2283
+										  'event_espresso'
2284
+									  ),
2285
+									  $metabox_callback
2286
+								  );
2287
+					throw new EE_Error($error_msg);
2288
+				}
2289
+			}
2290
+		}
2291
+	}
2292
+
2293
+
2294
+	/**
2295
+	 * _add_screen_columns
2296
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2297
+	 * the dynamic column template and we'll setup the column options for the page.
2298
+	 *
2299
+	 * @return void
2300
+	 */
2301
+	private function _add_screen_columns()
2302
+	{
2303
+		if (
2304
+			is_array($this->_route_config)
2305
+			&& isset($this->_route_config['columns'])
2306
+			&& is_array($this->_route_config['columns'])
2307
+			&& count($this->_route_config['columns']) === 2
2308
+		) {
2309
+			add_screen_option(
2310
+				'layout_columns',
2311
+				array(
2312
+					'max'     => (int) $this->_route_config['columns'][0],
2313
+					'default' => (int) $this->_route_config['columns'][1],
2314
+				)
2315
+			);
2316
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2317
+			$screen_id = $this->_current_screen->id;
2318
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2319
+			$total_columns = ! empty($screen_columns)
2320
+				? $screen_columns
2321
+				: $this->_route_config['columns'][1];
2322
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2323
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2324
+			$this->_template_args['screen'] = $this->_current_screen;
2325
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2326
+										   . 'admin_details_metabox_column_wrapper.template.php';
2327
+			// finally if we don't have has_metaboxes set in the route config
2328
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2329
+			$this->_route_config['has_metaboxes'] = true;
2330
+		}
2331
+	}
2332
+
2333
+
2334
+
2335
+	/** GLOBALLY AVAILABLE METABOXES **/
2336
+
2337
+
2338
+	/**
2339
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2340
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2341
+	 * these get loaded on.
2342
+	 */
2343
+	private function _espresso_news_post_box()
2344
+	{
2345
+		$news_box_title = apply_filters(
2346
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2347
+			esc_html__('New @ Event Espresso', 'event_espresso')
2348
+		);
2349
+		add_meta_box(
2350
+			'espresso_news_post_box',
2351
+			$news_box_title,
2352
+			array(
2353
+				$this,
2354
+				'espresso_news_post_box',
2355
+			),
2356
+			$this->_wp_page_slug,
2357
+			'side'
2358
+		);
2359
+	}
2360
+
2361
+
2362
+	/**
2363
+	 * Code for setting up espresso ratings request metabox.
2364
+	 */
2365
+	protected function _espresso_ratings_request()
2366
+	{
2367
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2368
+			return;
2369
+		}
2370
+		$ratings_box_title = apply_filters(
2371
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2372
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2373
+		);
2374
+		add_meta_box(
2375
+			'espresso_ratings_request',
2376
+			$ratings_box_title,
2377
+			array(
2378
+				$this,
2379
+				'espresso_ratings_request',
2380
+			),
2381
+			$this->_wp_page_slug,
2382
+			'side'
2383
+		);
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * Code for setting up espresso ratings request metabox content.
2389
+	 *
2390
+	 * @throws DomainException
2391
+	 */
2392
+	public function espresso_ratings_request()
2393
+	{
2394
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2395
+	}
2396
+
2397
+
2398
+	public static function cached_rss_display($rss_id, $url)
2399
+	{
2400
+		$loading = '<p class="widget-loading hide-if-no-js">'
2401
+				   . __('Loading&#8230;', 'event_espresso')
2402
+				   . '</p><p class="hide-if-js">'
2403
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2404
+				   . '</p>';
2405
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2406
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2407
+		$post = '</div>' . "\n";
2408
+		$cache_key = 'ee_rss_' . md5($rss_id);
2409
+		$output = get_transient($cache_key);
2410
+		if ($output !== false) {
2411
+			echo $pre . $output . $post;
2412
+			return true;
2413
+		}
2414
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2415
+			echo $pre . $loading . $post;
2416
+			return false;
2417
+		}
2418
+		ob_start();
2419
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2420
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2421
+		return true;
2422
+	}
2423
+
2424
+
2425
+	public function espresso_news_post_box()
2426
+	{
2427
+		?>
2428 2428
         <div class="padding">
2429 2429
             <div id="espresso_news_post_box_content" class="infolinks">
2430 2430
                 <?php
2431
-                // Get RSS Feed(s)
2432
-                EE_Admin_Page::cached_rss_display(
2433
-                    'espresso_news_post_box_content',
2434
-                    urlencode(
2435
-                        apply_filters(
2436
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2437
-                            'http://eventespresso.com/feed/'
2438
-                        )
2439
-                    )
2440
-                );
2441
-                ?>
2431
+				// Get RSS Feed(s)
2432
+				EE_Admin_Page::cached_rss_display(
2433
+					'espresso_news_post_box_content',
2434
+					urlencode(
2435
+						apply_filters(
2436
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2437
+							'http://eventespresso.com/feed/'
2438
+						)
2439
+					)
2440
+				);
2441
+				?>
2442 2442
             </div>
2443 2443
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2444 2444
         </div>
2445 2445
         <?php
2446
-    }
2447
-
2448
-
2449
-    private function _espresso_links_post_box()
2450
-    {
2451
-        // Hiding until we actually have content to put in here...
2452
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2453
-    }
2454
-
2455
-
2456
-    public function espresso_links_post_box()
2457
-    {
2458
-        // Hiding until we actually have content to put in here...
2459
-        // EEH_Template::display_template(
2460
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2461
-        // );
2462
-    }
2463
-
2464
-
2465
-    protected function _espresso_sponsors_post_box()
2466
-    {
2467
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2468
-            add_meta_box(
2469
-                'espresso_sponsors_post_box',
2470
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2471
-                array($this, 'espresso_sponsors_post_box'),
2472
-                $this->_wp_page_slug,
2473
-                'side'
2474
-            );
2475
-        }
2476
-    }
2477
-
2478
-
2479
-    public function espresso_sponsors_post_box()
2480
-    {
2481
-        EEH_Template::display_template(
2482
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2483
-        );
2484
-    }
2485
-
2486
-
2487
-    private function _publish_post_box()
2488
-    {
2489
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2490
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2491
-        // then we'll use that for the metabox label.
2492
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2493
-        if (! empty($this->_labels['publishbox'])) {
2494
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2495
-                : $this->_labels['publishbox'];
2496
-        } else {
2497
-            $box_label = esc_html__('Publish', 'event_espresso');
2498
-        }
2499
-        $box_label = apply_filters(
2500
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2501
-            $box_label,
2502
-            $this->_req_action,
2503
-            $this
2504
-        );
2505
-        add_meta_box(
2506
-            $meta_box_ref,
2507
-            $box_label,
2508
-            array($this, 'editor_overview'),
2509
-            $this->_current_screen->id,
2510
-            'side',
2511
-            'high'
2512
-        );
2513
-    }
2514
-
2515
-
2516
-    public function editor_overview()
2517
-    {
2518
-        // if we have extra content set let's add it in if not make sure its empty
2519
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2520
-            ? $this->_template_args['publish_box_extra_content']
2521
-            : '';
2522
-        echo EEH_Template::display_template(
2523
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2524
-            $this->_template_args,
2525
-            true
2526
-        );
2527
-    }
2528
-
2529
-
2530
-    /** end of globally available metaboxes section **/
2531
-
2532
-
2533
-    /**
2534
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2535
-     * protected method.
2536
-     *
2537
-     * @see   $this->_set_publish_post_box_vars for param details
2538
-     * @since 4.6.0
2539
-     * @param string $name
2540
-     * @param int    $id
2541
-     * @param bool   $delete
2542
-     * @param string $save_close_redirect_URL
2543
-     * @param bool   $both_btns
2544
-     * @throws EE_Error
2545
-     * @throws InvalidArgumentException
2546
-     * @throws InvalidDataTypeException
2547
-     * @throws InvalidInterfaceException
2548
-     */
2549
-    public function set_publish_post_box_vars(
2550
-        $name = '',
2551
-        $id = 0,
2552
-        $delete = false,
2553
-        $save_close_redirect_URL = '',
2554
-        $both_btns = true
2555
-    ) {
2556
-        $this->_set_publish_post_box_vars(
2557
-            $name,
2558
-            $id,
2559
-            $delete,
2560
-            $save_close_redirect_URL,
2561
-            $both_btns
2562
-        );
2563
-    }
2564
-
2565
-
2566
-    /**
2567
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2568
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2569
-     * save, and save and close buttons to work properly, then you will want to include a
2570
-     * values for the name and id arguments.
2571
-     *
2572
-     * @todo  Add in validation for name/id arguments.
2573
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2574
-     * @param    int     $id                      id attached to the item published
2575
-     * @param    string  $delete                  page route callback for the delete action
2576
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2577
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2578
-     *                                            the Save button
2579
-     * @throws EE_Error
2580
-     * @throws InvalidArgumentException
2581
-     * @throws InvalidDataTypeException
2582
-     * @throws InvalidInterfaceException
2583
-     */
2584
-    protected function _set_publish_post_box_vars(
2585
-        $name = '',
2586
-        $id = 0,
2587
-        $delete = '',
2588
-        $save_close_redirect_URL = '',
2589
-        $both_btns = true
2590
-    ) {
2591
-        // if Save & Close, use a custom redirect URL or default to the main page?
2592
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2593
-            ? $save_close_redirect_URL
2594
-            : $this->_admin_base_url;
2595
-        // create the Save & Close and Save buttons
2596
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2597
-        // if we have extra content set let's add it in if not make sure its empty
2598
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2599
-            ? $this->_template_args['publish_box_extra_content']
2600
-            : '';
2601
-        if ($delete && ! empty($id)) {
2602
-            // make sure we have a default if just true is sent.
2603
-            $delete = ! empty($delete) ? $delete : 'delete';
2604
-            $delete_link_args = array($name => $id);
2605
-            $delete = $this->get_action_link_or_button(
2606
-                $delete,
2607
-                $delete,
2608
-                $delete_link_args,
2609
-                'submitdelete deletion'
2610
-            );
2611
-        }
2612
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2613
-        if (! empty($name) && ! empty($id)) {
2614
-            $hidden_field_arr[ $name ] = array(
2615
-                'type'  => 'hidden',
2616
-                'value' => $id,
2617
-            );
2618
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2619
-        } else {
2620
-            $hf = '';
2621
-        }
2622
-        // add hidden field
2623
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2624
-            ? $hf[ $name ]['field']
2625
-            : $hf;
2626
-    }
2627
-
2628
-
2629
-    /**
2630
-     * displays an error message to ppl who have javascript disabled
2631
-     *
2632
-     * @return void
2633
-     */
2634
-    private function _display_no_javascript_warning()
2635
-    {
2636
-        ?>
2446
+	}
2447
+
2448
+
2449
+	private function _espresso_links_post_box()
2450
+	{
2451
+		// Hiding until we actually have content to put in here...
2452
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2453
+	}
2454
+
2455
+
2456
+	public function espresso_links_post_box()
2457
+	{
2458
+		// Hiding until we actually have content to put in here...
2459
+		// EEH_Template::display_template(
2460
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2461
+		// );
2462
+	}
2463
+
2464
+
2465
+	protected function _espresso_sponsors_post_box()
2466
+	{
2467
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2468
+			add_meta_box(
2469
+				'espresso_sponsors_post_box',
2470
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2471
+				array($this, 'espresso_sponsors_post_box'),
2472
+				$this->_wp_page_slug,
2473
+				'side'
2474
+			);
2475
+		}
2476
+	}
2477
+
2478
+
2479
+	public function espresso_sponsors_post_box()
2480
+	{
2481
+		EEH_Template::display_template(
2482
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2483
+		);
2484
+	}
2485
+
2486
+
2487
+	private function _publish_post_box()
2488
+	{
2489
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2490
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2491
+		// then we'll use that for the metabox label.
2492
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2493
+		if (! empty($this->_labels['publishbox'])) {
2494
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2495
+				: $this->_labels['publishbox'];
2496
+		} else {
2497
+			$box_label = esc_html__('Publish', 'event_espresso');
2498
+		}
2499
+		$box_label = apply_filters(
2500
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2501
+			$box_label,
2502
+			$this->_req_action,
2503
+			$this
2504
+		);
2505
+		add_meta_box(
2506
+			$meta_box_ref,
2507
+			$box_label,
2508
+			array($this, 'editor_overview'),
2509
+			$this->_current_screen->id,
2510
+			'side',
2511
+			'high'
2512
+		);
2513
+	}
2514
+
2515
+
2516
+	public function editor_overview()
2517
+	{
2518
+		// if we have extra content set let's add it in if not make sure its empty
2519
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2520
+			? $this->_template_args['publish_box_extra_content']
2521
+			: '';
2522
+		echo EEH_Template::display_template(
2523
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2524
+			$this->_template_args,
2525
+			true
2526
+		);
2527
+	}
2528
+
2529
+
2530
+	/** end of globally available metaboxes section **/
2531
+
2532
+
2533
+	/**
2534
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2535
+	 * protected method.
2536
+	 *
2537
+	 * @see   $this->_set_publish_post_box_vars for param details
2538
+	 * @since 4.6.0
2539
+	 * @param string $name
2540
+	 * @param int    $id
2541
+	 * @param bool   $delete
2542
+	 * @param string $save_close_redirect_URL
2543
+	 * @param bool   $both_btns
2544
+	 * @throws EE_Error
2545
+	 * @throws InvalidArgumentException
2546
+	 * @throws InvalidDataTypeException
2547
+	 * @throws InvalidInterfaceException
2548
+	 */
2549
+	public function set_publish_post_box_vars(
2550
+		$name = '',
2551
+		$id = 0,
2552
+		$delete = false,
2553
+		$save_close_redirect_URL = '',
2554
+		$both_btns = true
2555
+	) {
2556
+		$this->_set_publish_post_box_vars(
2557
+			$name,
2558
+			$id,
2559
+			$delete,
2560
+			$save_close_redirect_URL,
2561
+			$both_btns
2562
+		);
2563
+	}
2564
+
2565
+
2566
+	/**
2567
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2568
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2569
+	 * save, and save and close buttons to work properly, then you will want to include a
2570
+	 * values for the name and id arguments.
2571
+	 *
2572
+	 * @todo  Add in validation for name/id arguments.
2573
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2574
+	 * @param    int     $id                      id attached to the item published
2575
+	 * @param    string  $delete                  page route callback for the delete action
2576
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2577
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2578
+	 *                                            the Save button
2579
+	 * @throws EE_Error
2580
+	 * @throws InvalidArgumentException
2581
+	 * @throws InvalidDataTypeException
2582
+	 * @throws InvalidInterfaceException
2583
+	 */
2584
+	protected function _set_publish_post_box_vars(
2585
+		$name = '',
2586
+		$id = 0,
2587
+		$delete = '',
2588
+		$save_close_redirect_URL = '',
2589
+		$both_btns = true
2590
+	) {
2591
+		// if Save & Close, use a custom redirect URL or default to the main page?
2592
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2593
+			? $save_close_redirect_URL
2594
+			: $this->_admin_base_url;
2595
+		// create the Save & Close and Save buttons
2596
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2597
+		// if we have extra content set let's add it in if not make sure its empty
2598
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2599
+			? $this->_template_args['publish_box_extra_content']
2600
+			: '';
2601
+		if ($delete && ! empty($id)) {
2602
+			// make sure we have a default if just true is sent.
2603
+			$delete = ! empty($delete) ? $delete : 'delete';
2604
+			$delete_link_args = array($name => $id);
2605
+			$delete = $this->get_action_link_or_button(
2606
+				$delete,
2607
+				$delete,
2608
+				$delete_link_args,
2609
+				'submitdelete deletion'
2610
+			);
2611
+		}
2612
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2613
+		if (! empty($name) && ! empty($id)) {
2614
+			$hidden_field_arr[ $name ] = array(
2615
+				'type'  => 'hidden',
2616
+				'value' => $id,
2617
+			);
2618
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2619
+		} else {
2620
+			$hf = '';
2621
+		}
2622
+		// add hidden field
2623
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2624
+			? $hf[ $name ]['field']
2625
+			: $hf;
2626
+	}
2627
+
2628
+
2629
+	/**
2630
+	 * displays an error message to ppl who have javascript disabled
2631
+	 *
2632
+	 * @return void
2633
+	 */
2634
+	private function _display_no_javascript_warning()
2635
+	{
2636
+		?>
2637 2637
         <noscript>
2638 2638
             <div id="no-js-message" class="error">
2639 2639
                 <p style="font-size:1.3em;">
2640 2640
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2641 2641
                     <?php esc_html_e(
2642
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2643
-                        'event_espresso'
2644
-                    ); ?>
2642
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2643
+						'event_espresso'
2644
+					); ?>
2645 2645
                 </p>
2646 2646
             </div>
2647 2647
         </noscript>
2648 2648
         <?php
2649
-    }
2650
-
2651
-
2652
-    /**
2653
-     * displays espresso success and/or error notices
2654
-     *
2655
-     * @return void
2656
-     */
2657
-    private function _display_espresso_notices()
2658
-    {
2659
-        $notices = $this->_get_transient(true);
2660
-        echo stripslashes($notices);
2661
-    }
2662
-
2663
-
2664
-    /**
2665
-     * spinny things pacify the masses
2666
-     *
2667
-     * @return void
2668
-     */
2669
-    protected function _add_admin_page_ajax_loading_img()
2670
-    {
2671
-        ?>
2649
+	}
2650
+
2651
+
2652
+	/**
2653
+	 * displays espresso success and/or error notices
2654
+	 *
2655
+	 * @return void
2656
+	 */
2657
+	private function _display_espresso_notices()
2658
+	{
2659
+		$notices = $this->_get_transient(true);
2660
+		echo stripslashes($notices);
2661
+	}
2662
+
2663
+
2664
+	/**
2665
+	 * spinny things pacify the masses
2666
+	 *
2667
+	 * @return void
2668
+	 */
2669
+	protected function _add_admin_page_ajax_loading_img()
2670
+	{
2671
+		?>
2672 2672
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2673 2673
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2674
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2674
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2675 2675
         </div>
2676 2676
         <?php
2677
-    }
2677
+	}
2678 2678
 
2679 2679
 
2680
-    /**
2681
-     * add admin page overlay for modal boxes
2682
-     *
2683
-     * @return void
2684
-     */
2685
-    protected function _add_admin_page_overlay()
2686
-    {
2687
-        ?>
2680
+	/**
2681
+	 * add admin page overlay for modal boxes
2682
+	 *
2683
+	 * @return void
2684
+	 */
2685
+	protected function _add_admin_page_overlay()
2686
+	{
2687
+		?>
2688 2688
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2689 2689
         <?php
2690
-    }
2691
-
2692
-
2693
-    /**
2694
-     * facade for add_meta_box
2695
-     *
2696
-     * @param string  $action        where the metabox get's displayed
2697
-     * @param string  $title         Title of Metabox (output in metabox header)
2698
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2699
-     *                               instead of the one created in here.
2700
-     * @param array   $callback_args an array of args supplied for the metabox
2701
-     * @param string  $column        what metabox column
2702
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2703
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2704
-     *                               created but just set our own callback for wp's add_meta_box.
2705
-     * @throws DomainException
2706
-     */
2707
-    public function _add_admin_page_meta_box(
2708
-        $action,
2709
-        $title,
2710
-        $callback,
2711
-        $callback_args,
2712
-        $column = 'normal',
2713
-        $priority = 'high',
2714
-        $create_func = true
2715
-    ) {
2716
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2717
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2718
-        if (empty($callback_args) && $create_func) {
2719
-            $callback_args = array(
2720
-                'template_path' => $this->_template_path,
2721
-                'template_args' => $this->_template_args,
2722
-            );
2723
-        }
2724
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2725
-        $call_back_func = $create_func
2726
-            ? static function ($post, $metabox) {
2727
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2728
-                echo EEH_Template::display_template(
2729
-                    $metabox['args']['template_path'],
2730
-                    $metabox['args']['template_args'],
2731
-                    true
2732
-                );
2733
-            }
2734
-            : $callback;
2735
-        add_meta_box(
2736
-            str_replace('_', '-', $action) . '-mbox',
2737
-            $title,
2738
-            $call_back_func,
2739
-            $this->_wp_page_slug,
2740
-            $column,
2741
-            $priority,
2742
-            $callback_args
2743
-        );
2744
-    }
2745
-
2746
-
2747
-    /**
2748
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2749
-     *
2750
-     * @throws DomainException
2751
-     * @throws EE_Error
2752
-     * @throws InvalidArgumentException
2753
-     * @throws InvalidDataTypeException
2754
-     * @throws InvalidInterfaceException
2755
-     */
2756
-    public function display_admin_page_with_metabox_columns()
2757
-    {
2758
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2759
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2760
-            $this->_column_template_path,
2761
-            $this->_template_args,
2762
-            true
2763
-        );
2764
-        // the final wrapper
2765
-        $this->admin_page_wrapper();
2766
-    }
2767
-
2768
-
2769
-    /**
2770
-     * generates  HTML wrapper for an admin details page
2771
-     *
2772
-     * @return void
2773
-     * @throws DomainException
2774
-     * @throws EE_Error
2775
-     * @throws InvalidArgumentException
2776
-     * @throws InvalidDataTypeException
2777
-     * @throws InvalidInterfaceException
2778
-     */
2779
-    public function display_admin_page_with_sidebar()
2780
-    {
2781
-        $this->_display_admin_page(true);
2782
-    }
2783
-
2784
-
2785
-    /**
2786
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2787
-     *
2788
-     * @return void
2789
-     * @throws DomainException
2790
-     * @throws EE_Error
2791
-     * @throws InvalidArgumentException
2792
-     * @throws InvalidDataTypeException
2793
-     * @throws InvalidInterfaceException
2794
-     */
2795
-    public function display_admin_page_with_no_sidebar()
2796
-    {
2797
-        $this->_display_admin_page();
2798
-    }
2799
-
2800
-
2801
-    /**
2802
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2803
-     *
2804
-     * @return void
2805
-     * @throws DomainException
2806
-     * @throws EE_Error
2807
-     * @throws InvalidArgumentException
2808
-     * @throws InvalidDataTypeException
2809
-     * @throws InvalidInterfaceException
2810
-     */
2811
-    public function display_about_admin_page()
2812
-    {
2813
-        $this->_display_admin_page(false, true);
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * display_admin_page
2819
-     * contains the code for actually displaying an admin page
2820
-     *
2821
-     * @param boolean $sidebar true with sidebar, false without
2822
-     * @param boolean $about   use the about admin wrapper instead of the default.
2823
-     * @return void
2824
-     * @throws DomainException
2825
-     * @throws EE_Error
2826
-     * @throws InvalidArgumentException
2827
-     * @throws InvalidDataTypeException
2828
-     * @throws InvalidInterfaceException
2829
-     */
2830
-    private function _display_admin_page($sidebar = false, $about = false)
2831
-    {
2832
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2833
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2834
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2835
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2836
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2837
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2838
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2839
-            ? 'poststuff'
2840
-            : 'espresso-default-admin';
2841
-        $template_path = $sidebar
2842
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2843
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2844
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2845
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2846
-        }
2847
-        $template_path = ! empty($this->_column_template_path)
2848
-            ? $this->_column_template_path : $template_path;
2849
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2850
-            ? $this->_template_args['admin_page_content']
2851
-            : '';
2852
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2853
-            ? $this->_template_args['before_admin_page_content']
2854
-            : '';
2855
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2856
-            ? $this->_template_args['after_admin_page_content']
2857
-            : '';
2858
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2859
-            $template_path,
2860
-            $this->_template_args,
2861
-            true
2862
-        );
2863
-        // the final template wrapper
2864
-        $this->admin_page_wrapper($about);
2865
-    }
2866
-
2867
-
2868
-    /**
2869
-     * This is used to display caf preview pages.
2870
-     *
2871
-     * @since 4.3.2
2872
-     * @param string $utm_campaign_source what is the key used for google analytics link
2873
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2874
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2875
-     * @return void
2876
-     * @throws DomainException
2877
-     * @throws EE_Error
2878
-     * @throws InvalidArgumentException
2879
-     * @throws InvalidDataTypeException
2880
-     * @throws InvalidInterfaceException
2881
-     */
2882
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2883
-    {
2884
-        // let's generate a default preview action button if there isn't one already present.
2885
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2886
-            'Upgrade to Event Espresso 4 Right Now',
2887
-            'event_espresso'
2888
-        );
2889
-        $buy_now_url = add_query_arg(
2890
-            array(
2891
-                'ee_ver'       => 'ee4',
2892
-                'utm_source'   => 'ee4_plugin_admin',
2893
-                'utm_medium'   => 'link',
2894
-                'utm_campaign' => $utm_campaign_source,
2895
-                'utm_content'  => 'buy_now_button',
2896
-            ),
2897
-            'http://eventespresso.com/pricing/'
2898
-        );
2899
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2900
-            ? $this->get_action_link_or_button(
2901
-                '',
2902
-                'buy_now',
2903
-                array(),
2904
-                'button-primary button-large',
2905
-                $buy_now_url,
2906
-                true
2907
-            )
2908
-            : $this->_template_args['preview_action_button'];
2909
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2910
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2911
-            $this->_template_args,
2912
-            true
2913
-        );
2914
-        $this->_display_admin_page($display_sidebar);
2915
-    }
2916
-
2917
-
2918
-    /**
2919
-     * display_admin_list_table_page_with_sidebar
2920
-     * generates HTML wrapper for an admin_page with list_table
2921
-     *
2922
-     * @return void
2923
-     * @throws DomainException
2924
-     * @throws EE_Error
2925
-     * @throws InvalidArgumentException
2926
-     * @throws InvalidDataTypeException
2927
-     * @throws InvalidInterfaceException
2928
-     */
2929
-    public function display_admin_list_table_page_with_sidebar()
2930
-    {
2931
-        $this->_display_admin_list_table_page(true);
2932
-    }
2933
-
2934
-
2935
-    /**
2936
-     * display_admin_list_table_page_with_no_sidebar
2937
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2938
-     *
2939
-     * @return void
2940
-     * @throws DomainException
2941
-     * @throws EE_Error
2942
-     * @throws InvalidArgumentException
2943
-     * @throws InvalidDataTypeException
2944
-     * @throws InvalidInterfaceException
2945
-     */
2946
-    public function display_admin_list_table_page_with_no_sidebar()
2947
-    {
2948
-        $this->_display_admin_list_table_page();
2949
-    }
2950
-
2951
-
2952
-    /**
2953
-     * generates html wrapper for an admin_list_table page
2954
-     *
2955
-     * @param boolean $sidebar whether to display with sidebar or not.
2956
-     * @return void
2957
-     * @throws DomainException
2958
-     * @throws EE_Error
2959
-     * @throws InvalidArgumentException
2960
-     * @throws InvalidDataTypeException
2961
-     * @throws InvalidInterfaceException
2962
-     */
2963
-    private function _display_admin_list_table_page($sidebar = false)
2964
-    {
2965
-        // setup search attributes
2966
-        $this->_set_search_attributes();
2967
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2968
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2969
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2970
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2971
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2972
-        $this->_template_args['list_table'] = $this->_list_table_object;
2973
-        $this->_template_args['current_route'] = $this->_req_action;
2974
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2975
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2976
-        if (! empty($ajax_sorting_callback)) {
2977
-            $sortable_list_table_form_fields = wp_nonce_field(
2978
-                $ajax_sorting_callback . '_nonce',
2979
-                $ajax_sorting_callback . '_nonce',
2980
-                false,
2981
-                false
2982
-            );
2983
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2984
-                                                . $this->page_slug
2985
-                                                . '" />';
2986
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2987
-                                                . $ajax_sorting_callback
2988
-                                                . '" />';
2989
-        } else {
2990
-            $sortable_list_table_form_fields = '';
2991
-        }
2992
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2993
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
2994
-            ? $this->_template_args['list_table_hidden_fields']
2995
-            : '';
2996
-        $nonce_ref = $this->_req_action . '_nonce';
2997
-        $hidden_form_fields .= '<input type="hidden" name="'
2998
-                               . $nonce_ref
2999
-                               . '" value="'
3000
-                               . wp_create_nonce($nonce_ref)
3001
-                               . '">';
3002
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3003
-        // display message about search results?
3004
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3005
-            ? '<p class="ee-search-results">' . sprintf(
3006
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3007
-                trim($this->_req_data['s'], '%')
3008
-            ) . '</p>'
3009
-            : '';
3010
-        // filter before_list_table template arg
3011
-        $this->_template_args['before_list_table'] = apply_filters(
3012
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3013
-            $this->_template_args['before_list_table'],
3014
-            $this->page_slug,
3015
-            $this->_req_data,
3016
-            $this->_req_action
3017
-        );
3018
-        // convert to array and filter again
3019
-        // arrays are easier to inject new items in a specific location,
3020
-        // but would not be backwards compatible, so we have to add a new filter
3021
-        $this->_template_args['before_list_table'] = implode(
3022
-            " \n",
3023
-            (array) apply_filters(
3024
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3025
-                (array) $this->_template_args['before_list_table'],
3026
-                $this->page_slug,
3027
-                $this->_req_data,
3028
-                $this->_req_action
3029
-            )
3030
-        );
3031
-        // filter after_list_table template arg
3032
-        $this->_template_args['after_list_table'] = apply_filters(
3033
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3034
-            $this->_template_args['after_list_table'],
3035
-            $this->page_slug,
3036
-            $this->_req_data,
3037
-            $this->_req_action
3038
-        );
3039
-        // convert to array and filter again
3040
-        // arrays are easier to inject new items in a specific location,
3041
-        // but would not be backwards compatible, so we have to add a new filter
3042
-        $this->_template_args['after_list_table'] = implode(
3043
-            " \n",
3044
-            (array) apply_filters(
3045
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3046
-                (array) $this->_template_args['after_list_table'],
3047
-                $this->page_slug,
3048
-                $this->_req_data,
3049
-                $this->_req_action
3050
-            )
3051
-        );
3052
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3053
-            $template_path,
3054
-            $this->_template_args,
3055
-            true
3056
-        );
3057
-        // the final template wrapper
3058
-        if ($sidebar) {
3059
-            $this->display_admin_page_with_sidebar();
3060
-        } else {
3061
-            $this->display_admin_page_with_no_sidebar();
3062
-        }
3063
-    }
3064
-
3065
-
3066
-    /**
3067
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3068
-     * html string for the legend.
3069
-     * $items are expected in an array in the following format:
3070
-     * $legend_items = array(
3071
-     *        'item_id' => array(
3072
-     *            'icon' => 'http://url_to_icon_being_described.png',
3073
-     *            'desc' => esc_html__('localized description of item');
3074
-     *        )
3075
-     * );
3076
-     *
3077
-     * @param  array $items see above for format of array
3078
-     * @return string html string of legend
3079
-     * @throws DomainException
3080
-     */
3081
-    protected function _display_legend($items)
3082
-    {
3083
-        $this->_template_args['items'] = apply_filters(
3084
-            'FHEE__EE_Admin_Page___display_legend__items',
3085
-            (array) $items,
3086
-            $this
3087
-        );
3088
-        /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3089
-        $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3090
-        if (! $status_change_notice->isDismissed()) {
3091
-            $this->_template_args['status_change_notice'] = EEH_Template::display_template(
3092
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3093
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3094
-                true
3095
-            );
3096
-        }
3097
-        return EEH_Template::display_template(
3098
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3099
-            $this->_template_args,
3100
-            true
3101
-        );
3102
-    }
3103
-
3104
-
3105
-    /**
3106
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3107
-     * The returned json object is created from an array in the following format:
3108
-     * array(
3109
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3110
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3111
-     *  'notices' => '', // - contains any EE_Error formatted notices
3112
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3113
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3114
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3115
-     *  that might be included in here)
3116
-     * )
3117
-     * The json object is populated by whatever is set in the $_template_args property.
3118
-     *
3119
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3120
-     *                                 instead of displayed.
3121
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3122
-     * @return void
3123
-     * @throws EE_Error
3124
-     * @throws InvalidArgumentException
3125
-     * @throws InvalidDataTypeException
3126
-     * @throws InvalidInterfaceException
3127
-     */
3128
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3129
-    {
3130
-        // make sure any EE_Error notices have been handled.
3131
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3132
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3133
-        unset($this->_template_args['data']);
3134
-        $json = array(
3135
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3136
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3137
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3138
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3139
-            'notices'   => EE_Error::get_notices(),
3140
-            'content'   => isset($this->_template_args['admin_page_content'])
3141
-                ? $this->_template_args['admin_page_content'] : '',
3142
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3143
-            'isEEajax'  => true
3144
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3145
-        );
3146
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3147
-        if (null === error_get_last() || ! headers_sent()) {
3148
-            header('Content-Type: application/json; charset=UTF-8');
3149
-        }
3150
-        echo wp_json_encode($json);
3151
-        exit();
3152
-    }
3153
-
3154
-
3155
-    /**
3156
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3157
-     *
3158
-     * @return void
3159
-     * @throws EE_Error
3160
-     * @throws InvalidArgumentException
3161
-     * @throws InvalidDataTypeException
3162
-     * @throws InvalidInterfaceException
3163
-     */
3164
-    public function return_json()
3165
-    {
3166
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3167
-            $this->_return_json();
3168
-        } else {
3169
-            throw new EE_Error(
3170
-                sprintf(
3171
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3172
-                    __FUNCTION__
3173
-                )
3174
-            );
3175
-        }
3176
-    }
3177
-
3178
-
3179
-    /**
3180
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3181
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3182
-     *
3183
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3184
-     */
3185
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3186
-    {
3187
-        $this->_hook_obj = $hook_obj;
3188
-    }
3189
-
3190
-
3191
-    /**
3192
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3193
-     *
3194
-     * @param boolean $about whether to use the special about page wrapper or default.
3195
-     * @return void
3196
-     * @throws DomainException
3197
-     * @throws EE_Error
3198
-     * @throws InvalidArgumentException
3199
-     * @throws InvalidDataTypeException
3200
-     * @throws InvalidInterfaceException
3201
-     */
3202
-    public function admin_page_wrapper($about = false)
3203
-    {
3204
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3206
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3207
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3208
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3209
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3210
-            isset($this->_template_args['before_admin_page_content'])
3211
-                ? $this->_template_args['before_admin_page_content']
3212
-                : ''
3213
-        );
3214
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3215
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3216
-            isset($this->_template_args['after_admin_page_content'])
3217
-                ? $this->_template_args['after_admin_page_content']
3218
-                : ''
3219
-        );
3220
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3221
-        // load settings page wrapper template
3222
-        $template_path = ! defined('DOING_AJAX')
3223
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3224
-            : EE_ADMIN_TEMPLATE
3225
-              . 'admin_wrapper_ajax.template.php';
3226
-        // about page?
3227
-        $template_path = $about
3228
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3229
-            : $template_path;
3230
-        if (defined('DOING_AJAX')) {
3231
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3232
-                $template_path,
3233
-                $this->_template_args,
3234
-                true
3235
-            );
3236
-            $this->_return_json();
3237
-        } else {
3238
-            EEH_Template::display_template($template_path, $this->_template_args);
3239
-        }
3240
-    }
3241
-
3242
-
3243
-    /**
3244
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3245
-     *
3246
-     * @return string html
3247
-     * @throws EE_Error
3248
-     */
3249
-    protected function _get_main_nav_tabs()
3250
-    {
3251
-        // let's generate the html using the EEH_Tabbed_Content helper.
3252
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3253
-        // (rather than setting in the page_routes array)
3254
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3255
-    }
3256
-
3257
-
3258
-    /**
3259
-     *        sort nav tabs
3260
-     *
3261
-     * @param $a
3262
-     * @param $b
3263
-     * @return int
3264
-     */
3265
-    private function _sort_nav_tabs($a, $b)
3266
-    {
3267
-        if ($a['order'] === $b['order']) {
3268
-            return 0;
3269
-        }
3270
-        return ($a['order'] < $b['order']) ? -1 : 1;
3271
-    }
3272
-
3273
-
3274
-    /**
3275
-     *    generates HTML for the forms used on admin pages
3276
-     *
3277
-     * @param    array $input_vars - array of input field details
3278
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3279
-     *                             use)
3280
-     * @param bool     $id
3281
-     * @return string
3282
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3283
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3284
-     */
3285
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3286
-    {
3287
-        return $generator === 'string'
3288
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3289
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3290
-    }
3291
-
3292
-
3293
-    /**
3294
-     * generates the "Save" and "Save & Close" buttons for edit forms
3295
-     *
3296
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3297
-     *                                   Close" button.
3298
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3299
-     *                                   'Save', [1] => 'save & close')
3300
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3301
-     *                                   via the "name" value in the button).  We can also use this to just dump
3302
-     *                                   default actions by submitting some other value.
3303
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3304
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3305
-     *                                   close (normal form handling).
3306
-     */
3307
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3308
-    {
3309
-        // make sure $text and $actions are in an array
3310
-        $text = (array) $text;
3311
-        $actions = (array) $actions;
3312
-        $referrer_url = empty($referrer)
3313
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3314
-              . $_SERVER['REQUEST_URI']
3315
-              . '" />'
3316
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3317
-              . $referrer
3318
-              . '" />';
3319
-        $button_text = ! empty($text)
3320
-            ? $text
3321
-            : array(
3322
-                esc_html__('Save', 'event_espresso'),
3323
-                esc_html__('Save and Close', 'event_espresso'),
3324
-            );
3325
-        $default_names = array('save', 'save_and_close');
3326
-        // add in a hidden index for the current page (so save and close redirects properly)
3327
-        $this->_template_args['save_buttons'] = $referrer_url;
3328
-        foreach ($button_text as $key => $button) {
3329
-            $ref = $default_names[ $key ];
3330
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3331
-                                                     . $ref
3332
-                                                     . '" value="'
3333
-                                                     . $button
3334
-                                                     . '" name="'
3335
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3336
-                                                     . '" id="'
3337
-                                                     . $this->_current_view . '_' . $ref
3338
-                                                     . '" />';
3339
-            if (! $both) {
3340
-                break;
3341
-            }
3342
-        }
3343
-    }
3344
-
3345
-
3346
-    /**
3347
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3348
-     *
3349
-     * @see   $this->_set_add_edit_form_tags() for details on params
3350
-     * @since 4.6.0
3351
-     * @param string $route
3352
-     * @param array  $additional_hidden_fields
3353
-     */
3354
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3355
-    {
3356
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3357
-    }
3358
-
3359
-
3360
-    /**
3361
-     * set form open and close tags on add/edit pages.
3362
-     *
3363
-     * @param string $route                    the route you want the form to direct to
3364
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3365
-     * @return void
3366
-     */
3367
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3368
-    {
3369
-        if (empty($route)) {
3370
-            $user_msg = esc_html__(
3371
-                'An error occurred. No action was set for this page\'s form.',
3372
-                'event_espresso'
3373
-            );
3374
-            $dev_msg = $user_msg . "\n"
3375
-                       . sprintf(
3376
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3377
-                           __FUNCTION__,
3378
-                           EE_Admin_Page::class
3379
-                       );
3380
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3381
-        }
3382
-        // open form
3383
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3384
-                                                             . $this->_admin_base_url
3385
-                                                             . '" id="'
3386
-                                                             . $route
3387
-                                                             . '_event_form" >';
3388
-        // add nonce
3389
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3390
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3391
-        // add REQUIRED form action
3392
-        $hidden_fields = array(
3393
-            'action' => array('type' => 'hidden', 'value' => $route),
3394
-        );
3395
-        // merge arrays
3396
-        $hidden_fields = is_array($additional_hidden_fields)
3397
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3398
-            : $hidden_fields;
3399
-        // generate form fields
3400
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3401
-        // add fields to form
3402
-        foreach ((array) $form_fields as $field_name => $form_field) {
3403
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3404
-        }
3405
-        // close form
3406
-        $this->_template_args['after_admin_page_content'] = '</form>';
3407
-    }
3408
-
3409
-
3410
-    /**
3411
-     * Public Wrapper for _redirect_after_action() method since its
3412
-     * discovered it would be useful for external code to have access.
3413
-     *
3414
-     * @param bool   $success
3415
-     * @param string $what
3416
-     * @param string $action_desc
3417
-     * @param array  $query_args
3418
-     * @param bool   $override_overwrite
3419
-     * @throws EE_Error
3420
-     * @throws InvalidArgumentException
3421
-     * @throws InvalidDataTypeException
3422
-     * @throws InvalidInterfaceException
3423
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3424
-     * @since 4.5.0
3425
-     */
3426
-    public function redirect_after_action(
3427
-        $success = false,
3428
-        $what = 'item',
3429
-        $action_desc = 'processed',
3430
-        $query_args = array(),
3431
-        $override_overwrite = false
3432
-    ) {
3433
-        $this->_redirect_after_action(
3434
-            $success,
3435
-            $what,
3436
-            $action_desc,
3437
-            $query_args,
3438
-            $override_overwrite
3439
-        );
3440
-    }
3441
-
3442
-
3443
-    /**
3444
-     * Helper method for merging existing request data with the returned redirect url.
3445
-     *
3446
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3447
-     * filters are still applied.
3448
-     *
3449
-     * @param array $new_route_data
3450
-     * @return array
3451
-     */
3452
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3453
-    {
3454
-        foreach ($this->_req_data as $ref => $value) {
3455
-            // unset nonces
3456
-            if (strpos($ref, 'nonce') !== false) {
3457
-                unset($this->_req_data[ $ref ]);
3458
-                continue;
3459
-            }
3460
-            // urlencode values.
3461
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3462
-            $this->_req_data[ $ref ] = $value;
3463
-        }
3464
-        return array_merge($this->_req_data, $new_route_data);
3465
-    }
3466
-
3467
-
3468
-    /**
3469
-     *    _redirect_after_action
3470
-     *
3471
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3472
-     * @param string $what               - what the action was performed on
3473
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3474
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3475
-     *                                   action is completed
3476
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3477
-     *                                   override this so that they show.
3478
-     * @return void
3479
-     * @throws EE_Error
3480
-     * @throws InvalidArgumentException
3481
-     * @throws InvalidDataTypeException
3482
-     * @throws InvalidInterfaceException
3483
-     */
3484
-    protected function _redirect_after_action(
3485
-        $success = 0,
3486
-        $what = 'item',
3487
-        $action_desc = 'processed',
3488
-        $query_args = array(),
3489
-        $override_overwrite = false
3490
-    ) {
3491
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3492
-        // class name for actions/filters.
3493
-        $classname = get_class($this);
3494
-        // set redirect url.
3495
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3496
-        // otherwise we go with whatever is set as the _admin_base_url
3497
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3498
-        $notices = EE_Error::get_notices(false);
3499
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3500
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3501
-            EE_Error::overwrite_success();
3502
-        }
3503
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3504
-            // how many records affected ? more than one record ? or just one ?
3505
-            if ($success > 1) {
3506
-                // set plural msg
3507
-                EE_Error::add_success(
3508
-                    sprintf(
3509
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3510
-                        $what,
3511
-                        $action_desc
3512
-                    ),
3513
-                    __FILE__,
3514
-                    __FUNCTION__,
3515
-                    __LINE__
3516
-                );
3517
-            } elseif ($success === 1) {
3518
-                // set singular msg
3519
-                EE_Error::add_success(
3520
-                    sprintf(
3521
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3522
-                        $what,
3523
-                        $action_desc
3524
-                    ),
3525
-                    __FILE__,
3526
-                    __FUNCTION__,
3527
-                    __LINE__
3528
-                );
3529
-            }
3530
-        }
3531
-        // check that $query_args isn't something crazy
3532
-        if (! is_array($query_args)) {
3533
-            $query_args = array();
3534
-        }
3535
-        /**
3536
-         * Allow injecting actions before the query_args are modified for possible different
3537
-         * redirections on save and close actions
3538
-         *
3539
-         * @since 4.2.0
3540
-         * @param array $query_args       The original query_args array coming into the
3541
-         *                                method.
3542
-         */
3543
-        do_action(
3544
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3545
-            $query_args
3546
-        );
3547
-        // calculate where we're going (if we have a "save and close" button pushed)
3548
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3549
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3550
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3551
-            // regenerate query args array from referrer URL
3552
-            parse_str($parsed_url['query'], $query_args);
3553
-            // correct page and action will be in the query args now
3554
-            $redirect_url = admin_url('admin.php');
3555
-        }
3556
-        // merge any default query_args set in _default_route_query_args property
3557
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3558
-            $args_to_merge = array();
3559
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3560
-                // is there a wp_referer array in our _default_route_query_args property?
3561
-                if ($query_param === 'wp_referer') {
3562
-                    $query_value = (array) $query_value;
3563
-                    foreach ($query_value as $reference => $value) {
3564
-                        if (strpos($reference, 'nonce') !== false) {
3565
-                            continue;
3566
-                        }
3567
-                        // finally we will override any arguments in the referer with
3568
-                        // what might be set on the _default_route_query_args array.
3569
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3570
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3571
-                        } else {
3572
-                            $args_to_merge[ $reference ] = urlencode($value);
3573
-                        }
3574
-                    }
3575
-                    continue;
3576
-                }
3577
-                $args_to_merge[ $query_param ] = $query_value;
3578
-            }
3579
-            // now let's merge these arguments but override with what was specifically sent in to the
3580
-            // redirect.
3581
-            $query_args = array_merge($args_to_merge, $query_args);
3582
-        }
3583
-        $this->_process_notices($query_args);
3584
-        // generate redirect url
3585
-        // if redirecting to anything other than the main page, add a nonce
3586
-        if (isset($query_args['action'])) {
3587
-            // manually generate wp_nonce and merge that with the query vars
3588
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3589
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3590
-        }
3591
-        // we're adding some hooks and filters in here for processing any things just before redirects
3592
-        // (example: an admin page has done an insert or update and we want to run something after that).
3593
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3594
-        $redirect_url = apply_filters(
3595
-            'FHEE_redirect_' . $classname . $this->_req_action,
3596
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3597
-            $query_args
3598
-        );
3599
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3600
-        if (defined('DOING_AJAX')) {
3601
-            $default_data = array(
3602
-                'close'        => true,
3603
-                'redirect_url' => $redirect_url,
3604
-                'where'        => 'main',
3605
-                'what'         => 'append',
3606
-            );
3607
-            $this->_template_args['success'] = $success;
3608
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3609
-                $default_data,
3610
-                $this->_template_args['data']
3611
-            ) : $default_data;
3612
-            $this->_return_json();
3613
-        }
3614
-        wp_safe_redirect($redirect_url);
3615
-        exit();
3616
-    }
3617
-
3618
-
3619
-    /**
3620
-     * process any notices before redirecting (or returning ajax request)
3621
-     * This method sets the $this->_template_args['notices'] attribute;
3622
-     *
3623
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3624
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3625
-     *                                  page_routes haven't been defined yet.
3626
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3627
-     *                                  still save a transient for the notice.
3628
-     * @return void
3629
-     * @throws EE_Error
3630
-     * @throws InvalidArgumentException
3631
-     * @throws InvalidDataTypeException
3632
-     * @throws InvalidInterfaceException
3633
-     */
3634
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3635
-    {
3636
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3637
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3638
-            $notices = EE_Error::get_notices(false);
3639
-            if (empty($this->_template_args['success'])) {
3640
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3641
-            }
3642
-            if (empty($this->_template_args['errors'])) {
3643
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3644
-            }
3645
-            if (empty($this->_template_args['attention'])) {
3646
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3647
-            }
3648
-        }
3649
-        $this->_template_args['notices'] = EE_Error::get_notices();
3650
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3651
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3652
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3653
-            $this->_add_transient(
3654
-                $route,
3655
-                $this->_template_args['notices'],
3656
-                true,
3657
-                $skip_route_verify
3658
-            );
3659
-        }
3660
-    }
3661
-
3662
-
3663
-    /**
3664
-     * get_action_link_or_button
3665
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3666
-     *
3667
-     * @param string $action        use this to indicate which action the url is generated with.
3668
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3669
-     *                              property.
3670
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3671
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3672
-     * @param string $base_url      If this is not provided
3673
-     *                              the _admin_base_url will be used as the default for the button base_url.
3674
-     *                              Otherwise this value will be used.
3675
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3676
-     * @return string
3677
-     * @throws InvalidArgumentException
3678
-     * @throws InvalidInterfaceException
3679
-     * @throws InvalidDataTypeException
3680
-     * @throws EE_Error
3681
-     */
3682
-    public function get_action_link_or_button(
3683
-        $action,
3684
-        $type = 'add',
3685
-        $extra_request = array(),
3686
-        $class = 'button-primary',
3687
-        $base_url = '',
3688
-        $exclude_nonce = false
3689
-    ) {
3690
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3691
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3692
-            throw new EE_Error(
3693
-                sprintf(
3694
-                    esc_html__(
3695
-                        'There is no page route for given action for the button.  This action was given: %s',
3696
-                        'event_espresso'
3697
-                    ),
3698
-                    $action
3699
-                )
3700
-            );
3701
-        }
3702
-        if (! isset($this->_labels['buttons'][ $type ])) {
3703
-            throw new EE_Error(
3704
-                sprintf(
3705
-                    __(
3706
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3707
-                        'event_espresso'
3708
-                    ),
3709
-                    $type
3710
-                )
3711
-            );
3712
-        }
3713
-        // finally check user access for this button.
3714
-        $has_access = $this->check_user_access($action, true);
3715
-        if (! $has_access) {
3716
-            return '';
3717
-        }
3718
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3719
-        $query_args = array(
3720
-            'action' => $action,
3721
-        );
3722
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3723
-        if (! empty($extra_request)) {
3724
-            $query_args = array_merge($extra_request, $query_args);
3725
-        }
3726
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3727
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3728
-    }
3729
-
3730
-
3731
-    /**
3732
-     * _per_page_screen_option
3733
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3734
-     *
3735
-     * @return void
3736
-     * @throws InvalidArgumentException
3737
-     * @throws InvalidInterfaceException
3738
-     * @throws InvalidDataTypeException
3739
-     */
3740
-    protected function _per_page_screen_option()
3741
-    {
3742
-        $option = 'per_page';
3743
-        $args = array(
3744
-            'label'   => apply_filters(
3745
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3746
-                $this->_admin_page_title,
3747
-                $this
3748
-            ),
3749
-            'default' => (int) apply_filters(
3750
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3751
-                20
3752
-            ),
3753
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3754
-        );
3755
-        // ONLY add the screen option if the user has access to it.
3756
-        if ($this->check_user_access($this->_current_view, true)) {
3757
-            add_screen_option($option, $args);
3758
-        }
3759
-    }
3760
-
3761
-
3762
-    /**
3763
-     * set_per_page_screen_option
3764
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3765
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3766
-     * admin_menu.
3767
-     *
3768
-     * @return void
3769
-     */
3770
-    private function _set_per_page_screen_options()
3771
-    {
3772
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3773
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3774
-            if (! $user = wp_get_current_user()) {
3775
-                return;
3776
-            }
3777
-            $option = $_POST['wp_screen_options']['option'];
3778
-            $value = $_POST['wp_screen_options']['value'];
3779
-            if ($option !== sanitize_key($option)) {
3780
-                return;
3781
-            }
3782
-            $map_option = $option;
3783
-            $option = str_replace('-', '_', $option);
3784
-            switch ($map_option) {
3785
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3786
-                    $value = (int) $value;
3787
-                    $max_value = apply_filters(
3788
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3789
-                        999,
3790
-                        $this->_current_page,
3791
-                        $this->_current_view
3792
-                    );
3793
-                    if ($value < 1) {
3794
-                        return;
3795
-                    }
3796
-                    $value = min($value, $max_value);
3797
-                    break;
3798
-                default:
3799
-                    $value = apply_filters(
3800
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3801
-                        false,
3802
-                        $option,
3803
-                        $value
3804
-                    );
3805
-                    if (false === $value) {
3806
-                        return;
3807
-                    }
3808
-                    break;
3809
-            }
3810
-            update_user_meta($user->ID, $option, $value);
3811
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3812
-            exit;
3813
-        }
3814
-    }
3815
-
3816
-
3817
-    /**
3818
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3819
-     *
3820
-     * @param array $data array that will be assigned to template args.
3821
-     */
3822
-    public function set_template_args($data)
3823
-    {
3824
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3825
-    }
3826
-
3827
-
3828
-    /**
3829
-     * This makes available the WP transient system for temporarily moving data between routes
3830
-     *
3831
-     * @param string $route             the route that should receive the transient
3832
-     * @param array  $data              the data that gets sent
3833
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3834
-     *                                  normal route transient.
3835
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3836
-     *                                  when we are adding a transient before page_routes have been defined.
3837
-     * @return void
3838
-     * @throws EE_Error
3839
-     */
3840
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3841
-    {
3842
-        $user_id = get_current_user_id();
3843
-        if (! $skip_route_verify) {
3844
-            $this->_verify_route($route);
3845
-        }
3846
-        // now let's set the string for what kind of transient we're setting
3847
-        $transient = $notices
3848
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3849
-            : 'rte_tx_' . $route . '_' . $user_id;
3850
-        $data = $notices ? array('notices' => $data) : $data;
3851
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3852
-        $existing = is_multisite() && is_network_admin()
3853
-            ? get_site_transient($transient)
3854
-            : get_transient($transient);
3855
-        if ($existing) {
3856
-            $data = array_merge((array) $data, (array) $existing);
3857
-        }
3858
-        if (is_multisite() && is_network_admin()) {
3859
-            set_site_transient($transient, $data, 8);
3860
-        } else {
3861
-            set_transient($transient, $data, 8);
3862
-        }
3863
-    }
3864
-
3865
-
3866
-    /**
3867
-     * this retrieves the temporary transient that has been set for moving data between routes.
3868
-     *
3869
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3870
-     * @param string $route
3871
-     * @return mixed data
3872
-     */
3873
-    protected function _get_transient($notices = false, $route = '')
3874
-    {
3875
-        $user_id = get_current_user_id();
3876
-        $route = ! $route ? $this->_req_action : $route;
3877
-        $transient = $notices
3878
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3879
-            : 'rte_tx_' . $route . '_' . $user_id;
3880
-        $data = is_multisite() && is_network_admin()
3881
-            ? get_site_transient($transient)
3882
-            : get_transient($transient);
3883
-        // delete transient after retrieval (just in case it hasn't expired);
3884
-        if (is_multisite() && is_network_admin()) {
3885
-            delete_site_transient($transient);
3886
-        } else {
3887
-            delete_transient($transient);
3888
-        }
3889
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3890
-    }
3891
-
3892
-
3893
-    /**
3894
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3895
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3896
-     * default route callback on the EE_Admin page you want it run.)
3897
-     *
3898
-     * @return void
3899
-     */
3900
-    protected function _transient_garbage_collection()
3901
-    {
3902
-        global $wpdb;
3903
-        // retrieve all existing transients
3904
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3905
-        if ($results = $wpdb->get_results($query)) {
3906
-            foreach ($results as $result) {
3907
-                $transient = str_replace('_transient_', '', $result->option_name);
3908
-                get_transient($transient);
3909
-                if (is_multisite() && is_network_admin()) {
3910
-                    get_site_transient($transient);
3911
-                }
3912
-            }
3913
-        }
3914
-    }
3915
-
3916
-
3917
-    /**
3918
-     * get_view
3919
-     *
3920
-     * @return string content of _view property
3921
-     */
3922
-    public function get_view()
3923
-    {
3924
-        return $this->_view;
3925
-    }
3926
-
3927
-
3928
-    /**
3929
-     * getter for the protected $_views property
3930
-     *
3931
-     * @return array
3932
-     */
3933
-    public function get_views()
3934
-    {
3935
-        return $this->_views;
3936
-    }
3937
-
3938
-
3939
-    /**
3940
-     * get_current_page
3941
-     *
3942
-     * @return string _current_page property value
3943
-     */
3944
-    public function get_current_page()
3945
-    {
3946
-        return $this->_current_page;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * get_current_view
3952
-     *
3953
-     * @return string _current_view property value
3954
-     */
3955
-    public function get_current_view()
3956
-    {
3957
-        return $this->_current_view;
3958
-    }
3959
-
3960
-
3961
-    /**
3962
-     * get_current_screen
3963
-     *
3964
-     * @return object The current WP_Screen object
3965
-     */
3966
-    public function get_current_screen()
3967
-    {
3968
-        return $this->_current_screen;
3969
-    }
3970
-
3971
-
3972
-    /**
3973
-     * get_current_page_view_url
3974
-     *
3975
-     * @return string This returns the url for the current_page_view.
3976
-     */
3977
-    public function get_current_page_view_url()
3978
-    {
3979
-        return $this->_current_page_view_url;
3980
-    }
3981
-
3982
-
3983
-    /**
3984
-     * just returns the _req_data property
3985
-     *
3986
-     * @return array
3987
-     */
3988
-    public function get_request_data()
3989
-    {
3990
-        return $this->_req_data;
3991
-    }
3992
-
3993
-
3994
-    /**
3995
-     * returns the _req_data protected property
3996
-     *
3997
-     * @return string
3998
-     */
3999
-    public function get_req_action()
4000
-    {
4001
-        return $this->_req_action;
4002
-    }
4003
-
4004
-
4005
-    /**
4006
-     * @return bool  value of $_is_caf property
4007
-     */
4008
-    public function is_caf()
4009
-    {
4010
-        return $this->_is_caf;
4011
-    }
4012
-
4013
-
4014
-    /**
4015
-     * @return mixed
4016
-     */
4017
-    public function default_espresso_metaboxes()
4018
-    {
4019
-        return $this->_default_espresso_metaboxes;
4020
-    }
4021
-
4022
-
4023
-    /**
4024
-     * @return mixed
4025
-     */
4026
-    public function admin_base_url()
4027
-    {
4028
-        return $this->_admin_base_url;
4029
-    }
4030
-
4031
-
4032
-    /**
4033
-     * @return mixed
4034
-     */
4035
-    public function wp_page_slug()
4036
-    {
4037
-        return $this->_wp_page_slug;
4038
-    }
4039
-
4040
-
4041
-    /**
4042
-     * updates  espresso configuration settings
4043
-     *
4044
-     * @param string                   $tab
4045
-     * @param EE_Config_Base|EE_Config $config
4046
-     * @param string                   $file file where error occurred
4047
-     * @param string                   $func function  where error occurred
4048
-     * @param string                   $line line no where error occurred
4049
-     * @return boolean
4050
-     */
4051
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
-    {
4053
-        // remove any options that are NOT going to be saved with the config settings.
4054
-        if (isset($config->core->ee_ueip_optin)) {
4055
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4056
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
-            update_option('ee_ueip_has_notified', true);
4058
-        }
4059
-        // and save it (note we're also doing the network save here)
4060
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4061
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
-        if ($config_saved && $net_saved) {
4063
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
-            return true;
4065
-        }
4066
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4067
-        return false;
4068
-    }
4069
-
4070
-
4071
-    /**
4072
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4073
-     *
4074
-     * @return array
4075
-     */
4076
-    public function get_yes_no_values()
4077
-    {
4078
-        return $this->_yes_no_values;
4079
-    }
4080
-
4081
-
4082
-    /**
4083
-     * @return string
4084
-     * @throws ReflectionException
4085
-     * @since $VID:$
4086
-     */
4087
-    protected function _get_dir()
4088
-    {
4089
-        $reflector = new ReflectionClass(get_class($this));
4090
-        return dirname($reflector->getFileName());
4091
-    }
4092
-
4093
-
4094
-    /**
4095
-     * A helper for getting a "next link".
4096
-     *
4097
-     * @param string $url   The url to link to
4098
-     * @param string $class The class to use.
4099
-     * @return string
4100
-     */
4101
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4102
-    {
4103
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4104
-    }
4105
-
4106
-
4107
-    /**
4108
-     * A helper for getting a "previous link".
4109
-     *
4110
-     * @param string $url   The url to link to
4111
-     * @param string $class The class to use.
4112
-     * @return string
4113
-     */
4114
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4115
-    {
4116
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4117
-    }
4118
-
4119
-
4120
-
4121
-
4122
-
4123
-
4124
-
4125
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4126
-
4127
-
4128
-    /**
4129
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4130
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4131
-     * _req_data array.
4132
-     *
4133
-     * @return bool success/fail
4134
-     * @throws EE_Error
4135
-     * @throws InvalidArgumentException
4136
-     * @throws ReflectionException
4137
-     * @throws InvalidDataTypeException
4138
-     * @throws InvalidInterfaceException
4139
-     */
4140
-    protected function _process_resend_registration()
4141
-    {
4142
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4143
-        do_action(
4144
-            'AHEE__EE_Admin_Page___process_resend_registration',
4145
-            $this->_template_args['success'],
4146
-            $this->_req_data
4147
-        );
4148
-        return $this->_template_args['success'];
4149
-    }
4150
-
4151
-
4152
-    /**
4153
-     * This automatically processes any payment message notifications when manual payment has been applied.
4154
-     *
4155
-     * @param EE_Payment $payment
4156
-     * @return bool success/fail
4157
-     */
4158
-    protected function _process_payment_notification(EE_Payment $payment)
4159
-    {
4160
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4161
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4162
-        $this->_template_args['success'] = apply_filters(
4163
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4164
-            false,
4165
-            $payment
4166
-        );
4167
-        return $this->_template_args['success'];
4168
-    }
2690
+	}
2691
+
2692
+
2693
+	/**
2694
+	 * facade for add_meta_box
2695
+	 *
2696
+	 * @param string  $action        where the metabox get's displayed
2697
+	 * @param string  $title         Title of Metabox (output in metabox header)
2698
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2699
+	 *                               instead of the one created in here.
2700
+	 * @param array   $callback_args an array of args supplied for the metabox
2701
+	 * @param string  $column        what metabox column
2702
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2703
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2704
+	 *                               created but just set our own callback for wp's add_meta_box.
2705
+	 * @throws DomainException
2706
+	 */
2707
+	public function _add_admin_page_meta_box(
2708
+		$action,
2709
+		$title,
2710
+		$callback,
2711
+		$callback_args,
2712
+		$column = 'normal',
2713
+		$priority = 'high',
2714
+		$create_func = true
2715
+	) {
2716
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2717
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2718
+		if (empty($callback_args) && $create_func) {
2719
+			$callback_args = array(
2720
+				'template_path' => $this->_template_path,
2721
+				'template_args' => $this->_template_args,
2722
+			);
2723
+		}
2724
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2725
+		$call_back_func = $create_func
2726
+			? static function ($post, $metabox) {
2727
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2728
+				echo EEH_Template::display_template(
2729
+					$metabox['args']['template_path'],
2730
+					$metabox['args']['template_args'],
2731
+					true
2732
+				);
2733
+			}
2734
+			: $callback;
2735
+		add_meta_box(
2736
+			str_replace('_', '-', $action) . '-mbox',
2737
+			$title,
2738
+			$call_back_func,
2739
+			$this->_wp_page_slug,
2740
+			$column,
2741
+			$priority,
2742
+			$callback_args
2743
+		);
2744
+	}
2745
+
2746
+
2747
+	/**
2748
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2749
+	 *
2750
+	 * @throws DomainException
2751
+	 * @throws EE_Error
2752
+	 * @throws InvalidArgumentException
2753
+	 * @throws InvalidDataTypeException
2754
+	 * @throws InvalidInterfaceException
2755
+	 */
2756
+	public function display_admin_page_with_metabox_columns()
2757
+	{
2758
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2759
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2760
+			$this->_column_template_path,
2761
+			$this->_template_args,
2762
+			true
2763
+		);
2764
+		// the final wrapper
2765
+		$this->admin_page_wrapper();
2766
+	}
2767
+
2768
+
2769
+	/**
2770
+	 * generates  HTML wrapper for an admin details page
2771
+	 *
2772
+	 * @return void
2773
+	 * @throws DomainException
2774
+	 * @throws EE_Error
2775
+	 * @throws InvalidArgumentException
2776
+	 * @throws InvalidDataTypeException
2777
+	 * @throws InvalidInterfaceException
2778
+	 */
2779
+	public function display_admin_page_with_sidebar()
2780
+	{
2781
+		$this->_display_admin_page(true);
2782
+	}
2783
+
2784
+
2785
+	/**
2786
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2787
+	 *
2788
+	 * @return void
2789
+	 * @throws DomainException
2790
+	 * @throws EE_Error
2791
+	 * @throws InvalidArgumentException
2792
+	 * @throws InvalidDataTypeException
2793
+	 * @throws InvalidInterfaceException
2794
+	 */
2795
+	public function display_admin_page_with_no_sidebar()
2796
+	{
2797
+		$this->_display_admin_page();
2798
+	}
2799
+
2800
+
2801
+	/**
2802
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2803
+	 *
2804
+	 * @return void
2805
+	 * @throws DomainException
2806
+	 * @throws EE_Error
2807
+	 * @throws InvalidArgumentException
2808
+	 * @throws InvalidDataTypeException
2809
+	 * @throws InvalidInterfaceException
2810
+	 */
2811
+	public function display_about_admin_page()
2812
+	{
2813
+		$this->_display_admin_page(false, true);
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * display_admin_page
2819
+	 * contains the code for actually displaying an admin page
2820
+	 *
2821
+	 * @param boolean $sidebar true with sidebar, false without
2822
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2823
+	 * @return void
2824
+	 * @throws DomainException
2825
+	 * @throws EE_Error
2826
+	 * @throws InvalidArgumentException
2827
+	 * @throws InvalidDataTypeException
2828
+	 * @throws InvalidInterfaceException
2829
+	 */
2830
+	private function _display_admin_page($sidebar = false, $about = false)
2831
+	{
2832
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2833
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2834
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2835
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2836
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2837
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2838
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2839
+			? 'poststuff'
2840
+			: 'espresso-default-admin';
2841
+		$template_path = $sidebar
2842
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2843
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2844
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2845
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2846
+		}
2847
+		$template_path = ! empty($this->_column_template_path)
2848
+			? $this->_column_template_path : $template_path;
2849
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2850
+			? $this->_template_args['admin_page_content']
2851
+			: '';
2852
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2853
+			? $this->_template_args['before_admin_page_content']
2854
+			: '';
2855
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2856
+			? $this->_template_args['after_admin_page_content']
2857
+			: '';
2858
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2859
+			$template_path,
2860
+			$this->_template_args,
2861
+			true
2862
+		);
2863
+		// the final template wrapper
2864
+		$this->admin_page_wrapper($about);
2865
+	}
2866
+
2867
+
2868
+	/**
2869
+	 * This is used to display caf preview pages.
2870
+	 *
2871
+	 * @since 4.3.2
2872
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2873
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2874
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2875
+	 * @return void
2876
+	 * @throws DomainException
2877
+	 * @throws EE_Error
2878
+	 * @throws InvalidArgumentException
2879
+	 * @throws InvalidDataTypeException
2880
+	 * @throws InvalidInterfaceException
2881
+	 */
2882
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2883
+	{
2884
+		// let's generate a default preview action button if there isn't one already present.
2885
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2886
+			'Upgrade to Event Espresso 4 Right Now',
2887
+			'event_espresso'
2888
+		);
2889
+		$buy_now_url = add_query_arg(
2890
+			array(
2891
+				'ee_ver'       => 'ee4',
2892
+				'utm_source'   => 'ee4_plugin_admin',
2893
+				'utm_medium'   => 'link',
2894
+				'utm_campaign' => $utm_campaign_source,
2895
+				'utm_content'  => 'buy_now_button',
2896
+			),
2897
+			'http://eventespresso.com/pricing/'
2898
+		);
2899
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2900
+			? $this->get_action_link_or_button(
2901
+				'',
2902
+				'buy_now',
2903
+				array(),
2904
+				'button-primary button-large',
2905
+				$buy_now_url,
2906
+				true
2907
+			)
2908
+			: $this->_template_args['preview_action_button'];
2909
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2910
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2911
+			$this->_template_args,
2912
+			true
2913
+		);
2914
+		$this->_display_admin_page($display_sidebar);
2915
+	}
2916
+
2917
+
2918
+	/**
2919
+	 * display_admin_list_table_page_with_sidebar
2920
+	 * generates HTML wrapper for an admin_page with list_table
2921
+	 *
2922
+	 * @return void
2923
+	 * @throws DomainException
2924
+	 * @throws EE_Error
2925
+	 * @throws InvalidArgumentException
2926
+	 * @throws InvalidDataTypeException
2927
+	 * @throws InvalidInterfaceException
2928
+	 */
2929
+	public function display_admin_list_table_page_with_sidebar()
2930
+	{
2931
+		$this->_display_admin_list_table_page(true);
2932
+	}
2933
+
2934
+
2935
+	/**
2936
+	 * display_admin_list_table_page_with_no_sidebar
2937
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2938
+	 *
2939
+	 * @return void
2940
+	 * @throws DomainException
2941
+	 * @throws EE_Error
2942
+	 * @throws InvalidArgumentException
2943
+	 * @throws InvalidDataTypeException
2944
+	 * @throws InvalidInterfaceException
2945
+	 */
2946
+	public function display_admin_list_table_page_with_no_sidebar()
2947
+	{
2948
+		$this->_display_admin_list_table_page();
2949
+	}
2950
+
2951
+
2952
+	/**
2953
+	 * generates html wrapper for an admin_list_table page
2954
+	 *
2955
+	 * @param boolean $sidebar whether to display with sidebar or not.
2956
+	 * @return void
2957
+	 * @throws DomainException
2958
+	 * @throws EE_Error
2959
+	 * @throws InvalidArgumentException
2960
+	 * @throws InvalidDataTypeException
2961
+	 * @throws InvalidInterfaceException
2962
+	 */
2963
+	private function _display_admin_list_table_page($sidebar = false)
2964
+	{
2965
+		// setup search attributes
2966
+		$this->_set_search_attributes();
2967
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2968
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2969
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2970
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2971
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2972
+		$this->_template_args['list_table'] = $this->_list_table_object;
2973
+		$this->_template_args['current_route'] = $this->_req_action;
2974
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2975
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2976
+		if (! empty($ajax_sorting_callback)) {
2977
+			$sortable_list_table_form_fields = wp_nonce_field(
2978
+				$ajax_sorting_callback . '_nonce',
2979
+				$ajax_sorting_callback . '_nonce',
2980
+				false,
2981
+				false
2982
+			);
2983
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2984
+												. $this->page_slug
2985
+												. '" />';
2986
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2987
+												. $ajax_sorting_callback
2988
+												. '" />';
2989
+		} else {
2990
+			$sortable_list_table_form_fields = '';
2991
+		}
2992
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2993
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
2994
+			? $this->_template_args['list_table_hidden_fields']
2995
+			: '';
2996
+		$nonce_ref = $this->_req_action . '_nonce';
2997
+		$hidden_form_fields .= '<input type="hidden" name="'
2998
+							   . $nonce_ref
2999
+							   . '" value="'
3000
+							   . wp_create_nonce($nonce_ref)
3001
+							   . '">';
3002
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3003
+		// display message about search results?
3004
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3005
+			? '<p class="ee-search-results">' . sprintf(
3006
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3007
+				trim($this->_req_data['s'], '%')
3008
+			) . '</p>'
3009
+			: '';
3010
+		// filter before_list_table template arg
3011
+		$this->_template_args['before_list_table'] = apply_filters(
3012
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3013
+			$this->_template_args['before_list_table'],
3014
+			$this->page_slug,
3015
+			$this->_req_data,
3016
+			$this->_req_action
3017
+		);
3018
+		// convert to array and filter again
3019
+		// arrays are easier to inject new items in a specific location,
3020
+		// but would not be backwards compatible, so we have to add a new filter
3021
+		$this->_template_args['before_list_table'] = implode(
3022
+			" \n",
3023
+			(array) apply_filters(
3024
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3025
+				(array) $this->_template_args['before_list_table'],
3026
+				$this->page_slug,
3027
+				$this->_req_data,
3028
+				$this->_req_action
3029
+			)
3030
+		);
3031
+		// filter after_list_table template arg
3032
+		$this->_template_args['after_list_table'] = apply_filters(
3033
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3034
+			$this->_template_args['after_list_table'],
3035
+			$this->page_slug,
3036
+			$this->_req_data,
3037
+			$this->_req_action
3038
+		);
3039
+		// convert to array and filter again
3040
+		// arrays are easier to inject new items in a specific location,
3041
+		// but would not be backwards compatible, so we have to add a new filter
3042
+		$this->_template_args['after_list_table'] = implode(
3043
+			" \n",
3044
+			(array) apply_filters(
3045
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3046
+				(array) $this->_template_args['after_list_table'],
3047
+				$this->page_slug,
3048
+				$this->_req_data,
3049
+				$this->_req_action
3050
+			)
3051
+		);
3052
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3053
+			$template_path,
3054
+			$this->_template_args,
3055
+			true
3056
+		);
3057
+		// the final template wrapper
3058
+		if ($sidebar) {
3059
+			$this->display_admin_page_with_sidebar();
3060
+		} else {
3061
+			$this->display_admin_page_with_no_sidebar();
3062
+		}
3063
+	}
3064
+
3065
+
3066
+	/**
3067
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3068
+	 * html string for the legend.
3069
+	 * $items are expected in an array in the following format:
3070
+	 * $legend_items = array(
3071
+	 *        'item_id' => array(
3072
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3073
+	 *            'desc' => esc_html__('localized description of item');
3074
+	 *        )
3075
+	 * );
3076
+	 *
3077
+	 * @param  array $items see above for format of array
3078
+	 * @return string html string of legend
3079
+	 * @throws DomainException
3080
+	 */
3081
+	protected function _display_legend($items)
3082
+	{
3083
+		$this->_template_args['items'] = apply_filters(
3084
+			'FHEE__EE_Admin_Page___display_legend__items',
3085
+			(array) $items,
3086
+			$this
3087
+		);
3088
+		/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3089
+		$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3090
+		if (! $status_change_notice->isDismissed()) {
3091
+			$this->_template_args['status_change_notice'] = EEH_Template::display_template(
3092
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3093
+				[ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3094
+				true
3095
+			);
3096
+		}
3097
+		return EEH_Template::display_template(
3098
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3099
+			$this->_template_args,
3100
+			true
3101
+		);
3102
+	}
3103
+
3104
+
3105
+	/**
3106
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3107
+	 * The returned json object is created from an array in the following format:
3108
+	 * array(
3109
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3110
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3111
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3112
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3113
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3114
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3115
+	 *  that might be included in here)
3116
+	 * )
3117
+	 * The json object is populated by whatever is set in the $_template_args property.
3118
+	 *
3119
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3120
+	 *                                 instead of displayed.
3121
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3122
+	 * @return void
3123
+	 * @throws EE_Error
3124
+	 * @throws InvalidArgumentException
3125
+	 * @throws InvalidDataTypeException
3126
+	 * @throws InvalidInterfaceException
3127
+	 */
3128
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3129
+	{
3130
+		// make sure any EE_Error notices have been handled.
3131
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3132
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3133
+		unset($this->_template_args['data']);
3134
+		$json = array(
3135
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3136
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3137
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3138
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3139
+			'notices'   => EE_Error::get_notices(),
3140
+			'content'   => isset($this->_template_args['admin_page_content'])
3141
+				? $this->_template_args['admin_page_content'] : '',
3142
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3143
+			'isEEajax'  => true
3144
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3145
+		);
3146
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3147
+		if (null === error_get_last() || ! headers_sent()) {
3148
+			header('Content-Type: application/json; charset=UTF-8');
3149
+		}
3150
+		echo wp_json_encode($json);
3151
+		exit();
3152
+	}
3153
+
3154
+
3155
+	/**
3156
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3157
+	 *
3158
+	 * @return void
3159
+	 * @throws EE_Error
3160
+	 * @throws InvalidArgumentException
3161
+	 * @throws InvalidDataTypeException
3162
+	 * @throws InvalidInterfaceException
3163
+	 */
3164
+	public function return_json()
3165
+	{
3166
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3167
+			$this->_return_json();
3168
+		} else {
3169
+			throw new EE_Error(
3170
+				sprintf(
3171
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3172
+					__FUNCTION__
3173
+				)
3174
+			);
3175
+		}
3176
+	}
3177
+
3178
+
3179
+	/**
3180
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3181
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3182
+	 *
3183
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3184
+	 */
3185
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3186
+	{
3187
+		$this->_hook_obj = $hook_obj;
3188
+	}
3189
+
3190
+
3191
+	/**
3192
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3193
+	 *
3194
+	 * @param boolean $about whether to use the special about page wrapper or default.
3195
+	 * @return void
3196
+	 * @throws DomainException
3197
+	 * @throws EE_Error
3198
+	 * @throws InvalidArgumentException
3199
+	 * @throws InvalidDataTypeException
3200
+	 * @throws InvalidInterfaceException
3201
+	 */
3202
+	public function admin_page_wrapper($about = false)
3203
+	{
3204
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3206
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3207
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3208
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3209
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3210
+			isset($this->_template_args['before_admin_page_content'])
3211
+				? $this->_template_args['before_admin_page_content']
3212
+				: ''
3213
+		);
3214
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3215
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3216
+			isset($this->_template_args['after_admin_page_content'])
3217
+				? $this->_template_args['after_admin_page_content']
3218
+				: ''
3219
+		);
3220
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3221
+		// load settings page wrapper template
3222
+		$template_path = ! defined('DOING_AJAX')
3223
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3224
+			: EE_ADMIN_TEMPLATE
3225
+			  . 'admin_wrapper_ajax.template.php';
3226
+		// about page?
3227
+		$template_path = $about
3228
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3229
+			: $template_path;
3230
+		if (defined('DOING_AJAX')) {
3231
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3232
+				$template_path,
3233
+				$this->_template_args,
3234
+				true
3235
+			);
3236
+			$this->_return_json();
3237
+		} else {
3238
+			EEH_Template::display_template($template_path, $this->_template_args);
3239
+		}
3240
+	}
3241
+
3242
+
3243
+	/**
3244
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3245
+	 *
3246
+	 * @return string html
3247
+	 * @throws EE_Error
3248
+	 */
3249
+	protected function _get_main_nav_tabs()
3250
+	{
3251
+		// let's generate the html using the EEH_Tabbed_Content helper.
3252
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3253
+		// (rather than setting in the page_routes array)
3254
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3255
+	}
3256
+
3257
+
3258
+	/**
3259
+	 *        sort nav tabs
3260
+	 *
3261
+	 * @param $a
3262
+	 * @param $b
3263
+	 * @return int
3264
+	 */
3265
+	private function _sort_nav_tabs($a, $b)
3266
+	{
3267
+		if ($a['order'] === $b['order']) {
3268
+			return 0;
3269
+		}
3270
+		return ($a['order'] < $b['order']) ? -1 : 1;
3271
+	}
3272
+
3273
+
3274
+	/**
3275
+	 *    generates HTML for the forms used on admin pages
3276
+	 *
3277
+	 * @param    array $input_vars - array of input field details
3278
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3279
+	 *                             use)
3280
+	 * @param bool     $id
3281
+	 * @return string
3282
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3283
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3284
+	 */
3285
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3286
+	{
3287
+		return $generator === 'string'
3288
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3289
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3290
+	}
3291
+
3292
+
3293
+	/**
3294
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3295
+	 *
3296
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3297
+	 *                                   Close" button.
3298
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3299
+	 *                                   'Save', [1] => 'save & close')
3300
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3301
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3302
+	 *                                   default actions by submitting some other value.
3303
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3304
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3305
+	 *                                   close (normal form handling).
3306
+	 */
3307
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3308
+	{
3309
+		// make sure $text and $actions are in an array
3310
+		$text = (array) $text;
3311
+		$actions = (array) $actions;
3312
+		$referrer_url = empty($referrer)
3313
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3314
+			  . $_SERVER['REQUEST_URI']
3315
+			  . '" />'
3316
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3317
+			  . $referrer
3318
+			  . '" />';
3319
+		$button_text = ! empty($text)
3320
+			? $text
3321
+			: array(
3322
+				esc_html__('Save', 'event_espresso'),
3323
+				esc_html__('Save and Close', 'event_espresso'),
3324
+			);
3325
+		$default_names = array('save', 'save_and_close');
3326
+		// add in a hidden index for the current page (so save and close redirects properly)
3327
+		$this->_template_args['save_buttons'] = $referrer_url;
3328
+		foreach ($button_text as $key => $button) {
3329
+			$ref = $default_names[ $key ];
3330
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3331
+													 . $ref
3332
+													 . '" value="'
3333
+													 . $button
3334
+													 . '" name="'
3335
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3336
+													 . '" id="'
3337
+													 . $this->_current_view . '_' . $ref
3338
+													 . '" />';
3339
+			if (! $both) {
3340
+				break;
3341
+			}
3342
+		}
3343
+	}
3344
+
3345
+
3346
+	/**
3347
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3348
+	 *
3349
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3350
+	 * @since 4.6.0
3351
+	 * @param string $route
3352
+	 * @param array  $additional_hidden_fields
3353
+	 */
3354
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3355
+	{
3356
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3357
+	}
3358
+
3359
+
3360
+	/**
3361
+	 * set form open and close tags on add/edit pages.
3362
+	 *
3363
+	 * @param string $route                    the route you want the form to direct to
3364
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3365
+	 * @return void
3366
+	 */
3367
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3368
+	{
3369
+		if (empty($route)) {
3370
+			$user_msg = esc_html__(
3371
+				'An error occurred. No action was set for this page\'s form.',
3372
+				'event_espresso'
3373
+			);
3374
+			$dev_msg = $user_msg . "\n"
3375
+					   . sprintf(
3376
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3377
+						   __FUNCTION__,
3378
+						   EE_Admin_Page::class
3379
+					   );
3380
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3381
+		}
3382
+		// open form
3383
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3384
+															 . $this->_admin_base_url
3385
+															 . '" id="'
3386
+															 . $route
3387
+															 . '_event_form" >';
3388
+		// add nonce
3389
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3390
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3391
+		// add REQUIRED form action
3392
+		$hidden_fields = array(
3393
+			'action' => array('type' => 'hidden', 'value' => $route),
3394
+		);
3395
+		// merge arrays
3396
+		$hidden_fields = is_array($additional_hidden_fields)
3397
+			? array_merge($hidden_fields, $additional_hidden_fields)
3398
+			: $hidden_fields;
3399
+		// generate form fields
3400
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3401
+		// add fields to form
3402
+		foreach ((array) $form_fields as $field_name => $form_field) {
3403
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3404
+		}
3405
+		// close form
3406
+		$this->_template_args['after_admin_page_content'] = '</form>';
3407
+	}
3408
+
3409
+
3410
+	/**
3411
+	 * Public Wrapper for _redirect_after_action() method since its
3412
+	 * discovered it would be useful for external code to have access.
3413
+	 *
3414
+	 * @param bool   $success
3415
+	 * @param string $what
3416
+	 * @param string $action_desc
3417
+	 * @param array  $query_args
3418
+	 * @param bool   $override_overwrite
3419
+	 * @throws EE_Error
3420
+	 * @throws InvalidArgumentException
3421
+	 * @throws InvalidDataTypeException
3422
+	 * @throws InvalidInterfaceException
3423
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3424
+	 * @since 4.5.0
3425
+	 */
3426
+	public function redirect_after_action(
3427
+		$success = false,
3428
+		$what = 'item',
3429
+		$action_desc = 'processed',
3430
+		$query_args = array(),
3431
+		$override_overwrite = false
3432
+	) {
3433
+		$this->_redirect_after_action(
3434
+			$success,
3435
+			$what,
3436
+			$action_desc,
3437
+			$query_args,
3438
+			$override_overwrite
3439
+		);
3440
+	}
3441
+
3442
+
3443
+	/**
3444
+	 * Helper method for merging existing request data with the returned redirect url.
3445
+	 *
3446
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3447
+	 * filters are still applied.
3448
+	 *
3449
+	 * @param array $new_route_data
3450
+	 * @return array
3451
+	 */
3452
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3453
+	{
3454
+		foreach ($this->_req_data as $ref => $value) {
3455
+			// unset nonces
3456
+			if (strpos($ref, 'nonce') !== false) {
3457
+				unset($this->_req_data[ $ref ]);
3458
+				continue;
3459
+			}
3460
+			// urlencode values.
3461
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3462
+			$this->_req_data[ $ref ] = $value;
3463
+		}
3464
+		return array_merge($this->_req_data, $new_route_data);
3465
+	}
3466
+
3467
+
3468
+	/**
3469
+	 *    _redirect_after_action
3470
+	 *
3471
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3472
+	 * @param string $what               - what the action was performed on
3473
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3474
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3475
+	 *                                   action is completed
3476
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3477
+	 *                                   override this so that they show.
3478
+	 * @return void
3479
+	 * @throws EE_Error
3480
+	 * @throws InvalidArgumentException
3481
+	 * @throws InvalidDataTypeException
3482
+	 * @throws InvalidInterfaceException
3483
+	 */
3484
+	protected function _redirect_after_action(
3485
+		$success = 0,
3486
+		$what = 'item',
3487
+		$action_desc = 'processed',
3488
+		$query_args = array(),
3489
+		$override_overwrite = false
3490
+	) {
3491
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3492
+		// class name for actions/filters.
3493
+		$classname = get_class($this);
3494
+		// set redirect url.
3495
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3496
+		// otherwise we go with whatever is set as the _admin_base_url
3497
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3498
+		$notices = EE_Error::get_notices(false);
3499
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3500
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3501
+			EE_Error::overwrite_success();
3502
+		}
3503
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3504
+			// how many records affected ? more than one record ? or just one ?
3505
+			if ($success > 1) {
3506
+				// set plural msg
3507
+				EE_Error::add_success(
3508
+					sprintf(
3509
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3510
+						$what,
3511
+						$action_desc
3512
+					),
3513
+					__FILE__,
3514
+					__FUNCTION__,
3515
+					__LINE__
3516
+				);
3517
+			} elseif ($success === 1) {
3518
+				// set singular msg
3519
+				EE_Error::add_success(
3520
+					sprintf(
3521
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3522
+						$what,
3523
+						$action_desc
3524
+					),
3525
+					__FILE__,
3526
+					__FUNCTION__,
3527
+					__LINE__
3528
+				);
3529
+			}
3530
+		}
3531
+		// check that $query_args isn't something crazy
3532
+		if (! is_array($query_args)) {
3533
+			$query_args = array();
3534
+		}
3535
+		/**
3536
+		 * Allow injecting actions before the query_args are modified for possible different
3537
+		 * redirections on save and close actions
3538
+		 *
3539
+		 * @since 4.2.0
3540
+		 * @param array $query_args       The original query_args array coming into the
3541
+		 *                                method.
3542
+		 */
3543
+		do_action(
3544
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3545
+			$query_args
3546
+		);
3547
+		// calculate where we're going (if we have a "save and close" button pushed)
3548
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3549
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3550
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3551
+			// regenerate query args array from referrer URL
3552
+			parse_str($parsed_url['query'], $query_args);
3553
+			// correct page and action will be in the query args now
3554
+			$redirect_url = admin_url('admin.php');
3555
+		}
3556
+		// merge any default query_args set in _default_route_query_args property
3557
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3558
+			$args_to_merge = array();
3559
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3560
+				// is there a wp_referer array in our _default_route_query_args property?
3561
+				if ($query_param === 'wp_referer') {
3562
+					$query_value = (array) $query_value;
3563
+					foreach ($query_value as $reference => $value) {
3564
+						if (strpos($reference, 'nonce') !== false) {
3565
+							continue;
3566
+						}
3567
+						// finally we will override any arguments in the referer with
3568
+						// what might be set on the _default_route_query_args array.
3569
+						if (isset($this->_default_route_query_args[ $reference ])) {
3570
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3571
+						} else {
3572
+							$args_to_merge[ $reference ] = urlencode($value);
3573
+						}
3574
+					}
3575
+					continue;
3576
+				}
3577
+				$args_to_merge[ $query_param ] = $query_value;
3578
+			}
3579
+			// now let's merge these arguments but override with what was specifically sent in to the
3580
+			// redirect.
3581
+			$query_args = array_merge($args_to_merge, $query_args);
3582
+		}
3583
+		$this->_process_notices($query_args);
3584
+		// generate redirect url
3585
+		// if redirecting to anything other than the main page, add a nonce
3586
+		if (isset($query_args['action'])) {
3587
+			// manually generate wp_nonce and merge that with the query vars
3588
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3589
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3590
+		}
3591
+		// we're adding some hooks and filters in here for processing any things just before redirects
3592
+		// (example: an admin page has done an insert or update and we want to run something after that).
3593
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3594
+		$redirect_url = apply_filters(
3595
+			'FHEE_redirect_' . $classname . $this->_req_action,
3596
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3597
+			$query_args
3598
+		);
3599
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3600
+		if (defined('DOING_AJAX')) {
3601
+			$default_data = array(
3602
+				'close'        => true,
3603
+				'redirect_url' => $redirect_url,
3604
+				'where'        => 'main',
3605
+				'what'         => 'append',
3606
+			);
3607
+			$this->_template_args['success'] = $success;
3608
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3609
+				$default_data,
3610
+				$this->_template_args['data']
3611
+			) : $default_data;
3612
+			$this->_return_json();
3613
+		}
3614
+		wp_safe_redirect($redirect_url);
3615
+		exit();
3616
+	}
3617
+
3618
+
3619
+	/**
3620
+	 * process any notices before redirecting (or returning ajax request)
3621
+	 * This method sets the $this->_template_args['notices'] attribute;
3622
+	 *
3623
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3624
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3625
+	 *                                  page_routes haven't been defined yet.
3626
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3627
+	 *                                  still save a transient for the notice.
3628
+	 * @return void
3629
+	 * @throws EE_Error
3630
+	 * @throws InvalidArgumentException
3631
+	 * @throws InvalidDataTypeException
3632
+	 * @throws InvalidInterfaceException
3633
+	 */
3634
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3635
+	{
3636
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3637
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3638
+			$notices = EE_Error::get_notices(false);
3639
+			if (empty($this->_template_args['success'])) {
3640
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3641
+			}
3642
+			if (empty($this->_template_args['errors'])) {
3643
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3644
+			}
3645
+			if (empty($this->_template_args['attention'])) {
3646
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3647
+			}
3648
+		}
3649
+		$this->_template_args['notices'] = EE_Error::get_notices();
3650
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3651
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3652
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3653
+			$this->_add_transient(
3654
+				$route,
3655
+				$this->_template_args['notices'],
3656
+				true,
3657
+				$skip_route_verify
3658
+			);
3659
+		}
3660
+	}
3661
+
3662
+
3663
+	/**
3664
+	 * get_action_link_or_button
3665
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3666
+	 *
3667
+	 * @param string $action        use this to indicate which action the url is generated with.
3668
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3669
+	 *                              property.
3670
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3671
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3672
+	 * @param string $base_url      If this is not provided
3673
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3674
+	 *                              Otherwise this value will be used.
3675
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3676
+	 * @return string
3677
+	 * @throws InvalidArgumentException
3678
+	 * @throws InvalidInterfaceException
3679
+	 * @throws InvalidDataTypeException
3680
+	 * @throws EE_Error
3681
+	 */
3682
+	public function get_action_link_or_button(
3683
+		$action,
3684
+		$type = 'add',
3685
+		$extra_request = array(),
3686
+		$class = 'button-primary',
3687
+		$base_url = '',
3688
+		$exclude_nonce = false
3689
+	) {
3690
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3691
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3692
+			throw new EE_Error(
3693
+				sprintf(
3694
+					esc_html__(
3695
+						'There is no page route for given action for the button.  This action was given: %s',
3696
+						'event_espresso'
3697
+					),
3698
+					$action
3699
+				)
3700
+			);
3701
+		}
3702
+		if (! isset($this->_labels['buttons'][ $type ])) {
3703
+			throw new EE_Error(
3704
+				sprintf(
3705
+					__(
3706
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3707
+						'event_espresso'
3708
+					),
3709
+					$type
3710
+				)
3711
+			);
3712
+		}
3713
+		// finally check user access for this button.
3714
+		$has_access = $this->check_user_access($action, true);
3715
+		if (! $has_access) {
3716
+			return '';
3717
+		}
3718
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3719
+		$query_args = array(
3720
+			'action' => $action,
3721
+		);
3722
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3723
+		if (! empty($extra_request)) {
3724
+			$query_args = array_merge($extra_request, $query_args);
3725
+		}
3726
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3727
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3728
+	}
3729
+
3730
+
3731
+	/**
3732
+	 * _per_page_screen_option
3733
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3734
+	 *
3735
+	 * @return void
3736
+	 * @throws InvalidArgumentException
3737
+	 * @throws InvalidInterfaceException
3738
+	 * @throws InvalidDataTypeException
3739
+	 */
3740
+	protected function _per_page_screen_option()
3741
+	{
3742
+		$option = 'per_page';
3743
+		$args = array(
3744
+			'label'   => apply_filters(
3745
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3746
+				$this->_admin_page_title,
3747
+				$this
3748
+			),
3749
+			'default' => (int) apply_filters(
3750
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3751
+				20
3752
+			),
3753
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3754
+		);
3755
+		// ONLY add the screen option if the user has access to it.
3756
+		if ($this->check_user_access($this->_current_view, true)) {
3757
+			add_screen_option($option, $args);
3758
+		}
3759
+	}
3760
+
3761
+
3762
+	/**
3763
+	 * set_per_page_screen_option
3764
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3765
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3766
+	 * admin_menu.
3767
+	 *
3768
+	 * @return void
3769
+	 */
3770
+	private function _set_per_page_screen_options()
3771
+	{
3772
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3773
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3774
+			if (! $user = wp_get_current_user()) {
3775
+				return;
3776
+			}
3777
+			$option = $_POST['wp_screen_options']['option'];
3778
+			$value = $_POST['wp_screen_options']['value'];
3779
+			if ($option !== sanitize_key($option)) {
3780
+				return;
3781
+			}
3782
+			$map_option = $option;
3783
+			$option = str_replace('-', '_', $option);
3784
+			switch ($map_option) {
3785
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3786
+					$value = (int) $value;
3787
+					$max_value = apply_filters(
3788
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3789
+						999,
3790
+						$this->_current_page,
3791
+						$this->_current_view
3792
+					);
3793
+					if ($value < 1) {
3794
+						return;
3795
+					}
3796
+					$value = min($value, $max_value);
3797
+					break;
3798
+				default:
3799
+					$value = apply_filters(
3800
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3801
+						false,
3802
+						$option,
3803
+						$value
3804
+					);
3805
+					if (false === $value) {
3806
+						return;
3807
+					}
3808
+					break;
3809
+			}
3810
+			update_user_meta($user->ID, $option, $value);
3811
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3812
+			exit;
3813
+		}
3814
+	}
3815
+
3816
+
3817
+	/**
3818
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3819
+	 *
3820
+	 * @param array $data array that will be assigned to template args.
3821
+	 */
3822
+	public function set_template_args($data)
3823
+	{
3824
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3825
+	}
3826
+
3827
+
3828
+	/**
3829
+	 * This makes available the WP transient system for temporarily moving data between routes
3830
+	 *
3831
+	 * @param string $route             the route that should receive the transient
3832
+	 * @param array  $data              the data that gets sent
3833
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3834
+	 *                                  normal route transient.
3835
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3836
+	 *                                  when we are adding a transient before page_routes have been defined.
3837
+	 * @return void
3838
+	 * @throws EE_Error
3839
+	 */
3840
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3841
+	{
3842
+		$user_id = get_current_user_id();
3843
+		if (! $skip_route_verify) {
3844
+			$this->_verify_route($route);
3845
+		}
3846
+		// now let's set the string for what kind of transient we're setting
3847
+		$transient = $notices
3848
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3849
+			: 'rte_tx_' . $route . '_' . $user_id;
3850
+		$data = $notices ? array('notices' => $data) : $data;
3851
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3852
+		$existing = is_multisite() && is_network_admin()
3853
+			? get_site_transient($transient)
3854
+			: get_transient($transient);
3855
+		if ($existing) {
3856
+			$data = array_merge((array) $data, (array) $existing);
3857
+		}
3858
+		if (is_multisite() && is_network_admin()) {
3859
+			set_site_transient($transient, $data, 8);
3860
+		} else {
3861
+			set_transient($transient, $data, 8);
3862
+		}
3863
+	}
3864
+
3865
+
3866
+	/**
3867
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3868
+	 *
3869
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3870
+	 * @param string $route
3871
+	 * @return mixed data
3872
+	 */
3873
+	protected function _get_transient($notices = false, $route = '')
3874
+	{
3875
+		$user_id = get_current_user_id();
3876
+		$route = ! $route ? $this->_req_action : $route;
3877
+		$transient = $notices
3878
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3879
+			: 'rte_tx_' . $route . '_' . $user_id;
3880
+		$data = is_multisite() && is_network_admin()
3881
+			? get_site_transient($transient)
3882
+			: get_transient($transient);
3883
+		// delete transient after retrieval (just in case it hasn't expired);
3884
+		if (is_multisite() && is_network_admin()) {
3885
+			delete_site_transient($transient);
3886
+		} else {
3887
+			delete_transient($transient);
3888
+		}
3889
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3890
+	}
3891
+
3892
+
3893
+	/**
3894
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3895
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3896
+	 * default route callback on the EE_Admin page you want it run.)
3897
+	 *
3898
+	 * @return void
3899
+	 */
3900
+	protected function _transient_garbage_collection()
3901
+	{
3902
+		global $wpdb;
3903
+		// retrieve all existing transients
3904
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3905
+		if ($results = $wpdb->get_results($query)) {
3906
+			foreach ($results as $result) {
3907
+				$transient = str_replace('_transient_', '', $result->option_name);
3908
+				get_transient($transient);
3909
+				if (is_multisite() && is_network_admin()) {
3910
+					get_site_transient($transient);
3911
+				}
3912
+			}
3913
+		}
3914
+	}
3915
+
3916
+
3917
+	/**
3918
+	 * get_view
3919
+	 *
3920
+	 * @return string content of _view property
3921
+	 */
3922
+	public function get_view()
3923
+	{
3924
+		return $this->_view;
3925
+	}
3926
+
3927
+
3928
+	/**
3929
+	 * getter for the protected $_views property
3930
+	 *
3931
+	 * @return array
3932
+	 */
3933
+	public function get_views()
3934
+	{
3935
+		return $this->_views;
3936
+	}
3937
+
3938
+
3939
+	/**
3940
+	 * get_current_page
3941
+	 *
3942
+	 * @return string _current_page property value
3943
+	 */
3944
+	public function get_current_page()
3945
+	{
3946
+		return $this->_current_page;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * get_current_view
3952
+	 *
3953
+	 * @return string _current_view property value
3954
+	 */
3955
+	public function get_current_view()
3956
+	{
3957
+		return $this->_current_view;
3958
+	}
3959
+
3960
+
3961
+	/**
3962
+	 * get_current_screen
3963
+	 *
3964
+	 * @return object The current WP_Screen object
3965
+	 */
3966
+	public function get_current_screen()
3967
+	{
3968
+		return $this->_current_screen;
3969
+	}
3970
+
3971
+
3972
+	/**
3973
+	 * get_current_page_view_url
3974
+	 *
3975
+	 * @return string This returns the url for the current_page_view.
3976
+	 */
3977
+	public function get_current_page_view_url()
3978
+	{
3979
+		return $this->_current_page_view_url;
3980
+	}
3981
+
3982
+
3983
+	/**
3984
+	 * just returns the _req_data property
3985
+	 *
3986
+	 * @return array
3987
+	 */
3988
+	public function get_request_data()
3989
+	{
3990
+		return $this->_req_data;
3991
+	}
3992
+
3993
+
3994
+	/**
3995
+	 * returns the _req_data protected property
3996
+	 *
3997
+	 * @return string
3998
+	 */
3999
+	public function get_req_action()
4000
+	{
4001
+		return $this->_req_action;
4002
+	}
4003
+
4004
+
4005
+	/**
4006
+	 * @return bool  value of $_is_caf property
4007
+	 */
4008
+	public function is_caf()
4009
+	{
4010
+		return $this->_is_caf;
4011
+	}
4012
+
4013
+
4014
+	/**
4015
+	 * @return mixed
4016
+	 */
4017
+	public function default_espresso_metaboxes()
4018
+	{
4019
+		return $this->_default_espresso_metaboxes;
4020
+	}
4021
+
4022
+
4023
+	/**
4024
+	 * @return mixed
4025
+	 */
4026
+	public function admin_base_url()
4027
+	{
4028
+		return $this->_admin_base_url;
4029
+	}
4030
+
4031
+
4032
+	/**
4033
+	 * @return mixed
4034
+	 */
4035
+	public function wp_page_slug()
4036
+	{
4037
+		return $this->_wp_page_slug;
4038
+	}
4039
+
4040
+
4041
+	/**
4042
+	 * updates  espresso configuration settings
4043
+	 *
4044
+	 * @param string                   $tab
4045
+	 * @param EE_Config_Base|EE_Config $config
4046
+	 * @param string                   $file file where error occurred
4047
+	 * @param string                   $func function  where error occurred
4048
+	 * @param string                   $line line no where error occurred
4049
+	 * @return boolean
4050
+	 */
4051
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
+	{
4053
+		// remove any options that are NOT going to be saved with the config settings.
4054
+		if (isset($config->core->ee_ueip_optin)) {
4055
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4056
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
+			update_option('ee_ueip_has_notified', true);
4058
+		}
4059
+		// and save it (note we're also doing the network save here)
4060
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4061
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
+		if ($config_saved && $net_saved) {
4063
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
+			return true;
4065
+		}
4066
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4067
+		return false;
4068
+	}
4069
+
4070
+
4071
+	/**
4072
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4073
+	 *
4074
+	 * @return array
4075
+	 */
4076
+	public function get_yes_no_values()
4077
+	{
4078
+		return $this->_yes_no_values;
4079
+	}
4080
+
4081
+
4082
+	/**
4083
+	 * @return string
4084
+	 * @throws ReflectionException
4085
+	 * @since $VID:$
4086
+	 */
4087
+	protected function _get_dir()
4088
+	{
4089
+		$reflector = new ReflectionClass(get_class($this));
4090
+		return dirname($reflector->getFileName());
4091
+	}
4092
+
4093
+
4094
+	/**
4095
+	 * A helper for getting a "next link".
4096
+	 *
4097
+	 * @param string $url   The url to link to
4098
+	 * @param string $class The class to use.
4099
+	 * @return string
4100
+	 */
4101
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4102
+	{
4103
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4104
+	}
4105
+
4106
+
4107
+	/**
4108
+	 * A helper for getting a "previous link".
4109
+	 *
4110
+	 * @param string $url   The url to link to
4111
+	 * @param string $class The class to use.
4112
+	 * @return string
4113
+	 */
4114
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4115
+	{
4116
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4117
+	}
4118
+
4119
+
4120
+
4121
+
4122
+
4123
+
4124
+
4125
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4126
+
4127
+
4128
+	/**
4129
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4130
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4131
+	 * _req_data array.
4132
+	 *
4133
+	 * @return bool success/fail
4134
+	 * @throws EE_Error
4135
+	 * @throws InvalidArgumentException
4136
+	 * @throws ReflectionException
4137
+	 * @throws InvalidDataTypeException
4138
+	 * @throws InvalidInterfaceException
4139
+	 */
4140
+	protected function _process_resend_registration()
4141
+	{
4142
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4143
+		do_action(
4144
+			'AHEE__EE_Admin_Page___process_resend_registration',
4145
+			$this->_template_args['success'],
4146
+			$this->_req_data
4147
+		);
4148
+		return $this->_template_args['success'];
4149
+	}
4150
+
4151
+
4152
+	/**
4153
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4154
+	 *
4155
+	 * @param EE_Payment $payment
4156
+	 * @return bool success/fail
4157
+	 */
4158
+	protected function _process_payment_notification(EE_Payment $payment)
4159
+	{
4160
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4161
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4162
+		$this->_template_args['success'] = apply_filters(
4163
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4164
+			false,
4165
+			$payment
4166
+		);
4167
+		return $this->_template_args['success'];
4168
+	}
4169 4169
 }
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
         );
555 555
         global $ee_menu_slugs;
556 556
         $ee_menu_slugs = (array) $ee_menu_slugs;
557
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
557
+        if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) {
558 558
             return;
559 559
         }
560 560
         // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
             ? $this->_req_data['route']
579 579
             : $this->_req_action;
580 580
         $this->_current_view = $this->_req_action;
581
-        $this->_req_nonce = $this->_req_action . '_nonce';
581
+        $this->_req_nonce = $this->_req_action.'_nonce';
582 582
         $this->_define_page_props();
583 583
         $this->_current_page_view_url = add_query_arg(
584 584
             array('page' => $this->_current_page, 'action' => $this->_current_view),
@@ -612,21 +612,21 @@  discard block
 block discarded – undo
612 612
         }
613 613
         // filter routes and page_config so addons can add their stuff. Filtering done per class
614 614
         $this->_page_routes = apply_filters(
615
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
615
+            'FHEE__'.get_class($this).'__page_setup__page_routes',
616 616
             $this->_page_routes,
617 617
             $this
618 618
         );
619 619
         $this->_page_config = apply_filters(
620
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
620
+            'FHEE__'.get_class($this).'__page_setup__page_config',
621 621
             $this->_page_config,
622 622
             $this
623 623
         );
624 624
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
625 625
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
626
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
626
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
627 627
             add_action(
628 628
                 'AHEE__EE_Admin_Page__route_admin_request',
629
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
629
+                array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view),
630 630
                 10,
631 631
                 2
632 632
             );
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
             if ($this->_is_UI_request) {
640 640
                 // admin_init stuff - global, all views for this page class, specific view
641 641
                 add_action('admin_init', array($this, 'admin_init'), 10);
642
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
643
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
642
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
643
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
644 644
                 }
645 645
             } else {
646 646
                 // hijack regular WP loading and route admin request immediately
@@ -659,12 +659,12 @@  discard block
 block discarded – undo
659 659
      */
660 660
     private function _do_other_page_hooks()
661 661
     {
662
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
662
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
663 663
         foreach ($registered_pages as $page) {
664 664
             // now let's setup the file name and class that should be present
665 665
             $classname = str_replace('.class.php', '', $page);
666 666
             // autoloaders should take care of loading file
667
-            if (! class_exists($classname)) {
667
+            if ( ! class_exists($classname)) {
668 668
                 $error_msg[] = sprintf(
669 669
                     esc_html__(
670 670
                         'Something went wrong with loading the %s admin hooks page.',
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                                    ),
682 682
                                    $page,
683 683
                                    '<br />',
684
-                                   '<strong>' . $classname . '</strong>'
684
+                                   '<strong>'.$classname.'</strong>'
685 685
                                );
686 686
                 throw new EE_Error(implode('||', $error_msg));
687 687
             }
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
         // load admin_notices - global, page class, and view specific
730 730
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
731 731
         add_action('admin_notices', array($this, 'admin_notices'), 10);
732
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
733
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
732
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
733
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
734 734
         }
735 735
         // load network admin_notices - global, page class, and view specific
736 736
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
737
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
738
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
737
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
738
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
739 739
         }
740 740
         // this will save any per_page screen options if they are present
741 741
         $this->_set_per_page_screen_options();
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
      */
857 857
     protected function _verify_routes()
858 858
     {
859
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
859
+        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
860 860
             return false;
861 861
         }
862 862
         $this->_route = false;
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
                 $this->_admin_page_title
869 869
             );
870 870
             // developer error msg
871
-            $error_msg .= '||' . $error_msg
871
+            $error_msg .= '||'.$error_msg
872 872
                           . esc_html__(
873 873
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
874 874
                               'event_espresso'
@@ -877,9 +877,9 @@  discard block
 block discarded – undo
877 877
         }
878 878
         // and that the requested page route exists
879 879
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
880
-            $this->_route = $this->_page_routes[ $this->_req_action ];
881
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
882
-                ? $this->_page_config[ $this->_req_action ] : array();
880
+            $this->_route = $this->_page_routes[$this->_req_action];
881
+            $this->_route_config = isset($this->_page_config[$this->_req_action])
882
+                ? $this->_page_config[$this->_req_action] : array();
883 883
         } else {
884 884
             // user error msg
885 885
             $error_msg = sprintf(
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
                 $this->_admin_page_title
891 891
             );
892 892
             // developer error msg
893
-            $error_msg .= '||' . $error_msg
893
+            $error_msg .= '||'.$error_msg
894 894
                           . sprintf(
895 895
                               esc_html__(
896 896
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
             throw new EE_Error($error_msg);
902 902
         }
903 903
         // and that a default route exists
904
-        if (! array_key_exists('default', $this->_page_routes)) {
904
+        if ( ! array_key_exists('default', $this->_page_routes)) {
905 905
             // user error msg
906 906
             $error_msg = sprintf(
907 907
                 esc_html__(
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
                 $this->_admin_page_title
912 912
             );
913 913
             // developer error msg
914
-            $error_msg .= '||' . $error_msg
914
+            $error_msg .= '||'.$error_msg
915 915
                           . esc_html__(
916 916
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
917 917
                               'event_espresso'
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
             $this->_admin_page_title
952 952
         );
953 953
         // developer error msg
954
-        $error_msg .= '||' . $error_msg
954
+        $error_msg .= '||'.$error_msg
955 955
                       . sprintf(
956 956
                           esc_html__(
957 957
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
     protected function _verify_nonce($nonce, $nonce_ref)
980 980
     {
981 981
         // verify nonce against expected value
982
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
982
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
983 983
             // these are not the droids you are looking for !!!
984 984
             $msg = sprintf(
985 985
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
                             EE_Admin_Page::class
997 997
                         );
998 998
             }
999
-            if (! defined('DOING_AJAX')) {
999
+            if ( ! defined('DOING_AJAX')) {
1000 1000
                 wp_die($msg);
1001 1001
             } else {
1002 1002
                 EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
      */
1022 1022
     protected function _route_admin_request()
1023 1023
     {
1024
-        if (! $this->_is_UI_request) {
1024
+        if ( ! $this->_is_UI_request) {
1025 1025
             $this->_verify_routes();
1026 1026
         }
1027 1027
         $nonce_check = isset($this->_route_config['require_nonce'])
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
             : true;
1030 1030
         if ($this->_req_action !== 'default' && $nonce_check) {
1031 1031
             // set nonce from post data
1032
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
1033
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1032
+            $nonce = isset($this->_req_data[$this->_req_nonce])
1033
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
1034 1034
                 : '';
1035 1035
             $this->_verify_nonce($nonce, $this->_req_nonce);
1036 1036
         }
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
         $error_msg = '';
1046 1046
         // action right before calling route
1047 1047
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1048
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1048
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1049 1049
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1050 1050
         }
1051 1051
         // right before calling the route, let's remove _wp_http_referer from the
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
             '_wp_http_referer',
1055 1055
             wp_unslash($_SERVER['REQUEST_URI'])
1056 1056
         );
1057
-        if (! empty($func)) {
1057
+        if ( ! empty($func)) {
1058 1058
             if (is_array($func)) {
1059 1059
                 list($class, $method) = $func;
1060 1060
             } elseif (strpos($func, '::') !== false) {
@@ -1063,7 +1063,7 @@  discard block
 block discarded – undo
1063 1063
                 $class = $this;
1064 1064
                 $method = $func;
1065 1065
             }
1066
-            if (! (is_object($class) && $class === $this)) {
1066
+            if ( ! (is_object($class) && $class === $this)) {
1067 1067
                 // send along this admin page object for access by addons.
1068 1068
                 $args['admin_page_object'] = $this;
1069 1069
             }
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
                     $method
1098 1098
                 );
1099 1099
             }
1100
-            if (! empty($error_msg)) {
1100
+            if ( ! empty($error_msg)) {
1101 1101
                 throw new EE_Error($error_msg);
1102 1102
             }
1103 1103
         }
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
                 if (strpos($key, 'nonce') !== false) {
1182 1182
                     continue;
1183 1183
                 }
1184
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1184
+                $args['wp_referer['.$key.']'] = $value;
1185 1185
             }
1186 1186
         }
1187 1187
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1222,8 +1222,8 @@  discard block
 block discarded – undo
1222 1222
     protected function _add_help_tabs()
1223 1223
     {
1224 1224
         $tour_buttons = '';
1225
-        if (isset($this->_page_config[ $this->_req_action ])) {
1226
-            $config = $this->_page_config[ $this->_req_action ];
1225
+        if (isset($this->_page_config[$this->_req_action])) {
1226
+            $config = $this->_page_config[$this->_req_action];
1227 1227
             // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1228 1228
             // is there a help tour for the current route?  if there is let's setup the tour buttons
1229 1229
             // if (isset($this->_help_tour[ $this->_req_action ])) {
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1247 1247
             if (is_array($config) && isset($config['help_sidebar'])) {
1248 1248
                 // check that the callback given is valid
1249
-                if (! method_exists($this, $config['help_sidebar'])) {
1249
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1250 1250
                     throw new EE_Error(
1251 1251
                         sprintf(
1252 1252
                             esc_html__(
@@ -1259,7 +1259,7 @@  discard block
 block discarded – undo
1259 1259
                     );
1260 1260
                 }
1261 1261
                 $content = apply_filters(
1262
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1262
+                    'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar',
1263 1263
                     $this->{$config['help_sidebar']}()
1264 1264
                 );
1265 1265
                 $content .= $tour_buttons; // add help tour buttons.
@@ -1267,30 +1267,30 @@  discard block
 block discarded – undo
1267 1267
                 $this->_current_screen->set_help_sidebar($content);
1268 1268
             }
1269 1269
             // if there ARE tour buttons...
1270
-            if (! empty($tour_buttons)) {
1270
+            if ( ! empty($tour_buttons)) {
1271 1271
                 // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1272
-                if (! isset($config['help_sidebar'])) {
1272
+                if ( ! isset($config['help_sidebar'])) {
1273 1273
                     $this->_current_screen->set_help_sidebar($tour_buttons);
1274 1274
                 }
1275 1275
                 // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1276
-                if (! isset($config['help_tabs'])) {
1276
+                if ( ! isset($config['help_tabs'])) {
1277 1277
                     $_ht['id'] = $this->page_slug;
1278 1278
                     $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1279 1279
                     $_ht['content'] = '<p>'
1280 1280
                                       . esc_html__(
1281 1281
                                           'The buttons to the right allow you to start/restart any help tours available for this page',
1282 1282
                                           'event_espresso'
1283
-                                      ) . '</p>';
1283
+                                      ).'</p>';
1284 1284
                     $this->_current_screen->add_help_tab($_ht);
1285 1285
                 }
1286 1286
             }
1287
-            if (! isset($config['help_tabs'])) {
1287
+            if ( ! isset($config['help_tabs'])) {
1288 1288
                 return;
1289 1289
             } //no help tabs for this route
1290 1290
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1291 1291
                 // we're here so there ARE help tabs!
1292 1292
                 // make sure we've got what we need
1293
-                if (! isset($cfg['title'])) {
1293
+                if ( ! isset($cfg['title'])) {
1294 1294
                     throw new EE_Error(
1295 1295
                         esc_html__(
1296 1296
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
                         )
1299 1299
                     );
1300 1300
                 }
1301
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1301
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1302 1302
                     throw new EE_Error(
1303 1303
                         esc_html__(
1304 1304
                             'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
@@ -1307,11 +1307,11 @@  discard block
 block discarded – undo
1307 1307
                     );
1308 1308
                 }
1309 1309
                 // first priority goes to content.
1310
-                if (! empty($cfg['content'])) {
1310
+                if ( ! empty($cfg['content'])) {
1311 1311
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1312 1312
                     // second priority goes to filename
1313
-                } elseif (! empty($cfg['filename'])) {
1314
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1313
+                } elseif ( ! empty($cfg['filename'])) {
1314
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1315 1315
                     // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1316 1316
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1317 1317
                                                              . basename($this->_get_dir())
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
                                                              . $cfg['filename']
1320 1320
                                                              . '.help_tab.php' : $file_path;
1321 1321
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1322
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1322
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1323 1323
                         EE_Error::add_error(
1324 1324
                             sprintf(
1325 1325
                                 esc_html__(
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
                     return;
1367 1367
                 }
1368 1368
                 // setup config array for help tab method
1369
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1369
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1370 1370
                 $_ht = array(
1371 1371
                     'id'       => $id,
1372 1372
                     'title'    => $cfg['title'],
@@ -1497,8 +1497,8 @@  discard block
 block discarded – undo
1497 1497
             $qtips = (array) $this->_route_config['qtips'];
1498 1498
             // load qtip loader
1499 1499
             $path = array(
1500
-                $this->_get_dir() . '/qtips/',
1501
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1500
+                $this->_get_dir().'/qtips/',
1501
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1502 1502
             );
1503 1503
             $qtip_loader = EEH_Qtip_Loader::instance();
1504 1504
             if ($qtip_loader instanceof EEH_Qtip_Loader) {
@@ -1541,12 +1541,12 @@  discard block
 block discarded – undo
1541 1541
                 // nav tab is only to appear when route requested.
1542 1542
                 continue;
1543 1543
             }
1544
-            if (! $this->check_user_access($slug, true)) {
1544
+            if ( ! $this->check_user_access($slug, true)) {
1545 1545
                 // no nav tab because current user does not have access.
1546 1546
                 continue;
1547 1547
             }
1548
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1549
-            $this->_nav_tabs[ $slug ] = array(
1548
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1549
+            $this->_nav_tabs[$slug] = array(
1550 1550
                 'url'       => isset($config['nav']['url'])
1551 1551
                     ? $config['nav']['url']
1552 1552
                     : EE_Admin_Page::add_query_args_and_nonce(
@@ -1558,14 +1558,14 @@  discard block
 block discarded – undo
1558 1558
                     : ucwords(
1559 1559
                         str_replace('_', ' ', $slug)
1560 1560
                     ),
1561
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1561
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1562 1562
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1563 1563
             );
1564 1564
             $i++;
1565 1565
         }
1566 1566
         // if $this->_nav_tabs is empty then lets set the default
1567 1567
         if (empty($this->_nav_tabs)) {
1568
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1568
+            $this->_nav_tabs[$this->_default_nav_tab_name] = array(
1569 1569
                 'url'       => $this->_admin_base_url,
1570 1570
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1571 1571
                 'css_class' => 'nav-tab-active',
@@ -1590,10 +1590,10 @@  discard block
 block discarded – undo
1590 1590
             foreach ($this->_route_config['labels'] as $label => $text) {
1591 1591
                 if (is_array($text)) {
1592 1592
                     foreach ($text as $sublabel => $subtext) {
1593
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1593
+                        $this->_labels[$label][$sublabel] = $subtext;
1594 1594
                     }
1595 1595
                 } else {
1596
-                    $this->_labels[ $label ] = $text;
1596
+                    $this->_labels[$label] = $text;
1597 1597
                 }
1598 1598
             }
1599 1599
         }
@@ -1615,12 +1615,12 @@  discard block
 block discarded – undo
1615 1615
     {
1616 1616
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1617 1617
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1618
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1618
+        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1619 1619
                       && is_array(
1620
-                          $this->_page_routes[ $route_to_check ]
1620
+                          $this->_page_routes[$route_to_check]
1621 1621
                       )
1622
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1623
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1622
+                      && ! empty($this->_page_routes[$route_to_check]['capability'])
1623
+            ? $this->_page_routes[$route_to_check]['capability'] : null;
1624 1624
         if (empty($capability) && empty($route_to_check)) {
1625 1625
             $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1626 1626
                 : $this->_route['capability'];
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
     public function admin_footer_global()
1736 1736
     {
1737 1737
         // dialog container for dialog helper
1738
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1738
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1739 1739
         $d_cont .= '<div class="ee-notices"></div>';
1740 1740
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1741 1741
         $d_cont .= '</div>';
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
         //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1747 1747
         // }
1748 1748
         // current set timezone for timezone js
1749
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1749
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1750 1750
     }
1751 1751
 
1752 1752
 
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
         // loop through the array and setup content
1781 1781
         foreach ($help_array as $trigger => $help) {
1782 1782
             // make sure the array is setup properly
1783
-            if (! isset($help['title'], $help['content'])) {
1783
+            if ( ! isset($help['title'], $help['content'])) {
1784 1784
                 throw new EE_Error(
1785 1785
                     esc_html__(
1786 1786
                         'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
                 'help_popup_content' => $help['content'],
1796 1796
             );
1797 1797
             $content .= EEH_Template::display_template(
1798
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1798
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1799 1799
                 $template_args,
1800 1800
                 true
1801 1801
             );
@@ -1817,15 +1817,15 @@  discard block
 block discarded – undo
1817 1817
     private function _get_help_content()
1818 1818
     {
1819 1819
         // what is the method we're looking for?
1820
-        $method_name = '_help_popup_content_' . $this->_req_action;
1820
+        $method_name = '_help_popup_content_'.$this->_req_action;
1821 1821
         // if method doesn't exist let's get out.
1822
-        if (! method_exists($this, $method_name)) {
1822
+        if ( ! method_exists($this, $method_name)) {
1823 1823
             return array();
1824 1824
         }
1825 1825
         // k we're good to go let's retrieve the help array
1826 1826
         $help_array = $this->{$method_name}();
1827 1827
         // make sure we've got an array!
1828
-        if (! is_array($help_array)) {
1828
+        if ( ! is_array($help_array)) {
1829 1829
             throw new EE_Error(
1830 1830
                 esc_html__(
1831 1831
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1857,8 +1857,8 @@  discard block
 block discarded – undo
1857 1857
         // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1858 1858
         $help_array = $this->_get_help_content();
1859 1859
         $help_content = '';
1860
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1861
-            $help_array[ $trigger_id ] = array(
1860
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1861
+            $help_array[$trigger_id] = array(
1862 1862
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1863 1863
                 'content' => esc_html__(
1864 1864
                     'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
@@ -2056,12 +2056,12 @@  discard block
 block discarded – undo
2056 2056
     protected function _set_list_table()
2057 2057
     {
2058 2058
         // first is this a list_table view?
2059
-        if (! isset($this->_route_config['list_table'])) {
2059
+        if ( ! isset($this->_route_config['list_table'])) {
2060 2060
             return;
2061 2061
         } //not a list_table view so get out.
2062 2062
         // list table functions are per view specific (because some admin pages might have more than one list table!)
2063
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2064
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2063
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
2064
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2065 2065
             // user error msg
2066 2066
             $error_msg = esc_html__(
2067 2067
                 'An error occurred. The requested list table views could not be found.',
@@ -2081,10 +2081,10 @@  discard block
 block discarded – undo
2081 2081
         }
2082 2082
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2083 2083
         $this->_views = apply_filters(
2084
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2084
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
2085 2085
             $this->_views
2086 2086
         );
2087
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2087
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
2088 2088
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2089 2089
         $this->_set_list_table_view();
2090 2090
         $this->_set_list_table_object();
@@ -2100,7 +2100,7 @@  discard block
 block discarded – undo
2100 2100
     {
2101 2101
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2102 2102
         // looking at active items or dumpster diving ?
2103
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2103
+        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2104 2104
             $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2105 2105
         } else {
2106 2106
             $this->_view = sanitize_key($this->_req_data['status']);
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
     protected function _set_list_table_object()
2122 2122
     {
2123 2123
         if (isset($this->_route_config['list_table'])) {
2124
-            if (! class_exists($this->_route_config['list_table'])) {
2124
+            if ( ! class_exists($this->_route_config['list_table'])) {
2125 2125
                 throw new EE_Error(
2126 2126
                     sprintf(
2127 2127
                         esc_html__(
@@ -2159,17 +2159,17 @@  discard block
 block discarded – undo
2159 2159
         foreach ($this->_views as $key => $view) {
2160 2160
             $query_args = array();
2161 2161
             // check for current view
2162
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2162
+            $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2163 2163
             $query_args['action'] = $this->_req_action;
2164
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2164
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2165 2165
             $query_args['status'] = $view['slug'];
2166 2166
             // merge any other arguments sent in.
2167
-            if (isset($extra_query_args[ $view['slug'] ])) {
2168
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2167
+            if (isset($extra_query_args[$view['slug']])) {
2168
+                foreach ($extra_query_args[$view['slug']] as $extra_query_arg) {
2169 2169
                     $query_args[] = $extra_query_arg;
2170 2170
                 }
2171 2171
             }
2172
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2172
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2173 2173
         }
2174 2174
         return $this->_views;
2175 2175
     }
@@ -2188,7 +2188,7 @@  discard block
 block discarded – undo
2188 2188
     {
2189 2189
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190 2190
         $values = array(10, 25, 50, 100);
2191
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2191
+        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2192 2192
         if ($max_entries) {
2193 2193
             $values[] = $max_entries;
2194 2194
             sort($values);
@@ -2200,14 +2200,14 @@  discard block
 block discarded – undo
2200 2200
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2201 2201
         foreach ($values as $value) {
2202 2202
             if ($value < $max_entries) {
2203
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2203
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2204 2204
                 $entries_per_page_dropdown .= '
2205
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2205
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2206 2206
             }
2207 2207
         }
2208
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2208
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2209 2209
         $entries_per_page_dropdown .= '
2210
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2210
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2211 2211
         $entries_per_page_dropdown .= '
2212 2212
 					</select>
2213 2213
 					entries
@@ -2231,7 +2231,7 @@  discard block
 block discarded – undo
2231 2231
             empty($this->_search_btn_label) ? $this->page_label
2232 2232
                 : $this->_search_btn_label
2233 2233
         );
2234
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2234
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2235 2235
     }
2236 2236
 
2237 2237
 
@@ -2319,7 +2319,7 @@  discard block
 block discarded – undo
2319 2319
             $total_columns = ! empty($screen_columns)
2320 2320
                 ? $screen_columns
2321 2321
                 : $this->_route_config['columns'][1];
2322
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2322
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2323 2323
             $this->_template_args['current_page'] = $this->_wp_page_slug;
2324 2324
             $this->_template_args['screen'] = $this->_current_screen;
2325 2325
             $this->_column_template_path = EE_ADMIN_TEMPLATE
@@ -2364,7 +2364,7 @@  discard block
 block discarded – undo
2364 2364
      */
2365 2365
     protected function _espresso_ratings_request()
2366 2366
     {
2367
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2367
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2368 2368
             return;
2369 2369
         }
2370 2370
         $ratings_box_title = apply_filters(
@@ -2391,7 +2391,7 @@  discard block
 block discarded – undo
2391 2391
      */
2392 2392
     public function espresso_ratings_request()
2393 2393
     {
2394
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2394
+        EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php');
2395 2395
     }
2396 2396
 
2397 2397
 
@@ -2402,17 +2402,17 @@  discard block
 block discarded – undo
2402 2402
                    . '</p><p class="hide-if-js">'
2403 2403
                    . esc_html__('This widget requires JavaScript.', 'event_espresso')
2404 2404
                    . '</p>';
2405
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2406
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2407
-        $post = '</div>' . "\n";
2408
-        $cache_key = 'ee_rss_' . md5($rss_id);
2405
+        $pre = '<div class="espresso-rss-display">'."\n\t";
2406
+        $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>';
2407
+        $post = '</div>'."\n";
2408
+        $cache_key = 'ee_rss_'.md5($rss_id);
2409 2409
         $output = get_transient($cache_key);
2410 2410
         if ($output !== false) {
2411
-            echo $pre . $output . $post;
2411
+            echo $pre.$output.$post;
2412 2412
             return true;
2413 2413
         }
2414
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2415
-            echo $pre . $loading . $post;
2414
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2415
+            echo $pre.$loading.$post;
2416 2416
             return false;
2417 2417
         }
2418 2418
         ob_start();
@@ -2479,19 +2479,19 @@  discard block
 block discarded – undo
2479 2479
     public function espresso_sponsors_post_box()
2480 2480
     {
2481 2481
         EEH_Template::display_template(
2482
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2482
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2483 2483
         );
2484 2484
     }
2485 2485
 
2486 2486
 
2487 2487
     private function _publish_post_box()
2488 2488
     {
2489
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2489
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2490 2490
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2491 2491
         // then we'll use that for the metabox label.
2492 2492
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2493
-        if (! empty($this->_labels['publishbox'])) {
2494
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2493
+        if ( ! empty($this->_labels['publishbox'])) {
2494
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2495 2495
                 : $this->_labels['publishbox'];
2496 2496
         } else {
2497 2497
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2520,7 +2520,7 @@  discard block
 block discarded – undo
2520 2520
             ? $this->_template_args['publish_box_extra_content']
2521 2521
             : '';
2522 2522
         echo EEH_Template::display_template(
2523
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2523
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2524 2524
             $this->_template_args,
2525 2525
             true
2526 2526
         );
@@ -2610,8 +2610,8 @@  discard block
 block discarded – undo
2610 2610
             );
2611 2611
         }
2612 2612
         $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2613
-        if (! empty($name) && ! empty($id)) {
2614
-            $hidden_field_arr[ $name ] = array(
2613
+        if ( ! empty($name) && ! empty($id)) {
2614
+            $hidden_field_arr[$name] = array(
2615 2615
                 'type'  => 'hidden',
2616 2616
                 'value' => $id,
2617 2617
             );
@@ -2621,7 +2621,7 @@  discard block
 block discarded – undo
2621 2621
         }
2622 2622
         // add hidden field
2623 2623
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2624
-            ? $hf[ $name ]['field']
2624
+            ? $hf[$name]['field']
2625 2625
             : $hf;
2626 2626
     }
2627 2627
 
@@ -2723,7 +2723,7 @@  discard block
 block discarded – undo
2723 2723
         }
2724 2724
         // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2725 2725
         $call_back_func = $create_func
2726
-            ? static function ($post, $metabox) {
2726
+            ? static function($post, $metabox) {
2727 2727
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2728 2728
                 echo EEH_Template::display_template(
2729 2729
                     $metabox['args']['template_path'],
@@ -2733,7 +2733,7 @@  discard block
 block discarded – undo
2733 2733
             }
2734 2734
             : $callback;
2735 2735
         add_meta_box(
2736
-            str_replace('_', '-', $action) . '-mbox',
2736
+            str_replace('_', '-', $action).'-mbox',
2737 2737
             $title,
2738 2738
             $call_back_func,
2739 2739
             $this->_wp_page_slug,
@@ -2840,9 +2840,9 @@  discard block
 block discarded – undo
2840 2840
             : 'espresso-default-admin';
2841 2841
         $template_path = $sidebar
2842 2842
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2843
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2843
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2844 2844
         if (defined('DOING_AJAX') && DOING_AJAX) {
2845
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2845
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2846 2846
         }
2847 2847
         $template_path = ! empty($this->_column_template_path)
2848 2848
             ? $this->_column_template_path : $template_path;
@@ -2907,7 +2907,7 @@  discard block
 block discarded – undo
2907 2907
             )
2908 2908
             : $this->_template_args['preview_action_button'];
2909 2909
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2910
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2910
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2911 2911
             $this->_template_args,
2912 2912
             true
2913 2913
         );
@@ -2965,7 +2965,7 @@  discard block
 block discarded – undo
2965 2965
         // setup search attributes
2966 2966
         $this->_set_search_attributes();
2967 2967
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2968
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2968
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2969 2969
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2970 2970
             ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2971 2971
             : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2973,10 +2973,10 @@  discard block
 block discarded – undo
2973 2973
         $this->_template_args['current_route'] = $this->_req_action;
2974 2974
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2975 2975
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2976
-        if (! empty($ajax_sorting_callback)) {
2976
+        if ( ! empty($ajax_sorting_callback)) {
2977 2977
             $sortable_list_table_form_fields = wp_nonce_field(
2978
-                $ajax_sorting_callback . '_nonce',
2979
-                $ajax_sorting_callback . '_nonce',
2978
+                $ajax_sorting_callback.'_nonce',
2979
+                $ajax_sorting_callback.'_nonce',
2980 2980
                 false,
2981 2981
                 false
2982 2982
             );
@@ -2993,7 +2993,7 @@  discard block
 block discarded – undo
2993 2993
         $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
2994 2994
             ? $this->_template_args['list_table_hidden_fields']
2995 2995
             : '';
2996
-        $nonce_ref = $this->_req_action . '_nonce';
2996
+        $nonce_ref = $this->_req_action.'_nonce';
2997 2997
         $hidden_form_fields .= '<input type="hidden" name="'
2998 2998
                                . $nonce_ref
2999 2999
                                . '" value="'
@@ -3002,10 +3002,10 @@  discard block
 block discarded – undo
3002 3002
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3003 3003
         // display message about search results?
3004 3004
         $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3005
-            ? '<p class="ee-search-results">' . sprintf(
3005
+            ? '<p class="ee-search-results">'.sprintf(
3006 3006
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3007 3007
                 trim($this->_req_data['s'], '%')
3008
-            ) . '</p>'
3008
+            ).'</p>'
3009 3009
             : '';
3010 3010
         // filter before_list_table template arg
3011 3011
         $this->_template_args['before_list_table'] = apply_filters(
@@ -3087,15 +3087,15 @@  discard block
 block discarded – undo
3087 3087
         );
3088 3088
         /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3089 3089
         $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3090
-        if (! $status_change_notice->isDismissed()) {
3090
+        if ( ! $status_change_notice->isDismissed()) {
3091 3091
             $this->_template_args['status_change_notice'] = EEH_Template::display_template(
3092
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3093
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3092
+                EE_ADMIN_TEMPLATE.'status_change_notice.template.php',
3093
+                ['context' => '__admin-legend', 'page_slug' => $this->page_slug],
3094 3094
                 true
3095 3095
             );
3096 3096
         }
3097 3097
         return EEH_Template::display_template(
3098
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3098
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
3099 3099
             $this->_template_args,
3100 3100
             true
3101 3101
         );
@@ -3326,17 +3326,17 @@  discard block
 block discarded – undo
3326 3326
         // add in a hidden index for the current page (so save and close redirects properly)
3327 3327
         $this->_template_args['save_buttons'] = $referrer_url;
3328 3328
         foreach ($button_text as $key => $button) {
3329
-            $ref = $default_names[ $key ];
3329
+            $ref = $default_names[$key];
3330 3330
             $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3331 3331
                                                      . $ref
3332 3332
                                                      . '" value="'
3333 3333
                                                      . $button
3334 3334
                                                      . '" name="'
3335
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3335
+                                                     . ( ! empty($actions) ? $actions[$key] : $ref)
3336 3336
                                                      . '" id="'
3337
-                                                     . $this->_current_view . '_' . $ref
3337
+                                                     . $this->_current_view.'_'.$ref
3338 3338
                                                      . '" />';
3339
-            if (! $both) {
3339
+            if ( ! $both) {
3340 3340
                 break;
3341 3341
             }
3342 3342
         }
@@ -3371,13 +3371,13 @@  discard block
 block discarded – undo
3371 3371
                 'An error occurred. No action was set for this page\'s form.',
3372 3372
                 'event_espresso'
3373 3373
             );
3374
-            $dev_msg = $user_msg . "\n"
3374
+            $dev_msg = $user_msg."\n"
3375 3375
                        . sprintf(
3376 3376
                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3377 3377
                            __FUNCTION__,
3378 3378
                            EE_Admin_Page::class
3379 3379
                        );
3380
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3380
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3381 3381
         }
3382 3382
         // open form
3383 3383
         $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
@@ -3386,8 +3386,8 @@  discard block
 block discarded – undo
3386 3386
                                                              . $route
3387 3387
                                                              . '_event_form" >';
3388 3388
         // add nonce
3389
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3390
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3389
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3390
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3391 3391
         // add REQUIRED form action
3392 3392
         $hidden_fields = array(
3393 3393
             'action' => array('type' => 'hidden', 'value' => $route),
@@ -3400,7 +3400,7 @@  discard block
 block discarded – undo
3400 3400
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3401 3401
         // add fields to form
3402 3402
         foreach ((array) $form_fields as $field_name => $form_field) {
3403
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3403
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3404 3404
         }
3405 3405
         // close form
3406 3406
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3454,12 +3454,12 @@  discard block
 block discarded – undo
3454 3454
         foreach ($this->_req_data as $ref => $value) {
3455 3455
             // unset nonces
3456 3456
             if (strpos($ref, 'nonce') !== false) {
3457
-                unset($this->_req_data[ $ref ]);
3457
+                unset($this->_req_data[$ref]);
3458 3458
                 continue;
3459 3459
             }
3460 3460
             // urlencode values.
3461 3461
             $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3462
-            $this->_req_data[ $ref ] = $value;
3462
+            $this->_req_data[$ref] = $value;
3463 3463
         }
3464 3464
         return array_merge($this->_req_data, $new_route_data);
3465 3465
     }
@@ -3497,10 +3497,10 @@  discard block
 block discarded – undo
3497 3497
         $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3498 3498
         $notices = EE_Error::get_notices(false);
3499 3499
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3500
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3500
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3501 3501
             EE_Error::overwrite_success();
3502 3502
         }
3503
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3503
+        if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3504 3504
             // how many records affected ? more than one record ? or just one ?
3505 3505
             if ($success > 1) {
3506 3506
                 // set plural msg
@@ -3529,7 +3529,7 @@  discard block
 block discarded – undo
3529 3529
             }
3530 3530
         }
3531 3531
         // check that $query_args isn't something crazy
3532
-        if (! is_array($query_args)) {
3532
+        if ( ! is_array($query_args)) {
3533 3533
             $query_args = array();
3534 3534
         }
3535 3535
         /**
@@ -3554,7 +3554,7 @@  discard block
 block discarded – undo
3554 3554
             $redirect_url = admin_url('admin.php');
3555 3555
         }
3556 3556
         // merge any default query_args set in _default_route_query_args property
3557
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3557
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3558 3558
             $args_to_merge = array();
3559 3559
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3560 3560
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3566,15 +3566,15 @@  discard block
 block discarded – undo
3566 3566
                         }
3567 3567
                         // finally we will override any arguments in the referer with
3568 3568
                         // what might be set on the _default_route_query_args array.
3569
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3570
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3569
+                        if (isset($this->_default_route_query_args[$reference])) {
3570
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3571 3571
                         } else {
3572
-                            $args_to_merge[ $reference ] = urlencode($value);
3572
+                            $args_to_merge[$reference] = urlencode($value);
3573 3573
                         }
3574 3574
                     }
3575 3575
                     continue;
3576 3576
                 }
3577
-                $args_to_merge[ $query_param ] = $query_value;
3577
+                $args_to_merge[$query_param] = $query_value;
3578 3578
             }
3579 3579
             // now let's merge these arguments but override with what was specifically sent in to the
3580 3580
             // redirect.
@@ -3586,13 +3586,13 @@  discard block
 block discarded – undo
3586 3586
         if (isset($query_args['action'])) {
3587 3587
             // manually generate wp_nonce and merge that with the query vars
3588 3588
             // becuz the wp_nonce_url function wrecks havoc on some vars
3589
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3589
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3590 3590
         }
3591 3591
         // we're adding some hooks and filters in here for processing any things just before redirects
3592 3592
         // (example: an admin page has done an insert or update and we want to run something after that).
3593
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3593
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
3594 3594
         $redirect_url = apply_filters(
3595
-            'FHEE_redirect_' . $classname . $this->_req_action,
3595
+            'FHEE_redirect_'.$classname.$this->_req_action,
3596 3596
             EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3597 3597
             $query_args
3598 3598
         );
@@ -3648,7 +3648,7 @@  discard block
 block discarded – undo
3648 3648
         }
3649 3649
         $this->_template_args['notices'] = EE_Error::get_notices();
3650 3650
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3651
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3651
+        if ( ! defined('DOING_AJAX') || $sticky_notices) {
3652 3652
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3653 3653
             $this->_add_transient(
3654 3654
                 $route,
@@ -3688,7 +3688,7 @@  discard block
 block discarded – undo
3688 3688
         $exclude_nonce = false
3689 3689
     ) {
3690 3690
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3691
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3691
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3692 3692
             throw new EE_Error(
3693 3693
                 sprintf(
3694 3694
                     esc_html__(
@@ -3699,7 +3699,7 @@  discard block
 block discarded – undo
3699 3699
                 )
3700 3700
             );
3701 3701
         }
3702
-        if (! isset($this->_labels['buttons'][ $type ])) {
3702
+        if ( ! isset($this->_labels['buttons'][$type])) {
3703 3703
             throw new EE_Error(
3704 3704
                 sprintf(
3705 3705
                     __(
@@ -3712,7 +3712,7 @@  discard block
 block discarded – undo
3712 3712
         }
3713 3713
         // finally check user access for this button.
3714 3714
         $has_access = $this->check_user_access($action, true);
3715
-        if (! $has_access) {
3715
+        if ( ! $has_access) {
3716 3716
             return '';
3717 3717
         }
3718 3718
         $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3720,11 +3720,11 @@  discard block
 block discarded – undo
3720 3720
             'action' => $action,
3721 3721
         );
3722 3722
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3723
-        if (! empty($extra_request)) {
3723
+        if ( ! empty($extra_request)) {
3724 3724
             $query_args = array_merge($extra_request, $query_args);
3725 3725
         }
3726 3726
         $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3727
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3727
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3728 3728
     }
3729 3729
 
3730 3730
 
@@ -3750,7 +3750,7 @@  discard block
 block discarded – undo
3750 3750
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3751 3751
                 20
3752 3752
             ),
3753
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3753
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3754 3754
         );
3755 3755
         // ONLY add the screen option if the user has access to it.
3756 3756
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3771,7 +3771,7 @@  discard block
 block discarded – undo
3771 3771
     {
3772 3772
         if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3773 3773
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3774
-            if (! $user = wp_get_current_user()) {
3774
+            if ( ! $user = wp_get_current_user()) {
3775 3775
                 return;
3776 3776
             }
3777 3777
             $option = $_POST['wp_screen_options']['option'];
@@ -3782,7 +3782,7 @@  discard block
 block discarded – undo
3782 3782
             $map_option = $option;
3783 3783
             $option = str_replace('-', '_', $option);
3784 3784
             switch ($map_option) {
3785
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3785
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3786 3786
                     $value = (int) $value;
3787 3787
                     $max_value = apply_filters(
3788 3788
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
@@ -3840,13 +3840,13 @@  discard block
 block discarded – undo
3840 3840
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3841 3841
     {
3842 3842
         $user_id = get_current_user_id();
3843
-        if (! $skip_route_verify) {
3843
+        if ( ! $skip_route_verify) {
3844 3844
             $this->_verify_route($route);
3845 3845
         }
3846 3846
         // now let's set the string for what kind of transient we're setting
3847 3847
         $transient = $notices
3848
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3849
-            : 'rte_tx_' . $route . '_' . $user_id;
3848
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3849
+            : 'rte_tx_'.$route.'_'.$user_id;
3850 3850
         $data = $notices ? array('notices' => $data) : $data;
3851 3851
         // is there already a transient for this route?  If there is then let's ADD to that transient
3852 3852
         $existing = is_multisite() && is_network_admin()
@@ -3875,8 +3875,8 @@  discard block
 block discarded – undo
3875 3875
         $user_id = get_current_user_id();
3876 3876
         $route = ! $route ? $this->_req_action : $route;
3877 3877
         $transient = $notices
3878
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3879
-            : 'rte_tx_' . $route . '_' . $user_id;
3878
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3879
+            : 'rte_tx_'.$route.'_'.$user_id;
3880 3880
         $data = is_multisite() && is_network_admin()
3881 3881
             ? get_site_transient($transient)
3882 3882
             : get_transient($transient);
@@ -4100,7 +4100,7 @@  discard block
 block discarded – undo
4100 4100
      */
4101 4101
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4102 4102
     {
4103
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4103
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4104 4104
     }
4105 4105
 
4106 4106
 
@@ -4113,7 +4113,7 @@  discard block
 block discarded – undo
4113 4113
      */
4114 4114
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4115 4115
     {
4116
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4116
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4117 4117
     }
4118 4118
 
4119 4119
 
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Indentation   +2113 added lines, -2113 removed lines patch added patch discarded remove patch
@@ -17,2117 +17,2117 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Used to reference when a registration has never been checked in.
22
-     *
23
-     * @deprecated use \EE_Checkin::status_checked_never instead
24
-     * @type int
25
-     */
26
-    const checkin_status_never = 2;
27
-
28
-    /**
29
-     * Used to reference when a registration has been checked in.
30
-     *
31
-     * @deprecated use \EE_Checkin::status_checked_in instead
32
-     * @type int
33
-     */
34
-    const checkin_status_in = 1;
35
-
36
-
37
-    /**
38
-     * Used to reference when a registration has been checked out.
39
-     *
40
-     * @deprecated use \EE_Checkin::status_checked_out instead
41
-     * @type int
42
-     */
43
-    const checkin_status_out = 0;
44
-
45
-
46
-    /**
47
-     * extra meta key for tracking reg status os trashed registrations
48
-     *
49
-     * @type string
50
-     */
51
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
-
53
-
54
-    /**
55
-     * extra meta key for tracking if registration has reserved ticket
56
-     *
57
-     * @type string
58
-     */
59
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
-
61
-
62
-    /**
63
-     * @param array  $props_n_values          incoming values
64
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
-     *                                        used.)
66
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
-     *                                        date_format and the second value is the time format
68
-     * @return EE_Registration
69
-     * @throws EE_Error
70
-     */
71
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
-    {
73
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param array  $props_n_values  incoming values from the database
80
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
-     *                                the website will be used.
82
-     * @return EE_Registration
83
-     */
84
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
-    {
86
-        return new self($props_n_values, true, $timezone);
87
-    }
88
-
89
-
90
-    /**
91
-     *        Set Event ID
92
-     *
93
-     * @param        int $EVT_ID Event ID
94
-     * @throws EE_Error
95
-     * @throws RuntimeException
96
-     */
97
-    public function set_event($EVT_ID = 0)
98
-    {
99
-        $this->set('EVT_ID', $EVT_ID);
100
-    }
101
-
102
-
103
-    /**
104
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
-     * be routed to internal methods
106
-     *
107
-     * @param string $field_name
108
-     * @param mixed  $field_value
109
-     * @param bool   $use_default
110
-     * @throws EE_Error
111
-     * @throws EntityNotFoundException
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws ReflectionException
116
-     * @throws RuntimeException
117
-     */
118
-    public function set($field_name, $field_value, $use_default = false)
119
-    {
120
-        switch ($field_name) {
121
-            case 'REG_code':
122
-                if (! empty($field_value) && $this->reg_code() === null) {
123
-                    $this->set_reg_code($field_value, $use_default);
124
-                }
125
-                break;
126
-            case 'STS_ID':
127
-                $this->set_status($field_value, $use_default);
128
-                break;
129
-            default:
130
-                parent::set($field_name, $field_value, $use_default);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * Set Status ID
137
-     * updates the registration status and ALSO...
138
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
-     *
141
-     * @param string                $new_STS_ID
142
-     * @param boolean               $use_default
143
-     * @param ContextInterface|null $context
144
-     * @return bool
145
-     * @throws DomainException
146
-     * @throws EE_Error
147
-     * @throws EntityNotFoundException
148
-     * @throws InvalidArgumentException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidInterfaceException
151
-     * @throws ReflectionException
152
-     * @throws RuntimeException
153
-     * @throws UnexpectedEntityException
154
-     */
155
-    public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
156
-    {
157
-        // get current REG_Status
158
-        $old_STS_ID = $this->status_ID();
159
-        // if status has changed
160
-        if (
161
-            $old_STS_ID !== $new_STS_ID // and that status has actually changed
162
-            && ! empty($old_STS_ID) // and that old status is actually set
163
-            && ! empty($new_STS_ID) // as well as the new status
164
-            && $this->ID() // ensure registration is in the db
165
-        ) {
166
-            // update internal status first
167
-            parent::set('STS_ID', $new_STS_ID, $use_default);
168
-            // THEN handle other changes that occur when reg status changes
169
-            // TO approved
170
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
171
-                // reserve a space by incrementing ticket and datetime sold values
172
-                $this->reserveRegistrationSpace();
173
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
174
-                // OR FROM  approved
175
-            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
176
-                // release a space by decrementing ticket and datetime sold values
177
-                $this->releaseRegistrationSpace();
178
-                do_action(
179
-                    'AHEE__EE_Registration__set_status__from_approved',
180
-                    $this,
181
-                    $old_STS_ID,
182
-                    $new_STS_ID,
183
-                    $context
184
-                );
185
-            }
186
-            // update status
187
-            parent::set('STS_ID', $new_STS_ID, $use_default);
188
-            $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
189
-            if ($this->statusChangeUpdatesTransaction($context)) {
190
-                $this->updateTransactionAfterStatusChange();
191
-            }
192
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
193
-            return true;
194
-        }
195
-        // even though the old value matches the new value, it's still good to
196
-        // allow the parent set method to have a say
197
-        parent::set('STS_ID', $new_STS_ID, $use_default);
198
-        return true;
199
-    }
200
-
201
-
202
-    /**
203
-     * update REGs and TXN when cancelled or declined registrations involved
204
-     *
205
-     * @param string                $new_STS_ID
206
-     * @param string                $old_STS_ID
207
-     * @param ContextInterface|null $context
208
-     * @throws EE_Error
209
-     * @throws InvalidArgumentException
210
-     * @throws InvalidDataTypeException
211
-     * @throws InvalidInterfaceException
212
-     * @throws ReflectionException
213
-     * @throws RuntimeException
214
-     */
215
-    private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
216
-    {
217
-        // these reg statuses should not be considered in any calculations involving monies owing
218
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
219
-        // true if registration has been cancelled or declined
220
-        $this->updateIfCanceled(
221
-            $closed_reg_statuses,
222
-            $new_STS_ID,
223
-            $old_STS_ID,
224
-            $context
225
-        );
226
-        $this->updateIfReinstated(
227
-            $closed_reg_statuses,
228
-            $new_STS_ID,
229
-            $old_STS_ID,
230
-            $context
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * update REGs and TXN when cancelled or declined registrations involved
237
-     *
238
-     * @param array                 $closed_reg_statuses
239
-     * @param string                $new_STS_ID
240
-     * @param string                $old_STS_ID
241
-     * @param ContextInterface|null $context
242
-     * @throws EE_Error
243
-     * @throws InvalidArgumentException
244
-     * @throws InvalidDataTypeException
245
-     * @throws InvalidInterfaceException
246
-     * @throws ReflectionException
247
-     * @throws RuntimeException
248
-     */
249
-    private function updateIfCanceled(
250
-        array $closed_reg_statuses,
251
-        $new_STS_ID,
252
-        $old_STS_ID,
253
-        ContextInterface $context = null
254
-    ) {
255
-        // true if registration has been cancelled or declined
256
-        if (
257
-            in_array($new_STS_ID, $closed_reg_statuses, true)
258
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
259
-        ) {
260
-            /** @type EE_Registration_Processor $registration_processor */
261
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
262
-            /** @type EE_Transaction_Processor $transaction_processor */
263
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
264
-            // cancelled or declined registration
265
-            $registration_processor->update_registration_after_being_canceled_or_declined(
266
-                $this,
267
-                $closed_reg_statuses
268
-            );
269
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
270
-                $this,
271
-                $closed_reg_statuses,
272
-                false
273
-            );
274
-            do_action(
275
-                'AHEE__EE_Registration__set_status__canceled_or_declined',
276
-                $this,
277
-                $old_STS_ID,
278
-                $new_STS_ID,
279
-                $context
280
-            );
281
-            return;
282
-        }
283
-    }
284
-
285
-
286
-    /**
287
-     * update REGs and TXN when cancelled or declined registrations involved
288
-     *
289
-     * @param array                 $closed_reg_statuses
290
-     * @param string                $new_STS_ID
291
-     * @param string                $old_STS_ID
292
-     * @param ContextInterface|null $context
293
-     * @throws EE_Error
294
-     * @throws InvalidArgumentException
295
-     * @throws InvalidDataTypeException
296
-     * @throws InvalidInterfaceException
297
-     * @throws ReflectionException
298
-     */
299
-    private function updateIfReinstated(
300
-        array $closed_reg_statuses,
301
-        $new_STS_ID,
302
-        $old_STS_ID,
303
-        ContextInterface $context = null
304
-    ) {
305
-        // true if reinstating cancelled or declined registration
306
-        if (
307
-            in_array($old_STS_ID, $closed_reg_statuses, true)
308
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
309
-        ) {
310
-            /** @type EE_Registration_Processor $registration_processor */
311
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
312
-            /** @type EE_Transaction_Processor $transaction_processor */
313
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
314
-            // reinstating cancelled or declined registration
315
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
316
-                $this,
317
-                $closed_reg_statuses
318
-            );
319
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
320
-                $this,
321
-                $closed_reg_statuses,
322
-                false
323
-            );
324
-            do_action(
325
-                'AHEE__EE_Registration__set_status__after_reinstated',
326
-                $this,
327
-                $old_STS_ID,
328
-                $new_STS_ID,
329
-                $context
330
-            );
331
-        }
332
-    }
333
-
334
-
335
-    /**
336
-     * @param ContextInterface|null $context
337
-     * @return bool
338
-     */
339
-    private function statusChangeUpdatesTransaction(ContextInterface $context = null)
340
-    {
341
-        $contexts_that_do_not_update_transaction = (array) apply_filters(
342
-            'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
343
-            array('spco_reg_step_attendee_information_process_registrations'),
344
-            $context,
345
-            $this
346
-        );
347
-        return ! (
348
-            $context instanceof ContextInterface
349
-            && in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
350
-        );
351
-    }
352
-
353
-
354
-    /**
355
-     * @throws EE_Error
356
-     * @throws EntityNotFoundException
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidDataTypeException
359
-     * @throws InvalidInterfaceException
360
-     * @throws ReflectionException
361
-     * @throws RuntimeException
362
-     */
363
-    private function updateTransactionAfterStatusChange()
364
-    {
365
-        /** @type EE_Transaction_Payments $transaction_payments */
366
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
367
-        $transaction_payments->recalculate_transaction_total($this->transaction(), false);
368
-        $this->transaction()->update_status_based_on_total_paid(true);
369
-    }
370
-
371
-
372
-    /**
373
-     *        get Status ID
374
-     */
375
-    public function status_ID()
376
-    {
377
-        return $this->get('STS_ID');
378
-    }
379
-
380
-
381
-    /**
382
-     * Gets the ticket this registration is for
383
-     *
384
-     * @param boolean $include_archived whether to include archived tickets or not.
385
-     *
386
-     * @return EE_Ticket|EE_Base_Class
387
-     * @throws EE_Error
388
-     */
389
-    public function ticket($include_archived = true)
390
-    {
391
-        $query_params = array();
392
-        if ($include_archived) {
393
-            $query_params['default_where_conditions'] = 'none';
394
-        }
395
-        return $this->get_first_related('Ticket', $query_params);
396
-    }
397
-
398
-
399
-    /**
400
-     * Gets the event this registration is for
401
-     *
402
-     * @return EE_Event
403
-     * @throws EE_Error
404
-     * @throws EntityNotFoundException
405
-     */
406
-    public function event()
407
-    {
408
-        $event = $this->get_first_related('Event');
409
-        if (! $event instanceof \EE_Event) {
410
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
411
-        }
412
-        return $event;
413
-    }
414
-
415
-
416
-    /**
417
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
418
-     * with the author of the event this registration is for.
419
-     *
420
-     * @since 4.5.0
421
-     * @return int
422
-     * @throws EE_Error
423
-     * @throws EntityNotFoundException
424
-     */
425
-    public function wp_user()
426
-    {
427
-        $event = $this->event();
428
-        if ($event instanceof EE_Event) {
429
-            return $event->wp_user();
430
-        }
431
-        return 0;
432
-    }
433
-
434
-
435
-    /**
436
-     * increments this registration's related ticket sold and corresponding datetime sold values
437
-     *
438
-     * @return void
439
-     * @throws DomainException
440
-     * @throws EE_Error
441
-     * @throws EntityNotFoundException
442
-     * @throws InvalidArgumentException
443
-     * @throws InvalidDataTypeException
444
-     * @throws InvalidInterfaceException
445
-     * @throws ReflectionException
446
-     * @throws UnexpectedEntityException
447
-     */
448
-    private function reserveRegistrationSpace()
449
-    {
450
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
451
-        // so stop tracking that this reg has a ticket reserved
452
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
453
-        $ticket = $this->ticket();
454
-        $ticket->increaseSold();
455
-        // possibly set event status to sold out
456
-        $this->event()->perform_sold_out_status_check();
457
-    }
458
-
459
-
460
-    /**
461
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
462
-     *
463
-     * @return void
464
-     * @throws DomainException
465
-     * @throws EE_Error
466
-     * @throws EntityNotFoundException
467
-     * @throws InvalidArgumentException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     * @throws ReflectionException
471
-     * @throws UnexpectedEntityException
472
-     */
473
-    private function releaseRegistrationSpace()
474
-    {
475
-        $ticket = $this->ticket();
476
-        $ticket->decreaseSold();
477
-        // possibly change event status from sold out back to previous status
478
-        $this->event()->perform_sold_out_status_check();
479
-    }
480
-
481
-
482
-    /**
483
-     * tracks this registration's ticket reservation in extra meta
484
-     * and can increment related ticket reserved and corresponding datetime reserved values
485
-     *
486
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
487
-     * @return void
488
-     * @throws EE_Error
489
-     * @throws InvalidArgumentException
490
-     * @throws InvalidDataTypeException
491
-     * @throws InvalidInterfaceException
492
-     * @throws ReflectionException
493
-     */
494
-    public function reserve_ticket($update_ticket = false, $source = 'unknown')
495
-    {
496
-        // only reserve ticket if space is not currently reserved
497
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
498
-            $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
499
-            // IMPORTANT !!!
500
-            // although checking $update_ticket first would be more efficient,
501
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
502
-            if (
503
-                $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
504
-                && $update_ticket
505
-            ) {
506
-                $ticket = $this->ticket();
507
-                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
508
-                $ticket->save();
509
-            }
510
-        }
511
-    }
512
-
513
-
514
-    /**
515
-     * stops tracking this registration's ticket reservation in extra meta
516
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
517
-     *
518
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
519
-     * @return void
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws InvalidDataTypeException
523
-     * @throws InvalidInterfaceException
524
-     * @throws ReflectionException
525
-     */
526
-    public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
527
-    {
528
-        // only release ticket if space is currently reserved
529
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
530
-            $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
531
-            // IMPORTANT !!!
532
-            // although checking $update_ticket first would be more efficient,
533
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
534
-            if (
535
-                $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
536
-                && $update_ticket
537
-            ) {
538
-                $ticket = $this->ticket();
539
-                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
540
-            }
541
-        }
542
-    }
543
-
544
-
545
-    /**
546
-     * Set Attendee ID
547
-     *
548
-     * @param        int $ATT_ID Attendee ID
549
-     * @throws EE_Error
550
-     * @throws RuntimeException
551
-     */
552
-    public function set_attendee_id($ATT_ID = 0)
553
-    {
554
-        $this->set('ATT_ID', $ATT_ID);
555
-    }
556
-
557
-
558
-    /**
559
-     *        Set Transaction ID
560
-     *
561
-     * @param        int $TXN_ID Transaction ID
562
-     * @throws EE_Error
563
-     * @throws RuntimeException
564
-     */
565
-    public function set_transaction_id($TXN_ID = 0)
566
-    {
567
-        $this->set('TXN_ID', $TXN_ID);
568
-    }
569
-
570
-
571
-    /**
572
-     *        Set Session
573
-     *
574
-     * @param    string $REG_session PHP Session ID
575
-     * @throws EE_Error
576
-     * @throws RuntimeException
577
-     */
578
-    public function set_session($REG_session = '')
579
-    {
580
-        $this->set('REG_session', $REG_session);
581
-    }
582
-
583
-
584
-    /**
585
-     *        Set Registration URL Link
586
-     *
587
-     * @param    string $REG_url_link Registration URL Link
588
-     * @throws EE_Error
589
-     * @throws RuntimeException
590
-     */
591
-    public function set_reg_url_link($REG_url_link = '')
592
-    {
593
-        $this->set('REG_url_link', $REG_url_link);
594
-    }
595
-
596
-
597
-    /**
598
-     *        Set Attendee Counter
599
-     *
600
-     * @param        int $REG_count Primary Attendee
601
-     * @throws EE_Error
602
-     * @throws RuntimeException
603
-     */
604
-    public function set_count($REG_count = 1)
605
-    {
606
-        $this->set('REG_count', $REG_count);
607
-    }
608
-
609
-
610
-    /**
611
-     *        Set Group Size
612
-     *
613
-     * @param        boolean $REG_group_size Group Registration
614
-     * @throws EE_Error
615
-     * @throws RuntimeException
616
-     */
617
-    public function set_group_size($REG_group_size = false)
618
-    {
619
-        $this->set('REG_group_size', $REG_group_size);
620
-    }
621
-
622
-
623
-    /**
624
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
625
-     *    EEM_Registration::status_id_not_approved
626
-     *
627
-     * @return        boolean
628
-     */
629
-    public function is_not_approved()
630
-    {
631
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
632
-    }
633
-
634
-
635
-    /**
636
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
637
-     *    EEM_Registration::status_id_pending_payment
638
-     *
639
-     * @return        boolean
640
-     */
641
-    public function is_pending_payment()
642
-    {
643
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
644
-    }
645
-
646
-
647
-    /**
648
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
649
-     *
650
-     * @return        boolean
651
-     */
652
-    public function is_approved()
653
-    {
654
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
655
-    }
656
-
657
-
658
-    /**
659
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
660
-     *
661
-     * @return        boolean
662
-     */
663
-    public function is_cancelled()
664
-    {
665
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
666
-    }
667
-
668
-
669
-    /**
670
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
671
-     *
672
-     * @return        boolean
673
-     */
674
-    public function is_declined()
675
-    {
676
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
677
-    }
678
-
679
-
680
-    /**
681
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
682
-     *    EEM_Registration::status_id_incomplete
683
-     *
684
-     * @return        boolean
685
-     */
686
-    public function is_incomplete()
687
-    {
688
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
689
-    }
690
-
691
-
692
-    /**
693
-     *        Set Registration Date
694
-     *
695
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
696
-     *                                                 Date
697
-     * @throws EE_Error
698
-     * @throws RuntimeException
699
-     */
700
-    public function set_reg_date($REG_date = false)
701
-    {
702
-        $this->set('REG_date', $REG_date);
703
-    }
704
-
705
-
706
-    /**
707
-     *    Set final price owing for this registration after all ticket/price modifications
708
-     *
709
-     * @access    public
710
-     * @param    float $REG_final_price
711
-     * @throws EE_Error
712
-     * @throws RuntimeException
713
-     */
714
-    public function set_final_price($REG_final_price = 0.00)
715
-    {
716
-        $this->set('REG_final_price', $REG_final_price);
717
-    }
718
-
719
-
720
-    /**
721
-     *    Set amount paid towards this registration's final price
722
-     *
723
-     * @access    public
724
-     * @param    float $REG_paid
725
-     * @throws EE_Error
726
-     * @throws RuntimeException
727
-     */
728
-    public function set_paid($REG_paid = 0.00)
729
-    {
730
-        $this->set('REG_paid', $REG_paid);
731
-    }
732
-
733
-
734
-    /**
735
-     *        Attendee Is Going
736
-     *
737
-     * @param        boolean $REG_att_is_going Attendee Is Going
738
-     * @throws EE_Error
739
-     * @throws RuntimeException
740
-     */
741
-    public function set_att_is_going($REG_att_is_going = false)
742
-    {
743
-        $this->set('REG_att_is_going', $REG_att_is_going);
744
-    }
745
-
746
-
747
-    /**
748
-     * Gets the related attendee
749
-     *
750
-     * @return EE_Attendee
751
-     * @throws EE_Error
752
-     */
753
-    public function attendee()
754
-    {
755
-        return $this->get_first_related('Attendee');
756
-    }
757
-
758
-    /**
759
-     * Gets the name of the attendee.
760
-     * @since $VID:$
761
-     * @param bool $apply_html_entities set to true if you want to use HTML entities.
762
-     * @return string
763
-     * @throws EE_Error
764
-     * @throws InvalidArgumentException
765
-     * @throws InvalidDataTypeException
766
-     * @throws InvalidInterfaceException
767
-     * @throws ReflectionException
768
-     */
769
-    public function attendeeName($apply_html_entities = false)
770
-    {
771
-        $attendee = $this->get_first_related('Attendee');
772
-        if ($attendee instanceof EE_Attendee) {
773
-            $attendee_name = $attendee->full_name($apply_html_entities);
774
-        } else {
775
-            $attendee_name = esc_html__('Unknown', 'event_espresso');
776
-        }
777
-        return $attendee_name;
778
-    }
779
-
780
-
781
-    /**
782
-     *        get Event ID
783
-     */
784
-    public function event_ID()
785
-    {
786
-        return $this->get('EVT_ID');
787
-    }
788
-
789
-
790
-    /**
791
-     *        get Event ID
792
-     */
793
-    public function event_name()
794
-    {
795
-        $event = $this->event_obj();
796
-        if ($event) {
797
-            return $event->name();
798
-        } else {
799
-            return null;
800
-        }
801
-    }
802
-
803
-
804
-    /**
805
-     * Fetches the event this registration is for
806
-     *
807
-     * @return EE_Event
808
-     * @throws EE_Error
809
-     */
810
-    public function event_obj()
811
-    {
812
-        return $this->get_first_related('Event');
813
-    }
814
-
815
-
816
-    /**
817
-     *        get Attendee ID
818
-     */
819
-    public function attendee_ID()
820
-    {
821
-        return $this->get('ATT_ID');
822
-    }
823
-
824
-
825
-    /**
826
-     *        get PHP Session ID
827
-     */
828
-    public function session_ID()
829
-    {
830
-        return $this->get('REG_session');
831
-    }
832
-
833
-
834
-    /**
835
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
836
-     *
837
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
838
-     * @return string
839
-     */
840
-    public function receipt_url($messenger = 'html')
841
-    {
842
-
843
-        /**
844
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template
845
-         * already in use on old system.  If there is then we just return the standard url for it.
846
-         *
847
-         * @since 4.5.0
848
-         */
849
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
850
-        $has_custom = EEH_Template::locate_template(
851
-            $template_relative_path,
852
-            array(),
853
-            true,
854
-            true,
855
-            true
856
-        );
857
-
858
-        if ($has_custom) {
859
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
860
-        }
861
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
862
-    }
863
-
864
-
865
-    /**
866
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
867
-     *
868
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
869
-     * @return string
870
-     * @throws EE_Error
871
-     */
872
-    public function invoice_url($messenger = 'html')
873
-    {
874
-        /**
875
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template
876
-         * already in use on old system.  If there is then we just return the standard url for it.
877
-         *
878
-         * @since 4.5.0
879
-         */
880
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
881
-        $has_custom = EEH_Template::locate_template(
882
-            $template_relative_path,
883
-            array(),
884
-            true,
885
-            true,
886
-            true
887
-        );
888
-
889
-        if ($has_custom) {
890
-            if ($messenger == 'html') {
891
-                return $this->invoice_url('launch');
892
-            }
893
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
894
-
895
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
896
-            if ($messenger == 'html') {
897
-                $query_args['html'] = true;
898
-            }
899
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
900
-        }
901
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
902
-    }
903
-
904
-
905
-    /**
906
-     * get Registration URL Link
907
-     *
908
-     * @access public
909
-     * @return string
910
-     * @throws EE_Error
911
-     */
912
-    public function reg_url_link()
913
-    {
914
-        return (string) $this->get('REG_url_link');
915
-    }
916
-
917
-
918
-    /**
919
-     * Echoes out invoice_url()
920
-     *
921
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
922
-     * @return void
923
-     * @throws EE_Error
924
-     */
925
-    public function e_invoice_url($type = 'launch')
926
-    {
927
-        echo $this->invoice_url($type);
928
-    }
929
-
930
-
931
-    /**
932
-     * Echoes out payment_overview_url
933
-     */
934
-    public function e_payment_overview_url()
935
-    {
936
-        echo $this->payment_overview_url();
937
-    }
938
-
939
-
940
-    /**
941
-     * Gets the URL for the checkout payment options reg step
942
-     * with this registration's REG_url_link added as a query parameter
943
-     *
944
-     * @param bool $clear_session Set to true when you want to clear the session on revisiting the
945
-     *                            payment overview url.
946
-     * @return string
947
-     * @throws InvalidInterfaceException
948
-     * @throws InvalidDataTypeException
949
-     * @throws EE_Error
950
-     * @throws InvalidArgumentException
951
-     */
952
-    public function payment_overview_url($clear_session = false)
953
-    {
954
-        return add_query_arg(
955
-            (array) apply_filters(
956
-                'FHEE__EE_Registration__payment_overview_url__query_args',
957
-                array(
958
-                    'e_reg_url_link' => $this->reg_url_link(),
959
-                    'step'           => 'payment_options',
960
-                    'revisit'        => true,
961
-                    'clear_session'  => (bool) $clear_session,
962
-                ),
963
-                $this
964
-            ),
965
-            EE_Registry::instance()->CFG->core->reg_page_url()
966
-        );
967
-    }
968
-
969
-
970
-    /**
971
-     * Gets the URL for the checkout attendee information reg step
972
-     * with this registration's REG_url_link added as a query parameter
973
-     *
974
-     * @return string
975
-     * @throws InvalidInterfaceException
976
-     * @throws InvalidDataTypeException
977
-     * @throws EE_Error
978
-     * @throws InvalidArgumentException
979
-     */
980
-    public function edit_attendee_information_url()
981
-    {
982
-        return add_query_arg(
983
-            (array) apply_filters(
984
-                'FHEE__EE_Registration__edit_attendee_information_url__query_args',
985
-                array(
986
-                    'e_reg_url_link' => $this->reg_url_link(),
987
-                    'step'           => 'attendee_information',
988
-                    'revisit'        => true,
989
-                ),
990
-                $this
991
-            ),
992
-            EE_Registry::instance()->CFG->core->reg_page_url()
993
-        );
994
-    }
995
-
996
-
997
-    /**
998
-     * Simply generates and returns the appropriate admin_url link to edit this registration
999
-     *
1000
-     * @return string
1001
-     * @throws EE_Error
1002
-     */
1003
-    public function get_admin_edit_url()
1004
-    {
1005
-        return EEH_URL::add_query_args_and_nonce(
1006
-            array(
1007
-                'page'    => 'espresso_registrations',
1008
-                'action'  => 'view_registration',
1009
-                '_REG_ID' => $this->ID(),
1010
-            ),
1011
-            admin_url('admin.php')
1012
-        );
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     *    is_primary_registrant?
1018
-     */
1019
-    public function is_primary_registrant()
1020
-    {
1021
-        return $this->get('REG_count') === 1 ? true : false;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * This returns the primary registration object for this registration group (which may be this object).
1027
-     *
1028
-     * @return EE_Registration
1029
-     * @throws EE_Error
1030
-     */
1031
-    public function get_primary_registration()
1032
-    {
1033
-        if ($this->is_primary_registrant()) {
1034
-            return $this;
1035
-        }
1036
-
1037
-        // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1038
-        /** @var EE_Registration $primary_registrant */
1039
-        $primary_registrant = EEM_Registration::instance()->get_one(
1040
-            array(
1041
-                array(
1042
-                    'TXN_ID'    => $this->transaction_ID(),
1043
-                    'REG_count' => 1,
1044
-                ),
1045
-            )
1046
-        );
1047
-        return $primary_registrant;
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     *        get  Attendee Number
1053
-     *
1054
-     * @access        public
1055
-     */
1056
-    public function count()
1057
-    {
1058
-        return $this->get('REG_count');
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     *        get Group Size
1064
-     */
1065
-    public function group_size()
1066
-    {
1067
-        return $this->get('REG_group_size');
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     *        get Registration Date
1073
-     */
1074
-    public function date()
1075
-    {
1076
-        return $this->get('REG_date');
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     * gets a pretty date
1082
-     *
1083
-     * @param string $date_format
1084
-     * @param string $time_format
1085
-     * @return string
1086
-     * @throws EE_Error
1087
-     */
1088
-    public function pretty_date($date_format = null, $time_format = null)
1089
-    {
1090
-        return $this->get_datetime('REG_date', $date_format, $time_format);
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * final_price
1096
-     * the registration's share of the transaction total, so that the
1097
-     * sum of all the transaction's REG_final_prices equal the transaction's total
1098
-     *
1099
-     * @return float
1100
-     * @throws EE_Error
1101
-     */
1102
-    public function final_price()
1103
-    {
1104
-        return $this->get('REG_final_price');
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * pretty_final_price
1110
-     *  final price as formatted string, with correct decimal places and currency symbol
1111
-     *
1112
-     * @return string
1113
-     * @throws EE_Error
1114
-     */
1115
-    public function pretty_final_price()
1116
-    {
1117
-        return $this->get_pretty('REG_final_price');
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * get paid (yeah)
1123
-     *
1124
-     * @return float
1125
-     * @throws EE_Error
1126
-     */
1127
-    public function paid()
1128
-    {
1129
-        return $this->get('REG_paid');
1130
-    }
1131
-
1132
-
1133
-    /**
1134
-     * pretty_paid
1135
-     *
1136
-     * @return float
1137
-     * @throws EE_Error
1138
-     */
1139
-    public function pretty_paid()
1140
-    {
1141
-        return $this->get_pretty('REG_paid');
1142
-    }
1143
-
1144
-
1145
-    /**
1146
-     * owes_monies_and_can_pay
1147
-     * whether or not this registration has monies owing and it's' status allows payment
1148
-     *
1149
-     * @param array $requires_payment
1150
-     * @return bool
1151
-     * @throws EE_Error
1152
-     */
1153
-    public function owes_monies_and_can_pay($requires_payment = array())
1154
-    {
1155
-        // these reg statuses require payment (if event is not free)
1156
-        $requires_payment = ! empty($requires_payment)
1157
-            ? $requires_payment
1158
-            : EEM_Registration::reg_statuses_that_allow_payment();
1159
-        if (
1160
-            in_array($this->status_ID(), $requires_payment) &&
1161
-            $this->final_price() != 0 &&
1162
-            $this->final_price() != $this->paid()
1163
-        ) {
1164
-            return true;
1165
-        } else {
1166
-            return false;
1167
-        }
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * Prints out the return value of $this->pretty_status()
1173
-     *
1174
-     * @param bool $show_icons
1175
-     * @return void
1176
-     * @throws EE_Error
1177
-     */
1178
-    public function e_pretty_status($show_icons = false)
1179
-    {
1180
-        echo $this->pretty_status($show_icons);
1181
-    }
1182
-
1183
-
1184
-    /**
1185
-     * Returns a nice version of the status for displaying to customers
1186
-     *
1187
-     * @param bool $show_icons
1188
-     * @return string
1189
-     * @throws EE_Error
1190
-     */
1191
-    public function pretty_status($show_icons = false)
1192
-    {
1193
-        $status = EEM_Status::instance()->localized_status(
1194
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1195
-            false,
1196
-            'sentence'
1197
-        );
1198
-        $icon = '';
1199
-        switch ($this->status_ID()) {
1200
-            case EEM_Registration::status_id_approved:
1201
-                $icon = $show_icons
1202
-                    ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1203
-                    : '';
1204
-                break;
1205
-            case EEM_Registration::status_id_pending_payment:
1206
-                $icon = $show_icons
1207
-                    ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1208
-                    : '';
1209
-                break;
1210
-            case EEM_Registration::status_id_not_approved:
1211
-                $icon = $show_icons
1212
-                    ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1213
-                    : '';
1214
-                break;
1215
-            case EEM_Registration::status_id_cancelled:
1216
-                $icon = $show_icons
1217
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1218
-                    : '';
1219
-                break;
1220
-            case EEM_Registration::status_id_incomplete:
1221
-                $icon = $show_icons
1222
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1223
-                    : '';
1224
-                break;
1225
-            case EEM_Registration::status_id_declined:
1226
-                $icon = $show_icons
1227
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1228
-                    : '';
1229
-                break;
1230
-            case EEM_Registration::status_id_wait_list:
1231
-                $icon = $show_icons
1232
-                    ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1233
-                    : '';
1234
-                break;
1235
-        }
1236
-        return $icon . $status[ $this->status_ID() ];
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     *        get Attendee Is Going
1242
-     */
1243
-    public function att_is_going()
1244
-    {
1245
-        return $this->get('REG_att_is_going');
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * Gets related answers
1251
-     *
1252
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1253
-     * @return EE_Answer[]
1254
-     * @throws EE_Error
1255
-     */
1256
-    public function answers($query_params = null)
1257
-    {
1258
-        return $this->get_many_related('Answer', $query_params);
1259
-    }
1260
-
1261
-
1262
-    /**
1263
-     * Gets the registration's answer value to the specified question
1264
-     * (either the question's ID or a question object)
1265
-     *
1266
-     * @param EE_Question|int $question
1267
-     * @param bool            $pretty_value
1268
-     * @return array|string if pretty_value= true, the result will always be a string
1269
-     * (because the answer might be an array of answer values, so passing pretty_value=true
1270
-     * will convert it into some kind of string)
1271
-     * @throws EE_Error
1272
-     */
1273
-    public function answer_value_to_question($question, $pretty_value = true)
1274
-    {
1275
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
1276
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * question_groups
1282
-     * returns an array of EE_Question_Group objects for this registration
1283
-     *
1284
-     * @return EE_Question_Group[]
1285
-     * @throws EE_Error
1286
-     * @throws InvalidArgumentException
1287
-     * @throws InvalidDataTypeException
1288
-     * @throws InvalidInterfaceException
1289
-     * @throws ReflectionException
1290
-     */
1291
-    public function question_groups()
1292
-    {
1293
-        return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1294
-    }
1295
-
1296
-
1297
-    /**
1298
-     * count_question_groups
1299
-     * returns a count of the number of EE_Question_Group objects for this registration
1300
-     *
1301
-     * @return int
1302
-     * @throws EE_Error
1303
-     * @throws EntityNotFoundException
1304
-     * @throws InvalidArgumentException
1305
-     * @throws InvalidDataTypeException
1306
-     * @throws InvalidInterfaceException
1307
-     * @throws ReflectionException
1308
-     */
1309
-    public function count_question_groups()
1310
-    {
1311
-        return EEM_Event::instance()->count_related(
1312
-            $this->event_ID(),
1313
-            'Question_Group',
1314
-            [
1315
-                [
1316
-                    'Event_Question_Group.'
1317
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1318
-                ]
1319
-            ]
1320
-        );
1321
-    }
1322
-
1323
-
1324
-    /**
1325
-     * Returns the registration date in the 'standard' string format
1326
-     * (function may be improved in the future to allow for different formats and timezones)
1327
-     *
1328
-     * @return string
1329
-     * @throws EE_Error
1330
-     */
1331
-    public function reg_date()
1332
-    {
1333
-        return $this->get_datetime('REG_date');
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1339
-     * the ticket this registration purchased, or the datetime they have registered
1340
-     * to attend)
1341
-     *
1342
-     * @return EE_Datetime_Ticket
1343
-     * @throws EE_Error
1344
-     */
1345
-    public function datetime_ticket()
1346
-    {
1347
-        return $this->get_first_related('Datetime_Ticket');
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * Sets the registration's datetime_ticket.
1353
-     *
1354
-     * @param EE_Datetime_Ticket $datetime_ticket
1355
-     * @return EE_Datetime_Ticket
1356
-     * @throws EE_Error
1357
-     */
1358
-    public function set_datetime_ticket($datetime_ticket)
1359
-    {
1360
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1361
-    }
1362
-
1363
-    /**
1364
-     * Gets deleted
1365
-     *
1366
-     * @return bool
1367
-     * @throws EE_Error
1368
-     */
1369
-    public function deleted()
1370
-    {
1371
-        return $this->get('REG_deleted');
1372
-    }
1373
-
1374
-    /**
1375
-     * Sets deleted
1376
-     *
1377
-     * @param boolean $deleted
1378
-     * @return bool
1379
-     * @throws EE_Error
1380
-     * @throws RuntimeException
1381
-     */
1382
-    public function set_deleted($deleted)
1383
-    {
1384
-        if ($deleted) {
1385
-            $this->delete();
1386
-        } else {
1387
-            $this->restore();
1388
-        }
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * Get the status object of this object
1394
-     *
1395
-     * @return EE_Status
1396
-     * @throws EE_Error
1397
-     */
1398
-    public function status_obj()
1399
-    {
1400
-        return $this->get_first_related('Status');
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * Returns the number of times this registration has checked into any of the datetimes
1406
-     * its available for
1407
-     *
1408
-     * @return int
1409
-     * @throws EE_Error
1410
-     */
1411
-    public function count_checkins()
1412
-    {
1413
-        return $this->get_model()->count_related($this, 'Checkin');
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1419
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1420
-     *
1421
-     * @return int
1422
-     * @throws EE_Error
1423
-     */
1424
-    public function count_checkins_not_checkedout()
1425
-    {
1426
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1427
-    }
1428
-
1429
-
1430
-    /**
1431
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1432
-     *
1433
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1434
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1435
-     *                                          consider registration status as well as datetime access.
1436
-     * @return bool
1437
-     * @throws EE_Error
1438
-     */
1439
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1440
-    {
1441
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1442
-
1443
-        // first check registration status
1444
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1445
-            return false;
1446
-        }
1447
-        // is there a datetime ticket that matches this dtt_ID?
1448
-        if (
1449
-            ! (EEM_Datetime_Ticket::instance()->exists(
1450
-                array(
1451
-                array(
1452
-                    'TKT_ID' => $this->get('TKT_ID'),
1453
-                    'DTT_ID' => $DTT_ID,
1454
-                ),
1455
-                )
1456
-            ))
1457
-        ) {
1458
-            return false;
1459
-        }
1460
-
1461
-        // final check is against TKT_uses
1462
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1468
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1469
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1470
-     * then return false.  Otherwise return true.
1471
-     *
1472
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1473
-     * @return bool true means can checkin.  false means cannot checkin.
1474
-     * @throws EE_Error
1475
-     */
1476
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1477
-    {
1478
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1479
-
1480
-        if (! $DTT_ID) {
1481
-            return false;
1482
-        }
1483
-
1484
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1485
-
1486
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1487
-        // check-in or not.
1488
-        if (! $max_uses || $max_uses === EE_INF) {
1489
-            return true;
1490
-        }
1491
-
1492
-        // does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1493
-        // go ahead and toggle.
1494
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1495
-            return true;
1496
-        }
1497
-
1498
-        // made it here so the last check is whether the number of checkins per unique datetime on this registration
1499
-        // disallows further check-ins.
1500
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1501
-            array(
1502
-                array(
1503
-                    'REG_ID' => $this->ID(),
1504
-                    'CHK_in' => true,
1505
-                ),
1506
-            ),
1507
-            'DTT_ID',
1508
-            true
1509
-        );
1510
-        // checkins have already reached their max number of uses
1511
-        // so registrant can NOT checkin
1512
-        if ($count_unique_dtt_checkins >= $max_uses) {
1513
-            EE_Error::add_error(
1514
-                esc_html__(
1515
-                    'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1516
-                    'event_espresso'
1517
-                ),
1518
-                __FILE__,
1519
-                __FUNCTION__,
1520
-                __LINE__
1521
-            );
1522
-            return false;
1523
-        }
1524
-        return true;
1525
-    }
1526
-
1527
-
1528
-    /**
1529
-     * toggle Check-in status for this registration
1530
-     * Check-ins are toggled in the following order:
1531
-     * never checked in -> checked in
1532
-     * checked in -> checked out
1533
-     * checked out -> checked in
1534
-     *
1535
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1536
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1537
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1538
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1539
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1540
-     * @throws EE_Error
1541
-     */
1542
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1543
-    {
1544
-        if (empty($DTT_ID)) {
1545
-            $datetime = $this->get_latest_related_datetime();
1546
-            $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1547
-            // verify the registration can checkin for the given DTT_ID
1548
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1549
-            EE_Error::add_error(
1550
-                sprintf(
1551
-                    esc_html__(
1552
-                        'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1553
-                        'event_espresso'
1554
-                    ),
1555
-                    $this->ID(),
1556
-                    $DTT_ID
1557
-                ),
1558
-                __FILE__,
1559
-                __FUNCTION__,
1560
-                __LINE__
1561
-            );
1562
-            return false;
1563
-        }
1564
-        $status_paths = array(
1565
-            EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1566
-            EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1567
-            EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1568
-        );
1569
-        // start by getting the current status so we know what status we'll be changing to.
1570
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1571
-        $status_to = $status_paths[ $cur_status ];
1572
-        // database only records true for checked IN or false for checked OUT
1573
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1574
-        $new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1575
-        // add relation - note Check-ins are always creating new rows
1576
-        // because we are keeping track of Check-ins over time.
1577
-        // Eventually we'll probably want to show a list table
1578
-        // for the individual Check-ins so that they can be managed.
1579
-        $checkin = EE_Checkin::new_instance(
1580
-            array(
1581
-                'REG_ID' => $this->ID(),
1582
-                'DTT_ID' => $DTT_ID,
1583
-                'CHK_in' => $new_status,
1584
-            )
1585
-        );
1586
-        // if the record could not be saved then return false
1587
-        if ($checkin->save() === 0) {
1588
-            if (WP_DEBUG) {
1589
-                global $wpdb;
1590
-                $error = sprintf(
1591
-                    esc_html__(
1592
-                        'Registration check in update failed because of the following database error: %1$s%2$s',
1593
-                        'event_espresso'
1594
-                    ),
1595
-                    '<br />',
1596
-                    $wpdb->last_error
1597
-                );
1598
-            } else {
1599
-                $error = esc_html__(
1600
-                    'Registration check in update failed because of an unknown database error',
1601
-                    'event_espresso'
1602
-                );
1603
-            }
1604
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1605
-            return false;
1606
-        }
1607
-        // Fire a checked_in and checkout_out action.
1608
-        $checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out';
1609
-        do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID);
1610
-        return $status_to;
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1616
-     * "Latest" is defined by the `DTT_EVT_start` column.
1617
-     *
1618
-     * @return EE_Datetime|null
1619
-     * @throws EE_Error
1620
-     */
1621
-    public function get_latest_related_datetime()
1622
-    {
1623
-        return EEM_Datetime::instance()->get_one(
1624
-            array(
1625
-                array(
1626
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1627
-                ),
1628
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1629
-            )
1630
-        );
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1636
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1637
-     *
1638
-     * @throws EE_Error
1639
-     */
1640
-    public function get_earliest_related_datetime()
1641
-    {
1642
-        return EEM_Datetime::instance()->get_one(
1643
-            array(
1644
-                array(
1645
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1646
-                ),
1647
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1648
-            )
1649
-        );
1650
-    }
1651
-
1652
-
1653
-    /**
1654
-     * This method simply returns the check-in status for this registration and the given datetime.
1655
-     * If neither the datetime nor the checkin values are provided as arguments,
1656
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1657
-     *
1658
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1659
-     *                            (if empty we'll get the primary datetime for
1660
-     *                            this registration (via event) and use it's ID);
1661
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1662
-     *
1663
-     * @return int                Integer representing Check-in status.
1664
-     * @throws EE_Error
1665
-     */
1666
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1667
-    {
1668
-        $checkin_query_params = array(
1669
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1670
-        );
1671
-
1672
-        if ($DTT_ID > 0) {
1673
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1674
-        }
1675
-
1676
-        // get checkin object (if exists)
1677
-        $checkin = $checkin instanceof EE_Checkin
1678
-            ? $checkin
1679
-            : $this->get_first_related('Checkin', $checkin_query_params);
1680
-        if ($checkin instanceof EE_Checkin) {
1681
-            if ($checkin->get('CHK_in')) {
1682
-                return EE_Checkin::status_checked_in; // checked in
1683
-            }
1684
-            return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1685
-        }
1686
-        return EE_Checkin::status_checked_never; // never been checked in
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     * This method returns a localized message for the toggled Check-in message.
1692
-     *
1693
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1694
-     *                     then it is assumed Check-in for primary datetime was toggled.
1695
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1696
-     *                     message can be customized with the attendee name.
1697
-     * @return string internationalized message
1698
-     * @throws EE_Error
1699
-     */
1700
-    public function get_checkin_msg($DTT_ID, $error = false)
1701
-    {
1702
-        // let's get the attendee first so we can include the name of the attendee
1703
-        $attendee = $this->get_first_related('Attendee');
1704
-        if ($attendee instanceof EE_Attendee) {
1705
-            if ($error) {
1706
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1707
-            }
1708
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1709
-            // what is the status message going to be?
1710
-            switch ($cur_status) {
1711
-                case EE_Checkin::status_checked_never:
1712
-                    return sprintf(
1713
-                        __("%s has been removed from Check-in records", "event_espresso"),
1714
-                        $attendee->full_name()
1715
-                    );
1716
-                    break;
1717
-                case EE_Checkin::status_checked_in:
1718
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1719
-                    break;
1720
-                case EE_Checkin::status_checked_out:
1721
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1722
-                    break;
1723
-            }
1724
-        }
1725
-        return esc_html__("The check-in status could not be determined.", "event_espresso");
1726
-    }
1727
-
1728
-
1729
-    /**
1730
-     * Returns the related EE_Transaction to this registration
1731
-     *
1732
-     * @return EE_Transaction
1733
-     * @throws EE_Error
1734
-     * @throws EntityNotFoundException
1735
-     */
1736
-    public function transaction()
1737
-    {
1738
-        $transaction = $this->get_first_related('Transaction');
1739
-        if (! $transaction instanceof \EE_Transaction) {
1740
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1741
-        }
1742
-        return $transaction;
1743
-    }
1744
-
1745
-
1746
-    /**
1747
-     *        get Registration Code
1748
-     */
1749
-    public function reg_code()
1750
-    {
1751
-        return $this->get('REG_code');
1752
-    }
1753
-
1754
-
1755
-    /**
1756
-     *        get Transaction ID
1757
-     */
1758
-    public function transaction_ID()
1759
-    {
1760
-        return $this->get('TXN_ID');
1761
-    }
1762
-
1763
-
1764
-    /**
1765
-     * @return int
1766
-     * @throws EE_Error
1767
-     */
1768
-    public function ticket_ID()
1769
-    {
1770
-        return $this->get('TKT_ID');
1771
-    }
1772
-
1773
-
1774
-    /**
1775
-     *        Set Registration Code
1776
-     *
1777
-     * @access    public
1778
-     * @param    string  $REG_code Registration Code
1779
-     * @param    boolean $use_default
1780
-     * @throws EE_Error
1781
-     */
1782
-    public function set_reg_code($REG_code, $use_default = false)
1783
-    {
1784
-        if (empty($REG_code)) {
1785
-            EE_Error::add_error(
1786
-                esc_html__('REG_code can not be empty.', 'event_espresso'),
1787
-                __FILE__,
1788
-                __FUNCTION__,
1789
-                __LINE__
1790
-            );
1791
-            return;
1792
-        }
1793
-        if (! $this->reg_code()) {
1794
-            parent::set('REG_code', $REG_code, $use_default);
1795
-        } else {
1796
-            EE_Error::doing_it_wrong(
1797
-                __CLASS__ . '::' . __FUNCTION__,
1798
-                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1799
-                '4.6.0'
1800
-            );
1801
-        }
1802
-    }
1803
-
1804
-
1805
-    /**
1806
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1807
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1808
-     *    $registration->transaction()->registrations();
1809
-     *
1810
-     * @since 4.5.0
1811
-     * @return EE_Registration[] or empty array if this isn't a group registration.
1812
-     * @throws EE_Error
1813
-     */
1814
-    public function get_all_other_registrations_in_group()
1815
-    {
1816
-        if ($this->group_size() < 2) {
1817
-            return array();
1818
-        }
1819
-
1820
-        $query[0] = array(
1821
-            'TXN_ID' => $this->transaction_ID(),
1822
-            'REG_ID' => array('!=', $this->ID()),
1823
-            'TKT_ID' => $this->ticket_ID(),
1824
-        );
1825
-        /** @var EE_Registration[] $registrations */
1826
-        $registrations = $this->get_model()->get_all($query);
1827
-        return $registrations;
1828
-    }
1829
-
1830
-    /**
1831
-     * Return the link to the admin details for the object.
1832
-     *
1833
-     * @return string
1834
-     * @throws EE_Error
1835
-     */
1836
-    public function get_admin_details_link()
1837
-    {
1838
-        EE_Registry::instance()->load_helper('URL');
1839
-        return EEH_URL::add_query_args_and_nonce(
1840
-            array(
1841
-                'page'    => 'espresso_registrations',
1842
-                'action'  => 'view_registration',
1843
-                '_REG_ID' => $this->ID(),
1844
-            ),
1845
-            admin_url('admin.php')
1846
-        );
1847
-    }
1848
-
1849
-    /**
1850
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1851
-     *
1852
-     * @return string
1853
-     * @throws EE_Error
1854
-     */
1855
-    public function get_admin_edit_link()
1856
-    {
1857
-        return $this->get_admin_details_link();
1858
-    }
1859
-
1860
-    /**
1861
-     * Returns the link to a settings page for the object.
1862
-     *
1863
-     * @return string
1864
-     * @throws EE_Error
1865
-     */
1866
-    public function get_admin_settings_link()
1867
-    {
1868
-        return $this->get_admin_details_link();
1869
-    }
1870
-
1871
-    /**
1872
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1873
-     *
1874
-     * @return string
1875
-     */
1876
-    public function get_admin_overview_link()
1877
-    {
1878
-        EE_Registry::instance()->load_helper('URL');
1879
-        return EEH_URL::add_query_args_and_nonce(
1880
-            array(
1881
-                'page' => 'espresso_registrations',
1882
-            ),
1883
-            admin_url('admin.php')
1884
-        );
1885
-    }
1886
-
1887
-
1888
-    /**
1889
-     * @param array $query_params
1890
-     *
1891
-     * @return \EE_Registration[]
1892
-     * @throws EE_Error
1893
-     */
1894
-    public function payments($query_params = array())
1895
-    {
1896
-        return $this->get_many_related('Payment', $query_params);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * @param array $query_params
1902
-     *
1903
-     * @return \EE_Registration_Payment[]
1904
-     * @throws EE_Error
1905
-     */
1906
-    public function registration_payments($query_params = array())
1907
-    {
1908
-        return $this->get_many_related('Registration_Payment', $query_params);
1909
-    }
1910
-
1911
-
1912
-    /**
1913
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1914
-     * Note: if there are no payments on the registration there will be no payment method returned.
1915
-     *
1916
-     * @return EE_Payment_Method|null
1917
-     */
1918
-    public function payment_method()
1919
-    {
1920
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1921
-    }
1922
-
1923
-
1924
-    /**
1925
-     * @return \EE_Line_Item
1926
-     * @throws EntityNotFoundException
1927
-     * @throws EE_Error
1928
-     */
1929
-    public function ticket_line_item()
1930
-    {
1931
-        $ticket = $this->ticket();
1932
-        $transaction = $this->transaction();
1933
-        $line_item = null;
1934
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1935
-            $transaction->total_line_item(),
1936
-            'Ticket',
1937
-            array($ticket->ID())
1938
-        );
1939
-        foreach ($ticket_line_items as $ticket_line_item) {
1940
-            if (
1941
-                $ticket_line_item instanceof \EE_Line_Item
1942
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1943
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1944
-            ) {
1945
-                $line_item = $ticket_line_item;
1946
-                break;
1947
-            }
1948
-        }
1949
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1950
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1951
-        }
1952
-        return $line_item;
1953
-    }
1954
-
1955
-
1956
-    /**
1957
-     * Soft Deletes this model object.
1958
-     *
1959
-     * @return boolean | int
1960
-     * @throws RuntimeException
1961
-     * @throws EE_Error
1962
-     */
1963
-    public function delete()
1964
-    {
1965
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1966
-            $this->set_status(EEM_Registration::status_id_cancelled);
1967
-        }
1968
-        return parent::delete();
1969
-    }
1970
-
1971
-
1972
-    /**
1973
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1974
-     *
1975
-     * @throws EE_Error
1976
-     * @throws RuntimeException
1977
-     */
1978
-    public function restore()
1979
-    {
1980
-        $previous_status = $this->get_extra_meta(
1981
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1982
-            true,
1983
-            EEM_Registration::status_id_cancelled
1984
-        );
1985
-        if ($previous_status) {
1986
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1987
-            $this->set_status($previous_status);
1988
-        }
1989
-        return parent::restore();
1990
-    }
1991
-
1992
-
1993
-    /**
1994
-     * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1995
-     *
1996
-     * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1997
-     *                                           depending on whether the reg status changes to or from "Approved"
1998
-     * @return boolean whether the Registration status was updated
1999
-     * @throws EE_Error
2000
-     * @throws RuntimeException
2001
-     */
2002
-    public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
2003
-    {
2004
-        $paid = $this->paid();
2005
-        $price = $this->final_price();
2006
-        switch (true) {
2007
-            // overpaid or paid
2008
-            case EEH_Money::compare_floats($paid, $price, '>'):
2009
-            case EEH_Money::compare_floats($paid, $price):
2010
-                $new_status = EEM_Registration::status_id_approved;
2011
-                break;
2012
-            //  underpaid
2013
-            case EEH_Money::compare_floats($paid, $price, '<'):
2014
-                $new_status = EEM_Registration::status_id_pending_payment;
2015
-                break;
2016
-            // uhhh Houston...
2017
-            default:
2018
-                throw new RuntimeException(
2019
-                    esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
2020
-                );
2021
-        }
2022
-        if ($new_status !== $this->status_ID()) {
2023
-            if ($trigger_set_status_logic) {
2024
-                return $this->set_status($new_status);
2025
-            }
2026
-            parent::set('STS_ID', $new_status);
2027
-            return true;
2028
-        }
2029
-        return false;
2030
-    }
2031
-
2032
-
2033
-    /*************************** DEPRECATED ***************************/
2034
-
2035
-
2036
-    /**
2037
-     * @deprecated
2038
-     * @since     4.7.0
2039
-     * @access    public
2040
-     */
2041
-    public function price_paid()
2042
-    {
2043
-        EE_Error::doing_it_wrong(
2044
-            'EE_Registration::price_paid()',
2045
-            esc_html__(
2046
-                'This method is deprecated, please use EE_Registration::final_price() instead.',
2047
-                'event_espresso'
2048
-            ),
2049
-            '4.7.0'
2050
-        );
2051
-        return $this->final_price();
2052
-    }
2053
-
2054
-
2055
-    /**
2056
-     * @deprecated
2057
-     * @since     4.7.0
2058
-     * @access    public
2059
-     * @param    float $REG_final_price
2060
-     * @throws EE_Error
2061
-     * @throws RuntimeException
2062
-     */
2063
-    public function set_price_paid($REG_final_price = 0.00)
2064
-    {
2065
-        EE_Error::doing_it_wrong(
2066
-            'EE_Registration::set_price_paid()',
2067
-            esc_html__(
2068
-                'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2069
-                'event_espresso'
2070
-            ),
2071
-            '4.7.0'
2072
-        );
2073
-        $this->set_final_price($REG_final_price);
2074
-    }
2075
-
2076
-
2077
-    /**
2078
-     * @deprecated
2079
-     * @since 4.7.0
2080
-     * @return string
2081
-     * @throws EE_Error
2082
-     */
2083
-    public function pretty_price_paid()
2084
-    {
2085
-        EE_Error::doing_it_wrong(
2086
-            'EE_Registration::pretty_price_paid()',
2087
-            esc_html__(
2088
-                'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2089
-                'event_espresso'
2090
-            ),
2091
-            '4.7.0'
2092
-        );
2093
-        return $this->pretty_final_price();
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * Gets the primary datetime related to this registration via the related Event to this registration
2099
-     *
2100
-     * @deprecated 4.9.17
2101
-     * @return EE_Datetime
2102
-     * @throws EE_Error
2103
-     * @throws EntityNotFoundException
2104
-     */
2105
-    public function get_related_primary_datetime()
2106
-    {
2107
-        EE_Error::doing_it_wrong(
2108
-            __METHOD__,
2109
-            esc_html__(
2110
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2111
-                'event_espresso'
2112
-            ),
2113
-            '4.9.17',
2114
-            '5.0.0'
2115
-        );
2116
-        return $this->event()->primary_datetime();
2117
-    }
2118
-
2119
-    /**
2120
-     * Returns the contact's name (or "Unknown" if there is no contact.)
2121
-     * @since $VID:$
2122
-     * @return string
2123
-     * @throws EE_Error
2124
-     * @throws InvalidArgumentException
2125
-     * @throws InvalidDataTypeException
2126
-     * @throws InvalidInterfaceException
2127
-     * @throws ReflectionException
2128
-     */
2129
-    public function name()
2130
-    {
2131
-        return $this->attendeeName();
2132
-    }
20
+	/**
21
+	 * Used to reference when a registration has never been checked in.
22
+	 *
23
+	 * @deprecated use \EE_Checkin::status_checked_never instead
24
+	 * @type int
25
+	 */
26
+	const checkin_status_never = 2;
27
+
28
+	/**
29
+	 * Used to reference when a registration has been checked in.
30
+	 *
31
+	 * @deprecated use \EE_Checkin::status_checked_in instead
32
+	 * @type int
33
+	 */
34
+	const checkin_status_in = 1;
35
+
36
+
37
+	/**
38
+	 * Used to reference when a registration has been checked out.
39
+	 *
40
+	 * @deprecated use \EE_Checkin::status_checked_out instead
41
+	 * @type int
42
+	 */
43
+	const checkin_status_out = 0;
44
+
45
+
46
+	/**
47
+	 * extra meta key for tracking reg status os trashed registrations
48
+	 *
49
+	 * @type string
50
+	 */
51
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
+
53
+
54
+	/**
55
+	 * extra meta key for tracking if registration has reserved ticket
56
+	 *
57
+	 * @type string
58
+	 */
59
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
+
61
+
62
+	/**
63
+	 * @param array  $props_n_values          incoming values
64
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
+	 *                                        used.)
66
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
+	 *                                        date_format and the second value is the time format
68
+	 * @return EE_Registration
69
+	 * @throws EE_Error
70
+	 */
71
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
+	{
73
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param array  $props_n_values  incoming values from the database
80
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
+	 *                                the website will be used.
82
+	 * @return EE_Registration
83
+	 */
84
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
+	{
86
+		return new self($props_n_values, true, $timezone);
87
+	}
88
+
89
+
90
+	/**
91
+	 *        Set Event ID
92
+	 *
93
+	 * @param        int $EVT_ID Event ID
94
+	 * @throws EE_Error
95
+	 * @throws RuntimeException
96
+	 */
97
+	public function set_event($EVT_ID = 0)
98
+	{
99
+		$this->set('EVT_ID', $EVT_ID);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
+	 * be routed to internal methods
106
+	 *
107
+	 * @param string $field_name
108
+	 * @param mixed  $field_value
109
+	 * @param bool   $use_default
110
+	 * @throws EE_Error
111
+	 * @throws EntityNotFoundException
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws ReflectionException
116
+	 * @throws RuntimeException
117
+	 */
118
+	public function set($field_name, $field_value, $use_default = false)
119
+	{
120
+		switch ($field_name) {
121
+			case 'REG_code':
122
+				if (! empty($field_value) && $this->reg_code() === null) {
123
+					$this->set_reg_code($field_value, $use_default);
124
+				}
125
+				break;
126
+			case 'STS_ID':
127
+				$this->set_status($field_value, $use_default);
128
+				break;
129
+			default:
130
+				parent::set($field_name, $field_value, $use_default);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * Set Status ID
137
+	 * updates the registration status and ALSO...
138
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
+	 *
141
+	 * @param string                $new_STS_ID
142
+	 * @param boolean               $use_default
143
+	 * @param ContextInterface|null $context
144
+	 * @return bool
145
+	 * @throws DomainException
146
+	 * @throws EE_Error
147
+	 * @throws EntityNotFoundException
148
+	 * @throws InvalidArgumentException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidInterfaceException
151
+	 * @throws ReflectionException
152
+	 * @throws RuntimeException
153
+	 * @throws UnexpectedEntityException
154
+	 */
155
+	public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
156
+	{
157
+		// get current REG_Status
158
+		$old_STS_ID = $this->status_ID();
159
+		// if status has changed
160
+		if (
161
+			$old_STS_ID !== $new_STS_ID // and that status has actually changed
162
+			&& ! empty($old_STS_ID) // and that old status is actually set
163
+			&& ! empty($new_STS_ID) // as well as the new status
164
+			&& $this->ID() // ensure registration is in the db
165
+		) {
166
+			// update internal status first
167
+			parent::set('STS_ID', $new_STS_ID, $use_default);
168
+			// THEN handle other changes that occur when reg status changes
169
+			// TO approved
170
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
171
+				// reserve a space by incrementing ticket and datetime sold values
172
+				$this->reserveRegistrationSpace();
173
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
174
+				// OR FROM  approved
175
+			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
176
+				// release a space by decrementing ticket and datetime sold values
177
+				$this->releaseRegistrationSpace();
178
+				do_action(
179
+					'AHEE__EE_Registration__set_status__from_approved',
180
+					$this,
181
+					$old_STS_ID,
182
+					$new_STS_ID,
183
+					$context
184
+				);
185
+			}
186
+			// update status
187
+			parent::set('STS_ID', $new_STS_ID, $use_default);
188
+			$this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
189
+			if ($this->statusChangeUpdatesTransaction($context)) {
190
+				$this->updateTransactionAfterStatusChange();
191
+			}
192
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
193
+			return true;
194
+		}
195
+		// even though the old value matches the new value, it's still good to
196
+		// allow the parent set method to have a say
197
+		parent::set('STS_ID', $new_STS_ID, $use_default);
198
+		return true;
199
+	}
200
+
201
+
202
+	/**
203
+	 * update REGs and TXN when cancelled or declined registrations involved
204
+	 *
205
+	 * @param string                $new_STS_ID
206
+	 * @param string                $old_STS_ID
207
+	 * @param ContextInterface|null $context
208
+	 * @throws EE_Error
209
+	 * @throws InvalidArgumentException
210
+	 * @throws InvalidDataTypeException
211
+	 * @throws InvalidInterfaceException
212
+	 * @throws ReflectionException
213
+	 * @throws RuntimeException
214
+	 */
215
+	private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
216
+	{
217
+		// these reg statuses should not be considered in any calculations involving monies owing
218
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
219
+		// true if registration has been cancelled or declined
220
+		$this->updateIfCanceled(
221
+			$closed_reg_statuses,
222
+			$new_STS_ID,
223
+			$old_STS_ID,
224
+			$context
225
+		);
226
+		$this->updateIfReinstated(
227
+			$closed_reg_statuses,
228
+			$new_STS_ID,
229
+			$old_STS_ID,
230
+			$context
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * update REGs and TXN when cancelled or declined registrations involved
237
+	 *
238
+	 * @param array                 $closed_reg_statuses
239
+	 * @param string                $new_STS_ID
240
+	 * @param string                $old_STS_ID
241
+	 * @param ContextInterface|null $context
242
+	 * @throws EE_Error
243
+	 * @throws InvalidArgumentException
244
+	 * @throws InvalidDataTypeException
245
+	 * @throws InvalidInterfaceException
246
+	 * @throws ReflectionException
247
+	 * @throws RuntimeException
248
+	 */
249
+	private function updateIfCanceled(
250
+		array $closed_reg_statuses,
251
+		$new_STS_ID,
252
+		$old_STS_ID,
253
+		ContextInterface $context = null
254
+	) {
255
+		// true if registration has been cancelled or declined
256
+		if (
257
+			in_array($new_STS_ID, $closed_reg_statuses, true)
258
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
259
+		) {
260
+			/** @type EE_Registration_Processor $registration_processor */
261
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
262
+			/** @type EE_Transaction_Processor $transaction_processor */
263
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
264
+			// cancelled or declined registration
265
+			$registration_processor->update_registration_after_being_canceled_or_declined(
266
+				$this,
267
+				$closed_reg_statuses
268
+			);
269
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
270
+				$this,
271
+				$closed_reg_statuses,
272
+				false
273
+			);
274
+			do_action(
275
+				'AHEE__EE_Registration__set_status__canceled_or_declined',
276
+				$this,
277
+				$old_STS_ID,
278
+				$new_STS_ID,
279
+				$context
280
+			);
281
+			return;
282
+		}
283
+	}
284
+
285
+
286
+	/**
287
+	 * update REGs and TXN when cancelled or declined registrations involved
288
+	 *
289
+	 * @param array                 $closed_reg_statuses
290
+	 * @param string                $new_STS_ID
291
+	 * @param string                $old_STS_ID
292
+	 * @param ContextInterface|null $context
293
+	 * @throws EE_Error
294
+	 * @throws InvalidArgumentException
295
+	 * @throws InvalidDataTypeException
296
+	 * @throws InvalidInterfaceException
297
+	 * @throws ReflectionException
298
+	 */
299
+	private function updateIfReinstated(
300
+		array $closed_reg_statuses,
301
+		$new_STS_ID,
302
+		$old_STS_ID,
303
+		ContextInterface $context = null
304
+	) {
305
+		// true if reinstating cancelled or declined registration
306
+		if (
307
+			in_array($old_STS_ID, $closed_reg_statuses, true)
308
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
309
+		) {
310
+			/** @type EE_Registration_Processor $registration_processor */
311
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
312
+			/** @type EE_Transaction_Processor $transaction_processor */
313
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
314
+			// reinstating cancelled or declined registration
315
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
316
+				$this,
317
+				$closed_reg_statuses
318
+			);
319
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
320
+				$this,
321
+				$closed_reg_statuses,
322
+				false
323
+			);
324
+			do_action(
325
+				'AHEE__EE_Registration__set_status__after_reinstated',
326
+				$this,
327
+				$old_STS_ID,
328
+				$new_STS_ID,
329
+				$context
330
+			);
331
+		}
332
+	}
333
+
334
+
335
+	/**
336
+	 * @param ContextInterface|null $context
337
+	 * @return bool
338
+	 */
339
+	private function statusChangeUpdatesTransaction(ContextInterface $context = null)
340
+	{
341
+		$contexts_that_do_not_update_transaction = (array) apply_filters(
342
+			'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
343
+			array('spco_reg_step_attendee_information_process_registrations'),
344
+			$context,
345
+			$this
346
+		);
347
+		return ! (
348
+			$context instanceof ContextInterface
349
+			&& in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
350
+		);
351
+	}
352
+
353
+
354
+	/**
355
+	 * @throws EE_Error
356
+	 * @throws EntityNotFoundException
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidDataTypeException
359
+	 * @throws InvalidInterfaceException
360
+	 * @throws ReflectionException
361
+	 * @throws RuntimeException
362
+	 */
363
+	private function updateTransactionAfterStatusChange()
364
+	{
365
+		/** @type EE_Transaction_Payments $transaction_payments */
366
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
367
+		$transaction_payments->recalculate_transaction_total($this->transaction(), false);
368
+		$this->transaction()->update_status_based_on_total_paid(true);
369
+	}
370
+
371
+
372
+	/**
373
+	 *        get Status ID
374
+	 */
375
+	public function status_ID()
376
+	{
377
+		return $this->get('STS_ID');
378
+	}
379
+
380
+
381
+	/**
382
+	 * Gets the ticket this registration is for
383
+	 *
384
+	 * @param boolean $include_archived whether to include archived tickets or not.
385
+	 *
386
+	 * @return EE_Ticket|EE_Base_Class
387
+	 * @throws EE_Error
388
+	 */
389
+	public function ticket($include_archived = true)
390
+	{
391
+		$query_params = array();
392
+		if ($include_archived) {
393
+			$query_params['default_where_conditions'] = 'none';
394
+		}
395
+		return $this->get_first_related('Ticket', $query_params);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Gets the event this registration is for
401
+	 *
402
+	 * @return EE_Event
403
+	 * @throws EE_Error
404
+	 * @throws EntityNotFoundException
405
+	 */
406
+	public function event()
407
+	{
408
+		$event = $this->get_first_related('Event');
409
+		if (! $event instanceof \EE_Event) {
410
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
411
+		}
412
+		return $event;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
418
+	 * with the author of the event this registration is for.
419
+	 *
420
+	 * @since 4.5.0
421
+	 * @return int
422
+	 * @throws EE_Error
423
+	 * @throws EntityNotFoundException
424
+	 */
425
+	public function wp_user()
426
+	{
427
+		$event = $this->event();
428
+		if ($event instanceof EE_Event) {
429
+			return $event->wp_user();
430
+		}
431
+		return 0;
432
+	}
433
+
434
+
435
+	/**
436
+	 * increments this registration's related ticket sold and corresponding datetime sold values
437
+	 *
438
+	 * @return void
439
+	 * @throws DomainException
440
+	 * @throws EE_Error
441
+	 * @throws EntityNotFoundException
442
+	 * @throws InvalidArgumentException
443
+	 * @throws InvalidDataTypeException
444
+	 * @throws InvalidInterfaceException
445
+	 * @throws ReflectionException
446
+	 * @throws UnexpectedEntityException
447
+	 */
448
+	private function reserveRegistrationSpace()
449
+	{
450
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
451
+		// so stop tracking that this reg has a ticket reserved
452
+		$this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
453
+		$ticket = $this->ticket();
454
+		$ticket->increaseSold();
455
+		// possibly set event status to sold out
456
+		$this->event()->perform_sold_out_status_check();
457
+	}
458
+
459
+
460
+	/**
461
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
462
+	 *
463
+	 * @return void
464
+	 * @throws DomainException
465
+	 * @throws EE_Error
466
+	 * @throws EntityNotFoundException
467
+	 * @throws InvalidArgumentException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 * @throws ReflectionException
471
+	 * @throws UnexpectedEntityException
472
+	 */
473
+	private function releaseRegistrationSpace()
474
+	{
475
+		$ticket = $this->ticket();
476
+		$ticket->decreaseSold();
477
+		// possibly change event status from sold out back to previous status
478
+		$this->event()->perform_sold_out_status_check();
479
+	}
480
+
481
+
482
+	/**
483
+	 * tracks this registration's ticket reservation in extra meta
484
+	 * and can increment related ticket reserved and corresponding datetime reserved values
485
+	 *
486
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
487
+	 * @return void
488
+	 * @throws EE_Error
489
+	 * @throws InvalidArgumentException
490
+	 * @throws InvalidDataTypeException
491
+	 * @throws InvalidInterfaceException
492
+	 * @throws ReflectionException
493
+	 */
494
+	public function reserve_ticket($update_ticket = false, $source = 'unknown')
495
+	{
496
+		// only reserve ticket if space is not currently reserved
497
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
498
+			$this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
499
+			// IMPORTANT !!!
500
+			// although checking $update_ticket first would be more efficient,
501
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
502
+			if (
503
+				$this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
504
+				&& $update_ticket
505
+			) {
506
+				$ticket = $this->ticket();
507
+				$ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
508
+				$ticket->save();
509
+			}
510
+		}
511
+	}
512
+
513
+
514
+	/**
515
+	 * stops tracking this registration's ticket reservation in extra meta
516
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
517
+	 *
518
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
519
+	 * @return void
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws InvalidDataTypeException
523
+	 * @throws InvalidInterfaceException
524
+	 * @throws ReflectionException
525
+	 */
526
+	public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
527
+	{
528
+		// only release ticket if space is currently reserved
529
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
530
+			$this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
531
+			// IMPORTANT !!!
532
+			// although checking $update_ticket first would be more efficient,
533
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
534
+			if (
535
+				$this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
536
+				&& $update_ticket
537
+			) {
538
+				$ticket = $this->ticket();
539
+				$ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
540
+			}
541
+		}
542
+	}
543
+
544
+
545
+	/**
546
+	 * Set Attendee ID
547
+	 *
548
+	 * @param        int $ATT_ID Attendee ID
549
+	 * @throws EE_Error
550
+	 * @throws RuntimeException
551
+	 */
552
+	public function set_attendee_id($ATT_ID = 0)
553
+	{
554
+		$this->set('ATT_ID', $ATT_ID);
555
+	}
556
+
557
+
558
+	/**
559
+	 *        Set Transaction ID
560
+	 *
561
+	 * @param        int $TXN_ID Transaction ID
562
+	 * @throws EE_Error
563
+	 * @throws RuntimeException
564
+	 */
565
+	public function set_transaction_id($TXN_ID = 0)
566
+	{
567
+		$this->set('TXN_ID', $TXN_ID);
568
+	}
569
+
570
+
571
+	/**
572
+	 *        Set Session
573
+	 *
574
+	 * @param    string $REG_session PHP Session ID
575
+	 * @throws EE_Error
576
+	 * @throws RuntimeException
577
+	 */
578
+	public function set_session($REG_session = '')
579
+	{
580
+		$this->set('REG_session', $REG_session);
581
+	}
582
+
583
+
584
+	/**
585
+	 *        Set Registration URL Link
586
+	 *
587
+	 * @param    string $REG_url_link Registration URL Link
588
+	 * @throws EE_Error
589
+	 * @throws RuntimeException
590
+	 */
591
+	public function set_reg_url_link($REG_url_link = '')
592
+	{
593
+		$this->set('REG_url_link', $REG_url_link);
594
+	}
595
+
596
+
597
+	/**
598
+	 *        Set Attendee Counter
599
+	 *
600
+	 * @param        int $REG_count Primary Attendee
601
+	 * @throws EE_Error
602
+	 * @throws RuntimeException
603
+	 */
604
+	public function set_count($REG_count = 1)
605
+	{
606
+		$this->set('REG_count', $REG_count);
607
+	}
608
+
609
+
610
+	/**
611
+	 *        Set Group Size
612
+	 *
613
+	 * @param        boolean $REG_group_size Group Registration
614
+	 * @throws EE_Error
615
+	 * @throws RuntimeException
616
+	 */
617
+	public function set_group_size($REG_group_size = false)
618
+	{
619
+		$this->set('REG_group_size', $REG_group_size);
620
+	}
621
+
622
+
623
+	/**
624
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
625
+	 *    EEM_Registration::status_id_not_approved
626
+	 *
627
+	 * @return        boolean
628
+	 */
629
+	public function is_not_approved()
630
+	{
631
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
632
+	}
633
+
634
+
635
+	/**
636
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
637
+	 *    EEM_Registration::status_id_pending_payment
638
+	 *
639
+	 * @return        boolean
640
+	 */
641
+	public function is_pending_payment()
642
+	{
643
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
644
+	}
645
+
646
+
647
+	/**
648
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
649
+	 *
650
+	 * @return        boolean
651
+	 */
652
+	public function is_approved()
653
+	{
654
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
655
+	}
656
+
657
+
658
+	/**
659
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
660
+	 *
661
+	 * @return        boolean
662
+	 */
663
+	public function is_cancelled()
664
+	{
665
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
666
+	}
667
+
668
+
669
+	/**
670
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
671
+	 *
672
+	 * @return        boolean
673
+	 */
674
+	public function is_declined()
675
+	{
676
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
677
+	}
678
+
679
+
680
+	/**
681
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
682
+	 *    EEM_Registration::status_id_incomplete
683
+	 *
684
+	 * @return        boolean
685
+	 */
686
+	public function is_incomplete()
687
+	{
688
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
689
+	}
690
+
691
+
692
+	/**
693
+	 *        Set Registration Date
694
+	 *
695
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
696
+	 *                                                 Date
697
+	 * @throws EE_Error
698
+	 * @throws RuntimeException
699
+	 */
700
+	public function set_reg_date($REG_date = false)
701
+	{
702
+		$this->set('REG_date', $REG_date);
703
+	}
704
+
705
+
706
+	/**
707
+	 *    Set final price owing for this registration after all ticket/price modifications
708
+	 *
709
+	 * @access    public
710
+	 * @param    float $REG_final_price
711
+	 * @throws EE_Error
712
+	 * @throws RuntimeException
713
+	 */
714
+	public function set_final_price($REG_final_price = 0.00)
715
+	{
716
+		$this->set('REG_final_price', $REG_final_price);
717
+	}
718
+
719
+
720
+	/**
721
+	 *    Set amount paid towards this registration's final price
722
+	 *
723
+	 * @access    public
724
+	 * @param    float $REG_paid
725
+	 * @throws EE_Error
726
+	 * @throws RuntimeException
727
+	 */
728
+	public function set_paid($REG_paid = 0.00)
729
+	{
730
+		$this->set('REG_paid', $REG_paid);
731
+	}
732
+
733
+
734
+	/**
735
+	 *        Attendee Is Going
736
+	 *
737
+	 * @param        boolean $REG_att_is_going Attendee Is Going
738
+	 * @throws EE_Error
739
+	 * @throws RuntimeException
740
+	 */
741
+	public function set_att_is_going($REG_att_is_going = false)
742
+	{
743
+		$this->set('REG_att_is_going', $REG_att_is_going);
744
+	}
745
+
746
+
747
+	/**
748
+	 * Gets the related attendee
749
+	 *
750
+	 * @return EE_Attendee
751
+	 * @throws EE_Error
752
+	 */
753
+	public function attendee()
754
+	{
755
+		return $this->get_first_related('Attendee');
756
+	}
757
+
758
+	/**
759
+	 * Gets the name of the attendee.
760
+	 * @since $VID:$
761
+	 * @param bool $apply_html_entities set to true if you want to use HTML entities.
762
+	 * @return string
763
+	 * @throws EE_Error
764
+	 * @throws InvalidArgumentException
765
+	 * @throws InvalidDataTypeException
766
+	 * @throws InvalidInterfaceException
767
+	 * @throws ReflectionException
768
+	 */
769
+	public function attendeeName($apply_html_entities = false)
770
+	{
771
+		$attendee = $this->get_first_related('Attendee');
772
+		if ($attendee instanceof EE_Attendee) {
773
+			$attendee_name = $attendee->full_name($apply_html_entities);
774
+		} else {
775
+			$attendee_name = esc_html__('Unknown', 'event_espresso');
776
+		}
777
+		return $attendee_name;
778
+	}
779
+
780
+
781
+	/**
782
+	 *        get Event ID
783
+	 */
784
+	public function event_ID()
785
+	{
786
+		return $this->get('EVT_ID');
787
+	}
788
+
789
+
790
+	/**
791
+	 *        get Event ID
792
+	 */
793
+	public function event_name()
794
+	{
795
+		$event = $this->event_obj();
796
+		if ($event) {
797
+			return $event->name();
798
+		} else {
799
+			return null;
800
+		}
801
+	}
802
+
803
+
804
+	/**
805
+	 * Fetches the event this registration is for
806
+	 *
807
+	 * @return EE_Event
808
+	 * @throws EE_Error
809
+	 */
810
+	public function event_obj()
811
+	{
812
+		return $this->get_first_related('Event');
813
+	}
814
+
815
+
816
+	/**
817
+	 *        get Attendee ID
818
+	 */
819
+	public function attendee_ID()
820
+	{
821
+		return $this->get('ATT_ID');
822
+	}
823
+
824
+
825
+	/**
826
+	 *        get PHP Session ID
827
+	 */
828
+	public function session_ID()
829
+	{
830
+		return $this->get('REG_session');
831
+	}
832
+
833
+
834
+	/**
835
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
836
+	 *
837
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
838
+	 * @return string
839
+	 */
840
+	public function receipt_url($messenger = 'html')
841
+	{
842
+
843
+		/**
844
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template
845
+		 * already in use on old system.  If there is then we just return the standard url for it.
846
+		 *
847
+		 * @since 4.5.0
848
+		 */
849
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
850
+		$has_custom = EEH_Template::locate_template(
851
+			$template_relative_path,
852
+			array(),
853
+			true,
854
+			true,
855
+			true
856
+		);
857
+
858
+		if ($has_custom) {
859
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
860
+		}
861
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
862
+	}
863
+
864
+
865
+	/**
866
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
867
+	 *
868
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
869
+	 * @return string
870
+	 * @throws EE_Error
871
+	 */
872
+	public function invoice_url($messenger = 'html')
873
+	{
874
+		/**
875
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template
876
+		 * already in use on old system.  If there is then we just return the standard url for it.
877
+		 *
878
+		 * @since 4.5.0
879
+		 */
880
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
881
+		$has_custom = EEH_Template::locate_template(
882
+			$template_relative_path,
883
+			array(),
884
+			true,
885
+			true,
886
+			true
887
+		);
888
+
889
+		if ($has_custom) {
890
+			if ($messenger == 'html') {
891
+				return $this->invoice_url('launch');
892
+			}
893
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
894
+
895
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
896
+			if ($messenger == 'html') {
897
+				$query_args['html'] = true;
898
+			}
899
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
900
+		}
901
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
902
+	}
903
+
904
+
905
+	/**
906
+	 * get Registration URL Link
907
+	 *
908
+	 * @access public
909
+	 * @return string
910
+	 * @throws EE_Error
911
+	 */
912
+	public function reg_url_link()
913
+	{
914
+		return (string) $this->get('REG_url_link');
915
+	}
916
+
917
+
918
+	/**
919
+	 * Echoes out invoice_url()
920
+	 *
921
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
922
+	 * @return void
923
+	 * @throws EE_Error
924
+	 */
925
+	public function e_invoice_url($type = 'launch')
926
+	{
927
+		echo $this->invoice_url($type);
928
+	}
929
+
930
+
931
+	/**
932
+	 * Echoes out payment_overview_url
933
+	 */
934
+	public function e_payment_overview_url()
935
+	{
936
+		echo $this->payment_overview_url();
937
+	}
938
+
939
+
940
+	/**
941
+	 * Gets the URL for the checkout payment options reg step
942
+	 * with this registration's REG_url_link added as a query parameter
943
+	 *
944
+	 * @param bool $clear_session Set to true when you want to clear the session on revisiting the
945
+	 *                            payment overview url.
946
+	 * @return string
947
+	 * @throws InvalidInterfaceException
948
+	 * @throws InvalidDataTypeException
949
+	 * @throws EE_Error
950
+	 * @throws InvalidArgumentException
951
+	 */
952
+	public function payment_overview_url($clear_session = false)
953
+	{
954
+		return add_query_arg(
955
+			(array) apply_filters(
956
+				'FHEE__EE_Registration__payment_overview_url__query_args',
957
+				array(
958
+					'e_reg_url_link' => $this->reg_url_link(),
959
+					'step'           => 'payment_options',
960
+					'revisit'        => true,
961
+					'clear_session'  => (bool) $clear_session,
962
+				),
963
+				$this
964
+			),
965
+			EE_Registry::instance()->CFG->core->reg_page_url()
966
+		);
967
+	}
968
+
969
+
970
+	/**
971
+	 * Gets the URL for the checkout attendee information reg step
972
+	 * with this registration's REG_url_link added as a query parameter
973
+	 *
974
+	 * @return string
975
+	 * @throws InvalidInterfaceException
976
+	 * @throws InvalidDataTypeException
977
+	 * @throws EE_Error
978
+	 * @throws InvalidArgumentException
979
+	 */
980
+	public function edit_attendee_information_url()
981
+	{
982
+		return add_query_arg(
983
+			(array) apply_filters(
984
+				'FHEE__EE_Registration__edit_attendee_information_url__query_args',
985
+				array(
986
+					'e_reg_url_link' => $this->reg_url_link(),
987
+					'step'           => 'attendee_information',
988
+					'revisit'        => true,
989
+				),
990
+				$this
991
+			),
992
+			EE_Registry::instance()->CFG->core->reg_page_url()
993
+		);
994
+	}
995
+
996
+
997
+	/**
998
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
999
+	 *
1000
+	 * @return string
1001
+	 * @throws EE_Error
1002
+	 */
1003
+	public function get_admin_edit_url()
1004
+	{
1005
+		return EEH_URL::add_query_args_and_nonce(
1006
+			array(
1007
+				'page'    => 'espresso_registrations',
1008
+				'action'  => 'view_registration',
1009
+				'_REG_ID' => $this->ID(),
1010
+			),
1011
+			admin_url('admin.php')
1012
+		);
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 *    is_primary_registrant?
1018
+	 */
1019
+	public function is_primary_registrant()
1020
+	{
1021
+		return $this->get('REG_count') === 1 ? true : false;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * This returns the primary registration object for this registration group (which may be this object).
1027
+	 *
1028
+	 * @return EE_Registration
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	public function get_primary_registration()
1032
+	{
1033
+		if ($this->is_primary_registrant()) {
1034
+			return $this;
1035
+		}
1036
+
1037
+		// k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1038
+		/** @var EE_Registration $primary_registrant */
1039
+		$primary_registrant = EEM_Registration::instance()->get_one(
1040
+			array(
1041
+				array(
1042
+					'TXN_ID'    => $this->transaction_ID(),
1043
+					'REG_count' => 1,
1044
+				),
1045
+			)
1046
+		);
1047
+		return $primary_registrant;
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 *        get  Attendee Number
1053
+	 *
1054
+	 * @access        public
1055
+	 */
1056
+	public function count()
1057
+	{
1058
+		return $this->get('REG_count');
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 *        get Group Size
1064
+	 */
1065
+	public function group_size()
1066
+	{
1067
+		return $this->get('REG_group_size');
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 *        get Registration Date
1073
+	 */
1074
+	public function date()
1075
+	{
1076
+		return $this->get('REG_date');
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 * gets a pretty date
1082
+	 *
1083
+	 * @param string $date_format
1084
+	 * @param string $time_format
1085
+	 * @return string
1086
+	 * @throws EE_Error
1087
+	 */
1088
+	public function pretty_date($date_format = null, $time_format = null)
1089
+	{
1090
+		return $this->get_datetime('REG_date', $date_format, $time_format);
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * final_price
1096
+	 * the registration's share of the transaction total, so that the
1097
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
1098
+	 *
1099
+	 * @return float
1100
+	 * @throws EE_Error
1101
+	 */
1102
+	public function final_price()
1103
+	{
1104
+		return $this->get('REG_final_price');
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * pretty_final_price
1110
+	 *  final price as formatted string, with correct decimal places and currency symbol
1111
+	 *
1112
+	 * @return string
1113
+	 * @throws EE_Error
1114
+	 */
1115
+	public function pretty_final_price()
1116
+	{
1117
+		return $this->get_pretty('REG_final_price');
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * get paid (yeah)
1123
+	 *
1124
+	 * @return float
1125
+	 * @throws EE_Error
1126
+	 */
1127
+	public function paid()
1128
+	{
1129
+		return $this->get('REG_paid');
1130
+	}
1131
+
1132
+
1133
+	/**
1134
+	 * pretty_paid
1135
+	 *
1136
+	 * @return float
1137
+	 * @throws EE_Error
1138
+	 */
1139
+	public function pretty_paid()
1140
+	{
1141
+		return $this->get_pretty('REG_paid');
1142
+	}
1143
+
1144
+
1145
+	/**
1146
+	 * owes_monies_and_can_pay
1147
+	 * whether or not this registration has monies owing and it's' status allows payment
1148
+	 *
1149
+	 * @param array $requires_payment
1150
+	 * @return bool
1151
+	 * @throws EE_Error
1152
+	 */
1153
+	public function owes_monies_and_can_pay($requires_payment = array())
1154
+	{
1155
+		// these reg statuses require payment (if event is not free)
1156
+		$requires_payment = ! empty($requires_payment)
1157
+			? $requires_payment
1158
+			: EEM_Registration::reg_statuses_that_allow_payment();
1159
+		if (
1160
+			in_array($this->status_ID(), $requires_payment) &&
1161
+			$this->final_price() != 0 &&
1162
+			$this->final_price() != $this->paid()
1163
+		) {
1164
+			return true;
1165
+		} else {
1166
+			return false;
1167
+		}
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * Prints out the return value of $this->pretty_status()
1173
+	 *
1174
+	 * @param bool $show_icons
1175
+	 * @return void
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	public function e_pretty_status($show_icons = false)
1179
+	{
1180
+		echo $this->pretty_status($show_icons);
1181
+	}
1182
+
1183
+
1184
+	/**
1185
+	 * Returns a nice version of the status for displaying to customers
1186
+	 *
1187
+	 * @param bool $show_icons
1188
+	 * @return string
1189
+	 * @throws EE_Error
1190
+	 */
1191
+	public function pretty_status($show_icons = false)
1192
+	{
1193
+		$status = EEM_Status::instance()->localized_status(
1194
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1195
+			false,
1196
+			'sentence'
1197
+		);
1198
+		$icon = '';
1199
+		switch ($this->status_ID()) {
1200
+			case EEM_Registration::status_id_approved:
1201
+				$icon = $show_icons
1202
+					? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1203
+					: '';
1204
+				break;
1205
+			case EEM_Registration::status_id_pending_payment:
1206
+				$icon = $show_icons
1207
+					? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1208
+					: '';
1209
+				break;
1210
+			case EEM_Registration::status_id_not_approved:
1211
+				$icon = $show_icons
1212
+					? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1213
+					: '';
1214
+				break;
1215
+			case EEM_Registration::status_id_cancelled:
1216
+				$icon = $show_icons
1217
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1218
+					: '';
1219
+				break;
1220
+			case EEM_Registration::status_id_incomplete:
1221
+				$icon = $show_icons
1222
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1223
+					: '';
1224
+				break;
1225
+			case EEM_Registration::status_id_declined:
1226
+				$icon = $show_icons
1227
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1228
+					: '';
1229
+				break;
1230
+			case EEM_Registration::status_id_wait_list:
1231
+				$icon = $show_icons
1232
+					? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1233
+					: '';
1234
+				break;
1235
+		}
1236
+		return $icon . $status[ $this->status_ID() ];
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 *        get Attendee Is Going
1242
+	 */
1243
+	public function att_is_going()
1244
+	{
1245
+		return $this->get('REG_att_is_going');
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * Gets related answers
1251
+	 *
1252
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1253
+	 * @return EE_Answer[]
1254
+	 * @throws EE_Error
1255
+	 */
1256
+	public function answers($query_params = null)
1257
+	{
1258
+		return $this->get_many_related('Answer', $query_params);
1259
+	}
1260
+
1261
+
1262
+	/**
1263
+	 * Gets the registration's answer value to the specified question
1264
+	 * (either the question's ID or a question object)
1265
+	 *
1266
+	 * @param EE_Question|int $question
1267
+	 * @param bool            $pretty_value
1268
+	 * @return array|string if pretty_value= true, the result will always be a string
1269
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
1270
+	 * will convert it into some kind of string)
1271
+	 * @throws EE_Error
1272
+	 */
1273
+	public function answer_value_to_question($question, $pretty_value = true)
1274
+	{
1275
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
1276
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * question_groups
1282
+	 * returns an array of EE_Question_Group objects for this registration
1283
+	 *
1284
+	 * @return EE_Question_Group[]
1285
+	 * @throws EE_Error
1286
+	 * @throws InvalidArgumentException
1287
+	 * @throws InvalidDataTypeException
1288
+	 * @throws InvalidInterfaceException
1289
+	 * @throws ReflectionException
1290
+	 */
1291
+	public function question_groups()
1292
+	{
1293
+		return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1294
+	}
1295
+
1296
+
1297
+	/**
1298
+	 * count_question_groups
1299
+	 * returns a count of the number of EE_Question_Group objects for this registration
1300
+	 *
1301
+	 * @return int
1302
+	 * @throws EE_Error
1303
+	 * @throws EntityNotFoundException
1304
+	 * @throws InvalidArgumentException
1305
+	 * @throws InvalidDataTypeException
1306
+	 * @throws InvalidInterfaceException
1307
+	 * @throws ReflectionException
1308
+	 */
1309
+	public function count_question_groups()
1310
+	{
1311
+		return EEM_Event::instance()->count_related(
1312
+			$this->event_ID(),
1313
+			'Question_Group',
1314
+			[
1315
+				[
1316
+					'Event_Question_Group.'
1317
+					. EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1318
+				]
1319
+			]
1320
+		);
1321
+	}
1322
+
1323
+
1324
+	/**
1325
+	 * Returns the registration date in the 'standard' string format
1326
+	 * (function may be improved in the future to allow for different formats and timezones)
1327
+	 *
1328
+	 * @return string
1329
+	 * @throws EE_Error
1330
+	 */
1331
+	public function reg_date()
1332
+	{
1333
+		return $this->get_datetime('REG_date');
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1339
+	 * the ticket this registration purchased, or the datetime they have registered
1340
+	 * to attend)
1341
+	 *
1342
+	 * @return EE_Datetime_Ticket
1343
+	 * @throws EE_Error
1344
+	 */
1345
+	public function datetime_ticket()
1346
+	{
1347
+		return $this->get_first_related('Datetime_Ticket');
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * Sets the registration's datetime_ticket.
1353
+	 *
1354
+	 * @param EE_Datetime_Ticket $datetime_ticket
1355
+	 * @return EE_Datetime_Ticket
1356
+	 * @throws EE_Error
1357
+	 */
1358
+	public function set_datetime_ticket($datetime_ticket)
1359
+	{
1360
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1361
+	}
1362
+
1363
+	/**
1364
+	 * Gets deleted
1365
+	 *
1366
+	 * @return bool
1367
+	 * @throws EE_Error
1368
+	 */
1369
+	public function deleted()
1370
+	{
1371
+		return $this->get('REG_deleted');
1372
+	}
1373
+
1374
+	/**
1375
+	 * Sets deleted
1376
+	 *
1377
+	 * @param boolean $deleted
1378
+	 * @return bool
1379
+	 * @throws EE_Error
1380
+	 * @throws RuntimeException
1381
+	 */
1382
+	public function set_deleted($deleted)
1383
+	{
1384
+		if ($deleted) {
1385
+			$this->delete();
1386
+		} else {
1387
+			$this->restore();
1388
+		}
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * Get the status object of this object
1394
+	 *
1395
+	 * @return EE_Status
1396
+	 * @throws EE_Error
1397
+	 */
1398
+	public function status_obj()
1399
+	{
1400
+		return $this->get_first_related('Status');
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * Returns the number of times this registration has checked into any of the datetimes
1406
+	 * its available for
1407
+	 *
1408
+	 * @return int
1409
+	 * @throws EE_Error
1410
+	 */
1411
+	public function count_checkins()
1412
+	{
1413
+		return $this->get_model()->count_related($this, 'Checkin');
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1419
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1420
+	 *
1421
+	 * @return int
1422
+	 * @throws EE_Error
1423
+	 */
1424
+	public function count_checkins_not_checkedout()
1425
+	{
1426
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1427
+	}
1428
+
1429
+
1430
+	/**
1431
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1432
+	 *
1433
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1434
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1435
+	 *                                          consider registration status as well as datetime access.
1436
+	 * @return bool
1437
+	 * @throws EE_Error
1438
+	 */
1439
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1440
+	{
1441
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1442
+
1443
+		// first check registration status
1444
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1445
+			return false;
1446
+		}
1447
+		// is there a datetime ticket that matches this dtt_ID?
1448
+		if (
1449
+			! (EEM_Datetime_Ticket::instance()->exists(
1450
+				array(
1451
+				array(
1452
+					'TKT_ID' => $this->get('TKT_ID'),
1453
+					'DTT_ID' => $DTT_ID,
1454
+				),
1455
+				)
1456
+			))
1457
+		) {
1458
+			return false;
1459
+		}
1460
+
1461
+		// final check is against TKT_uses
1462
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1468
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1469
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1470
+	 * then return false.  Otherwise return true.
1471
+	 *
1472
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1473
+	 * @return bool true means can checkin.  false means cannot checkin.
1474
+	 * @throws EE_Error
1475
+	 */
1476
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1477
+	{
1478
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1479
+
1480
+		if (! $DTT_ID) {
1481
+			return false;
1482
+		}
1483
+
1484
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1485
+
1486
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1487
+		// check-in or not.
1488
+		if (! $max_uses || $max_uses === EE_INF) {
1489
+			return true;
1490
+		}
1491
+
1492
+		// does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1493
+		// go ahead and toggle.
1494
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1495
+			return true;
1496
+		}
1497
+
1498
+		// made it here so the last check is whether the number of checkins per unique datetime on this registration
1499
+		// disallows further check-ins.
1500
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1501
+			array(
1502
+				array(
1503
+					'REG_ID' => $this->ID(),
1504
+					'CHK_in' => true,
1505
+				),
1506
+			),
1507
+			'DTT_ID',
1508
+			true
1509
+		);
1510
+		// checkins have already reached their max number of uses
1511
+		// so registrant can NOT checkin
1512
+		if ($count_unique_dtt_checkins >= $max_uses) {
1513
+			EE_Error::add_error(
1514
+				esc_html__(
1515
+					'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1516
+					'event_espresso'
1517
+				),
1518
+				__FILE__,
1519
+				__FUNCTION__,
1520
+				__LINE__
1521
+			);
1522
+			return false;
1523
+		}
1524
+		return true;
1525
+	}
1526
+
1527
+
1528
+	/**
1529
+	 * toggle Check-in status for this registration
1530
+	 * Check-ins are toggled in the following order:
1531
+	 * never checked in -> checked in
1532
+	 * checked in -> checked out
1533
+	 * checked out -> checked in
1534
+	 *
1535
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1536
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1537
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1538
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1539
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1540
+	 * @throws EE_Error
1541
+	 */
1542
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1543
+	{
1544
+		if (empty($DTT_ID)) {
1545
+			$datetime = $this->get_latest_related_datetime();
1546
+			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1547
+			// verify the registration can checkin for the given DTT_ID
1548
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1549
+			EE_Error::add_error(
1550
+				sprintf(
1551
+					esc_html__(
1552
+						'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1553
+						'event_espresso'
1554
+					),
1555
+					$this->ID(),
1556
+					$DTT_ID
1557
+				),
1558
+				__FILE__,
1559
+				__FUNCTION__,
1560
+				__LINE__
1561
+			);
1562
+			return false;
1563
+		}
1564
+		$status_paths = array(
1565
+			EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1566
+			EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1567
+			EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1568
+		);
1569
+		// start by getting the current status so we know what status we'll be changing to.
1570
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1571
+		$status_to = $status_paths[ $cur_status ];
1572
+		// database only records true for checked IN or false for checked OUT
1573
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1574
+		$new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1575
+		// add relation - note Check-ins are always creating new rows
1576
+		// because we are keeping track of Check-ins over time.
1577
+		// Eventually we'll probably want to show a list table
1578
+		// for the individual Check-ins so that they can be managed.
1579
+		$checkin = EE_Checkin::new_instance(
1580
+			array(
1581
+				'REG_ID' => $this->ID(),
1582
+				'DTT_ID' => $DTT_ID,
1583
+				'CHK_in' => $new_status,
1584
+			)
1585
+		);
1586
+		// if the record could not be saved then return false
1587
+		if ($checkin->save() === 0) {
1588
+			if (WP_DEBUG) {
1589
+				global $wpdb;
1590
+				$error = sprintf(
1591
+					esc_html__(
1592
+						'Registration check in update failed because of the following database error: %1$s%2$s',
1593
+						'event_espresso'
1594
+					),
1595
+					'<br />',
1596
+					$wpdb->last_error
1597
+				);
1598
+			} else {
1599
+				$error = esc_html__(
1600
+					'Registration check in update failed because of an unknown database error',
1601
+					'event_espresso'
1602
+				);
1603
+			}
1604
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1605
+			return false;
1606
+		}
1607
+		// Fire a checked_in and checkout_out action.
1608
+		$checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out';
1609
+		do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID);
1610
+		return $status_to;
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1616
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1617
+	 *
1618
+	 * @return EE_Datetime|null
1619
+	 * @throws EE_Error
1620
+	 */
1621
+	public function get_latest_related_datetime()
1622
+	{
1623
+		return EEM_Datetime::instance()->get_one(
1624
+			array(
1625
+				array(
1626
+					'Ticket.Registration.REG_ID' => $this->ID(),
1627
+				),
1628
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1629
+			)
1630
+		);
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1636
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1637
+	 *
1638
+	 * @throws EE_Error
1639
+	 */
1640
+	public function get_earliest_related_datetime()
1641
+	{
1642
+		return EEM_Datetime::instance()->get_one(
1643
+			array(
1644
+				array(
1645
+					'Ticket.Registration.REG_ID' => $this->ID(),
1646
+				),
1647
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1648
+			)
1649
+		);
1650
+	}
1651
+
1652
+
1653
+	/**
1654
+	 * This method simply returns the check-in status for this registration and the given datetime.
1655
+	 * If neither the datetime nor the checkin values are provided as arguments,
1656
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1657
+	 *
1658
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1659
+	 *                            (if empty we'll get the primary datetime for
1660
+	 *                            this registration (via event) and use it's ID);
1661
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1662
+	 *
1663
+	 * @return int                Integer representing Check-in status.
1664
+	 * @throws EE_Error
1665
+	 */
1666
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1667
+	{
1668
+		$checkin_query_params = array(
1669
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1670
+		);
1671
+
1672
+		if ($DTT_ID > 0) {
1673
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1674
+		}
1675
+
1676
+		// get checkin object (if exists)
1677
+		$checkin = $checkin instanceof EE_Checkin
1678
+			? $checkin
1679
+			: $this->get_first_related('Checkin', $checkin_query_params);
1680
+		if ($checkin instanceof EE_Checkin) {
1681
+			if ($checkin->get('CHK_in')) {
1682
+				return EE_Checkin::status_checked_in; // checked in
1683
+			}
1684
+			return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1685
+		}
1686
+		return EE_Checkin::status_checked_never; // never been checked in
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 * This method returns a localized message for the toggled Check-in message.
1692
+	 *
1693
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1694
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1695
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1696
+	 *                     message can be customized with the attendee name.
1697
+	 * @return string internationalized message
1698
+	 * @throws EE_Error
1699
+	 */
1700
+	public function get_checkin_msg($DTT_ID, $error = false)
1701
+	{
1702
+		// let's get the attendee first so we can include the name of the attendee
1703
+		$attendee = $this->get_first_related('Attendee');
1704
+		if ($attendee instanceof EE_Attendee) {
1705
+			if ($error) {
1706
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1707
+			}
1708
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1709
+			// what is the status message going to be?
1710
+			switch ($cur_status) {
1711
+				case EE_Checkin::status_checked_never:
1712
+					return sprintf(
1713
+						__("%s has been removed from Check-in records", "event_espresso"),
1714
+						$attendee->full_name()
1715
+					);
1716
+					break;
1717
+				case EE_Checkin::status_checked_in:
1718
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1719
+					break;
1720
+				case EE_Checkin::status_checked_out:
1721
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1722
+					break;
1723
+			}
1724
+		}
1725
+		return esc_html__("The check-in status could not be determined.", "event_espresso");
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * Returns the related EE_Transaction to this registration
1731
+	 *
1732
+	 * @return EE_Transaction
1733
+	 * @throws EE_Error
1734
+	 * @throws EntityNotFoundException
1735
+	 */
1736
+	public function transaction()
1737
+	{
1738
+		$transaction = $this->get_first_related('Transaction');
1739
+		if (! $transaction instanceof \EE_Transaction) {
1740
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1741
+		}
1742
+		return $transaction;
1743
+	}
1744
+
1745
+
1746
+	/**
1747
+	 *        get Registration Code
1748
+	 */
1749
+	public function reg_code()
1750
+	{
1751
+		return $this->get('REG_code');
1752
+	}
1753
+
1754
+
1755
+	/**
1756
+	 *        get Transaction ID
1757
+	 */
1758
+	public function transaction_ID()
1759
+	{
1760
+		return $this->get('TXN_ID');
1761
+	}
1762
+
1763
+
1764
+	/**
1765
+	 * @return int
1766
+	 * @throws EE_Error
1767
+	 */
1768
+	public function ticket_ID()
1769
+	{
1770
+		return $this->get('TKT_ID');
1771
+	}
1772
+
1773
+
1774
+	/**
1775
+	 *        Set Registration Code
1776
+	 *
1777
+	 * @access    public
1778
+	 * @param    string  $REG_code Registration Code
1779
+	 * @param    boolean $use_default
1780
+	 * @throws EE_Error
1781
+	 */
1782
+	public function set_reg_code($REG_code, $use_default = false)
1783
+	{
1784
+		if (empty($REG_code)) {
1785
+			EE_Error::add_error(
1786
+				esc_html__('REG_code can not be empty.', 'event_espresso'),
1787
+				__FILE__,
1788
+				__FUNCTION__,
1789
+				__LINE__
1790
+			);
1791
+			return;
1792
+		}
1793
+		if (! $this->reg_code()) {
1794
+			parent::set('REG_code', $REG_code, $use_default);
1795
+		} else {
1796
+			EE_Error::doing_it_wrong(
1797
+				__CLASS__ . '::' . __FUNCTION__,
1798
+				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1799
+				'4.6.0'
1800
+			);
1801
+		}
1802
+	}
1803
+
1804
+
1805
+	/**
1806
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1807
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1808
+	 *    $registration->transaction()->registrations();
1809
+	 *
1810
+	 * @since 4.5.0
1811
+	 * @return EE_Registration[] or empty array if this isn't a group registration.
1812
+	 * @throws EE_Error
1813
+	 */
1814
+	public function get_all_other_registrations_in_group()
1815
+	{
1816
+		if ($this->group_size() < 2) {
1817
+			return array();
1818
+		}
1819
+
1820
+		$query[0] = array(
1821
+			'TXN_ID' => $this->transaction_ID(),
1822
+			'REG_ID' => array('!=', $this->ID()),
1823
+			'TKT_ID' => $this->ticket_ID(),
1824
+		);
1825
+		/** @var EE_Registration[] $registrations */
1826
+		$registrations = $this->get_model()->get_all($query);
1827
+		return $registrations;
1828
+	}
1829
+
1830
+	/**
1831
+	 * Return the link to the admin details for the object.
1832
+	 *
1833
+	 * @return string
1834
+	 * @throws EE_Error
1835
+	 */
1836
+	public function get_admin_details_link()
1837
+	{
1838
+		EE_Registry::instance()->load_helper('URL');
1839
+		return EEH_URL::add_query_args_and_nonce(
1840
+			array(
1841
+				'page'    => 'espresso_registrations',
1842
+				'action'  => 'view_registration',
1843
+				'_REG_ID' => $this->ID(),
1844
+			),
1845
+			admin_url('admin.php')
1846
+		);
1847
+	}
1848
+
1849
+	/**
1850
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1851
+	 *
1852
+	 * @return string
1853
+	 * @throws EE_Error
1854
+	 */
1855
+	public function get_admin_edit_link()
1856
+	{
1857
+		return $this->get_admin_details_link();
1858
+	}
1859
+
1860
+	/**
1861
+	 * Returns the link to a settings page for the object.
1862
+	 *
1863
+	 * @return string
1864
+	 * @throws EE_Error
1865
+	 */
1866
+	public function get_admin_settings_link()
1867
+	{
1868
+		return $this->get_admin_details_link();
1869
+	}
1870
+
1871
+	/**
1872
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1873
+	 *
1874
+	 * @return string
1875
+	 */
1876
+	public function get_admin_overview_link()
1877
+	{
1878
+		EE_Registry::instance()->load_helper('URL');
1879
+		return EEH_URL::add_query_args_and_nonce(
1880
+			array(
1881
+				'page' => 'espresso_registrations',
1882
+			),
1883
+			admin_url('admin.php')
1884
+		);
1885
+	}
1886
+
1887
+
1888
+	/**
1889
+	 * @param array $query_params
1890
+	 *
1891
+	 * @return \EE_Registration[]
1892
+	 * @throws EE_Error
1893
+	 */
1894
+	public function payments($query_params = array())
1895
+	{
1896
+		return $this->get_many_related('Payment', $query_params);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * @param array $query_params
1902
+	 *
1903
+	 * @return \EE_Registration_Payment[]
1904
+	 * @throws EE_Error
1905
+	 */
1906
+	public function registration_payments($query_params = array())
1907
+	{
1908
+		return $this->get_many_related('Registration_Payment', $query_params);
1909
+	}
1910
+
1911
+
1912
+	/**
1913
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1914
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1915
+	 *
1916
+	 * @return EE_Payment_Method|null
1917
+	 */
1918
+	public function payment_method()
1919
+	{
1920
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1921
+	}
1922
+
1923
+
1924
+	/**
1925
+	 * @return \EE_Line_Item
1926
+	 * @throws EntityNotFoundException
1927
+	 * @throws EE_Error
1928
+	 */
1929
+	public function ticket_line_item()
1930
+	{
1931
+		$ticket = $this->ticket();
1932
+		$transaction = $this->transaction();
1933
+		$line_item = null;
1934
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1935
+			$transaction->total_line_item(),
1936
+			'Ticket',
1937
+			array($ticket->ID())
1938
+		);
1939
+		foreach ($ticket_line_items as $ticket_line_item) {
1940
+			if (
1941
+				$ticket_line_item instanceof \EE_Line_Item
1942
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1943
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1944
+			) {
1945
+				$line_item = $ticket_line_item;
1946
+				break;
1947
+			}
1948
+		}
1949
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1950
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1951
+		}
1952
+		return $line_item;
1953
+	}
1954
+
1955
+
1956
+	/**
1957
+	 * Soft Deletes this model object.
1958
+	 *
1959
+	 * @return boolean | int
1960
+	 * @throws RuntimeException
1961
+	 * @throws EE_Error
1962
+	 */
1963
+	public function delete()
1964
+	{
1965
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1966
+			$this->set_status(EEM_Registration::status_id_cancelled);
1967
+		}
1968
+		return parent::delete();
1969
+	}
1970
+
1971
+
1972
+	/**
1973
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1974
+	 *
1975
+	 * @throws EE_Error
1976
+	 * @throws RuntimeException
1977
+	 */
1978
+	public function restore()
1979
+	{
1980
+		$previous_status = $this->get_extra_meta(
1981
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1982
+			true,
1983
+			EEM_Registration::status_id_cancelled
1984
+		);
1985
+		if ($previous_status) {
1986
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1987
+			$this->set_status($previous_status);
1988
+		}
1989
+		return parent::restore();
1990
+	}
1991
+
1992
+
1993
+	/**
1994
+	 * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1995
+	 *
1996
+	 * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1997
+	 *                                           depending on whether the reg status changes to or from "Approved"
1998
+	 * @return boolean whether the Registration status was updated
1999
+	 * @throws EE_Error
2000
+	 * @throws RuntimeException
2001
+	 */
2002
+	public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
2003
+	{
2004
+		$paid = $this->paid();
2005
+		$price = $this->final_price();
2006
+		switch (true) {
2007
+			// overpaid or paid
2008
+			case EEH_Money::compare_floats($paid, $price, '>'):
2009
+			case EEH_Money::compare_floats($paid, $price):
2010
+				$new_status = EEM_Registration::status_id_approved;
2011
+				break;
2012
+			//  underpaid
2013
+			case EEH_Money::compare_floats($paid, $price, '<'):
2014
+				$new_status = EEM_Registration::status_id_pending_payment;
2015
+				break;
2016
+			// uhhh Houston...
2017
+			default:
2018
+				throw new RuntimeException(
2019
+					esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
2020
+				);
2021
+		}
2022
+		if ($new_status !== $this->status_ID()) {
2023
+			if ($trigger_set_status_logic) {
2024
+				return $this->set_status($new_status);
2025
+			}
2026
+			parent::set('STS_ID', $new_status);
2027
+			return true;
2028
+		}
2029
+		return false;
2030
+	}
2031
+
2032
+
2033
+	/*************************** DEPRECATED ***************************/
2034
+
2035
+
2036
+	/**
2037
+	 * @deprecated
2038
+	 * @since     4.7.0
2039
+	 * @access    public
2040
+	 */
2041
+	public function price_paid()
2042
+	{
2043
+		EE_Error::doing_it_wrong(
2044
+			'EE_Registration::price_paid()',
2045
+			esc_html__(
2046
+				'This method is deprecated, please use EE_Registration::final_price() instead.',
2047
+				'event_espresso'
2048
+			),
2049
+			'4.7.0'
2050
+		);
2051
+		return $this->final_price();
2052
+	}
2053
+
2054
+
2055
+	/**
2056
+	 * @deprecated
2057
+	 * @since     4.7.0
2058
+	 * @access    public
2059
+	 * @param    float $REG_final_price
2060
+	 * @throws EE_Error
2061
+	 * @throws RuntimeException
2062
+	 */
2063
+	public function set_price_paid($REG_final_price = 0.00)
2064
+	{
2065
+		EE_Error::doing_it_wrong(
2066
+			'EE_Registration::set_price_paid()',
2067
+			esc_html__(
2068
+				'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2069
+				'event_espresso'
2070
+			),
2071
+			'4.7.0'
2072
+		);
2073
+		$this->set_final_price($REG_final_price);
2074
+	}
2075
+
2076
+
2077
+	/**
2078
+	 * @deprecated
2079
+	 * @since 4.7.0
2080
+	 * @return string
2081
+	 * @throws EE_Error
2082
+	 */
2083
+	public function pretty_price_paid()
2084
+	{
2085
+		EE_Error::doing_it_wrong(
2086
+			'EE_Registration::pretty_price_paid()',
2087
+			esc_html__(
2088
+				'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2089
+				'event_espresso'
2090
+			),
2091
+			'4.7.0'
2092
+		);
2093
+		return $this->pretty_final_price();
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * Gets the primary datetime related to this registration via the related Event to this registration
2099
+	 *
2100
+	 * @deprecated 4.9.17
2101
+	 * @return EE_Datetime
2102
+	 * @throws EE_Error
2103
+	 * @throws EntityNotFoundException
2104
+	 */
2105
+	public function get_related_primary_datetime()
2106
+	{
2107
+		EE_Error::doing_it_wrong(
2108
+			__METHOD__,
2109
+			esc_html__(
2110
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2111
+				'event_espresso'
2112
+			),
2113
+			'4.9.17',
2114
+			'5.0.0'
2115
+		);
2116
+		return $this->event()->primary_datetime();
2117
+	}
2118
+
2119
+	/**
2120
+	 * Returns the contact's name (or "Unknown" if there is no contact.)
2121
+	 * @since $VID:$
2122
+	 * @return string
2123
+	 * @throws EE_Error
2124
+	 * @throws InvalidArgumentException
2125
+	 * @throws InvalidDataTypeException
2126
+	 * @throws InvalidInterfaceException
2127
+	 * @throws ReflectionException
2128
+	 */
2129
+	public function name()
2130
+	{
2131
+		return $this->attendeeName();
2132
+	}
2133 2133
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1526 added lines, -1526 removed lines patch added patch discarded remove patch
@@ -14,1530 +14,1530 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    protected static $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    protected static $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        // call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        // if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            // we are going to make sure we ONLY have those subsections to include
111
-            // AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        // ok so we are definitely going to want the forms JS,
132
-        // so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            // ok so they've constructed this object after when they should have.
135
-            // just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if (
262
-            $this->cached_request_data === null
263
-            || (
264
-                $req_data !== null
265
-                && $req_data !== $this->cached_request_data
266
-            )
267
-        ) {
268
-            $req_data = apply_filters(
269
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
270
-                $req_data,
271
-                $this
272
-            );
273
-            if ($req_data === null) {
274
-                $req_data = array_merge($_GET, $_POST);
275
-            }
276
-            $req_data = apply_filters(
277
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
278
-                $req_data,
279
-                $this
280
-            );
281
-            $this->cached_request_data = (array) $req_data;
282
-        }
283
-        return $this->cached_request_data;
284
-    }
285
-
286
-
287
-    /**
288
-     * After the form section is initially created, call this to sanitize the data in the submission
289
-     * which relates to this form section, validate it, and set it as properties on the form.
290
-     *
291
-     * @param array|null $req_data should usually be $_POST (the default).
292
-     *                             However, you CAN supply a different array.
293
-     *                             Consider using set_defaults() instead however.
294
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
295
-     *                             the inputs will have the correct name in the request data for this function
296
-     *                             to find them and populate the form with them.
297
-     *                             If you have a flat form (with only input subsections),
298
-     *                             you can supply a flat array where keys
299
-     *                             are the form input names and values are their values)
300
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
301
-     *                             of course, to validate that data, and set errors on the invalid values.
302
-     *                             But if the data has already been validated
303
-     *                             (eg you validated the data then stored it in the DB)
304
-     *                             you may want to skip this step.
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidInterfaceException
307
-     * @throws InvalidDataTypeException
308
-     * @throws EE_Error
309
-     */
310
-    public function receive_form_submission($req_data = null, $validate = true)
311
-    {
312
-        $req_data = $this->getCachedRequest($req_data);
313
-        $this->_normalize($req_data);
314
-        if ($validate) {
315
-            $this->_validate();
316
-            // if it's invalid, we're going to want to re-display so remember what they submitted
317
-            if (! $this->is_valid()) {
318
-                $this->store_submitted_form_data_in_session();
319
-            }
320
-        }
321
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
322
-            $this->set_submission_error_message();
323
-        }
324
-        do_action(
325
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
326
-            $req_data,
327
-            $this,
328
-            $validate
329
-        );
330
-    }
331
-
332
-
333
-    /**
334
-     * caches the originally submitted input values in the session
335
-     * so that they can be used to repopulate the form if it failed validation
336
-     *
337
-     * @return boolean whether or not the data was successfully stored in the session
338
-     * @throws InvalidArgumentException
339
-     * @throws InvalidInterfaceException
340
-     * @throws InvalidDataTypeException
341
-     * @throws EE_Error
342
-     */
343
-    protected function store_submitted_form_data_in_session()
344
-    {
345
-        return EE_Registry::instance()->SSN->set_session_data(
346
-            array(
347
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
348
-            )
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * retrieves the originally submitted input values in the session
355
-     * so that they can be used to repopulate the form if it failed validation
356
-     *
357
-     * @return array
358
-     * @throws InvalidArgumentException
359
-     * @throws InvalidInterfaceException
360
-     * @throws InvalidDataTypeException
361
-     */
362
-    protected function get_submitted_form_data_from_session()
363
-    {
364
-        $session = EE_Registry::instance()->SSN;
365
-        if ($session instanceof EE_Session) {
366
-            return $session->get_session_data(
367
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
368
-            );
369
-        }
370
-        return array();
371
-    }
372
-
373
-
374
-    /**
375
-     * flushed the originally submitted input values from the session
376
-     *
377
-     * @return boolean whether or not the data was successfully removed from the session
378
-     * @throws InvalidArgumentException
379
-     * @throws InvalidInterfaceException
380
-     * @throws InvalidDataTypeException
381
-     */
382
-    public static function flush_submitted_form_data_from_session()
383
-    {
384
-        return EE_Registry::instance()->SSN->reset_data(
385
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
386
-        );
387
-    }
388
-
389
-
390
-    /**
391
-     * Populates this form and its subsections with data from the session.
392
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
393
-     * validation errors when displaying too)
394
-     * Returns true if the form was populated from the session, false otherwise
395
-     *
396
-     * @return boolean
397
-     * @throws InvalidArgumentException
398
-     * @throws InvalidInterfaceException
399
-     * @throws InvalidDataTypeException
400
-     * @throws EE_Error
401
-     */
402
-    public function populate_from_session()
403
-    {
404
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
405
-        if (empty($form_data_in_session)) {
406
-            return false;
407
-        }
408
-        $this->receive_form_submission($form_data_in_session);
409
-        add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
410
-        if ($this->form_data_present_in($form_data_in_session)) {
411
-            return true;
412
-        }
413
-        return false;
414
-    }
415
-
416
-
417
-    /**
418
-     * Populates the default data for the form, given an array where keys are
419
-     * the input names, and values are their values (preferably normalized to be their
420
-     * proper PHP types, not all strings... although that should be ok too).
421
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
422
-     * the value being an array formatted in teh same way
423
-     *
424
-     * @param array $default_data
425
-     * @throws EE_Error
426
-     */
427
-    public function populate_defaults($default_data)
428
-    {
429
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
430
-            if (isset($default_data[ $subsection_name ])) {
431
-                if ($subsection instanceof EE_Form_Input_Base) {
432
-                    $subsection->set_default($default_data[ $subsection_name ]);
433
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
434
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
435
-                }
436
-            }
437
-        }
438
-    }
439
-
440
-
441
-    /**
442
-     * returns true if subsection exists
443
-     *
444
-     * @param string $name
445
-     * @return boolean
446
-     */
447
-    public function subsection_exists($name)
448
-    {
449
-        return isset($this->_subsections[ $name ]) ? true : false;
450
-    }
451
-
452
-
453
-    /**
454
-     * Gets the subsection specified by its name
455
-     *
456
-     * @param string  $name
457
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
458
-     *                                                      so that the inputs will be properly configured.
459
-     *                                                      However, some client code may be ok
460
-     *                                                      with construction finalize being called later
461
-     *                                                      (realizing that the subsections' html names
462
-     *                                                      might not be set yet, etc.)
463
-     * @return EE_Form_Section_Base
464
-     * @throws EE_Error
465
-     */
466
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
467
-    {
468
-        if ($require_construction_to_be_finalized) {
469
-            $this->ensure_construct_finalized_called();
470
-        }
471
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
472
-    }
473
-
474
-
475
-    /**
476
-     * Gets all the validatable subsections of this form section
477
-     *
478
-     * @return EE_Form_Section_Validatable[]
479
-     * @throws EE_Error
480
-     */
481
-    public function get_validatable_subsections()
482
-    {
483
-        $validatable_subsections = array();
484
-        foreach ($this->subsections() as $name => $obj) {
485
-            if ($obj instanceof EE_Form_Section_Validatable) {
486
-                $validatable_subsections[ $name ] = $obj;
487
-            }
488
-        }
489
-        return $validatable_subsections;
490
-    }
491
-
492
-
493
-    /**
494
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
495
-     * throw an EE_Error.
496
-     *
497
-     * @param string  $name
498
-     * @param boolean $require_construction_to_be_finalized most client code should
499
-     *                                                      leave this as TRUE so that the inputs will be properly
500
-     *                                                      configured. However, some client code may be ok with
501
-     *                                                      construction finalize being called later
502
-     *                                                      (realizing that the subsections' html names might not be
503
-     *                                                      set yet, etc.)
504
-     * @return EE_Form_Input_Base
505
-     * @throws EE_Error
506
-     */
507
-    public function get_input($name, $require_construction_to_be_finalized = true)
508
-    {
509
-        $subsection = $this->get_subsection(
510
-            $name,
511
-            $require_construction_to_be_finalized
512
-        );
513
-        if (! $subsection instanceof EE_Form_Input_Base) {
514
-            throw new EE_Error(
515
-                sprintf(
516
-                    esc_html__(
517
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
518
-                        'event_espresso'
519
-                    ),
520
-                    $name,
521
-                    get_class($this),
522
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
523
-                )
524
-            );
525
-        }
526
-        return $subsection;
527
-    }
528
-
529
-
530
-    /**
531
-     * Like get_input(), gets the proper subsection of the form given the name,
532
-     * otherwise throws an EE_Error
533
-     *
534
-     * @param string  $name
535
-     * @param boolean $require_construction_to_be_finalized most client code should
536
-     *                                                      leave this as TRUE so that the inputs will be properly
537
-     *                                                      configured. However, some client code may be ok with
538
-     *                                                      construction finalize being called later
539
-     *                                                      (realizing that the subsections' html names might not be
540
-     *                                                      set yet, etc.)
541
-     * @return EE_Form_Section_Proper
542
-     * @throws EE_Error
543
-     */
544
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
545
-    {
546
-        $subsection = $this->get_subsection(
547
-            $name,
548
-            $require_construction_to_be_finalized
549
-        );
550
-        if (! $subsection instanceof EE_Form_Section_Proper) {
551
-            throw new EE_Error(
552
-                sprintf(
553
-                    esc_html__(
554
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
555
-                        'event_espresso'
556
-                    ),
557
-                    $name,
558
-                    get_class($this)
559
-                )
560
-            );
561
-        }
562
-        return $subsection;
563
-    }
564
-
565
-
566
-    /**
567
-     * Gets the value of the specified input. Should be called after receive_form_submission()
568
-     * or populate_defaults() on the form, where the normalized value on the input is set.
569
-     *
570
-     * @param string $name
571
-     * @return mixed depending on the input's type and its normalization strategy
572
-     * @throws EE_Error
573
-     */
574
-    public function get_input_value($name)
575
-    {
576
-        $input = $this->get_input($name);
577
-        return $input->normalized_value();
578
-    }
579
-
580
-
581
-    /**
582
-     * Checks if this form section itself is valid, and then checks its subsections
583
-     *
584
-     * @throws EE_Error
585
-     * @return boolean
586
-     */
587
-    public function is_valid()
588
-    {
589
-        if ($this->is_valid === null) {
590
-            if (! $this->has_received_submission()) {
591
-                throw new EE_Error(
592
-                    sprintf(
593
-                        esc_html__(
594
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
595
-                            'event_espresso'
596
-                        )
597
-                    )
598
-                );
599
-            }
600
-            if (! parent::is_valid()) {
601
-                $this->is_valid = false;
602
-            } else {
603
-                // ok so no general errors to this entire form section.
604
-                // so let's check the subsections, but only set errors if that hasn't been done yet
605
-                $this->is_valid = true;
606
-                foreach ($this->get_validatable_subsections() as $subsection) {
607
-                    if (! $subsection->is_valid()) {
608
-                        $this->is_valid = false;
609
-                    }
610
-                }
611
-            }
612
-        }
613
-        return $this->is_valid;
614
-    }
615
-
616
-
617
-    /**
618
-     * gets the default name of this form section if none is specified
619
-     *
620
-     * @return void
621
-     */
622
-    protected function _set_default_name_if_empty()
623
-    {
624
-        if (! $this->_name) {
625
-            $classname    = get_class($this);
626
-            $default_name = str_replace('EE_', '', $classname);
627
-            $this->_name  = $default_name;
628
-        }
629
-    }
630
-
631
-
632
-    /**
633
-     * Returns the HTML for the form, except for the form opening and closing tags
634
-     * (as the form section doesn't know where you necessarily want to send the information to),
635
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
636
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
637
-     * Not doing_it_wrong because theoretically this CAN be used properly,
638
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
639
-     * any CSS.
640
-     *
641
-     * @throws InvalidArgumentException
642
-     * @throws InvalidInterfaceException
643
-     * @throws InvalidDataTypeException
644
-     * @throws EE_Error
645
-     */
646
-    public function get_html_and_js()
647
-    {
648
-        $this->enqueue_js();
649
-        return $this->get_html();
650
-    }
651
-
652
-
653
-    /**
654
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
655
-     *
656
-     * @param bool $display_previously_submitted_data
657
-     * @return string
658
-     * @throws InvalidArgumentException
659
-     * @throws InvalidInterfaceException
660
-     * @throws InvalidDataTypeException
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     * @throws EE_Error
664
-     */
665
-    public function get_html($display_previously_submitted_data = true)
666
-    {
667
-        $this->ensure_construct_finalized_called();
668
-        if ($display_previously_submitted_data) {
669
-            $this->populate_from_session();
670
-        }
671
-        return $this->_form_html_filter
672
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
673
-            : $this->_layout_strategy->layout_form();
674
-    }
675
-
676
-
677
-    /**
678
-     * enqueues JS and CSS for the form.
679
-     * It is preferred to call this before wp_enqueue_scripts so the
680
-     * scripts and styles can be put in the header, but if called later
681
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
682
-     * only be in the header; but in HTML5 its ok in the body.
683
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
684
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
685
-     *
686
-     * @return void
687
-     * @throws EE_Error
688
-     */
689
-    public function enqueue_js()
690
-    {
691
-        $this->_enqueue_and_localize_form_js();
692
-        foreach ($this->subsections() as $subsection) {
693
-            $subsection->enqueue_js();
694
-        }
695
-    }
696
-
697
-
698
-    /**
699
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
700
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
701
-     * the wp_enqueue_scripts hook.
702
-     * However, registering the form js and localizing it can happen when we
703
-     * actually output the form (which is preferred, seeing how teh form's fields
704
-     * could change until it's actually outputted)
705
-     *
706
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
707
-     *                                                    to be triggered automatically or not
708
-     * @return void
709
-     */
710
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
711
-    {
712
-        wp_register_script(
713
-            'ee_form_section_validation',
714
-            EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
715
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
716
-            EVENT_ESPRESSO_VERSION,
717
-            true
718
-        );
719
-        wp_localize_script(
720
-            'ee_form_section_validation',
721
-            'ee_form_section_validation_init',
722
-            array('init' => $init_form_validation_automatically ? '1' : '0')
723
-        );
724
-    }
725
-
726
-
727
-    /**
728
-     * gets the variables used by form_section_validation.js.
729
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
730
-     * but before the wordpress hook wp_loaded
731
-     *
732
-     * @throws EE_Error
733
-     */
734
-    public function _enqueue_and_localize_form_js()
735
-    {
736
-        $this->ensure_construct_finalized_called();
737
-        // actually, we don't want to localize just yet. There may be other forms on the page.
738
-        // so we need to add our form section data to a static variable accessible by all form sections
739
-        // and localize it just before the footer
740
-        $this->localize_validation_rules();
741
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
742
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
743
-    }
744
-
745
-
746
-    /**
747
-     * add our form section data to a static variable accessible by all form sections
748
-     *
749
-     * @param bool $return_for_subsection
750
-     * @return void
751
-     * @throws EE_Error
752
-     */
753
-    public function localize_validation_rules($return_for_subsection = false)
754
-    {
755
-        // we only want to localize vars ONCE for the entire form,
756
-        // so if the form section doesn't have a parent, then it must be the top dog
757
-        if ($return_for_subsection || ! $this->parent_section()) {
758
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
759
-                'form_section_id'  => $this->html_id(true),
760
-                'validation_rules' => $this->get_jquery_validation_rules(),
761
-                'other_data'       => $this->get_other_js_data(),
762
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
763
-            );
764
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
765
-        }
766
-    }
767
-
768
-
769
-    /**
770
-     * Gets an array of extra data that will be useful for client-side javascript.
771
-     * This is primarily data added by inputs and forms in addition to any
772
-     * scripts they might enqueue
773
-     *
774
-     * @param array $form_other_js_data
775
-     * @return array
776
-     * @throws EE_Error
777
-     */
778
-    public function get_other_js_data($form_other_js_data = array())
779
-    {
780
-        foreach ($this->subsections() as $subsection) {
781
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
782
-        }
783
-        return $form_other_js_data;
784
-    }
785
-
786
-
787
-    /**
788
-     * Gets a flat array of inputs for this form section and its subsections.
789
-     * Keys are their form names, and values are the inputs themselves
790
-     *
791
-     * @return EE_Form_Input_Base
792
-     * @throws EE_Error
793
-     */
794
-    public function inputs_in_subsections()
795
-    {
796
-        $inputs = array();
797
-        foreach ($this->subsections() as $subsection) {
798
-            if ($subsection instanceof EE_Form_Input_Base) {
799
-                $inputs[ $subsection->html_name() ] = $subsection;
800
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
801
-                $inputs += $subsection->inputs_in_subsections();
802
-            }
803
-        }
804
-        return $inputs;
805
-    }
806
-
807
-
808
-    /**
809
-     * Gets a flat array of all the validation errors.
810
-     * Keys are html names (because those should be unique)
811
-     * and values are a string of all their validation errors
812
-     *
813
-     * @return string[]
814
-     * @throws EE_Error
815
-     */
816
-    public function subsection_validation_errors_by_html_name()
817
-    {
818
-        $inputs = $this->inputs();
819
-        $errors = array();
820
-        foreach ($inputs as $form_input) {
821
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
822
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
823
-            }
824
-        }
825
-        return $errors;
826
-    }
827
-
828
-
829
-    /**
830
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
831
-     * Should be setup by each form during the _enqueues_and_localize_form_js
832
-     *
833
-     * @throws InvalidArgumentException
834
-     * @throws InvalidInterfaceException
835
-     * @throws InvalidDataTypeException
836
-     */
837
-    public static function localize_script_for_all_forms()
838
-    {
839
-        // allow inputs and stuff to hook in their JS and stuff here
840
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
841
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
842
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
843
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
844
-            : 'wp_default';
845
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
846
-        wp_enqueue_script('ee_form_section_validation');
847
-        wp_localize_script(
848
-            'ee_form_section_validation',
849
-            'ee_form_section_vars',
850
-            EE_Form_Section_Proper::$_js_localization
851
-        );
852
-    }
853
-
854
-
855
-    /**
856
-     * ensure_scripts_localized
857
-     *
858
-     * @throws EE_Error
859
-     */
860
-    public function ensure_scripts_localized()
861
-    {
862
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
863
-            $this->_enqueue_and_localize_form_js();
864
-        }
865
-    }
866
-
867
-
868
-    /**
869
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
870
-     * is that the key here should be the same as the custom validation rule put in the JS file
871
-     *
872
-     * @return array keys are custom validation rules, and values are internationalized strings
873
-     */
874
-    private static function _get_localized_error_messages()
875
-    {
876
-        return array(
877
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
878
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
879
-        );
880
-    }
881
-
882
-
883
-    /**
884
-     * @return array
885
-     */
886
-    public static function js_localization()
887
-    {
888
-        return self::$_js_localization;
889
-    }
890
-
891
-
892
-    /**
893
-     * @return void
894
-     */
895
-    public static function reset_js_localization()
896
-    {
897
-        self::$_js_localization = array();
898
-    }
899
-
900
-
901
-    /**
902
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
903
-     * See parent function for more...
904
-     *
905
-     * @return array
906
-     * @throws EE_Error
907
-     */
908
-    public function get_jquery_validation_rules()
909
-    {
910
-        $jquery_validation_rules = array();
911
-        foreach ($this->get_validatable_subsections() as $subsection) {
912
-            $jquery_validation_rules = array_merge(
913
-                $jquery_validation_rules,
914
-                $subsection->get_jquery_validation_rules()
915
-            );
916
-        }
917
-        return $jquery_validation_rules;
918
-    }
919
-
920
-
921
-    /**
922
-     * Sanitizes all the data and sets the sanitized value of each field
923
-     *
924
-     * @param array $req_data like $_POST
925
-     * @return void
926
-     * @throws EE_Error
927
-     */
928
-    protected function _normalize($req_data)
929
-    {
930
-        $this->_received_submission = true;
931
-        $this->_validation_errors   = array();
932
-        foreach ($this->get_validatable_subsections() as $subsection) {
933
-            try {
934
-                $subsection->_normalize($req_data);
935
-            } catch (EE_Validation_Error $e) {
936
-                $subsection->add_validation_error($e);
937
-            }
938
-        }
939
-    }
940
-
941
-
942
-    /**
943
-     * Performs validation on this form section and its subsections.
944
-     * For each subsection,
945
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
946
-     * and passes it the subsection, then calls _validate on that subsection.
947
-     * If you need to perform validation on the form as a whole (considering multiple)
948
-     * you would be best to override this _validate method,
949
-     * calling parent::_validate() first.
950
-     *
951
-     * @throws EE_Error
952
-     */
953
-    protected function _validate()
954
-    {
955
-        // reset the cache of whether this form is valid or not- we're re-validating it now
956
-        $this->is_valid = null;
957
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
958
-            if (method_exists($this, '_validate_' . $subsection_name)) {
959
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
960
-            }
961
-            $subsection->_validate();
962
-        }
963
-    }
964
-
965
-
966
-    /**
967
-     * Gets all the validated inputs for the form section
968
-     *
969
-     * @return array
970
-     * @throws EE_Error
971
-     */
972
-    public function valid_data()
973
-    {
974
-        $inputs = array();
975
-        foreach ($this->subsections() as $subsection_name => $subsection) {
976
-            if ($subsection instanceof EE_Form_Section_Proper) {
977
-                $inputs[ $subsection_name ] = $subsection->valid_data();
978
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
979
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
980
-            }
981
-        }
982
-        return $inputs;
983
-    }
984
-
985
-
986
-    /**
987
-     * Gets all the inputs on this form section
988
-     *
989
-     * @return EE_Form_Input_Base[]
990
-     * @throws EE_Error
991
-     */
992
-    public function inputs()
993
-    {
994
-        $inputs = array();
995
-        foreach ($this->subsections() as $subsection_name => $subsection) {
996
-            if ($subsection instanceof EE_Form_Input_Base) {
997
-                $inputs[ $subsection_name ] = $subsection;
998
-            }
999
-        }
1000
-        return $inputs;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * Gets all the subsections which are a proper form
1006
-     *
1007
-     * @return EE_Form_Section_Proper[]
1008
-     * @throws EE_Error
1009
-     */
1010
-    public function subforms()
1011
-    {
1012
-        $form_sections = array();
1013
-        foreach ($this->subsections() as $name => $obj) {
1014
-            if ($obj instanceof EE_Form_Section_Proper) {
1015
-                $form_sections[ $name ] = $obj;
1016
-            }
1017
-        }
1018
-        return $form_sections;
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1024
-     * Consider using inputs() or subforms()
1025
-     * if you only want form inputs or proper form sections.
1026
-     *
1027
-     * @param boolean $require_construction_to_be_finalized most client code should
1028
-     *                                                      leave this as TRUE so that the inputs will be properly
1029
-     *                                                      configured. However, some client code may be ok with
1030
-     *                                                      construction finalize being called later
1031
-     *                                                      (realizing that the subsections' html names might not be
1032
-     *                                                      set yet, etc.)
1033
-     * @return EE_Form_Section_Proper[]
1034
-     * @throws EE_Error
1035
-     */
1036
-    public function subsections($require_construction_to_be_finalized = true)
1037
-    {
1038
-        if ($require_construction_to_be_finalized) {
1039
-            $this->ensure_construct_finalized_called();
1040
-        }
1041
-        return $this->_subsections;
1042
-    }
1043
-
1044
-
1045
-    /**
1046
-     * Returns whether this form has any subforms or inputs
1047
-     * @return bool
1048
-     */
1049
-    public function hasSubsections()
1050
-    {
1051
-        return ! empty($this->_subsections);
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * Returns a simple array where keys are input names, and values are their normalized
1057
-     * values. (Similar to calling get_input_value on inputs)
1058
-     *
1059
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1060
-     *                                        or just this forms' direct children inputs
1061
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1062
-     *                                        or allow multidimensional array
1063
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1064
-     *                                        with array keys being input names
1065
-     *                                        (regardless of whether they are from a subsection or not),
1066
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1067
-     *                                        where keys are always subsection names and values are either
1068
-     *                                        the input's normalized value, or an array like the top-level array
1069
-     * @throws EE_Error
1070
-     */
1071
-    public function input_values($include_subform_inputs = false, $flatten = false)
1072
-    {
1073
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1074
-    }
1075
-
1076
-
1077
-    /**
1078
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1079
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1080
-     * is not necessarily the value we want to display to users. This creates an array
1081
-     * where keys are the input names, and values are their display values
1082
-     *
1083
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1084
-     *                                        or just this forms' direct children inputs
1085
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1086
-     *                                        or allow multidimensional array
1087
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1088
-     *                                        with array keys being input names
1089
-     *                                        (regardless of whether they are from a subsection or not),
1090
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1091
-     *                                        where keys are always subsection names and values are either
1092
-     *                                        the input's normalized value, or an array like the top-level array
1093
-     * @throws EE_Error
1094
-     */
1095
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1096
-    {
1097
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Gets the input values from the form
1103
-     *
1104
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1105
-     *                                        or just the normalized value
1106
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1107
-     *                                        or just this forms' direct children inputs
1108
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1109
-     *                                        or allow multidimensional array
1110
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1111
-     *                                        input names (regardless of whether they are from a subsection or not),
1112
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1113
-     *                                        where keys are always subsection names and values are either
1114
-     *                                        the input's normalized value, or an array like the top-level array
1115
-     * @throws EE_Error
1116
-     */
1117
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1118
-    {
1119
-        $input_values = array();
1120
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1121
-            if ($subsection instanceof EE_Form_Input_Base) {
1122
-                $input_values[ $subsection_name ] = $pretty
1123
-                    ? $subsection->pretty_value()
1124
-                    : $subsection->normalized_value();
1125
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1126
-                $subform_input_values = $subsection->_input_values(
1127
-                    $pretty,
1128
-                    $include_subform_inputs,
1129
-                    $flatten
1130
-                );
1131
-                if ($flatten) {
1132
-                    $input_values = array_merge($input_values, $subform_input_values);
1133
-                } else {
1134
-                    $input_values[ $subsection_name ] = $subform_input_values;
1135
-                }
1136
-            }
1137
-        }
1138
-        return $input_values;
1139
-    }
1140
-
1141
-
1142
-    /**
1143
-     * Gets the originally submitted input values from the form
1144
-     *
1145
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1146
-     *                                   or just this forms' direct children inputs
1147
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1148
-     *                                   with array keys being input names
1149
-     *                                   (regardless of whether they are from a subsection or not),
1150
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1151
-     *                                   where keys are always subsection names and values are either
1152
-     *                                   the input's normalized value, or an array like the top-level array
1153
-     * @throws EE_Error
1154
-     */
1155
-    public function submitted_values($include_subforms = false)
1156
-    {
1157
-        $submitted_values = array();
1158
-        foreach ($this->subsections() as $subsection) {
1159
-            if ($subsection instanceof EE_Form_Input_Base) {
1160
-                // is this input part of an array of inputs?
1161
-                if (strpos($subsection->html_name(), '[') !== false) {
1162
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1163
-                        explode(
1164
-                            '[',
1165
-                            str_replace(']', '', $subsection->html_name())
1166
-                        ),
1167
-                        $subsection->raw_value()
1168
-                    );
1169
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1170
-                } else {
1171
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1172
-                }
1173
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1174
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1175
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1176
-            }
1177
-        }
1178
-        return $submitted_values;
1179
-    }
1180
-
1181
-
1182
-    /**
1183
-     * Indicates whether or not this form has received a submission yet
1184
-     * (ie, had receive_form_submission called on it yet)
1185
-     *
1186
-     * @return boolean
1187
-     * @throws EE_Error
1188
-     */
1189
-    public function has_received_submission()
1190
-    {
1191
-        $this->ensure_construct_finalized_called();
1192
-        return $this->_received_submission;
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * Equivalent to passing 'exclude' in the constructor's options array.
1198
-     * Removes the listed inputs from the form
1199
-     *
1200
-     * @param array $inputs_to_exclude values are the input names
1201
-     * @return void
1202
-     */
1203
-    public function exclude(array $inputs_to_exclude = array())
1204
-    {
1205
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1206
-            unset($this->_subsections[ $input_to_exclude_name ]);
1207
-        }
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1213
-     * @param array $inputs_to_hide
1214
-     * @throws EE_Error
1215
-     */
1216
-    public function hide(array $inputs_to_hide = array())
1217
-    {
1218
-        foreach ($inputs_to_hide as $input_to_hide) {
1219
-            $input = $this->get_input($input_to_hide);
1220
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1221
-        }
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * add_subsections
1227
-     * Adds the listed subsections to the form section.
1228
-     * If $subsection_name_to_target is provided,
1229
-     * then new subsections are added before or after that subsection,
1230
-     * otherwise to the start or end of the entire subsections array.
1231
-     *
1232
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1233
-     *                                                          where keys are their names
1234
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1235
-     *                                                          should be added before or after
1236
-     *                                                          IF $subsection_name_to_target is null,
1237
-     *                                                          then $new_subsections will be added to
1238
-     *                                                          the beginning or end of the entire subsections array
1239
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1240
-     *                                                          $subsection_name_to_target,
1241
-     *                                                          or if $subsection_name_to_target is null,
1242
-     *                                                          before or after entire subsections array
1243
-     * @return void
1244
-     * @throws EE_Error
1245
-     */
1246
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1247
-    {
1248
-        foreach ($new_subsections as $subsection_name => $subsection) {
1249
-            if (! $subsection instanceof EE_Form_Section_Base) {
1250
-                EE_Error::add_error(
1251
-                    sprintf(
1252
-                        esc_html__(
1253
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1254
-                            'event_espresso'
1255
-                        ),
1256
-                        get_class($subsection),
1257
-                        $subsection_name,
1258
-                        $this->name()
1259
-                    )
1260
-                );
1261
-                unset($new_subsections[ $subsection_name ]);
1262
-            }
1263
-        }
1264
-        $this->_subsections = EEH_Array::insert_into_array(
1265
-            $this->_subsections,
1266
-            $new_subsections,
1267
-            $subsection_name_to_target,
1268
-            $add_before
1269
-        );
1270
-        if ($this->_construction_finalized) {
1271
-            foreach ($this->_subsections as $name => $subsection) {
1272
-                $subsection->_construct_finalize($this, $name);
1273
-            }
1274
-        }
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * @param string $subsection_name
1280
-     * @param bool   $recursive
1281
-     * @return bool
1282
-     */
1283
-    public function has_subsection($subsection_name, $recursive = false)
1284
-    {
1285
-        foreach ($this->_subsections as $name => $subsection) {
1286
-            if (
1287
-                $name === $subsection_name
1288
-                || (
1289
-                    $recursive
1290
-                    && $subsection instanceof EE_Form_Section_Proper
1291
-                    && $subsection->has_subsection($subsection_name, $recursive)
1292
-                )
1293
-            ) {
1294
-                return true;
1295
-            }
1296
-        }
1297
-        return false;
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * Just gets all validatable subsections to clean their sensitive data
1304
-     *
1305
-     * @throws EE_Error
1306
-     */
1307
-    public function clean_sensitive_data()
1308
-    {
1309
-        foreach ($this->get_validatable_subsections() as $subsection) {
1310
-            $subsection->clean_sensitive_data();
1311
-        }
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1317
-     * @param string                           $form_submission_error_message
1318
-     * @param EE_Form_Section_Validatable $form_section unused
1319
-     * @throws EE_Error
1320
-     */
1321
-    public function set_submission_error_message(
1322
-        $form_submission_error_message = ''
1323
-    ) {
1324
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1325
-            ? $form_submission_error_message
1326
-            : $this->getAllValidationErrorsString();
1327
-    }
1328
-
1329
-
1330
-    /**
1331
-     * Returns the cached error message. A default value is set for this during _validate(),
1332
-     * (called during receive_form_submission) but it can be explicitly set using
1333
-     * set_submission_error_message
1334
-     *
1335
-     * @return string
1336
-     */
1337
-    public function submission_error_message()
1338
-    {
1339
-        return $this->_form_submission_error_message;
1340
-    }
1341
-
1342
-
1343
-    /**
1344
-     * Sets a message to display if the data submitted to the form was valid.
1345
-     * @param string $form_submission_success_message
1346
-     */
1347
-    public function set_submission_success_message($form_submission_success_message = '')
1348
-    {
1349
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1350
-            ? $form_submission_success_message
1351
-            : esc_html__('Form submitted successfully', 'event_espresso');
1352
-    }
1353
-
1354
-
1355
-    /**
1356
-     * Gets a message appropriate for display when the form is correctly submitted
1357
-     * @return string
1358
-     */
1359
-    public function submission_success_message()
1360
-    {
1361
-        return $this->_form_submission_success_message;
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     * Returns the prefix that should be used on child of this form section for
1367
-     * their html names. If this form section itself has a parent, prepends ITS
1368
-     * prefix onto this form section's prefix. Used primarily by
1369
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1370
-     *
1371
-     * @return string
1372
-     * @throws EE_Error
1373
-     */
1374
-    public function html_name_prefix()
1375
-    {
1376
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1377
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1378
-        }
1379
-        return $this->name();
1380
-    }
1381
-
1382
-
1383
-    /**
1384
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1385
-     * calls it (assumes there is no parent and that we want the name to be whatever
1386
-     * was set, which is probably nothing, or the classname)
1387
-     *
1388
-     * @return string
1389
-     * @throws EE_Error
1390
-     */
1391
-    public function name()
1392
-    {
1393
-        $this->ensure_construct_finalized_called();
1394
-        return parent::name();
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     * @return EE_Form_Section_Proper
1400
-     * @throws EE_Error
1401
-     */
1402
-    public function parent_section()
1403
-    {
1404
-        $this->ensure_construct_finalized_called();
1405
-        return parent::parent_section();
1406
-    }
1407
-
1408
-
1409
-    /**
1410
-     * make sure construction finalized was called, otherwise children might not be ready
1411
-     *
1412
-     * @return void
1413
-     * @throws EE_Error
1414
-     */
1415
-    public function ensure_construct_finalized_called()
1416
-    {
1417
-        if (! $this->_construction_finalized) {
1418
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1419
-        }
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1425
-     * are in teh form data. If any are found, returns true. Else false
1426
-     *
1427
-     * @param array $req_data
1428
-     * @return boolean
1429
-     * @throws EE_Error
1430
-     */
1431
-    public function form_data_present_in($req_data = null)
1432
-    {
1433
-        $req_data = $this->getCachedRequest($req_data);
1434
-        foreach ($this->subsections() as $subsection) {
1435
-            if ($subsection instanceof EE_Form_Input_Base) {
1436
-                if ($subsection->form_data_present_in($req_data)) {
1437
-                    return true;
1438
-                }
1439
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1440
-                if ($subsection->form_data_present_in($req_data)) {
1441
-                    return true;
1442
-                }
1443
-            }
1444
-        }
1445
-        return false;
1446
-    }
1447
-
1448
-
1449
-    /**
1450
-     * Gets validation errors for this form section and subsections
1451
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1452
-     * gets the validation errors for ALL subsection
1453
-     *
1454
-     * @return EE_Validation_Error[]
1455
-     * @throws EE_Error
1456
-     */
1457
-    public function get_validation_errors_accumulated()
1458
-    {
1459
-        $validation_errors = $this->get_validation_errors();
1460
-        foreach ($this->get_validatable_subsections() as $subsection) {
1461
-            if ($subsection instanceof EE_Form_Section_Proper) {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1463
-            } else {
1464
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1465
-            }
1466
-            if ($validation_errors_on_this_subsection) {
1467
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1468
-            }
1469
-        }
1470
-        return $validation_errors;
1471
-    }
1472
-
1473
-    /**
1474
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1475
-     * This traverses the form section tree to generate this, but you probably want to instead use
1476
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1477
-     *
1478
-     * @return string
1479
-     * @since 4.9.59.p
1480
-     */
1481
-    protected function getAllValidationErrorsString()
1482
-    {
1483
-        $submission_error_messages = array();
1484
-        // bad, bad, bad registrant
1485
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1486
-            if ($validation_error instanceof EE_Validation_Error) {
1487
-                $form_section = $validation_error->get_form_section();
1488
-                if ($form_section instanceof EE_Form_Input_Base) {
1489
-                    $label = $validation_error->get_form_section()->html_label_text();
1490
-                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1491
-                    $label = $validation_error->get_form_section()->name();
1492
-                } else {
1493
-                    $label = esc_html__('Unknown', 'event_espresso');
1494
-                }
1495
-                $submission_error_messages[] = sprintf(
1496
-                    __('%s : %s', 'event_espresso'),
1497
-                    $label,
1498
-                    $validation_error->getMessage()
1499
-                );
1500
-            }
1501
-        }
1502
-        return implode('<br>', $submission_error_messages);
1503
-    }
1504
-
1505
-
1506
-    /**
1507
-     * This isn't just the name of an input, it's a path pointing to an input. The
1508
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1509
-     * dot-dot-slash (../) means to ascend into the parent section.
1510
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1511
-     * which will be returned.
1512
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1513
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1514
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1515
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1516
-     * Etc
1517
-     *
1518
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1519
-     * @return EE_Form_Section_Base
1520
-     * @throws EE_Error
1521
-     */
1522
-    public function find_section_from_path($form_section_path)
1523
-    {
1524
-        // check if we can find the input from purely going straight up the tree
1525
-        $input = parent::find_section_from_path($form_section_path);
1526
-        if ($input instanceof EE_Form_Section_Base) {
1527
-            return $input;
1528
-        }
1529
-        $next_slash_pos = strpos($form_section_path, '/');
1530
-        if ($next_slash_pos !== false) {
1531
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1532
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1533
-        } else {
1534
-            $child_section_name = $form_section_path;
1535
-            $subpath            = '';
1536
-        }
1537
-        $child_section = $this->get_subsection($child_section_name);
1538
-        if ($child_section instanceof EE_Form_Section_Base) {
1539
-            return $child_section->find_section_from_path($subpath);
1540
-        }
1541
-        return null;
1542
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	protected static $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	protected static $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		// call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		// if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			// we are going to make sure we ONLY have those subsections to include
111
+			// AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		// ok so we are definitely going to want the forms JS,
132
+		// so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			// ok so they've constructed this object after when they should have.
135
+			// just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if (
262
+			$this->cached_request_data === null
263
+			|| (
264
+				$req_data !== null
265
+				&& $req_data !== $this->cached_request_data
266
+			)
267
+		) {
268
+			$req_data = apply_filters(
269
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
270
+				$req_data,
271
+				$this
272
+			);
273
+			if ($req_data === null) {
274
+				$req_data = array_merge($_GET, $_POST);
275
+			}
276
+			$req_data = apply_filters(
277
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
278
+				$req_data,
279
+				$this
280
+			);
281
+			$this->cached_request_data = (array) $req_data;
282
+		}
283
+		return $this->cached_request_data;
284
+	}
285
+
286
+
287
+	/**
288
+	 * After the form section is initially created, call this to sanitize the data in the submission
289
+	 * which relates to this form section, validate it, and set it as properties on the form.
290
+	 *
291
+	 * @param array|null $req_data should usually be $_POST (the default).
292
+	 *                             However, you CAN supply a different array.
293
+	 *                             Consider using set_defaults() instead however.
294
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
295
+	 *                             the inputs will have the correct name in the request data for this function
296
+	 *                             to find them and populate the form with them.
297
+	 *                             If you have a flat form (with only input subsections),
298
+	 *                             you can supply a flat array where keys
299
+	 *                             are the form input names and values are their values)
300
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
301
+	 *                             of course, to validate that data, and set errors on the invalid values.
302
+	 *                             But if the data has already been validated
303
+	 *                             (eg you validated the data then stored it in the DB)
304
+	 *                             you may want to skip this step.
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidInterfaceException
307
+	 * @throws InvalidDataTypeException
308
+	 * @throws EE_Error
309
+	 */
310
+	public function receive_form_submission($req_data = null, $validate = true)
311
+	{
312
+		$req_data = $this->getCachedRequest($req_data);
313
+		$this->_normalize($req_data);
314
+		if ($validate) {
315
+			$this->_validate();
316
+			// if it's invalid, we're going to want to re-display so remember what they submitted
317
+			if (! $this->is_valid()) {
318
+				$this->store_submitted_form_data_in_session();
319
+			}
320
+		}
321
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
322
+			$this->set_submission_error_message();
323
+		}
324
+		do_action(
325
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
326
+			$req_data,
327
+			$this,
328
+			$validate
329
+		);
330
+	}
331
+
332
+
333
+	/**
334
+	 * caches the originally submitted input values in the session
335
+	 * so that they can be used to repopulate the form if it failed validation
336
+	 *
337
+	 * @return boolean whether or not the data was successfully stored in the session
338
+	 * @throws InvalidArgumentException
339
+	 * @throws InvalidInterfaceException
340
+	 * @throws InvalidDataTypeException
341
+	 * @throws EE_Error
342
+	 */
343
+	protected function store_submitted_form_data_in_session()
344
+	{
345
+		return EE_Registry::instance()->SSN->set_session_data(
346
+			array(
347
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
348
+			)
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * retrieves the originally submitted input values in the session
355
+	 * so that they can be used to repopulate the form if it failed validation
356
+	 *
357
+	 * @return array
358
+	 * @throws InvalidArgumentException
359
+	 * @throws InvalidInterfaceException
360
+	 * @throws InvalidDataTypeException
361
+	 */
362
+	protected function get_submitted_form_data_from_session()
363
+	{
364
+		$session = EE_Registry::instance()->SSN;
365
+		if ($session instanceof EE_Session) {
366
+			return $session->get_session_data(
367
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
368
+			);
369
+		}
370
+		return array();
371
+	}
372
+
373
+
374
+	/**
375
+	 * flushed the originally submitted input values from the session
376
+	 *
377
+	 * @return boolean whether or not the data was successfully removed from the session
378
+	 * @throws InvalidArgumentException
379
+	 * @throws InvalidInterfaceException
380
+	 * @throws InvalidDataTypeException
381
+	 */
382
+	public static function flush_submitted_form_data_from_session()
383
+	{
384
+		return EE_Registry::instance()->SSN->reset_data(
385
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
386
+		);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Populates this form and its subsections with data from the session.
392
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
393
+	 * validation errors when displaying too)
394
+	 * Returns true if the form was populated from the session, false otherwise
395
+	 *
396
+	 * @return boolean
397
+	 * @throws InvalidArgumentException
398
+	 * @throws InvalidInterfaceException
399
+	 * @throws InvalidDataTypeException
400
+	 * @throws EE_Error
401
+	 */
402
+	public function populate_from_session()
403
+	{
404
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
405
+		if (empty($form_data_in_session)) {
406
+			return false;
407
+		}
408
+		$this->receive_form_submission($form_data_in_session);
409
+		add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
410
+		if ($this->form_data_present_in($form_data_in_session)) {
411
+			return true;
412
+		}
413
+		return false;
414
+	}
415
+
416
+
417
+	/**
418
+	 * Populates the default data for the form, given an array where keys are
419
+	 * the input names, and values are their values (preferably normalized to be their
420
+	 * proper PHP types, not all strings... although that should be ok too).
421
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
422
+	 * the value being an array formatted in teh same way
423
+	 *
424
+	 * @param array $default_data
425
+	 * @throws EE_Error
426
+	 */
427
+	public function populate_defaults($default_data)
428
+	{
429
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
430
+			if (isset($default_data[ $subsection_name ])) {
431
+				if ($subsection instanceof EE_Form_Input_Base) {
432
+					$subsection->set_default($default_data[ $subsection_name ]);
433
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
434
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
435
+				}
436
+			}
437
+		}
438
+	}
439
+
440
+
441
+	/**
442
+	 * returns true if subsection exists
443
+	 *
444
+	 * @param string $name
445
+	 * @return boolean
446
+	 */
447
+	public function subsection_exists($name)
448
+	{
449
+		return isset($this->_subsections[ $name ]) ? true : false;
450
+	}
451
+
452
+
453
+	/**
454
+	 * Gets the subsection specified by its name
455
+	 *
456
+	 * @param string  $name
457
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
458
+	 *                                                      so that the inputs will be properly configured.
459
+	 *                                                      However, some client code may be ok
460
+	 *                                                      with construction finalize being called later
461
+	 *                                                      (realizing that the subsections' html names
462
+	 *                                                      might not be set yet, etc.)
463
+	 * @return EE_Form_Section_Base
464
+	 * @throws EE_Error
465
+	 */
466
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
467
+	{
468
+		if ($require_construction_to_be_finalized) {
469
+			$this->ensure_construct_finalized_called();
470
+		}
471
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
472
+	}
473
+
474
+
475
+	/**
476
+	 * Gets all the validatable subsections of this form section
477
+	 *
478
+	 * @return EE_Form_Section_Validatable[]
479
+	 * @throws EE_Error
480
+	 */
481
+	public function get_validatable_subsections()
482
+	{
483
+		$validatable_subsections = array();
484
+		foreach ($this->subsections() as $name => $obj) {
485
+			if ($obj instanceof EE_Form_Section_Validatable) {
486
+				$validatable_subsections[ $name ] = $obj;
487
+			}
488
+		}
489
+		return $validatable_subsections;
490
+	}
491
+
492
+
493
+	/**
494
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
495
+	 * throw an EE_Error.
496
+	 *
497
+	 * @param string  $name
498
+	 * @param boolean $require_construction_to_be_finalized most client code should
499
+	 *                                                      leave this as TRUE so that the inputs will be properly
500
+	 *                                                      configured. However, some client code may be ok with
501
+	 *                                                      construction finalize being called later
502
+	 *                                                      (realizing that the subsections' html names might not be
503
+	 *                                                      set yet, etc.)
504
+	 * @return EE_Form_Input_Base
505
+	 * @throws EE_Error
506
+	 */
507
+	public function get_input($name, $require_construction_to_be_finalized = true)
508
+	{
509
+		$subsection = $this->get_subsection(
510
+			$name,
511
+			$require_construction_to_be_finalized
512
+		);
513
+		if (! $subsection instanceof EE_Form_Input_Base) {
514
+			throw new EE_Error(
515
+				sprintf(
516
+					esc_html__(
517
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
518
+						'event_espresso'
519
+					),
520
+					$name,
521
+					get_class($this),
522
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
523
+				)
524
+			);
525
+		}
526
+		return $subsection;
527
+	}
528
+
529
+
530
+	/**
531
+	 * Like get_input(), gets the proper subsection of the form given the name,
532
+	 * otherwise throws an EE_Error
533
+	 *
534
+	 * @param string  $name
535
+	 * @param boolean $require_construction_to_be_finalized most client code should
536
+	 *                                                      leave this as TRUE so that the inputs will be properly
537
+	 *                                                      configured. However, some client code may be ok with
538
+	 *                                                      construction finalize being called later
539
+	 *                                                      (realizing that the subsections' html names might not be
540
+	 *                                                      set yet, etc.)
541
+	 * @return EE_Form_Section_Proper
542
+	 * @throws EE_Error
543
+	 */
544
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
545
+	{
546
+		$subsection = $this->get_subsection(
547
+			$name,
548
+			$require_construction_to_be_finalized
549
+		);
550
+		if (! $subsection instanceof EE_Form_Section_Proper) {
551
+			throw new EE_Error(
552
+				sprintf(
553
+					esc_html__(
554
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
555
+						'event_espresso'
556
+					),
557
+					$name,
558
+					get_class($this)
559
+				)
560
+			);
561
+		}
562
+		return $subsection;
563
+	}
564
+
565
+
566
+	/**
567
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
568
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
569
+	 *
570
+	 * @param string $name
571
+	 * @return mixed depending on the input's type and its normalization strategy
572
+	 * @throws EE_Error
573
+	 */
574
+	public function get_input_value($name)
575
+	{
576
+		$input = $this->get_input($name);
577
+		return $input->normalized_value();
578
+	}
579
+
580
+
581
+	/**
582
+	 * Checks if this form section itself is valid, and then checks its subsections
583
+	 *
584
+	 * @throws EE_Error
585
+	 * @return boolean
586
+	 */
587
+	public function is_valid()
588
+	{
589
+		if ($this->is_valid === null) {
590
+			if (! $this->has_received_submission()) {
591
+				throw new EE_Error(
592
+					sprintf(
593
+						esc_html__(
594
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
595
+							'event_espresso'
596
+						)
597
+					)
598
+				);
599
+			}
600
+			if (! parent::is_valid()) {
601
+				$this->is_valid = false;
602
+			} else {
603
+				// ok so no general errors to this entire form section.
604
+				// so let's check the subsections, but only set errors if that hasn't been done yet
605
+				$this->is_valid = true;
606
+				foreach ($this->get_validatable_subsections() as $subsection) {
607
+					if (! $subsection->is_valid()) {
608
+						$this->is_valid = false;
609
+					}
610
+				}
611
+			}
612
+		}
613
+		return $this->is_valid;
614
+	}
615
+
616
+
617
+	/**
618
+	 * gets the default name of this form section if none is specified
619
+	 *
620
+	 * @return void
621
+	 */
622
+	protected function _set_default_name_if_empty()
623
+	{
624
+		if (! $this->_name) {
625
+			$classname    = get_class($this);
626
+			$default_name = str_replace('EE_', '', $classname);
627
+			$this->_name  = $default_name;
628
+		}
629
+	}
630
+
631
+
632
+	/**
633
+	 * Returns the HTML for the form, except for the form opening and closing tags
634
+	 * (as the form section doesn't know where you necessarily want to send the information to),
635
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
636
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
637
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
638
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
639
+	 * any CSS.
640
+	 *
641
+	 * @throws InvalidArgumentException
642
+	 * @throws InvalidInterfaceException
643
+	 * @throws InvalidDataTypeException
644
+	 * @throws EE_Error
645
+	 */
646
+	public function get_html_and_js()
647
+	{
648
+		$this->enqueue_js();
649
+		return $this->get_html();
650
+	}
651
+
652
+
653
+	/**
654
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
655
+	 *
656
+	 * @param bool $display_previously_submitted_data
657
+	 * @return string
658
+	 * @throws InvalidArgumentException
659
+	 * @throws InvalidInterfaceException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 * @throws EE_Error
664
+	 */
665
+	public function get_html($display_previously_submitted_data = true)
666
+	{
667
+		$this->ensure_construct_finalized_called();
668
+		if ($display_previously_submitted_data) {
669
+			$this->populate_from_session();
670
+		}
671
+		return $this->_form_html_filter
672
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
673
+			: $this->_layout_strategy->layout_form();
674
+	}
675
+
676
+
677
+	/**
678
+	 * enqueues JS and CSS for the form.
679
+	 * It is preferred to call this before wp_enqueue_scripts so the
680
+	 * scripts and styles can be put in the header, but if called later
681
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
682
+	 * only be in the header; but in HTML5 its ok in the body.
683
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
684
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
685
+	 *
686
+	 * @return void
687
+	 * @throws EE_Error
688
+	 */
689
+	public function enqueue_js()
690
+	{
691
+		$this->_enqueue_and_localize_form_js();
692
+		foreach ($this->subsections() as $subsection) {
693
+			$subsection->enqueue_js();
694
+		}
695
+	}
696
+
697
+
698
+	/**
699
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
700
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
701
+	 * the wp_enqueue_scripts hook.
702
+	 * However, registering the form js and localizing it can happen when we
703
+	 * actually output the form (which is preferred, seeing how teh form's fields
704
+	 * could change until it's actually outputted)
705
+	 *
706
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
707
+	 *                                                    to be triggered automatically or not
708
+	 * @return void
709
+	 */
710
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
711
+	{
712
+		wp_register_script(
713
+			'ee_form_section_validation',
714
+			EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
715
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
716
+			EVENT_ESPRESSO_VERSION,
717
+			true
718
+		);
719
+		wp_localize_script(
720
+			'ee_form_section_validation',
721
+			'ee_form_section_validation_init',
722
+			array('init' => $init_form_validation_automatically ? '1' : '0')
723
+		);
724
+	}
725
+
726
+
727
+	/**
728
+	 * gets the variables used by form_section_validation.js.
729
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
730
+	 * but before the wordpress hook wp_loaded
731
+	 *
732
+	 * @throws EE_Error
733
+	 */
734
+	public function _enqueue_and_localize_form_js()
735
+	{
736
+		$this->ensure_construct_finalized_called();
737
+		// actually, we don't want to localize just yet. There may be other forms on the page.
738
+		// so we need to add our form section data to a static variable accessible by all form sections
739
+		// and localize it just before the footer
740
+		$this->localize_validation_rules();
741
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
742
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
743
+	}
744
+
745
+
746
+	/**
747
+	 * add our form section data to a static variable accessible by all form sections
748
+	 *
749
+	 * @param bool $return_for_subsection
750
+	 * @return void
751
+	 * @throws EE_Error
752
+	 */
753
+	public function localize_validation_rules($return_for_subsection = false)
754
+	{
755
+		// we only want to localize vars ONCE for the entire form,
756
+		// so if the form section doesn't have a parent, then it must be the top dog
757
+		if ($return_for_subsection || ! $this->parent_section()) {
758
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
759
+				'form_section_id'  => $this->html_id(true),
760
+				'validation_rules' => $this->get_jquery_validation_rules(),
761
+				'other_data'       => $this->get_other_js_data(),
762
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
763
+			);
764
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
765
+		}
766
+	}
767
+
768
+
769
+	/**
770
+	 * Gets an array of extra data that will be useful for client-side javascript.
771
+	 * This is primarily data added by inputs and forms in addition to any
772
+	 * scripts they might enqueue
773
+	 *
774
+	 * @param array $form_other_js_data
775
+	 * @return array
776
+	 * @throws EE_Error
777
+	 */
778
+	public function get_other_js_data($form_other_js_data = array())
779
+	{
780
+		foreach ($this->subsections() as $subsection) {
781
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
782
+		}
783
+		return $form_other_js_data;
784
+	}
785
+
786
+
787
+	/**
788
+	 * Gets a flat array of inputs for this form section and its subsections.
789
+	 * Keys are their form names, and values are the inputs themselves
790
+	 *
791
+	 * @return EE_Form_Input_Base
792
+	 * @throws EE_Error
793
+	 */
794
+	public function inputs_in_subsections()
795
+	{
796
+		$inputs = array();
797
+		foreach ($this->subsections() as $subsection) {
798
+			if ($subsection instanceof EE_Form_Input_Base) {
799
+				$inputs[ $subsection->html_name() ] = $subsection;
800
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
801
+				$inputs += $subsection->inputs_in_subsections();
802
+			}
803
+		}
804
+		return $inputs;
805
+	}
806
+
807
+
808
+	/**
809
+	 * Gets a flat array of all the validation errors.
810
+	 * Keys are html names (because those should be unique)
811
+	 * and values are a string of all their validation errors
812
+	 *
813
+	 * @return string[]
814
+	 * @throws EE_Error
815
+	 */
816
+	public function subsection_validation_errors_by_html_name()
817
+	{
818
+		$inputs = $this->inputs();
819
+		$errors = array();
820
+		foreach ($inputs as $form_input) {
821
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
822
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
823
+			}
824
+		}
825
+		return $errors;
826
+	}
827
+
828
+
829
+	/**
830
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
831
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
832
+	 *
833
+	 * @throws InvalidArgumentException
834
+	 * @throws InvalidInterfaceException
835
+	 * @throws InvalidDataTypeException
836
+	 */
837
+	public static function localize_script_for_all_forms()
838
+	{
839
+		// allow inputs and stuff to hook in their JS and stuff here
840
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
841
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
842
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
843
+			? EE_Registry::instance()->CFG->registration->email_validation_level
844
+			: 'wp_default';
845
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
846
+		wp_enqueue_script('ee_form_section_validation');
847
+		wp_localize_script(
848
+			'ee_form_section_validation',
849
+			'ee_form_section_vars',
850
+			EE_Form_Section_Proper::$_js_localization
851
+		);
852
+	}
853
+
854
+
855
+	/**
856
+	 * ensure_scripts_localized
857
+	 *
858
+	 * @throws EE_Error
859
+	 */
860
+	public function ensure_scripts_localized()
861
+	{
862
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
863
+			$this->_enqueue_and_localize_form_js();
864
+		}
865
+	}
866
+
867
+
868
+	/**
869
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
870
+	 * is that the key here should be the same as the custom validation rule put in the JS file
871
+	 *
872
+	 * @return array keys are custom validation rules, and values are internationalized strings
873
+	 */
874
+	private static function _get_localized_error_messages()
875
+	{
876
+		return array(
877
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
878
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
879
+		);
880
+	}
881
+
882
+
883
+	/**
884
+	 * @return array
885
+	 */
886
+	public static function js_localization()
887
+	{
888
+		return self::$_js_localization;
889
+	}
890
+
891
+
892
+	/**
893
+	 * @return void
894
+	 */
895
+	public static function reset_js_localization()
896
+	{
897
+		self::$_js_localization = array();
898
+	}
899
+
900
+
901
+	/**
902
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
903
+	 * See parent function for more...
904
+	 *
905
+	 * @return array
906
+	 * @throws EE_Error
907
+	 */
908
+	public function get_jquery_validation_rules()
909
+	{
910
+		$jquery_validation_rules = array();
911
+		foreach ($this->get_validatable_subsections() as $subsection) {
912
+			$jquery_validation_rules = array_merge(
913
+				$jquery_validation_rules,
914
+				$subsection->get_jquery_validation_rules()
915
+			);
916
+		}
917
+		return $jquery_validation_rules;
918
+	}
919
+
920
+
921
+	/**
922
+	 * Sanitizes all the data and sets the sanitized value of each field
923
+	 *
924
+	 * @param array $req_data like $_POST
925
+	 * @return void
926
+	 * @throws EE_Error
927
+	 */
928
+	protected function _normalize($req_data)
929
+	{
930
+		$this->_received_submission = true;
931
+		$this->_validation_errors   = array();
932
+		foreach ($this->get_validatable_subsections() as $subsection) {
933
+			try {
934
+				$subsection->_normalize($req_data);
935
+			} catch (EE_Validation_Error $e) {
936
+				$subsection->add_validation_error($e);
937
+			}
938
+		}
939
+	}
940
+
941
+
942
+	/**
943
+	 * Performs validation on this form section and its subsections.
944
+	 * For each subsection,
945
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
946
+	 * and passes it the subsection, then calls _validate on that subsection.
947
+	 * If you need to perform validation on the form as a whole (considering multiple)
948
+	 * you would be best to override this _validate method,
949
+	 * calling parent::_validate() first.
950
+	 *
951
+	 * @throws EE_Error
952
+	 */
953
+	protected function _validate()
954
+	{
955
+		// reset the cache of whether this form is valid or not- we're re-validating it now
956
+		$this->is_valid = null;
957
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
958
+			if (method_exists($this, '_validate_' . $subsection_name)) {
959
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
960
+			}
961
+			$subsection->_validate();
962
+		}
963
+	}
964
+
965
+
966
+	/**
967
+	 * Gets all the validated inputs for the form section
968
+	 *
969
+	 * @return array
970
+	 * @throws EE_Error
971
+	 */
972
+	public function valid_data()
973
+	{
974
+		$inputs = array();
975
+		foreach ($this->subsections() as $subsection_name => $subsection) {
976
+			if ($subsection instanceof EE_Form_Section_Proper) {
977
+				$inputs[ $subsection_name ] = $subsection->valid_data();
978
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
979
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
980
+			}
981
+		}
982
+		return $inputs;
983
+	}
984
+
985
+
986
+	/**
987
+	 * Gets all the inputs on this form section
988
+	 *
989
+	 * @return EE_Form_Input_Base[]
990
+	 * @throws EE_Error
991
+	 */
992
+	public function inputs()
993
+	{
994
+		$inputs = array();
995
+		foreach ($this->subsections() as $subsection_name => $subsection) {
996
+			if ($subsection instanceof EE_Form_Input_Base) {
997
+				$inputs[ $subsection_name ] = $subsection;
998
+			}
999
+		}
1000
+		return $inputs;
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * Gets all the subsections which are a proper form
1006
+	 *
1007
+	 * @return EE_Form_Section_Proper[]
1008
+	 * @throws EE_Error
1009
+	 */
1010
+	public function subforms()
1011
+	{
1012
+		$form_sections = array();
1013
+		foreach ($this->subsections() as $name => $obj) {
1014
+			if ($obj instanceof EE_Form_Section_Proper) {
1015
+				$form_sections[ $name ] = $obj;
1016
+			}
1017
+		}
1018
+		return $form_sections;
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1024
+	 * Consider using inputs() or subforms()
1025
+	 * if you only want form inputs or proper form sections.
1026
+	 *
1027
+	 * @param boolean $require_construction_to_be_finalized most client code should
1028
+	 *                                                      leave this as TRUE so that the inputs will be properly
1029
+	 *                                                      configured. However, some client code may be ok with
1030
+	 *                                                      construction finalize being called later
1031
+	 *                                                      (realizing that the subsections' html names might not be
1032
+	 *                                                      set yet, etc.)
1033
+	 * @return EE_Form_Section_Proper[]
1034
+	 * @throws EE_Error
1035
+	 */
1036
+	public function subsections($require_construction_to_be_finalized = true)
1037
+	{
1038
+		if ($require_construction_to_be_finalized) {
1039
+			$this->ensure_construct_finalized_called();
1040
+		}
1041
+		return $this->_subsections;
1042
+	}
1043
+
1044
+
1045
+	/**
1046
+	 * Returns whether this form has any subforms or inputs
1047
+	 * @return bool
1048
+	 */
1049
+	public function hasSubsections()
1050
+	{
1051
+		return ! empty($this->_subsections);
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * Returns a simple array where keys are input names, and values are their normalized
1057
+	 * values. (Similar to calling get_input_value on inputs)
1058
+	 *
1059
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1060
+	 *                                        or just this forms' direct children inputs
1061
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1062
+	 *                                        or allow multidimensional array
1063
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1064
+	 *                                        with array keys being input names
1065
+	 *                                        (regardless of whether they are from a subsection or not),
1066
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1067
+	 *                                        where keys are always subsection names and values are either
1068
+	 *                                        the input's normalized value, or an array like the top-level array
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	public function input_values($include_subform_inputs = false, $flatten = false)
1072
+	{
1073
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1074
+	}
1075
+
1076
+
1077
+	/**
1078
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1079
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1080
+	 * is not necessarily the value we want to display to users. This creates an array
1081
+	 * where keys are the input names, and values are their display values
1082
+	 *
1083
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1084
+	 *                                        or just this forms' direct children inputs
1085
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1086
+	 *                                        or allow multidimensional array
1087
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1088
+	 *                                        with array keys being input names
1089
+	 *                                        (regardless of whether they are from a subsection or not),
1090
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1091
+	 *                                        where keys are always subsection names and values are either
1092
+	 *                                        the input's normalized value, or an array like the top-level array
1093
+	 * @throws EE_Error
1094
+	 */
1095
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1096
+	{
1097
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Gets the input values from the form
1103
+	 *
1104
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1105
+	 *                                        or just the normalized value
1106
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1107
+	 *                                        or just this forms' direct children inputs
1108
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1109
+	 *                                        or allow multidimensional array
1110
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1111
+	 *                                        input names (regardless of whether they are from a subsection or not),
1112
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1113
+	 *                                        where keys are always subsection names and values are either
1114
+	 *                                        the input's normalized value, or an array like the top-level array
1115
+	 * @throws EE_Error
1116
+	 */
1117
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1118
+	{
1119
+		$input_values = array();
1120
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1121
+			if ($subsection instanceof EE_Form_Input_Base) {
1122
+				$input_values[ $subsection_name ] = $pretty
1123
+					? $subsection->pretty_value()
1124
+					: $subsection->normalized_value();
1125
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1126
+				$subform_input_values = $subsection->_input_values(
1127
+					$pretty,
1128
+					$include_subform_inputs,
1129
+					$flatten
1130
+				);
1131
+				if ($flatten) {
1132
+					$input_values = array_merge($input_values, $subform_input_values);
1133
+				} else {
1134
+					$input_values[ $subsection_name ] = $subform_input_values;
1135
+				}
1136
+			}
1137
+		}
1138
+		return $input_values;
1139
+	}
1140
+
1141
+
1142
+	/**
1143
+	 * Gets the originally submitted input values from the form
1144
+	 *
1145
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1146
+	 *                                   or just this forms' direct children inputs
1147
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1148
+	 *                                   with array keys being input names
1149
+	 *                                   (regardless of whether they are from a subsection or not),
1150
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1151
+	 *                                   where keys are always subsection names and values are either
1152
+	 *                                   the input's normalized value, or an array like the top-level array
1153
+	 * @throws EE_Error
1154
+	 */
1155
+	public function submitted_values($include_subforms = false)
1156
+	{
1157
+		$submitted_values = array();
1158
+		foreach ($this->subsections() as $subsection) {
1159
+			if ($subsection instanceof EE_Form_Input_Base) {
1160
+				// is this input part of an array of inputs?
1161
+				if (strpos($subsection->html_name(), '[') !== false) {
1162
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1163
+						explode(
1164
+							'[',
1165
+							str_replace(']', '', $subsection->html_name())
1166
+						),
1167
+						$subsection->raw_value()
1168
+					);
1169
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1170
+				} else {
1171
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1172
+				}
1173
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1174
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1175
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1176
+			}
1177
+		}
1178
+		return $submitted_values;
1179
+	}
1180
+
1181
+
1182
+	/**
1183
+	 * Indicates whether or not this form has received a submission yet
1184
+	 * (ie, had receive_form_submission called on it yet)
1185
+	 *
1186
+	 * @return boolean
1187
+	 * @throws EE_Error
1188
+	 */
1189
+	public function has_received_submission()
1190
+	{
1191
+		$this->ensure_construct_finalized_called();
1192
+		return $this->_received_submission;
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1198
+	 * Removes the listed inputs from the form
1199
+	 *
1200
+	 * @param array $inputs_to_exclude values are the input names
1201
+	 * @return void
1202
+	 */
1203
+	public function exclude(array $inputs_to_exclude = array())
1204
+	{
1205
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1206
+			unset($this->_subsections[ $input_to_exclude_name ]);
1207
+		}
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1213
+	 * @param array $inputs_to_hide
1214
+	 * @throws EE_Error
1215
+	 */
1216
+	public function hide(array $inputs_to_hide = array())
1217
+	{
1218
+		foreach ($inputs_to_hide as $input_to_hide) {
1219
+			$input = $this->get_input($input_to_hide);
1220
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1221
+		}
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * add_subsections
1227
+	 * Adds the listed subsections to the form section.
1228
+	 * If $subsection_name_to_target is provided,
1229
+	 * then new subsections are added before or after that subsection,
1230
+	 * otherwise to the start or end of the entire subsections array.
1231
+	 *
1232
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1233
+	 *                                                          where keys are their names
1234
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1235
+	 *                                                          should be added before or after
1236
+	 *                                                          IF $subsection_name_to_target is null,
1237
+	 *                                                          then $new_subsections will be added to
1238
+	 *                                                          the beginning or end of the entire subsections array
1239
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1240
+	 *                                                          $subsection_name_to_target,
1241
+	 *                                                          or if $subsection_name_to_target is null,
1242
+	 *                                                          before or after entire subsections array
1243
+	 * @return void
1244
+	 * @throws EE_Error
1245
+	 */
1246
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1247
+	{
1248
+		foreach ($new_subsections as $subsection_name => $subsection) {
1249
+			if (! $subsection instanceof EE_Form_Section_Base) {
1250
+				EE_Error::add_error(
1251
+					sprintf(
1252
+						esc_html__(
1253
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1254
+							'event_espresso'
1255
+						),
1256
+						get_class($subsection),
1257
+						$subsection_name,
1258
+						$this->name()
1259
+					)
1260
+				);
1261
+				unset($new_subsections[ $subsection_name ]);
1262
+			}
1263
+		}
1264
+		$this->_subsections = EEH_Array::insert_into_array(
1265
+			$this->_subsections,
1266
+			$new_subsections,
1267
+			$subsection_name_to_target,
1268
+			$add_before
1269
+		);
1270
+		if ($this->_construction_finalized) {
1271
+			foreach ($this->_subsections as $name => $subsection) {
1272
+				$subsection->_construct_finalize($this, $name);
1273
+			}
1274
+		}
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * @param string $subsection_name
1280
+	 * @param bool   $recursive
1281
+	 * @return bool
1282
+	 */
1283
+	public function has_subsection($subsection_name, $recursive = false)
1284
+	{
1285
+		foreach ($this->_subsections as $name => $subsection) {
1286
+			if (
1287
+				$name === $subsection_name
1288
+				|| (
1289
+					$recursive
1290
+					&& $subsection instanceof EE_Form_Section_Proper
1291
+					&& $subsection->has_subsection($subsection_name, $recursive)
1292
+				)
1293
+			) {
1294
+				return true;
1295
+			}
1296
+		}
1297
+		return false;
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * Just gets all validatable subsections to clean their sensitive data
1304
+	 *
1305
+	 * @throws EE_Error
1306
+	 */
1307
+	public function clean_sensitive_data()
1308
+	{
1309
+		foreach ($this->get_validatable_subsections() as $subsection) {
1310
+			$subsection->clean_sensitive_data();
1311
+		}
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1317
+	 * @param string                           $form_submission_error_message
1318
+	 * @param EE_Form_Section_Validatable $form_section unused
1319
+	 * @throws EE_Error
1320
+	 */
1321
+	public function set_submission_error_message(
1322
+		$form_submission_error_message = ''
1323
+	) {
1324
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1325
+			? $form_submission_error_message
1326
+			: $this->getAllValidationErrorsString();
1327
+	}
1328
+
1329
+
1330
+	/**
1331
+	 * Returns the cached error message. A default value is set for this during _validate(),
1332
+	 * (called during receive_form_submission) but it can be explicitly set using
1333
+	 * set_submission_error_message
1334
+	 *
1335
+	 * @return string
1336
+	 */
1337
+	public function submission_error_message()
1338
+	{
1339
+		return $this->_form_submission_error_message;
1340
+	}
1341
+
1342
+
1343
+	/**
1344
+	 * Sets a message to display if the data submitted to the form was valid.
1345
+	 * @param string $form_submission_success_message
1346
+	 */
1347
+	public function set_submission_success_message($form_submission_success_message = '')
1348
+	{
1349
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1350
+			? $form_submission_success_message
1351
+			: esc_html__('Form submitted successfully', 'event_espresso');
1352
+	}
1353
+
1354
+
1355
+	/**
1356
+	 * Gets a message appropriate for display when the form is correctly submitted
1357
+	 * @return string
1358
+	 */
1359
+	public function submission_success_message()
1360
+	{
1361
+		return $this->_form_submission_success_message;
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 * Returns the prefix that should be used on child of this form section for
1367
+	 * their html names. If this form section itself has a parent, prepends ITS
1368
+	 * prefix onto this form section's prefix. Used primarily by
1369
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1370
+	 *
1371
+	 * @return string
1372
+	 * @throws EE_Error
1373
+	 */
1374
+	public function html_name_prefix()
1375
+	{
1376
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1377
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1378
+		}
1379
+		return $this->name();
1380
+	}
1381
+
1382
+
1383
+	/**
1384
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1385
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1386
+	 * was set, which is probably nothing, or the classname)
1387
+	 *
1388
+	 * @return string
1389
+	 * @throws EE_Error
1390
+	 */
1391
+	public function name()
1392
+	{
1393
+		$this->ensure_construct_finalized_called();
1394
+		return parent::name();
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * @return EE_Form_Section_Proper
1400
+	 * @throws EE_Error
1401
+	 */
1402
+	public function parent_section()
1403
+	{
1404
+		$this->ensure_construct_finalized_called();
1405
+		return parent::parent_section();
1406
+	}
1407
+
1408
+
1409
+	/**
1410
+	 * make sure construction finalized was called, otherwise children might not be ready
1411
+	 *
1412
+	 * @return void
1413
+	 * @throws EE_Error
1414
+	 */
1415
+	public function ensure_construct_finalized_called()
1416
+	{
1417
+		if (! $this->_construction_finalized) {
1418
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1419
+		}
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1425
+	 * are in teh form data. If any are found, returns true. Else false
1426
+	 *
1427
+	 * @param array $req_data
1428
+	 * @return boolean
1429
+	 * @throws EE_Error
1430
+	 */
1431
+	public function form_data_present_in($req_data = null)
1432
+	{
1433
+		$req_data = $this->getCachedRequest($req_data);
1434
+		foreach ($this->subsections() as $subsection) {
1435
+			if ($subsection instanceof EE_Form_Input_Base) {
1436
+				if ($subsection->form_data_present_in($req_data)) {
1437
+					return true;
1438
+				}
1439
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1440
+				if ($subsection->form_data_present_in($req_data)) {
1441
+					return true;
1442
+				}
1443
+			}
1444
+		}
1445
+		return false;
1446
+	}
1447
+
1448
+
1449
+	/**
1450
+	 * Gets validation errors for this form section and subsections
1451
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1452
+	 * gets the validation errors for ALL subsection
1453
+	 *
1454
+	 * @return EE_Validation_Error[]
1455
+	 * @throws EE_Error
1456
+	 */
1457
+	public function get_validation_errors_accumulated()
1458
+	{
1459
+		$validation_errors = $this->get_validation_errors();
1460
+		foreach ($this->get_validatable_subsections() as $subsection) {
1461
+			if ($subsection instanceof EE_Form_Section_Proper) {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1463
+			} else {
1464
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1465
+			}
1466
+			if ($validation_errors_on_this_subsection) {
1467
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1468
+			}
1469
+		}
1470
+		return $validation_errors;
1471
+	}
1472
+
1473
+	/**
1474
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1475
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1476
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1477
+	 *
1478
+	 * @return string
1479
+	 * @since 4.9.59.p
1480
+	 */
1481
+	protected function getAllValidationErrorsString()
1482
+	{
1483
+		$submission_error_messages = array();
1484
+		// bad, bad, bad registrant
1485
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1486
+			if ($validation_error instanceof EE_Validation_Error) {
1487
+				$form_section = $validation_error->get_form_section();
1488
+				if ($form_section instanceof EE_Form_Input_Base) {
1489
+					$label = $validation_error->get_form_section()->html_label_text();
1490
+				} elseif ($form_section instanceof EE_Form_Section_Validatable) {
1491
+					$label = $validation_error->get_form_section()->name();
1492
+				} else {
1493
+					$label = esc_html__('Unknown', 'event_espresso');
1494
+				}
1495
+				$submission_error_messages[] = sprintf(
1496
+					__('%s : %s', 'event_espresso'),
1497
+					$label,
1498
+					$validation_error->getMessage()
1499
+				);
1500
+			}
1501
+		}
1502
+		return implode('<br>', $submission_error_messages);
1503
+	}
1504
+
1505
+
1506
+	/**
1507
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1508
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1509
+	 * dot-dot-slash (../) means to ascend into the parent section.
1510
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1511
+	 * which will be returned.
1512
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1513
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1514
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1515
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1516
+	 * Etc
1517
+	 *
1518
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1519
+	 * @return EE_Form_Section_Base
1520
+	 * @throws EE_Error
1521
+	 */
1522
+	public function find_section_from_path($form_section_path)
1523
+	{
1524
+		// check if we can find the input from purely going straight up the tree
1525
+		$input = parent::find_section_from_path($form_section_path);
1526
+		if ($input instanceof EE_Form_Section_Base) {
1527
+			return $input;
1528
+		}
1529
+		$next_slash_pos = strpos($form_section_path, '/');
1530
+		if ($next_slash_pos !== false) {
1531
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1532
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1533
+		} else {
1534
+			$child_section_name = $form_section_path;
1535
+			$subpath            = '';
1536
+		}
1537
+		$child_section = $this->get_subsection($child_section_name);
1538
+		if ($child_section instanceof EE_Form_Section_Base) {
1539
+			return $child_section->find_section_from_path($subpath);
1540
+		}
1541
+		return null;
1542
+	}
1543 1543
 }
Please login to merge, or discard this patch.
libraries/messages/data_class/EE_Messages_Preview_incoming_data.class.php 1 patch
Indentation   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -20,585 +20,585 @@
 block discarded – undo
20 20
 class EE_Messages_Preview_incoming_data extends EE_Messages_incoming_data
21 21
 {
22 22
 
23
-    // some specific properties we need for this class
24
-    private $_events = array();
25
-    private $_attendees = array();
26
-    private $_registrations = array();
27
-
28
-
29
-    /**
30
-     * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
31
-     * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
32
-     * we'll get the first three published events from the users database and use that as a source.
33
-     *
34
-     * @param array $data
35
-     */
36
-    public function __construct($data = array())
37
-    {
38
-        $this->_data = isset($data['event_ids']) ? $data['event_ids'] : array();
39
-        $this->_setup_attendees_events();
40
-        parent::__construct($data);
41
-    }
42
-
43
-
44
-    /**
45
-     * Returns database safe representation of the data later used to when instantiating this object.
46
-     *
47
-     * @param array $data The incoming data to be prepped.
48
-     *
49
-     * @return array   The prepped data for db
50
-     */
51
-    public static function convert_data_for_persistent_storage($data)
52
-    {
53
-        return $data;
54
-    }
55
-
56
-
57
-    /**
58
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
59
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
60
-     *
61
-     * @param array $data
62
-     *
63
-     * @return array
64
-     */
65
-    public static function convert_data_from_persistent_storage($data)
66
-    {
67
-        return $data;
68
-    }
69
-
70
-
71
-    /**
72
-     * This will just setup the _events property in the expected format.
73
-     *
74
-     * @throws \EE_Error
75
-     */
76
-    private function _setup_attendees_events()
77
-    {
78
-
79
-        // setup some attendee objects
80
-        $attendees = $this->_get_some_attendees();
81
-
82
-        // if empty $data we'll do a query to get some events from the server. otherwise we'll retrieve the event data for the given ids.
83
-        $events = $this->_get_some_events($this->_data);
84
-
85
-        $answers_n_questions = $this->_get_some_q_and_as();
86
-
87
-        if (count($events) < 1) {
88
-            throw new EE_Error(__(
89
-                'We can\'t generate a preview for you because there are no active events in your database',
90
-                'event_espresso'
91
-            ));
92
-        }
93
-
94
-
95
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
96
-
97
-
98
-        // we'll actually use the generated line_item identifiers for our loop
99
-        $dtts = $tkts = array();
100
-        foreach ($events as $id => $event) {
101
-            if (! $event instanceof EE_Event) {
102
-                continue;
103
-            }
104
-            $this->_events[ $id ]['ID']       = $id;
105
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
106
-            $datetime                       = $event->get_first_related('Datetime');
107
-            $tickets                        = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
108
-                'Ticket',
109
-                array('default_where_conditions' => 'none')
110
-            ) : array();
111
-            $this->_events[ $id ]['event']    = $event;
112
-            $this->_events[ $id ]['reg_objs'] = array();
113
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
114
-            $this->_events[ $id ]['dtt_objs'] = array();
115
-
116
-            $dttcache = array();
117
-            $tkts     = array();
118
-            foreach ($tickets as $ticket) {
119
-                if (! $ticket instanceof EE_Ticket) {
120
-                    continue;
121
-                }
122
-                $reldatetime                     = $ticket->datetimes();
123
-                $tkts[ $ticket->ID() ]             = array();
124
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
125
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
126
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
127
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
128
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
129
-                foreach ($reldatetime as $datetime) {
130
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
131
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
132
-                        $dtts[ $datetime->ID() ]['datetime']               = $datetime;
133
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]             = $ticket;
134
-                        $dtts[ $datetime->ID() ]['evt_objs'][]             = $event;
135
-                        $dttcache[ $datetime->ID() ]                       = $datetime;
136
-                    }
137
-                }
138
-            }
139
-
140
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
141
-            $this->_events[ $id ]['att_objs']        = $attendees;
142
-
143
-            // let's also setup the dummy attendees property!
144
-            foreach ($attendees as $att_key => $attendee) {
145
-                if (! $attendee instanceof EE_Attendee) {
146
-                    continue;
147
-                }
148
-                $this->_attendees[ $att_key ]['line_ref'][] = $id;  // so later it can be determined what events this attendee registered for!
149
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
150
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
151
-                // $this->_attendees[$att_key]['registration_id'] = 0;
152
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
153
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
154
-                if ($att_key == 999999991) {
155
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
158
-                } elseif ($att_key == 999999992) {
159
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
162
-                } elseif ($att_key == 999999993) {
163
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
166
-                }
167
-            }
168
-        }
169
-
170
-        $this->tickets            = $tkts;
171
-        $this->datetimes          = $dtts;
172
-        $this->answers            = $answers_n_questions['answers'];
173
-        $this->questions          = $answers_n_questions['questions'];
174
-        $this->total_ticket_count = count($tkts) * count($this->_attendees);
175
-    }
176
-
177
-
178
-    /**
179
-     * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
180
-     *
181
-     * @access private
182
-     * @return array an array of attendee objects
183
-     */
184
-    private function _get_some_attendees()
185
-    {
186
-        // let's just setup a dummy array of various attendee details
187
-        $dummy_attendees = array(
188
-            0 => array(
189
-                'Luke',
190
-                'Skywalker',
191
-                '[email protected]',
192
-                '804 Bantha Dr.',
193
-                'Complex 8',
194
-                'Mos Eisley',
195
-                32,
196
-                'US',
197
-                'f0r3e',
198
-                '222-333-4763',
199
-                false,
200
-                '999999991'
201
-            ),
202
-            1 => array(
203
-                'Princess',
204
-                'Leia',
205
-                '[email protected]',
206
-                '1456 Valley Way Boulevard',
207
-                'Suite 9',
208
-                'Alderaan',
209
-                15,
210
-                'US',
211
-                'c1h2c',
212
-                '78-123-111-1111',
213
-                false,
214
-                '999999992'
215
-            ),
216
-            2 => array(
217
-                'Yoda',
218
-                'I Am',
219
-                '[email protected]',
220
-                '4th Tree',
221
-                '5th Knot',
222
-                'Marsh',
223
-                22,
224
-                'US',
225
-                'l18n',
226
-                '999-999-9999',
227
-                false,
228
-                '999999993'
229
-            ),
230
-        );
231
-
232
-        // let's generate the attendee objects
233
-        $attendees = array();
234
-        $var_array = array(
235
-            'fname',
236
-            'lname',
237
-            'email',
238
-            'address',
239
-            'address2',
240
-            'city',
241
-            'staid',
242
-            'cntry',
243
-            'zip',
244
-            'phone',
245
-            'deleted',
246
-            'attid'
247
-        );
248
-
249
-        // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
250
-        foreach ($dummy_attendees as $dummy) {
251
-            $att = array_combine($var_array, $dummy);
252
-            extract($att);
253
-            /** @var $fname string */
254
-            /** @var $lname string */
255
-            /** @var $address string */
256
-            /** @var $address2 string */
257
-            /** @var $city string */
258
-            /** @var $staid string */
259
-            /** @var $cntry string */
260
-            /** @var $zip string */
261
-            /** @var $email string */
262
-            /** @var $phone string */
263
-            /** @var $attid string */
264
-            $attendees[ $attid ] = EE_Attendee::new_instance(
265
-                array(
266
-                    'ATT_fname'    => $fname,
267
-                    'ATT_lname'    => $lname,
268
-                    'ATT_address'  => $address,
269
-                    'ATT_address2' => $address2,
270
-                    'ATT_city'     => $city,
271
-                    'STA_ID'       => $staid,
272
-                    'CNT_ISO'      => $cntry,
273
-                    'ATT_zip'      => $zip,
274
-                    'ATT_email'    => $email,
275
-                    'ATT_phone'    => $phone,
276
-                    'ATT_ID'       => $attid
277
-                )
278
-            );
279
-        }
280
-
281
-        return $attendees;
282
-    }
283
-
284
-
285
-    /**
286
-     * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
287
-     * This will be used in our dummy data setup
288
-     * @return array
289
-     */
290
-    private function _get_some_q_and_as()
291
-    {
292
-
293
-
294
-        $quests_array = array(
295
-            0 => array(
296
-                555,
297
-                __('What is your favorite planet?', 'event_espresso'),
298
-                0
299
-            ),
300
-            1 => array(
301
-                556,
302
-                __('What is your favorite food?', 'event_espresso'),
303
-                0
304
-            ),
305
-            2 => array(
306
-                557,
307
-                __('How many lightyears have you travelled', 'event_espresso'),
308
-                0
309
-            )
310
-        );
311
-
312
-
313
-        $ans_array = array(
314
-            0 => array(
315
-                999,
316
-                555,
317
-                'Tattoine'
318
-            ),
319
-            1 => array(
320
-                1000,
321
-                555,
322
-                'Alderaan'
323
-            ),
324
-            2 => array(
325
-                1001,
326
-                555,
327
-                'Dantooine'
328
-            ),
329
-            3 => array(
330
-                1002,
331
-                556,
332
-                'Fish Fingers'
333
-            ),
334
-            4 => array(
335
-                1003,
336
-                556,
337
-                'Sushi'
338
-            ),
339
-            5 => array(
340
-                1004,
341
-                556,
342
-                'Water'
343
-            ),
344
-            6 => array(
345
-                1005,
346
-                557,
347
-                'A lot',
348
-            ),
349
-            7 => array(
350
-                1006,
351
-                557,
352
-                "That's none of your business."
353
-            ),
354
-            8 => array(
355
-                1007,
356
-                557,
357
-                "People less travel me then."
358
-            )
359
-        );
360
-
361
-        $qst_columns = array('QST_ID', 'QST_display_text', 'QST_system');
362
-        $ans_columns = array('ANS_ID', 'QST_ID', 'ANS_value');
363
-
364
-        // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
365
-        // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
366
-
367
-        $qsts = array();
368
-        // first the questions
369
-        foreach ($quests_array as $qst) {
370
-            $qstobj                  = array_combine($qst_columns, $qst);
371
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
372
-        }
373
-
374
-        // now the answers (and we'll setup our arrays)
375
-        $q_n_as = array();
376
-        foreach ($ans_array as $ans) {
377
-            $ansobj                             = array_combine($ans_columns, $ans);
378
-            $ansobj                             = EE_Answer::new_instance($ansobj);
379
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
380
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
381
-        }
382
-
383
-        return $q_n_as;
384
-    }
385
-
386
-
387
-    /**
388
-     * Return an array of event objects from the database
389
-     *
390
-     * If event ids are not included then we'll just retrieve the first published event from the database.
391
-     *
392
-     * @param  array $event_ids if set, this will be an array of event ids to obtain events for.
393
-     *
394
-     * @return array    An array of event objects from the db.
395
-     */
396
-    private function _get_some_events($event_ids = array())
397
-    {
398
-
399
-        // HEY, if we have an evt_id then we want to make sure we use that for the preview (because a specific event template is being viewed);
400
-        $event_ids = isset($_REQUEST['evt_id']) && ! empty($_REQUEST['evt_id'])
401
-            ? array($_REQUEST['evt_id'])
402
-            : $event_ids;
403
-
404
-        $limit = ! empty($event_ids)
405
-            ? null
406
-            : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
407
-
408
-        $where = ! empty($event_ids)
409
-            ? array(
410
-                'EVT_ID'                 => array('IN', $event_ids),
411
-                'Datetime.Ticket.TKT_ID' => array('>', 1)
412
-            )
413
-            : array('Datetime.Ticket.TKT_ID' => array('>', 1));
414
-
415
-        $events = EE_Registry::instance()->load_model('Event')->get_all(array($where, 'limit' => $limit));
416
-
417
-        return $events;
418
-    }
419
-
420
-
421
-    protected function _setup_data()
422
-    {
423
-
424
-        // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
425
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
426
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
427
-            $session = EE_Registry::instance()->SSN;
428
-        } else {
429
-            $session = EE_Registry::instance()->load_core('Session');
430
-        }
431
-        $cart = EE_Cart::instance(null, $session);
432
-
433
-
434
-        // add tickets to cart
435
-        foreach ($this->tickets as $ticket) {
436
-            $cart->add_ticket_to_cart($ticket['ticket']);
437
-        }
438
-
439
-
440
-        // setup txn property
441
-        $this->txn = EE_Transaction::new_instance(
442
-            array(
443
-                'TXN_timestamp'    => time(), // unix timestamp
444
-                'TXN_total'        => 0, // txn_total
445
-                'TXN_paid'         => 0, // txn_paid
446
-                'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
447
-                'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
448
-                'TXN_hash_salt'    => null, // hash salt blank as well
449
-                'TXN_ID'           => 999999
450
-            )
451
-        );
452
-
453
-
454
-        // setup reg_objects
455
-        // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
456
-        $this->reg_objs = array();
457
-        $regid          = 9999990;
458
-        foreach ($this->_attendees as $key => $attendee) {
459
-            // note we need to setup reg_objects for each event this attendee belongs to
460
-            $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
461
-            $regtxn = $this->txn->ID();
462
-            $regcnt = 1;
463
-            foreach ($attendee['line_ref'] as $evtid) {
464
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
465
-                    if (! $ticket instanceof EE_Ticket) {
466
-                        continue;
467
-                    }
468
-                    $reg_array                                        = array(
469
-                        'EVT_ID'           => $evtid,
470
-                        'ATT_ID'           => $regatt,
471
-                        'TXN_ID'           => $regtxn,
472
-                        'TKT_ID'           => $ticket->ID(),
473
-                        'STS_ID'           => EEM_Registration::status_id_pending_payment,
474
-                        'REG_date'         => time(),
475
-                        'REG_final_price'  => $ticket->get('TKT_price'),
476
-                        'REG_session'      => 'dummy_session_id',
477
-                        'REG_code'         => $regid . '-dummy-generated-code',
478
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
479
-                        'REG_count'        => $regcnt,
480
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
481
-                        'REG_att_is_going' => true,
482
-                        'REG_ID'           => $regid
483
-                    );
484
-                    $REG_OBJ                                          = EE_Registration::new_instance($reg_array);
485
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
486
-                    $this->_events[ $evtid ]['reg_objs'][]              = $REG_OBJ;
487
-                    $this->reg_objs[]                                 = $REG_OBJ;
488
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
489
-
490
-                    $regcnt++;
491
-                    $regid++;
492
-                }
493
-            }
494
-        }
495
-
496
-
497
-        // setup line items!
498
-        $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
499
-
500
-        // add tickets
501
-        foreach ($this->tickets as $tktid => $item) {
502
-            $qty    = $item['count'];
503
-            $ticket = $item['ticket'];
504
-            EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
505
-        }
506
-
507
-        $shipping_line_item = EE_Line_Item::new_instance(array(
508
-            'LIN_name'       => __('Shipping Surcharge', 'event_espresso'),
509
-            'LIN_desc'       => __('Sent via Millenium Falcon', 'event_espresso'),
510
-            'LIN_unit_price' => 20,
511
-            'LIN_quantity'   => 1,
512
-            'LIN_is_taxable' => true,
513
-            'LIN_total'      => 20,
514
-            'LIN_type'       => EEM_Line_Item::type_line_item
515
-        ));
516
-        EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
517
-        $this->additional_line_items = array($shipping_line_item);
518
-
519
-        // now let's add taxes
520
-        EEH_Line_Item::apply_taxes($line_item_total);
521
-
522
-        // now we should be able to get the items we need from this object
523
-        $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
524
-        $line_items       = array();
525
-        foreach ($event_line_items as $line_id => $line_item) {
526
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
527
-                continue;
528
-            }
529
-            $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
530
-            foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
531
-                if (! $ticket_line_item instanceof EE_Line_Item) {
532
-                    continue;
533
-                }
534
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
535
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
536
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
537
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             = $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
538
-            }
539
-        }
540
-
541
-        $this->line_items_with_children = $line_items;
542
-        $this->tax_line_items           = $line_item_total->tax_descendants();
543
-
544
-        // add proper total to transaction object.
545
-        $grand_total                 = $line_item_total->recalculate_total_including_taxes();
546
-        $this->grand_total_line_item = $line_item_total;
547
-        $this->txn->set_total($grand_total);
548
-
549
-
550
-        // add additional details for each registration
551
-        foreach ($this->reg_objs as $reg) {
552
-            if (! $reg instanceof EE_Registration) {
553
-                continue;
554
-            }
555
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
556
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
557
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
558
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
559
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
560
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
561
-        }
562
-
563
-
564
-        // events and attendees
565
-        $this->events        = $this->_events;
566
-        $this->attendees     = $this->_attendees;
567
-        $this->registrations = $this->_registrations;
568
-
569
-        $attendees_to_shift = $this->_attendees;
570
-
571
-        // setup primary attendee property
572
-        $this->primary_attendee_data = array(
573
-            'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
574
-                ? $this->_attendees[999999991]['att_obj']->fname()
575
-                : '',
576
-
577
-            'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
578
-                ? $this->_attendees[999999991]['att_obj']->lname()
579
-                : '',
580
-
581
-            'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
582
-                ? $this->_attendees[999999991]['att_obj']->email()
583
-                : '',
584
-
585
-            'att_obj' => $this->_attendees[999999991]['att_obj'],
586
-
587
-            'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs'])
588
-        );
589
-
590
-        // reg_info property
591
-        // note this isn't referenced by any shortcode parsers so we'll ignore for now.
592
-        $this->reg_info = array();
593
-
594
-        // let's set a reg_obj for messengers expecting one.
595
-        $this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
596
-
597
-        // the below are just dummy items.
598
-        $this->user_id     = 1;
599
-        $this->ip_address  = '192.0.2.1';
600
-        $this->user_agent  = '';
601
-        $this->init_access = time();
602
-        $this->last_access = time();
603
-    }
23
+	// some specific properties we need for this class
24
+	private $_events = array();
25
+	private $_attendees = array();
26
+	private $_registrations = array();
27
+
28
+
29
+	/**
30
+	 * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
31
+	 * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
32
+	 * we'll get the first three published events from the users database and use that as a source.
33
+	 *
34
+	 * @param array $data
35
+	 */
36
+	public function __construct($data = array())
37
+	{
38
+		$this->_data = isset($data['event_ids']) ? $data['event_ids'] : array();
39
+		$this->_setup_attendees_events();
40
+		parent::__construct($data);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Returns database safe representation of the data later used to when instantiating this object.
46
+	 *
47
+	 * @param array $data The incoming data to be prepped.
48
+	 *
49
+	 * @return array   The prepped data for db
50
+	 */
51
+	public static function convert_data_for_persistent_storage($data)
52
+	{
53
+		return $data;
54
+	}
55
+
56
+
57
+	/**
58
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
59
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
60
+	 *
61
+	 * @param array $data
62
+	 *
63
+	 * @return array
64
+	 */
65
+	public static function convert_data_from_persistent_storage($data)
66
+	{
67
+		return $data;
68
+	}
69
+
70
+
71
+	/**
72
+	 * This will just setup the _events property in the expected format.
73
+	 *
74
+	 * @throws \EE_Error
75
+	 */
76
+	private function _setup_attendees_events()
77
+	{
78
+
79
+		// setup some attendee objects
80
+		$attendees = $this->_get_some_attendees();
81
+
82
+		// if empty $data we'll do a query to get some events from the server. otherwise we'll retrieve the event data for the given ids.
83
+		$events = $this->_get_some_events($this->_data);
84
+
85
+		$answers_n_questions = $this->_get_some_q_and_as();
86
+
87
+		if (count($events) < 1) {
88
+			throw new EE_Error(__(
89
+				'We can\'t generate a preview for you because there are no active events in your database',
90
+				'event_espresso'
91
+			));
92
+		}
93
+
94
+
95
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
96
+
97
+
98
+		// we'll actually use the generated line_item identifiers for our loop
99
+		$dtts = $tkts = array();
100
+		foreach ($events as $id => $event) {
101
+			if (! $event instanceof EE_Event) {
102
+				continue;
103
+			}
104
+			$this->_events[ $id ]['ID']       = $id;
105
+			$this->_events[ $id ]['name']     = $event->get('EVT_name');
106
+			$datetime                       = $event->get_first_related('Datetime');
107
+			$tickets                        = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
108
+				'Ticket',
109
+				array('default_where_conditions' => 'none')
110
+			) : array();
111
+			$this->_events[ $id ]['event']    = $event;
112
+			$this->_events[ $id ]['reg_objs'] = array();
113
+			$this->_events[ $id ]['tkt_objs'] = $tickets;
114
+			$this->_events[ $id ]['dtt_objs'] = array();
115
+
116
+			$dttcache = array();
117
+			$tkts     = array();
118
+			foreach ($tickets as $ticket) {
119
+				if (! $ticket instanceof EE_Ticket) {
120
+					continue;
121
+				}
122
+				$reldatetime                     = $ticket->datetimes();
123
+				$tkts[ $ticket->ID() ]             = array();
124
+				$tkts[ $ticket->ID() ]['ticket']   = $ticket;
125
+				$tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
126
+				$tkts[ $ticket->ID() ]['att_objs'] = $attendees;
127
+				$tkts[ $ticket->ID() ]['count']    = count($attendees);
128
+				$tkts[ $ticket->ID() ]['EE_Event'] = $event;
129
+				foreach ($reldatetime as $datetime) {
130
+					if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
131
+						$this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
132
+						$dtts[ $datetime->ID() ]['datetime']               = $datetime;
133
+						$dtts[ $datetime->ID() ]['tkt_objs'][]             = $ticket;
134
+						$dtts[ $datetime->ID() ]['evt_objs'][]             = $event;
135
+						$dttcache[ $datetime->ID() ]                       = $datetime;
136
+					}
137
+				}
138
+			}
139
+
140
+			$this->_events[ $id ]['total_attendees'] = count($attendees);
141
+			$this->_events[ $id ]['att_objs']        = $attendees;
142
+
143
+			// let's also setup the dummy attendees property!
144
+			foreach ($attendees as $att_key => $attendee) {
145
+				if (! $attendee instanceof EE_Attendee) {
146
+					continue;
147
+				}
148
+				$this->_attendees[ $att_key ]['line_ref'][] = $id;  // so later it can be determined what events this attendee registered for!
149
+				$this->_attendees[ $att_key ]['evt_objs'][] = $event;
150
+				$this->_attendees[ $att_key ]['att_obj']    = $attendee;
151
+				// $this->_attendees[$att_key]['registration_id'] = 0;
152
+				$this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
153
+				$this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
154
+				if ($att_key == 999999991) {
155
+					$this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
+					$this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
+					$this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
158
+				} elseif ($att_key == 999999992) {
159
+					$this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
+					$this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
+					$this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
162
+				} elseif ($att_key == 999999993) {
163
+					$this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
+					$this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
+					$this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
166
+				}
167
+			}
168
+		}
169
+
170
+		$this->tickets            = $tkts;
171
+		$this->datetimes          = $dtts;
172
+		$this->answers            = $answers_n_questions['answers'];
173
+		$this->questions          = $answers_n_questions['questions'];
174
+		$this->total_ticket_count = count($tkts) * count($this->_attendees);
175
+	}
176
+
177
+
178
+	/**
179
+	 * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
180
+	 *
181
+	 * @access private
182
+	 * @return array an array of attendee objects
183
+	 */
184
+	private function _get_some_attendees()
185
+	{
186
+		// let's just setup a dummy array of various attendee details
187
+		$dummy_attendees = array(
188
+			0 => array(
189
+				'Luke',
190
+				'Skywalker',
191
+				'[email protected]',
192
+				'804 Bantha Dr.',
193
+				'Complex 8',
194
+				'Mos Eisley',
195
+				32,
196
+				'US',
197
+				'f0r3e',
198
+				'222-333-4763',
199
+				false,
200
+				'999999991'
201
+			),
202
+			1 => array(
203
+				'Princess',
204
+				'Leia',
205
+				'[email protected]',
206
+				'1456 Valley Way Boulevard',
207
+				'Suite 9',
208
+				'Alderaan',
209
+				15,
210
+				'US',
211
+				'c1h2c',
212
+				'78-123-111-1111',
213
+				false,
214
+				'999999992'
215
+			),
216
+			2 => array(
217
+				'Yoda',
218
+				'I Am',
219
+				'[email protected]',
220
+				'4th Tree',
221
+				'5th Knot',
222
+				'Marsh',
223
+				22,
224
+				'US',
225
+				'l18n',
226
+				'999-999-9999',
227
+				false,
228
+				'999999993'
229
+			),
230
+		);
231
+
232
+		// let's generate the attendee objects
233
+		$attendees = array();
234
+		$var_array = array(
235
+			'fname',
236
+			'lname',
237
+			'email',
238
+			'address',
239
+			'address2',
240
+			'city',
241
+			'staid',
242
+			'cntry',
243
+			'zip',
244
+			'phone',
245
+			'deleted',
246
+			'attid'
247
+		);
248
+
249
+		// EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
250
+		foreach ($dummy_attendees as $dummy) {
251
+			$att = array_combine($var_array, $dummy);
252
+			extract($att);
253
+			/** @var $fname string */
254
+			/** @var $lname string */
255
+			/** @var $address string */
256
+			/** @var $address2 string */
257
+			/** @var $city string */
258
+			/** @var $staid string */
259
+			/** @var $cntry string */
260
+			/** @var $zip string */
261
+			/** @var $email string */
262
+			/** @var $phone string */
263
+			/** @var $attid string */
264
+			$attendees[ $attid ] = EE_Attendee::new_instance(
265
+				array(
266
+					'ATT_fname'    => $fname,
267
+					'ATT_lname'    => $lname,
268
+					'ATT_address'  => $address,
269
+					'ATT_address2' => $address2,
270
+					'ATT_city'     => $city,
271
+					'STA_ID'       => $staid,
272
+					'CNT_ISO'      => $cntry,
273
+					'ATT_zip'      => $zip,
274
+					'ATT_email'    => $email,
275
+					'ATT_phone'    => $phone,
276
+					'ATT_ID'       => $attid
277
+				)
278
+			);
279
+		}
280
+
281
+		return $attendees;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
287
+	 * This will be used in our dummy data setup
288
+	 * @return array
289
+	 */
290
+	private function _get_some_q_and_as()
291
+	{
292
+
293
+
294
+		$quests_array = array(
295
+			0 => array(
296
+				555,
297
+				__('What is your favorite planet?', 'event_espresso'),
298
+				0
299
+			),
300
+			1 => array(
301
+				556,
302
+				__('What is your favorite food?', 'event_espresso'),
303
+				0
304
+			),
305
+			2 => array(
306
+				557,
307
+				__('How many lightyears have you travelled', 'event_espresso'),
308
+				0
309
+			)
310
+		);
311
+
312
+
313
+		$ans_array = array(
314
+			0 => array(
315
+				999,
316
+				555,
317
+				'Tattoine'
318
+			),
319
+			1 => array(
320
+				1000,
321
+				555,
322
+				'Alderaan'
323
+			),
324
+			2 => array(
325
+				1001,
326
+				555,
327
+				'Dantooine'
328
+			),
329
+			3 => array(
330
+				1002,
331
+				556,
332
+				'Fish Fingers'
333
+			),
334
+			4 => array(
335
+				1003,
336
+				556,
337
+				'Sushi'
338
+			),
339
+			5 => array(
340
+				1004,
341
+				556,
342
+				'Water'
343
+			),
344
+			6 => array(
345
+				1005,
346
+				557,
347
+				'A lot',
348
+			),
349
+			7 => array(
350
+				1006,
351
+				557,
352
+				"That's none of your business."
353
+			),
354
+			8 => array(
355
+				1007,
356
+				557,
357
+				"People less travel me then."
358
+			)
359
+		);
360
+
361
+		$qst_columns = array('QST_ID', 'QST_display_text', 'QST_system');
362
+		$ans_columns = array('ANS_ID', 'QST_ID', 'ANS_value');
363
+
364
+		// EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
365
+		// EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
366
+
367
+		$qsts = array();
368
+		// first the questions
369
+		foreach ($quests_array as $qst) {
370
+			$qstobj                  = array_combine($qst_columns, $qst);
371
+			$qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
372
+		}
373
+
374
+		// now the answers (and we'll setup our arrays)
375
+		$q_n_as = array();
376
+		foreach ($ans_array as $ans) {
377
+			$ansobj                             = array_combine($ans_columns, $ans);
378
+			$ansobj                             = EE_Answer::new_instance($ansobj);
379
+			$q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
380
+			$q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
381
+		}
382
+
383
+		return $q_n_as;
384
+	}
385
+
386
+
387
+	/**
388
+	 * Return an array of event objects from the database
389
+	 *
390
+	 * If event ids are not included then we'll just retrieve the first published event from the database.
391
+	 *
392
+	 * @param  array $event_ids if set, this will be an array of event ids to obtain events for.
393
+	 *
394
+	 * @return array    An array of event objects from the db.
395
+	 */
396
+	private function _get_some_events($event_ids = array())
397
+	{
398
+
399
+		// HEY, if we have an evt_id then we want to make sure we use that for the preview (because a specific event template is being viewed);
400
+		$event_ids = isset($_REQUEST['evt_id']) && ! empty($_REQUEST['evt_id'])
401
+			? array($_REQUEST['evt_id'])
402
+			: $event_ids;
403
+
404
+		$limit = ! empty($event_ids)
405
+			? null
406
+			: apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
407
+
408
+		$where = ! empty($event_ids)
409
+			? array(
410
+				'EVT_ID'                 => array('IN', $event_ids),
411
+				'Datetime.Ticket.TKT_ID' => array('>', 1)
412
+			)
413
+			: array('Datetime.Ticket.TKT_ID' => array('>', 1));
414
+
415
+		$events = EE_Registry::instance()->load_model('Event')->get_all(array($where, 'limit' => $limit));
416
+
417
+		return $events;
418
+	}
419
+
420
+
421
+	protected function _setup_data()
422
+	{
423
+
424
+		// need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
425
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
426
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
427
+			$session = EE_Registry::instance()->SSN;
428
+		} else {
429
+			$session = EE_Registry::instance()->load_core('Session');
430
+		}
431
+		$cart = EE_Cart::instance(null, $session);
432
+
433
+
434
+		// add tickets to cart
435
+		foreach ($this->tickets as $ticket) {
436
+			$cart->add_ticket_to_cart($ticket['ticket']);
437
+		}
438
+
439
+
440
+		// setup txn property
441
+		$this->txn = EE_Transaction::new_instance(
442
+			array(
443
+				'TXN_timestamp'    => time(), // unix timestamp
444
+				'TXN_total'        => 0, // txn_total
445
+				'TXN_paid'         => 0, // txn_paid
446
+				'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
447
+				'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
448
+				'TXN_hash_salt'    => null, // hash salt blank as well
449
+				'TXN_ID'           => 999999
450
+			)
451
+		);
452
+
453
+
454
+		// setup reg_objects
455
+		// note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
456
+		$this->reg_objs = array();
457
+		$regid          = 9999990;
458
+		foreach ($this->_attendees as $key => $attendee) {
459
+			// note we need to setup reg_objects for each event this attendee belongs to
460
+			$regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
461
+			$regtxn = $this->txn->ID();
462
+			$regcnt = 1;
463
+			foreach ($attendee['line_ref'] as $evtid) {
464
+				foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
465
+					if (! $ticket instanceof EE_Ticket) {
466
+						continue;
467
+					}
468
+					$reg_array                                        = array(
469
+						'EVT_ID'           => $evtid,
470
+						'ATT_ID'           => $regatt,
471
+						'TXN_ID'           => $regtxn,
472
+						'TKT_ID'           => $ticket->ID(),
473
+						'STS_ID'           => EEM_Registration::status_id_pending_payment,
474
+						'REG_date'         => time(),
475
+						'REG_final_price'  => $ticket->get('TKT_price'),
476
+						'REG_session'      => 'dummy_session_id',
477
+						'REG_code'         => $regid . '-dummy-generated-code',
478
+						'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
479
+						'REG_count'        => $regcnt,
480
+						'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
481
+						'REG_att_is_going' => true,
482
+						'REG_ID'           => $regid
483
+					);
484
+					$REG_OBJ                                          = EE_Registration::new_instance($reg_array);
485
+					$this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
486
+					$this->_events[ $evtid ]['reg_objs'][]              = $REG_OBJ;
487
+					$this->reg_objs[]                                 = $REG_OBJ;
488
+					$this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
489
+
490
+					$regcnt++;
491
+					$regid++;
492
+				}
493
+			}
494
+		}
495
+
496
+
497
+		// setup line items!
498
+		$line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
499
+
500
+		// add tickets
501
+		foreach ($this->tickets as $tktid => $item) {
502
+			$qty    = $item['count'];
503
+			$ticket = $item['ticket'];
504
+			EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
505
+		}
506
+
507
+		$shipping_line_item = EE_Line_Item::new_instance(array(
508
+			'LIN_name'       => __('Shipping Surcharge', 'event_espresso'),
509
+			'LIN_desc'       => __('Sent via Millenium Falcon', 'event_espresso'),
510
+			'LIN_unit_price' => 20,
511
+			'LIN_quantity'   => 1,
512
+			'LIN_is_taxable' => true,
513
+			'LIN_total'      => 20,
514
+			'LIN_type'       => EEM_Line_Item::type_line_item
515
+		));
516
+		EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
517
+		$this->additional_line_items = array($shipping_line_item);
518
+
519
+		// now let's add taxes
520
+		EEH_Line_Item::apply_taxes($line_item_total);
521
+
522
+		// now we should be able to get the items we need from this object
523
+		$event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
524
+		$line_items       = array();
525
+		foreach ($event_line_items as $line_id => $line_item) {
526
+			if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
527
+				continue;
528
+			}
529
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
530
+			foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
531
+				if (! $ticket_line_item instanceof EE_Line_Item) {
532
+					continue;
533
+				}
534
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
535
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
536
+				$line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
537
+				$line_items[ $ticket_line_item->ID() ]['EE_Ticket']             = $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
538
+			}
539
+		}
540
+
541
+		$this->line_items_with_children = $line_items;
542
+		$this->tax_line_items           = $line_item_total->tax_descendants();
543
+
544
+		// add proper total to transaction object.
545
+		$grand_total                 = $line_item_total->recalculate_total_including_taxes();
546
+		$this->grand_total_line_item = $line_item_total;
547
+		$this->txn->set_total($grand_total);
548
+
549
+
550
+		// add additional details for each registration
551
+		foreach ($this->reg_objs as $reg) {
552
+			if (! $reg instanceof EE_Registration) {
553
+				continue;
554
+			}
555
+			$this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
556
+			$this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
557
+			$this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
558
+			$this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
559
+			$this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
560
+			$this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
561
+		}
562
+
563
+
564
+		// events and attendees
565
+		$this->events        = $this->_events;
566
+		$this->attendees     = $this->_attendees;
567
+		$this->registrations = $this->_registrations;
568
+
569
+		$attendees_to_shift = $this->_attendees;
570
+
571
+		// setup primary attendee property
572
+		$this->primary_attendee_data = array(
573
+			'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
574
+				? $this->_attendees[999999991]['att_obj']->fname()
575
+				: '',
576
+
577
+			'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
578
+				? $this->_attendees[999999991]['att_obj']->lname()
579
+				: '',
580
+
581
+			'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
582
+				? $this->_attendees[999999991]['att_obj']->email()
583
+				: '',
584
+
585
+			'att_obj' => $this->_attendees[999999991]['att_obj'],
586
+
587
+			'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs'])
588
+		);
589
+
590
+		// reg_info property
591
+		// note this isn't referenced by any shortcode parsers so we'll ignore for now.
592
+		$this->reg_info = array();
593
+
594
+		// let's set a reg_obj for messengers expecting one.
595
+		$this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
596
+
597
+		// the below are just dummy items.
598
+		$this->user_id     = 1;
599
+		$this->ip_address  = '192.0.2.1';
600
+		$this->user_agent  = '';
601
+		$this->init_access = time();
602
+		$this->last_access = time();
603
+	}
604 604
 }
Please login to merge, or discard this patch.