Completed
Branch BUG/3558-event-drs-save-error (8271de)
by
unknown
05:57 queued 03:06
created
core/db_classes/EE_Event.class.php 1 patch
Indentation   +1482 added lines, -1482 removed lines patch added patch discarded remove patch
@@ -16,1486 +16,1486 @@
 block discarded – undo
16 16
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
17 17
 {
18 18
 
19
-    /**
20
-     * cached value for the the logical active status for the event
21
-     *
22
-     * @see get_active_status()
23
-     * @var string
24
-     */
25
-    protected $_active_status = '';
26
-
27
-    /**
28
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
29
-     *
30
-     * @var EE_Datetime
31
-     */
32
-    protected $_Primary_Datetime;
33
-
34
-    /**
35
-     * @var EventSpacesCalculator $available_spaces_calculator
36
-     */
37
-    protected $available_spaces_calculator;
38
-
39
-
40
-    /**
41
-     * @param array  $props_n_values          incoming values
42
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
43
-     *                                        used.)
44
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
45
-     *                                        date_format and the second value is the time format
46
-     * @return EE_Event
47
-     * @throws EE_Error
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
53
-    }
54
-
55
-
56
-    /**
57
-     * @param array  $props_n_values  incoming values from the database
58
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
-     *                                the website will be used.
60
-     * @return EE_Event
61
-     * @throws EE_Error
62
-     */
63
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
64
-    {
65
-        return new self($props_n_values, true, $timezone);
66
-    }
67
-
68
-
69
-    /**
70
-     * @return EventSpacesCalculator
71
-     * @throws \EE_Error
72
-     */
73
-    public function getAvailableSpacesCalculator()
74
-    {
75
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
76
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
77
-        }
78
-        return $this->available_spaces_calculator;
79
-    }
80
-
81
-
82
-    /**
83
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
84
-     *
85
-     * @param string $field_name
86
-     * @param mixed  $field_value
87
-     * @param bool   $use_default
88
-     * @throws EE_Error
89
-     */
90
-    public function set($field_name, $field_value, $use_default = false)
91
-    {
92
-        switch ($field_name) {
93
-            case 'status':
94
-                $this->set_status($field_value, $use_default);
95
-                break;
96
-            default:
97
-                parent::set($field_name, $field_value, $use_default);
98
-        }
99
-    }
100
-
101
-
102
-    /**
103
-     *    set_status
104
-     * Checks if event status is being changed to SOLD OUT
105
-     * and updates event meta data with previous event status
106
-     * so that we can revert things if/when the event is no longer sold out
107
-     *
108
-     * @access public
109
-     * @param string $new_status
110
-     * @param bool   $use_default
111
-     * @return void
112
-     * @throws EE_Error
113
-     */
114
-    public function set_status($new_status = null, $use_default = false)
115
-    {
116
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
117
-        if (empty($new_status) && ! $use_default) {
118
-            return;
119
-        }
120
-        // get current Event status
121
-        $old_status = $this->status();
122
-        // if status has changed
123
-        if ($old_status !== $new_status) {
124
-            // TO sold_out
125
-            if ($new_status === EEM_Event::sold_out) {
126
-                // save the previous event status so that we can revert if the event is no longer sold out
127
-                $this->add_post_meta('_previous_event_status', $old_status);
128
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
129
-            // OR FROM  sold_out
130
-            } elseif ($old_status === EEM_Event::sold_out) {
131
-                $this->delete_post_meta('_previous_event_status');
132
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
133
-            }
134
-            // clear out the active status so that it gets reset the next time it is requested
135
-            $this->_active_status = null;
136
-            // update status
137
-            parent::set('status', $new_status, $use_default);
138
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
139
-            return;
140
-        }
141
-        // even though the old value matches the new value, it's still good to
142
-        // allow the parent set method to have a say
143
-        parent::set('status', $new_status, $use_default);
144
-    }
145
-
146
-
147
-    /**
148
-     * Gets all the datetimes for this event
149
-     *
150
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
151
-     * @return EE_Base_Class[]|EE_Datetime[]
152
-     * @throws EE_Error
153
-     */
154
-    public function datetimes($query_params = array())
155
-    {
156
-        return $this->get_many_related('Datetime', $query_params);
157
-    }
158
-
159
-
160
-    /**
161
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
162
-     *
163
-     * @return EE_Base_Class[]|EE_Datetime[]
164
-     * @throws EE_Error
165
-     */
166
-    public function datetimes_in_chronological_order()
167
-    {
168
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
169
-    }
170
-
171
-
172
-    /**
173
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
174
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
175
-     * after running our query, so that this timezone isn't set for EVERY query
176
-     * on EEM_Datetime for the rest of the request, no?
177
-     *
178
-     * @param boolean $show_expired whether or not to include expired events
179
-     * @param boolean $show_deleted whether or not to include deleted events
180
-     * @param null    $limit
181
-     * @return EE_Datetime[]
182
-     * @throws EE_Error
183
-     */
184
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
185
-    {
186
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
187
-            $this->ID(),
188
-            $show_expired,
189
-            $show_deleted,
190
-            $limit
191
-        );
192
-    }
193
-
194
-
195
-    /**
196
-     * Returns one related datetime. Mostly only used by some legacy code.
197
-     *
198
-     * @return EE_Base_Class|EE_Datetime
199
-     * @throws EE_Error
200
-     */
201
-    public function first_datetime()
202
-    {
203
-        return $this->get_first_related('Datetime');
204
-    }
205
-
206
-
207
-    /**
208
-     * Returns the 'primary' datetime for the event
209
-     *
210
-     * @param bool $try_to_exclude_expired
211
-     * @param bool $try_to_exclude_deleted
212
-     * @return EE_Datetime
213
-     * @throws EE_Error
214
-     */
215
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
216
-    {
217
-        if (! empty($this->_Primary_Datetime)) {
218
-            return $this->_Primary_Datetime;
219
-        }
220
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
221
-            $this->ID(),
222
-            $try_to_exclude_expired,
223
-            $try_to_exclude_deleted
224
-        );
225
-        return $this->_Primary_Datetime;
226
-    }
227
-
228
-
229
-    /**
230
-     * Gets all the tickets available for purchase of this event
231
-     *
232
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
233
-     * @return EE_Base_Class[]|EE_Ticket[]
234
-     * @throws EE_Error
235
-     */
236
-    public function tickets($query_params = array())
237
-    {
238
-        // first get all datetimes
239
-        $datetimes = $this->datetimes_ordered();
240
-        if (! $datetimes) {
241
-            return array();
242
-        }
243
-        $datetime_ids = array();
244
-        foreach ($datetimes as $datetime) {
245
-            $datetime_ids[] = $datetime->ID();
246
-        }
247
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
248
-        // if incoming $query_params has where conditions let's merge but not override existing.
249
-        if (is_array($query_params) && isset($query_params[0])) {
250
-            $where_params = array_merge($query_params[0], $where_params);
251
-            unset($query_params[0]);
252
-        }
253
-        // now add $where_params to $query_params
254
-        $query_params[0] = $where_params;
255
-        return EEM_Ticket::instance()->get_all($query_params);
256
-    }
257
-
258
-
259
-    /**
260
-     * get all unexpired untrashed tickets
261
-     *
262
-     * @return EE_Ticket[]
263
-     * @throws EE_Error
264
-     */
265
-    public function active_tickets()
266
-    {
267
-        return $this->tickets(
268
-            array(
269
-                array(
270
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
271
-                    'TKT_deleted'  => false,
272
-                ),
273
-            )
274
-        );
275
-    }
276
-
277
-
278
-    /**
279
-     * @return bool
280
-     * @throws EE_Error
281
-     */
282
-    public function additional_limit()
283
-    {
284
-        return $this->get('EVT_additional_limit');
285
-    }
286
-
287
-
288
-    /**
289
-     * @return bool
290
-     * @throws EE_Error
291
-     */
292
-    public function allow_overflow()
293
-    {
294
-        return $this->get('EVT_allow_overflow');
295
-    }
296
-
297
-
298
-    /**
299
-     * @return bool
300
-     * @throws EE_Error
301
-     */
302
-    public function created()
303
-    {
304
-        return $this->get('EVT_created');
305
-    }
306
-
307
-
308
-    /**
309
-     * @return bool
310
-     * @throws EE_Error
311
-     */
312
-    public function description()
313
-    {
314
-        return $this->get('EVT_desc');
315
-    }
316
-
317
-
318
-    /**
319
-     * Runs do_shortcode and wpautop on the description
320
-     *
321
-     * @return string of html
322
-     * @throws EE_Error
323
-     */
324
-    public function description_filtered()
325
-    {
326
-        return $this->get_pretty('EVT_desc');
327
-    }
328
-
329
-
330
-    /**
331
-     * @return bool
332
-     * @throws EE_Error
333
-     */
334
-    public function display_description()
335
-    {
336
-        return $this->get('EVT_display_desc');
337
-    }
338
-
339
-
340
-    /**
341
-     * @return bool
342
-     * @throws EE_Error
343
-     */
344
-    public function display_ticket_selector()
345
-    {
346
-        return (bool) $this->get('EVT_display_ticket_selector');
347
-    }
348
-
349
-
350
-    /**
351
-     * @return bool
352
-     * @throws EE_Error
353
-     */
354
-    public function external_url()
355
-    {
356
-        return $this->get('EVT_external_URL');
357
-    }
358
-
359
-
360
-    /**
361
-     * @return bool
362
-     * @throws EE_Error
363
-     */
364
-    public function member_only()
365
-    {
366
-        return $this->get('EVT_member_only');
367
-    }
368
-
369
-
370
-    /**
371
-     * @return bool
372
-     * @throws EE_Error
373
-     */
374
-    public function phone()
375
-    {
376
-        return $this->get('EVT_phone');
377
-    }
378
-
379
-
380
-    /**
381
-     * @return bool
382
-     * @throws EE_Error
383
-     */
384
-    public function modified()
385
-    {
386
-        return $this->get('EVT_modified');
387
-    }
388
-
389
-
390
-    /**
391
-     * @return bool
392
-     * @throws EE_Error
393
-     */
394
-    public function name()
395
-    {
396
-        return $this->get('EVT_name');
397
-    }
398
-
399
-
400
-    /**
401
-     * @return bool
402
-     * @throws EE_Error
403
-     */
404
-    public function order()
405
-    {
406
-        return $this->get('EVT_order');
407
-    }
408
-
409
-
410
-    /**
411
-     * @return bool|string
412
-     * @throws EE_Error
413
-     */
414
-    public function default_registration_status()
415
-    {
416
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
417
-        return ! empty($event_default_registration_status)
418
-            ? $event_default_registration_status
419
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
420
-    }
421
-
422
-
423
-    /**
424
-     * @param int  $num_words
425
-     * @param null $more
426
-     * @param bool $not_full_desc
427
-     * @return bool|string
428
-     * @throws EE_Error
429
-     */
430
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
431
-    {
432
-        $short_desc = $this->get('EVT_short_desc');
433
-        if (! empty($short_desc) || $not_full_desc) {
434
-            return $short_desc;
435
-        }
436
-        $full_desc = $this->get('EVT_desc');
437
-        return wp_trim_words($full_desc, $num_words, $more);
438
-    }
439
-
440
-
441
-    /**
442
-     * @return bool
443
-     * @throws EE_Error
444
-     */
445
-    public function slug()
446
-    {
447
-        return $this->get('EVT_slug');
448
-    }
449
-
450
-
451
-    /**
452
-     * @return bool
453
-     * @throws EE_Error
454
-     */
455
-    public function timezone_string()
456
-    {
457
-        return $this->get('EVT_timezone_string');
458
-    }
459
-
460
-
461
-    /**
462
-     * @return bool
463
-     * @throws EE_Error
464
-     */
465
-    public function visible_on()
466
-    {
467
-        return $this->get('EVT_visible_on');
468
-    }
469
-
470
-
471
-    /**
472
-     * @return int
473
-     * @throws EE_Error
474
-     */
475
-    public function wp_user()
476
-    {
477
-        return $this->get('EVT_wp_user');
478
-    }
479
-
480
-
481
-    /**
482
-     * @return bool
483
-     * @throws EE_Error
484
-     */
485
-    public function donations()
486
-    {
487
-        return $this->get('EVT_donations');
488
-    }
489
-
490
-
491
-    /**
492
-     * @param $limit
493
-     * @throws EE_Error
494
-     */
495
-    public function set_additional_limit($limit)
496
-    {
497
-        $this->set('EVT_additional_limit', $limit);
498
-    }
499
-
500
-
501
-    /**
502
-     * @param $created
503
-     * @throws EE_Error
504
-     */
505
-    public function set_created($created)
506
-    {
507
-        $this->set('EVT_created', $created);
508
-    }
509
-
510
-
511
-    /**
512
-     * @param $desc
513
-     * @throws EE_Error
514
-     */
515
-    public function set_description($desc)
516
-    {
517
-        $this->set('EVT_desc', $desc);
518
-    }
519
-
520
-
521
-    /**
522
-     * @param $display_desc
523
-     * @throws EE_Error
524
-     */
525
-    public function set_display_description($display_desc)
526
-    {
527
-        $this->set('EVT_display_desc', $display_desc);
528
-    }
529
-
530
-
531
-    /**
532
-     * @param $display_ticket_selector
533
-     * @throws EE_Error
534
-     */
535
-    public function set_display_ticket_selector($display_ticket_selector)
536
-    {
537
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
538
-    }
539
-
540
-
541
-    /**
542
-     * @param $external_url
543
-     * @throws EE_Error
544
-     */
545
-    public function set_external_url($external_url)
546
-    {
547
-        $this->set('EVT_external_URL', $external_url);
548
-    }
549
-
550
-
551
-    /**
552
-     * @param $member_only
553
-     * @throws EE_Error
554
-     */
555
-    public function set_member_only($member_only)
556
-    {
557
-        $this->set('EVT_member_only', $member_only);
558
-    }
559
-
560
-
561
-    /**
562
-     * @param $event_phone
563
-     * @throws EE_Error
564
-     */
565
-    public function set_event_phone($event_phone)
566
-    {
567
-        $this->set('EVT_phone', $event_phone);
568
-    }
569
-
570
-
571
-    /**
572
-     * @param $modified
573
-     * @throws EE_Error
574
-     */
575
-    public function set_modified($modified)
576
-    {
577
-        $this->set('EVT_modified', $modified);
578
-    }
579
-
580
-
581
-    /**
582
-     * @param $name
583
-     * @throws EE_Error
584
-     */
585
-    public function set_name($name)
586
-    {
587
-        $this->set('EVT_name', $name);
588
-    }
589
-
590
-
591
-    /**
592
-     * @param $order
593
-     * @throws EE_Error
594
-     */
595
-    public function set_order($order)
596
-    {
597
-        $this->set('EVT_order', $order);
598
-    }
599
-
600
-
601
-    /**
602
-     * @param $short_desc
603
-     * @throws EE_Error
604
-     */
605
-    public function set_short_description($short_desc)
606
-    {
607
-        $this->set('EVT_short_desc', $short_desc);
608
-    }
609
-
610
-
611
-    /**
612
-     * @param $slug
613
-     * @throws EE_Error
614
-     */
615
-    public function set_slug($slug)
616
-    {
617
-        $this->set('EVT_slug', $slug);
618
-    }
619
-
620
-
621
-    /**
622
-     * @param $timezone_string
623
-     * @throws EE_Error
624
-     */
625
-    public function set_timezone_string($timezone_string)
626
-    {
627
-        $this->set('EVT_timezone_string', $timezone_string);
628
-    }
629
-
630
-
631
-    /**
632
-     * @param $visible_on
633
-     * @throws EE_Error
634
-     */
635
-    public function set_visible_on($visible_on)
636
-    {
637
-        $this->set('EVT_visible_on', $visible_on);
638
-    }
639
-
640
-
641
-    /**
642
-     * @param $wp_user
643
-     * @throws EE_Error
644
-     */
645
-    public function set_wp_user($wp_user)
646
-    {
647
-        $this->set('EVT_wp_user', $wp_user);
648
-    }
649
-
650
-
651
-    /**
652
-     * @param $default_registration_status
653
-     * @throws EE_Error
654
-     */
655
-    public function set_default_registration_status($default_registration_status)
656
-    {
657
-        $this->set('EVT_default_registration_status', $default_registration_status);
658
-    }
659
-
660
-
661
-    /**
662
-     * @param $donations
663
-     * @throws EE_Error
664
-     */
665
-    public function set_donations($donations)
666
-    {
667
-        $this->set('EVT_donations', $donations);
668
-    }
669
-
670
-
671
-    /**
672
-     * Adds a venue to this event
673
-     *
674
-     * @param int|EE_Venue /int $venue_id_or_obj
675
-     * @return EE_Base_Class|EE_Venue
676
-     * @throws EE_Error
677
-     * @throws ReflectionException
678
-     */
679
-    public function add_venue($venue_id_or_obj): EE_Venue
680
-    {
681
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
682
-    }
683
-
684
-
685
-    /**
686
-     * Removes a venue from the event
687
-     *
688
-     * @param EE_Venue /int $venue_id_or_obj
689
-     * @return EE_Base_Class|EE_Venue
690
-     * @throws EE_Error
691
-     * @throws ReflectionException
692
-     */
693
-    public function remove_venue($venue_id_or_obj): EE_Venue
694
-    {
695
-        $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
696
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
697
-    }
698
-
699
-
700
-    /**
701
-     * Gets the venue related to the event. May provide additional $query_params if desired
702
-     *
703
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
704
-     * @return int
705
-     * @throws EE_Error
706
-     * @throws ReflectionException
707
-     */
708
-    public function venue_ID(array $query_params = array()): int
709
-    {
710
-        $venue = $this->get_first_related('Venue', $query_params);
711
-        return $venue instanceof EE_Venue ? $venue->ID() : 0;
712
-    }
713
-
714
-
715
-    /**
716
-     * Gets the venue related to the event. May provide additional $query_params if desired
717
-     *
718
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
719
-     * @return EE_Base_Class|EE_Venue
720
-     * @throws EE_Error
721
-     * @throws ReflectionException
722
-     */
723
-    public function venue(array $query_params = array())
724
-    {
725
-        return $this->get_first_related('Venue', $query_params);
726
-    }
727
-
728
-
729
-    /**
730
-     * @param array $query_params
731
-     * @return EE_Base_Class[]|EE_Venue[]
732
-     * @throws EE_Error
733
-     * @throws ReflectionException
734
-     * @deprecated $VID:$
735
-     */
736
-    public function venues(array $query_params = array()): array
737
-    {
738
-        return [$this->venue($query_params)];
739
-    }
740
-
741
-
742
-    /**
743
-     * check if event id is present and if event is published
744
-     *
745
-     * @access public
746
-     * @return boolean true yes, false no
747
-     * @throws EE_Error
748
-     */
749
-    private function _has_ID_and_is_published()
750
-    {
751
-        // first check if event id is present and not NULL,
752
-        // then check if this event is published (or any of the equivalent "published" statuses)
753
-        return
754
-            $this->ID() && $this->ID() !== null
755
-            && (
756
-                $this->status() === 'publish'
757
-                || $this->status() === EEM_Event::sold_out
758
-                || $this->status() === EEM_Event::postponed
759
-                || $this->status() === EEM_Event::cancelled
760
-            );
761
-    }
762
-
763
-
764
-    /**
765
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
766
-     *
767
-     * @access public
768
-     * @return boolean true yes, false no
769
-     * @throws EE_Error
770
-     */
771
-    public function is_upcoming()
772
-    {
773
-        // check if event id is present and if this event is published
774
-        if ($this->is_inactive()) {
775
-            return false;
776
-        }
777
-        // set initial value
778
-        $upcoming = false;
779
-        // next let's get all datetimes and loop through them
780
-        $datetimes = $this->datetimes_in_chronological_order();
781
-        foreach ($datetimes as $datetime) {
782
-            if ($datetime instanceof EE_Datetime) {
783
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
784
-                if ($datetime->is_expired()) {
785
-                    continue;
786
-                }
787
-                // if this dtt is active then we return false.
788
-                if ($datetime->is_active()) {
789
-                    return false;
790
-                }
791
-                // otherwise let's check upcoming status
792
-                $upcoming = $datetime->is_upcoming();
793
-            }
794
-        }
795
-        return $upcoming;
796
-    }
797
-
798
-
799
-    /**
800
-     * @return bool
801
-     * @throws EE_Error
802
-     */
803
-    public function is_active()
804
-    {
805
-        // check if event id is present and if this event is published
806
-        if ($this->is_inactive()) {
807
-            return false;
808
-        }
809
-        // set initial value
810
-        $active = false;
811
-        // next let's get all datetimes and loop through them
812
-        $datetimes = $this->datetimes_in_chronological_order();
813
-        foreach ($datetimes as $datetime) {
814
-            if ($datetime instanceof EE_Datetime) {
815
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
816
-                if ($datetime->is_expired()) {
817
-                    continue;
818
-                }
819
-                // if this dtt is upcoming then we return false.
820
-                if ($datetime->is_upcoming()) {
821
-                    return false;
822
-                }
823
-                // otherwise let's check active status
824
-                $active = $datetime->is_active();
825
-            }
826
-        }
827
-        return $active;
828
-    }
829
-
830
-
831
-    /**
832
-     * @return bool
833
-     * @throws EE_Error
834
-     */
835
-    public function is_expired()
836
-    {
837
-        // check if event id is present and if this event is published
838
-        if ($this->is_inactive()) {
839
-            return false;
840
-        }
841
-        // set initial value
842
-        $expired = false;
843
-        // first let's get all datetimes and loop through them
844
-        $datetimes = $this->datetimes_in_chronological_order();
845
-        foreach ($datetimes as $datetime) {
846
-            if ($datetime instanceof EE_Datetime) {
847
-                // if this dtt is upcoming or active then we return false.
848
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
849
-                    return false;
850
-                }
851
-                // otherwise let's check active status
852
-                $expired = $datetime->is_expired();
853
-            }
854
-        }
855
-        return $expired;
856
-    }
857
-
858
-
859
-    /**
860
-     * @return bool
861
-     * @throws EE_Error
862
-     */
863
-    public function is_inactive()
864
-    {
865
-        // check if event id is present and if this event is published
866
-        if ($this->_has_ID_and_is_published()) {
867
-            return false;
868
-        }
869
-        return true;
870
-    }
871
-
872
-
873
-    /**
874
-     * calculate spaces remaining based on "saleable" tickets
875
-     *
876
-     * @param array $tickets
877
-     * @param bool  $filtered
878
-     * @return int|float
879
-     * @throws EE_Error
880
-     * @throws DomainException
881
-     * @throws UnexpectedEntityException
882
-     */
883
-    public function spaces_remaining($tickets = array(), $filtered = true)
884
-    {
885
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
886
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
887
-        return $filtered
888
-            ? apply_filters(
889
-                'FHEE_EE_Event__spaces_remaining',
890
-                $spaces_remaining,
891
-                $this,
892
-                $tickets
893
-            )
894
-            : $spaces_remaining;
895
-    }
896
-
897
-
898
-    /**
899
-     *    perform_sold_out_status_check
900
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
901
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
902
-     *
903
-     * @return bool    return the ACTUAL sold out state.
904
-     * @throws EE_Error
905
-     * @throws DomainException
906
-     * @throws UnexpectedEntityException
907
-     */
908
-    public function perform_sold_out_status_check()
909
-    {
910
-        // get all tickets
911
-        $tickets = $this->tickets(
912
-            array(
913
-                'default_where_conditions' => 'none',
914
-                'order_by' => array('TKT_qty' => 'ASC'),
915
-            )
916
-        );
917
-        $all_expired = true;
918
-        foreach ($tickets as $ticket) {
919
-            if (! $ticket->is_expired()) {
920
-                $all_expired = false;
921
-                break;
922
-            }
923
-        }
924
-        // if all the tickets are just expired, then don't update the event status to sold out
925
-        if ($all_expired) {
926
-            return true;
927
-        }
928
-        $spaces_remaining = $this->spaces_remaining($tickets);
929
-        if ($spaces_remaining < 1) {
930
-            if ($this->status() !== EEM_Event::post_status_private) {
931
-                $this->set_status(EEM_Event::sold_out);
932
-                $this->save();
933
-            }
934
-            $sold_out = true;
935
-        } else {
936
-            $sold_out = false;
937
-            // was event previously marked as sold out ?
938
-            if ($this->status() === EEM_Event::sold_out) {
939
-                // revert status to previous value, if it was set
940
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
941
-                if ($previous_event_status) {
942
-                    $this->set_status($previous_event_status);
943
-                    $this->save();
944
-                }
945
-            }
946
-        }
947
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
948
-        return $sold_out;
949
-    }
950
-
951
-
952
-    /**
953
-     * This returns the total remaining spaces for sale on this event.
954
-     *
955
-     * @uses EE_Event::total_available_spaces()
956
-     * @return float|int
957
-     * @throws EE_Error
958
-     * @throws DomainException
959
-     * @throws UnexpectedEntityException
960
-     */
961
-    public function spaces_remaining_for_sale()
962
-    {
963
-        return $this->total_available_spaces(true);
964
-    }
965
-
966
-
967
-    /**
968
-     * This returns the total spaces available for an event
969
-     * while considering all the qtys on the tickets and the reg limits
970
-     * on the datetimes attached to this event.
971
-     *
972
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
973
-     *                              If this is false, then we return the most tickets that could ever be sold
974
-     *                              for this event with the datetime and tickets setup on the event under optimal
975
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
976
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
977
-     *                              may appear to equal remaining tickets.  However, the more tickets are
978
-     *                              sold out, the more accurate the "live" total is.
979
-     * @return float|int
980
-     * @throws EE_Error
981
-     * @throws DomainException
982
-     * @throws UnexpectedEntityException
983
-     */
984
-    public function total_available_spaces($consider_sold = false)
985
-    {
986
-        $spaces_available = $consider_sold
987
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
988
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
989
-        return apply_filters(
990
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
991
-            $spaces_available,
992
-            $this,
993
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
994
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
995
-        );
996
-    }
997
-
998
-
999
-    /**
1000
-     * Checks if the event is set to sold out
1001
-     *
1002
-     * @param  bool $actual whether or not to perform calculations to not only figure the
1003
-     *                      actual status but also to flip the status if necessary to sold
1004
-     *                      out If false, we just check the existing status of the event
1005
-     * @return boolean
1006
-     * @throws EE_Error
1007
-     */
1008
-    public function is_sold_out($actual = false)
1009
-    {
1010
-        if (! $actual) {
1011
-            return $this->status() === EEM_Event::sold_out;
1012
-        }
1013
-        return $this->perform_sold_out_status_check();
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * Checks if the event is marked as postponed
1019
-     *
1020
-     * @return boolean
1021
-     */
1022
-    public function is_postponed()
1023
-    {
1024
-        return $this->status() === EEM_Event::postponed;
1025
-    }
1026
-
1027
-
1028
-    /**
1029
-     * Checks if the event is marked as cancelled
1030
-     *
1031
-     * @return boolean
1032
-     */
1033
-    public function is_cancelled()
1034
-    {
1035
-        return $this->status() === EEM_Event::cancelled;
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1041
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1042
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1043
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1044
-     * the event is considered expired.
1045
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1046
-     * status set on the EVENT when it is not published and thus is done
1047
-     *
1048
-     * @param bool $reset
1049
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1050
-     * @throws EE_Error
1051
-     */
1052
-    public function get_active_status($reset = false)
1053
-    {
1054
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1055
-        if (! empty($this->_active_status) && ! $reset) {
1056
-            return $this->_active_status;
1057
-        }
1058
-        // first check if event id is present on this object
1059
-        if (! $this->ID()) {
1060
-            return false;
1061
-        }
1062
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1063
-        // if event is published:
1064
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1065
-            // active?
1066
-            if (
1067
-                EEM_Datetime::instance()->get_datetime_count_for_status(
1068
-                    EE_Datetime::active,
1069
-                    $where_params_for_event
1070
-                ) > 0
1071
-            ) {
1072
-                $this->_active_status = EE_Datetime::active;
1073
-            } else {
1074
-                // upcoming?
1075
-                if (
1076
-                    EEM_Datetime::instance()->get_datetime_count_for_status(
1077
-                        EE_Datetime::upcoming,
1078
-                        $where_params_for_event
1079
-                    ) > 0
1080
-                ) {
1081
-                    $this->_active_status = EE_Datetime::upcoming;
1082
-                } else {
1083
-                    // expired?
1084
-                    if (
1085
-                        EEM_Datetime::instance()->get_datetime_count_for_status(
1086
-                            EE_Datetime::expired,
1087
-                            $where_params_for_event
1088
-                        ) > 0
1089
-                    ) {
1090
-                        $this->_active_status = EE_Datetime::expired;
1091
-                    } else {
1092
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1093
-                        // attached to the event.  So in this case it will just be considered inactive.
1094
-                        $this->_active_status = EE_Datetime::inactive;
1095
-                    }
1096
-                }
1097
-            }
1098
-        } else {
1099
-            // the event is not published, so let's just set it's active status according to its' post status
1100
-            switch ($this->status()) {
1101
-                case EEM_Event::sold_out:
1102
-                    $this->_active_status = EE_Datetime::sold_out;
1103
-                    break;
1104
-                case EEM_Event::cancelled:
1105
-                    $this->_active_status = EE_Datetime::cancelled;
1106
-                    break;
1107
-                case EEM_Event::postponed:
1108
-                    $this->_active_status = EE_Datetime::postponed;
1109
-                    break;
1110
-                default:
1111
-                    $this->_active_status = EE_Datetime::inactive;
1112
-            }
1113
-        }
1114
-        return $this->_active_status;
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     *    pretty_active_status
1120
-     *
1121
-     * @access public
1122
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1123
-     * @return mixed void|string
1124
-     * @throws EE_Error
1125
-     */
1126
-    public function pretty_active_status($echo = true)
1127
-    {
1128
-        $active_status = $this->get_active_status();
1129
-        $status = '<span class="ee-status event-active-status-'
1130
-                  . $active_status
1131
-                  . '">'
1132
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1133
-                  . '</span>';
1134
-        if ($echo) {
1135
-            echo $status;
1136
-            return '';
1137
-        }
1138
-        return $status;
1139
-    }
1140
-
1141
-
1142
-    /**
1143
-     * @return bool|int
1144
-     * @throws EE_Error
1145
-     */
1146
-    public function get_number_of_tickets_sold()
1147
-    {
1148
-        $tkt_sold = 0;
1149
-        if (! $this->ID()) {
1150
-            return 0;
1151
-        }
1152
-        $datetimes = $this->datetimes();
1153
-        foreach ($datetimes as $datetime) {
1154
-            if ($datetime instanceof EE_Datetime) {
1155
-                $tkt_sold += $datetime->sold();
1156
-            }
1157
-        }
1158
-        return $tkt_sold;
1159
-    }
1160
-
1161
-
1162
-    /**
1163
-     * This just returns a count of all the registrations for this event
1164
-     *
1165
-     * @access  public
1166
-     * @return int
1167
-     * @throws EE_Error
1168
-     */
1169
-    public function get_count_of_all_registrations()
1170
-    {
1171
-        return EEM_Event::instance()->count_related($this, 'Registration');
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * This returns the ticket with the earliest start time that is
1177
-     * available for this event (across all datetimes attached to the event)
1178
-     *
1179
-     * @return EE_Base_Class|EE_Ticket|null
1180
-     * @throws EE_Error
1181
-     */
1182
-    public function get_ticket_with_earliest_start_time()
1183
-    {
1184
-        $where['Datetime.EVT_ID'] = $this->ID();
1185
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1186
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * This returns the ticket with the latest end time that is available
1192
-     * for this event (across all datetimes attached to the event)
1193
-     *
1194
-     * @return EE_Base_Class|EE_Ticket|null
1195
-     * @throws EE_Error
1196
-     */
1197
-    public function get_ticket_with_latest_end_time()
1198
-    {
1199
-        $where['Datetime.EVT_ID'] = $this->ID();
1200
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1201
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * This returns the number of different ticket types currently on sale for this event.
1207
-     *
1208
-     * @return int
1209
-     * @throws EE_Error
1210
-     */
1211
-    public function countTicketsOnSale()
1212
-    {
1213
-        $where = array(
1214
-            'Datetime.EVT_ID' => $this->ID(),
1215
-            'TKT_start_date'  => array('<', time()),
1216
-            'TKT_end_date'    => array('>', time()),
1217
-        );
1218
-        return EEM_Ticket::instance()->count(array($where));
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * This returns whether there are any tickets on sale for this event.
1224
-     *
1225
-     * @return bool true = YES tickets on sale.
1226
-     * @throws EE_Error
1227
-     */
1228
-    public function tickets_on_sale()
1229
-    {
1230
-        return $this->countTicketsOnSale() > 0;
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1236
-     * to check for an external URL first
1237
-     *
1238
-     * @return string
1239
-     * @throws EE_Error
1240
-     */
1241
-    public function get_permalink()
1242
-    {
1243
-        if ($this->external_url()) {
1244
-            return $this->external_url();
1245
-        }
1246
-        return parent::get_permalink();
1247
-    }
1248
-
1249
-
1250
-    /**
1251
-     * Gets the first term for 'espresso_event_categories' we can find
1252
-     *
1253
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1254
-     * @return EE_Base_Class|EE_Term|null
1255
-     * @throws EE_Error
1256
-     */
1257
-    public function first_event_category($query_params = array())
1258
-    {
1259
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1260
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1261
-        return EEM_Term::instance()->get_one($query_params);
1262
-    }
1263
-
1264
-
1265
-    /**
1266
-     * Gets all terms for 'espresso_event_categories' we can find
1267
-     *
1268
-     * @param array $query_params
1269
-     * @return EE_Base_Class[]|EE_Term[]
1270
-     * @throws EE_Error
1271
-     */
1272
-    public function get_all_event_categories($query_params = array())
1273
-    {
1274
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1275
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1276
-        return EEM_Term::instance()->get_all($query_params);
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * Adds a question group to this event
1282
-     *
1283
-     * @param EE_Question_Group|int $question_group_id_or_obj
1284
-     * @param bool $for_primary if true, the question group will be added for the primary
1285
-     *                                           registrant, if false will be added for others. default: false
1286
-     * @return EE_Base_Class|EE_Question_Group
1287
-     * @throws EE_Error
1288
-     * @throws InvalidArgumentException
1289
-     * @throws InvalidDataTypeException
1290
-     * @throws InvalidInterfaceException
1291
-     * @throws ReflectionException
1292
-     */
1293
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1294
-    {
1295
-        // If the row already exists, it will be updated. If it doesn't, it will be inserted.
1296
-        // That's in EE_HABTM_Relation::add_relation_to().
1297
-        return $this->_add_relation_to(
1298
-            $question_group_id_or_obj,
1299
-            'Question_Group',
1300
-            [
1301
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1302
-            ]
1303
-        );
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * Removes a question group from the event
1309
-     *
1310
-     * @param EE_Question_Group|int $question_group_id_or_obj
1311
-     * @param bool $for_primary if true, the question group will be removed from the primary
1312
-     *                                           registrant, if false will be removed from others. default: false
1313
-     * @return EE_Base_Class|EE_Question_Group
1314
-     * @throws EE_Error
1315
-     * @throws InvalidArgumentException
1316
-     * @throws ReflectionException
1317
-     * @throws InvalidDataTypeException
1318
-     * @throws InvalidInterfaceException
1319
-     */
1320
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1321
-    {
1322
-        // If the question group is used for the other type (primary or additional)
1323
-        // then just update it. If not, delete it outright.
1324
-        $existing_relation = $this->get_first_related(
1325
-            'Event_Question_Group',
1326
-            [
1327
-                [
1328
-                    'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1329
-                ]
1330
-            ]
1331
-        );
1332
-        $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1333
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1334
-        if ($existing_relation->get($other_field) === false) {
1335
-            // Delete it. It's now no longer for primary or additional question groups.
1336
-            return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1337
-        }
1338
-        // Just update it. They'll still use this question group for the other category
1339
-        $existing_relation->save(
1340
-            [
1341
-                $field_to_update => false
1342
-            ]
1343
-        );
1344
-    }
1345
-
1346
-
1347
-    /**
1348
-     * Gets all the question groups, ordering them by QSG_order ascending
1349
-     *
1350
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1351
-     * @return EE_Base_Class[]|EE_Question_Group[]
1352
-     * @throws EE_Error
1353
-     */
1354
-    public function question_groups($query_params = array())
1355
-    {
1356
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1357
-        return $this->get_many_related('Question_Group', $query_params);
1358
-    }
1359
-
1360
-
1361
-    /**
1362
-     * Implementation for EEI_Has_Icon interface method.
1363
-     *
1364
-     * @see EEI_Visual_Representation for comments
1365
-     * @return string
1366
-     */
1367
-    public function get_icon()
1368
-    {
1369
-        return '<span class="dashicons dashicons-flag"></span>';
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * Implementation for EEI_Admin_Links interface method.
1375
-     *
1376
-     * @see EEI_Admin_Links for comments
1377
-     * @return string
1378
-     * @throws EE_Error
1379
-     */
1380
-    public function get_admin_details_link()
1381
-    {
1382
-        return $this->get_admin_edit_link();
1383
-    }
1384
-
1385
-
1386
-    /**
1387
-     * Implementation for EEI_Admin_Links interface method.
1388
-     *
1389
-     * @see EEI_Admin_Links for comments
1390
-     * @return string
1391
-     * @throws EE_Error
1392
-     */
1393
-    public function get_admin_edit_link()
1394
-    {
1395
-        return EEH_URL::add_query_args_and_nonce(
1396
-            array(
1397
-                'page'   => 'espresso_events',
1398
-                'action' => 'edit',
1399
-                'post'   => $this->ID(),
1400
-            ),
1401
-            admin_url('admin.php')
1402
-        );
1403
-    }
1404
-
1405
-
1406
-    /**
1407
-     * Implementation for EEI_Admin_Links interface method.
1408
-     *
1409
-     * @see EEI_Admin_Links for comments
1410
-     * @return string
1411
-     */
1412
-    public function get_admin_settings_link()
1413
-    {
1414
-        return EEH_URL::add_query_args_and_nonce(
1415
-            array(
1416
-                'page'   => 'espresso_events',
1417
-                'action' => 'default_event_settings',
1418
-            ),
1419
-            admin_url('admin.php')
1420
-        );
1421
-    }
1422
-
1423
-
1424
-    /**
1425
-     * Implementation for EEI_Admin_Links interface method.
1426
-     *
1427
-     * @see EEI_Admin_Links for comments
1428
-     * @return string
1429
-     */
1430
-    public function get_admin_overview_link()
1431
-    {
1432
-        return EEH_URL::add_query_args_and_nonce(
1433
-            array(
1434
-                'page'   => 'espresso_events',
1435
-                'action' => 'default',
1436
-            ),
1437
-            admin_url('admin.php')
1438
-        );
1439
-    }
1440
-
1441
-
1442
-    /**
1443
-     * @return string|null
1444
-     * @throws EE_Error
1445
-     * @throws ReflectionException
1446
-     */
1447
-    public function registrationFormUuid(): ?string
1448
-    {
1449
-        return $this->get('FSC_UUID');
1450
-    }
1451
-
1452
-
1453
-    /**
1454
-     * Gets all the form sections for this event
1455
-     *
1456
-     * @return EE_Base_Class[]|EE_Form_Section[]
1457
-     * @throws EE_Error
1458
-     * @throws ReflectionException
1459
-     */
1460
-    public function registrationForm()
1461
-    {
1462
-        $FSC_UUID = $this->registrationFormUuid();
1463
-
1464
-        if (empty($FSC_UUID)) {
1465
-            return [];
1466
-        }
1467
-
1468
-        return EEM_Form_Section::instance()->get_all([
1469
-            [
1470
-                'OR' => [
1471
-                    'FSC_UUID'      => $FSC_UUID, // top level form
1472
-                    'FSC_belongsTo' => $FSC_UUID, // child form sections
1473
-                ]
1474
-                ],
1475
-            'order_by' => ['FSC_order' => 'ASC'],
1476
-        ]);
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * @param string $UUID
1482
-     * @throws EE_Error
1483
-     */
1484
-    public function setRegistrationFormUuid(string $UUID): void
1485
-    {
1486
-        if (! Cuid::isCuid($UUID)) {
1487
-            throw new InvalidArgumentException(
1488
-                sprintf(
1489
-                /* translators: 1: UUID value, 2: UUID generator function. */
1490
-                    esc_html__(
1491
-                        'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.',
1492
-                        'event_espresso'
1493
-                    ),
1494
-                    $UUID,
1495
-                    '`Cuid::cuid()`'
1496
-                )
1497
-            );
1498
-        }
1499
-        $this->set('FSC_UUID', $UUID);
1500
-    }
19
+	/**
20
+	 * cached value for the the logical active status for the event
21
+	 *
22
+	 * @see get_active_status()
23
+	 * @var string
24
+	 */
25
+	protected $_active_status = '';
26
+
27
+	/**
28
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
29
+	 *
30
+	 * @var EE_Datetime
31
+	 */
32
+	protected $_Primary_Datetime;
33
+
34
+	/**
35
+	 * @var EventSpacesCalculator $available_spaces_calculator
36
+	 */
37
+	protected $available_spaces_calculator;
38
+
39
+
40
+	/**
41
+	 * @param array  $props_n_values          incoming values
42
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
43
+	 *                                        used.)
44
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
45
+	 *                                        date_format and the second value is the time format
46
+	 * @return EE_Event
47
+	 * @throws EE_Error
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param array  $props_n_values  incoming values from the database
58
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
+	 *                                the website will be used.
60
+	 * @return EE_Event
61
+	 * @throws EE_Error
62
+	 */
63
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
64
+	{
65
+		return new self($props_n_values, true, $timezone);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return EventSpacesCalculator
71
+	 * @throws \EE_Error
72
+	 */
73
+	public function getAvailableSpacesCalculator()
74
+	{
75
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
76
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
77
+		}
78
+		return $this->available_spaces_calculator;
79
+	}
80
+
81
+
82
+	/**
83
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
84
+	 *
85
+	 * @param string $field_name
86
+	 * @param mixed  $field_value
87
+	 * @param bool   $use_default
88
+	 * @throws EE_Error
89
+	 */
90
+	public function set($field_name, $field_value, $use_default = false)
91
+	{
92
+		switch ($field_name) {
93
+			case 'status':
94
+				$this->set_status($field_value, $use_default);
95
+				break;
96
+			default:
97
+				parent::set($field_name, $field_value, $use_default);
98
+		}
99
+	}
100
+
101
+
102
+	/**
103
+	 *    set_status
104
+	 * Checks if event status is being changed to SOLD OUT
105
+	 * and updates event meta data with previous event status
106
+	 * so that we can revert things if/when the event is no longer sold out
107
+	 *
108
+	 * @access public
109
+	 * @param string $new_status
110
+	 * @param bool   $use_default
111
+	 * @return void
112
+	 * @throws EE_Error
113
+	 */
114
+	public function set_status($new_status = null, $use_default = false)
115
+	{
116
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
117
+		if (empty($new_status) && ! $use_default) {
118
+			return;
119
+		}
120
+		// get current Event status
121
+		$old_status = $this->status();
122
+		// if status has changed
123
+		if ($old_status !== $new_status) {
124
+			// TO sold_out
125
+			if ($new_status === EEM_Event::sold_out) {
126
+				// save the previous event status so that we can revert if the event is no longer sold out
127
+				$this->add_post_meta('_previous_event_status', $old_status);
128
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
129
+			// OR FROM  sold_out
130
+			} elseif ($old_status === EEM_Event::sold_out) {
131
+				$this->delete_post_meta('_previous_event_status');
132
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
133
+			}
134
+			// clear out the active status so that it gets reset the next time it is requested
135
+			$this->_active_status = null;
136
+			// update status
137
+			parent::set('status', $new_status, $use_default);
138
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
139
+			return;
140
+		}
141
+		// even though the old value matches the new value, it's still good to
142
+		// allow the parent set method to have a say
143
+		parent::set('status', $new_status, $use_default);
144
+	}
145
+
146
+
147
+	/**
148
+	 * Gets all the datetimes for this event
149
+	 *
150
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
151
+	 * @return EE_Base_Class[]|EE_Datetime[]
152
+	 * @throws EE_Error
153
+	 */
154
+	public function datetimes($query_params = array())
155
+	{
156
+		return $this->get_many_related('Datetime', $query_params);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
162
+	 *
163
+	 * @return EE_Base_Class[]|EE_Datetime[]
164
+	 * @throws EE_Error
165
+	 */
166
+	public function datetimes_in_chronological_order()
167
+	{
168
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
169
+	}
170
+
171
+
172
+	/**
173
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
174
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
175
+	 * after running our query, so that this timezone isn't set for EVERY query
176
+	 * on EEM_Datetime for the rest of the request, no?
177
+	 *
178
+	 * @param boolean $show_expired whether or not to include expired events
179
+	 * @param boolean $show_deleted whether or not to include deleted events
180
+	 * @param null    $limit
181
+	 * @return EE_Datetime[]
182
+	 * @throws EE_Error
183
+	 */
184
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
185
+	{
186
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
187
+			$this->ID(),
188
+			$show_expired,
189
+			$show_deleted,
190
+			$limit
191
+		);
192
+	}
193
+
194
+
195
+	/**
196
+	 * Returns one related datetime. Mostly only used by some legacy code.
197
+	 *
198
+	 * @return EE_Base_Class|EE_Datetime
199
+	 * @throws EE_Error
200
+	 */
201
+	public function first_datetime()
202
+	{
203
+		return $this->get_first_related('Datetime');
204
+	}
205
+
206
+
207
+	/**
208
+	 * Returns the 'primary' datetime for the event
209
+	 *
210
+	 * @param bool $try_to_exclude_expired
211
+	 * @param bool $try_to_exclude_deleted
212
+	 * @return EE_Datetime
213
+	 * @throws EE_Error
214
+	 */
215
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
216
+	{
217
+		if (! empty($this->_Primary_Datetime)) {
218
+			return $this->_Primary_Datetime;
219
+		}
220
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
221
+			$this->ID(),
222
+			$try_to_exclude_expired,
223
+			$try_to_exclude_deleted
224
+		);
225
+		return $this->_Primary_Datetime;
226
+	}
227
+
228
+
229
+	/**
230
+	 * Gets all the tickets available for purchase of this event
231
+	 *
232
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
233
+	 * @return EE_Base_Class[]|EE_Ticket[]
234
+	 * @throws EE_Error
235
+	 */
236
+	public function tickets($query_params = array())
237
+	{
238
+		// first get all datetimes
239
+		$datetimes = $this->datetimes_ordered();
240
+		if (! $datetimes) {
241
+			return array();
242
+		}
243
+		$datetime_ids = array();
244
+		foreach ($datetimes as $datetime) {
245
+			$datetime_ids[] = $datetime->ID();
246
+		}
247
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
248
+		// if incoming $query_params has where conditions let's merge but not override existing.
249
+		if (is_array($query_params) && isset($query_params[0])) {
250
+			$where_params = array_merge($query_params[0], $where_params);
251
+			unset($query_params[0]);
252
+		}
253
+		// now add $where_params to $query_params
254
+		$query_params[0] = $where_params;
255
+		return EEM_Ticket::instance()->get_all($query_params);
256
+	}
257
+
258
+
259
+	/**
260
+	 * get all unexpired untrashed tickets
261
+	 *
262
+	 * @return EE_Ticket[]
263
+	 * @throws EE_Error
264
+	 */
265
+	public function active_tickets()
266
+	{
267
+		return $this->tickets(
268
+			array(
269
+				array(
270
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
271
+					'TKT_deleted'  => false,
272
+				),
273
+			)
274
+		);
275
+	}
276
+
277
+
278
+	/**
279
+	 * @return bool
280
+	 * @throws EE_Error
281
+	 */
282
+	public function additional_limit()
283
+	{
284
+		return $this->get('EVT_additional_limit');
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return bool
290
+	 * @throws EE_Error
291
+	 */
292
+	public function allow_overflow()
293
+	{
294
+		return $this->get('EVT_allow_overflow');
295
+	}
296
+
297
+
298
+	/**
299
+	 * @return bool
300
+	 * @throws EE_Error
301
+	 */
302
+	public function created()
303
+	{
304
+		return $this->get('EVT_created');
305
+	}
306
+
307
+
308
+	/**
309
+	 * @return bool
310
+	 * @throws EE_Error
311
+	 */
312
+	public function description()
313
+	{
314
+		return $this->get('EVT_desc');
315
+	}
316
+
317
+
318
+	/**
319
+	 * Runs do_shortcode and wpautop on the description
320
+	 *
321
+	 * @return string of html
322
+	 * @throws EE_Error
323
+	 */
324
+	public function description_filtered()
325
+	{
326
+		return $this->get_pretty('EVT_desc');
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return bool
332
+	 * @throws EE_Error
333
+	 */
334
+	public function display_description()
335
+	{
336
+		return $this->get('EVT_display_desc');
337
+	}
338
+
339
+
340
+	/**
341
+	 * @return bool
342
+	 * @throws EE_Error
343
+	 */
344
+	public function display_ticket_selector()
345
+	{
346
+		return (bool) $this->get('EVT_display_ticket_selector');
347
+	}
348
+
349
+
350
+	/**
351
+	 * @return bool
352
+	 * @throws EE_Error
353
+	 */
354
+	public function external_url()
355
+	{
356
+		return $this->get('EVT_external_URL');
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return bool
362
+	 * @throws EE_Error
363
+	 */
364
+	public function member_only()
365
+	{
366
+		return $this->get('EVT_member_only');
367
+	}
368
+
369
+
370
+	/**
371
+	 * @return bool
372
+	 * @throws EE_Error
373
+	 */
374
+	public function phone()
375
+	{
376
+		return $this->get('EVT_phone');
377
+	}
378
+
379
+
380
+	/**
381
+	 * @return bool
382
+	 * @throws EE_Error
383
+	 */
384
+	public function modified()
385
+	{
386
+		return $this->get('EVT_modified');
387
+	}
388
+
389
+
390
+	/**
391
+	 * @return bool
392
+	 * @throws EE_Error
393
+	 */
394
+	public function name()
395
+	{
396
+		return $this->get('EVT_name');
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return bool
402
+	 * @throws EE_Error
403
+	 */
404
+	public function order()
405
+	{
406
+		return $this->get('EVT_order');
407
+	}
408
+
409
+
410
+	/**
411
+	 * @return bool|string
412
+	 * @throws EE_Error
413
+	 */
414
+	public function default_registration_status()
415
+	{
416
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
417
+		return ! empty($event_default_registration_status)
418
+			? $event_default_registration_status
419
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
420
+	}
421
+
422
+
423
+	/**
424
+	 * @param int  $num_words
425
+	 * @param null $more
426
+	 * @param bool $not_full_desc
427
+	 * @return bool|string
428
+	 * @throws EE_Error
429
+	 */
430
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
431
+	{
432
+		$short_desc = $this->get('EVT_short_desc');
433
+		if (! empty($short_desc) || $not_full_desc) {
434
+			return $short_desc;
435
+		}
436
+		$full_desc = $this->get('EVT_desc');
437
+		return wp_trim_words($full_desc, $num_words, $more);
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return bool
443
+	 * @throws EE_Error
444
+	 */
445
+	public function slug()
446
+	{
447
+		return $this->get('EVT_slug');
448
+	}
449
+
450
+
451
+	/**
452
+	 * @return bool
453
+	 * @throws EE_Error
454
+	 */
455
+	public function timezone_string()
456
+	{
457
+		return $this->get('EVT_timezone_string');
458
+	}
459
+
460
+
461
+	/**
462
+	 * @return bool
463
+	 * @throws EE_Error
464
+	 */
465
+	public function visible_on()
466
+	{
467
+		return $this->get('EVT_visible_on');
468
+	}
469
+
470
+
471
+	/**
472
+	 * @return int
473
+	 * @throws EE_Error
474
+	 */
475
+	public function wp_user()
476
+	{
477
+		return $this->get('EVT_wp_user');
478
+	}
479
+
480
+
481
+	/**
482
+	 * @return bool
483
+	 * @throws EE_Error
484
+	 */
485
+	public function donations()
486
+	{
487
+		return $this->get('EVT_donations');
488
+	}
489
+
490
+
491
+	/**
492
+	 * @param $limit
493
+	 * @throws EE_Error
494
+	 */
495
+	public function set_additional_limit($limit)
496
+	{
497
+		$this->set('EVT_additional_limit', $limit);
498
+	}
499
+
500
+
501
+	/**
502
+	 * @param $created
503
+	 * @throws EE_Error
504
+	 */
505
+	public function set_created($created)
506
+	{
507
+		$this->set('EVT_created', $created);
508
+	}
509
+
510
+
511
+	/**
512
+	 * @param $desc
513
+	 * @throws EE_Error
514
+	 */
515
+	public function set_description($desc)
516
+	{
517
+		$this->set('EVT_desc', $desc);
518
+	}
519
+
520
+
521
+	/**
522
+	 * @param $display_desc
523
+	 * @throws EE_Error
524
+	 */
525
+	public function set_display_description($display_desc)
526
+	{
527
+		$this->set('EVT_display_desc', $display_desc);
528
+	}
529
+
530
+
531
+	/**
532
+	 * @param $display_ticket_selector
533
+	 * @throws EE_Error
534
+	 */
535
+	public function set_display_ticket_selector($display_ticket_selector)
536
+	{
537
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
538
+	}
539
+
540
+
541
+	/**
542
+	 * @param $external_url
543
+	 * @throws EE_Error
544
+	 */
545
+	public function set_external_url($external_url)
546
+	{
547
+		$this->set('EVT_external_URL', $external_url);
548
+	}
549
+
550
+
551
+	/**
552
+	 * @param $member_only
553
+	 * @throws EE_Error
554
+	 */
555
+	public function set_member_only($member_only)
556
+	{
557
+		$this->set('EVT_member_only', $member_only);
558
+	}
559
+
560
+
561
+	/**
562
+	 * @param $event_phone
563
+	 * @throws EE_Error
564
+	 */
565
+	public function set_event_phone($event_phone)
566
+	{
567
+		$this->set('EVT_phone', $event_phone);
568
+	}
569
+
570
+
571
+	/**
572
+	 * @param $modified
573
+	 * @throws EE_Error
574
+	 */
575
+	public function set_modified($modified)
576
+	{
577
+		$this->set('EVT_modified', $modified);
578
+	}
579
+
580
+
581
+	/**
582
+	 * @param $name
583
+	 * @throws EE_Error
584
+	 */
585
+	public function set_name($name)
586
+	{
587
+		$this->set('EVT_name', $name);
588
+	}
589
+
590
+
591
+	/**
592
+	 * @param $order
593
+	 * @throws EE_Error
594
+	 */
595
+	public function set_order($order)
596
+	{
597
+		$this->set('EVT_order', $order);
598
+	}
599
+
600
+
601
+	/**
602
+	 * @param $short_desc
603
+	 * @throws EE_Error
604
+	 */
605
+	public function set_short_description($short_desc)
606
+	{
607
+		$this->set('EVT_short_desc', $short_desc);
608
+	}
609
+
610
+
611
+	/**
612
+	 * @param $slug
613
+	 * @throws EE_Error
614
+	 */
615
+	public function set_slug($slug)
616
+	{
617
+		$this->set('EVT_slug', $slug);
618
+	}
619
+
620
+
621
+	/**
622
+	 * @param $timezone_string
623
+	 * @throws EE_Error
624
+	 */
625
+	public function set_timezone_string($timezone_string)
626
+	{
627
+		$this->set('EVT_timezone_string', $timezone_string);
628
+	}
629
+
630
+
631
+	/**
632
+	 * @param $visible_on
633
+	 * @throws EE_Error
634
+	 */
635
+	public function set_visible_on($visible_on)
636
+	{
637
+		$this->set('EVT_visible_on', $visible_on);
638
+	}
639
+
640
+
641
+	/**
642
+	 * @param $wp_user
643
+	 * @throws EE_Error
644
+	 */
645
+	public function set_wp_user($wp_user)
646
+	{
647
+		$this->set('EVT_wp_user', $wp_user);
648
+	}
649
+
650
+
651
+	/**
652
+	 * @param $default_registration_status
653
+	 * @throws EE_Error
654
+	 */
655
+	public function set_default_registration_status($default_registration_status)
656
+	{
657
+		$this->set('EVT_default_registration_status', $default_registration_status);
658
+	}
659
+
660
+
661
+	/**
662
+	 * @param $donations
663
+	 * @throws EE_Error
664
+	 */
665
+	public function set_donations($donations)
666
+	{
667
+		$this->set('EVT_donations', $donations);
668
+	}
669
+
670
+
671
+	/**
672
+	 * Adds a venue to this event
673
+	 *
674
+	 * @param int|EE_Venue /int $venue_id_or_obj
675
+	 * @return EE_Base_Class|EE_Venue
676
+	 * @throws EE_Error
677
+	 * @throws ReflectionException
678
+	 */
679
+	public function add_venue($venue_id_or_obj): EE_Venue
680
+	{
681
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
682
+	}
683
+
684
+
685
+	/**
686
+	 * Removes a venue from the event
687
+	 *
688
+	 * @param EE_Venue /int $venue_id_or_obj
689
+	 * @return EE_Base_Class|EE_Venue
690
+	 * @throws EE_Error
691
+	 * @throws ReflectionException
692
+	 */
693
+	public function remove_venue($venue_id_or_obj): EE_Venue
694
+	{
695
+		$venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
696
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
697
+	}
698
+
699
+
700
+	/**
701
+	 * Gets the venue related to the event. May provide additional $query_params if desired
702
+	 *
703
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
704
+	 * @return int
705
+	 * @throws EE_Error
706
+	 * @throws ReflectionException
707
+	 */
708
+	public function venue_ID(array $query_params = array()): int
709
+	{
710
+		$venue = $this->get_first_related('Venue', $query_params);
711
+		return $venue instanceof EE_Venue ? $venue->ID() : 0;
712
+	}
713
+
714
+
715
+	/**
716
+	 * Gets the venue related to the event. May provide additional $query_params if desired
717
+	 *
718
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
719
+	 * @return EE_Base_Class|EE_Venue
720
+	 * @throws EE_Error
721
+	 * @throws ReflectionException
722
+	 */
723
+	public function venue(array $query_params = array())
724
+	{
725
+		return $this->get_first_related('Venue', $query_params);
726
+	}
727
+
728
+
729
+	/**
730
+	 * @param array $query_params
731
+	 * @return EE_Base_Class[]|EE_Venue[]
732
+	 * @throws EE_Error
733
+	 * @throws ReflectionException
734
+	 * @deprecated $VID:$
735
+	 */
736
+	public function venues(array $query_params = array()): array
737
+	{
738
+		return [$this->venue($query_params)];
739
+	}
740
+
741
+
742
+	/**
743
+	 * check if event id is present and if event is published
744
+	 *
745
+	 * @access public
746
+	 * @return boolean true yes, false no
747
+	 * @throws EE_Error
748
+	 */
749
+	private function _has_ID_and_is_published()
750
+	{
751
+		// first check if event id is present and not NULL,
752
+		// then check if this event is published (or any of the equivalent "published" statuses)
753
+		return
754
+			$this->ID() && $this->ID() !== null
755
+			&& (
756
+				$this->status() === 'publish'
757
+				|| $this->status() === EEM_Event::sold_out
758
+				|| $this->status() === EEM_Event::postponed
759
+				|| $this->status() === EEM_Event::cancelled
760
+			);
761
+	}
762
+
763
+
764
+	/**
765
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
766
+	 *
767
+	 * @access public
768
+	 * @return boolean true yes, false no
769
+	 * @throws EE_Error
770
+	 */
771
+	public function is_upcoming()
772
+	{
773
+		// check if event id is present and if this event is published
774
+		if ($this->is_inactive()) {
775
+			return false;
776
+		}
777
+		// set initial value
778
+		$upcoming = false;
779
+		// next let's get all datetimes and loop through them
780
+		$datetimes = $this->datetimes_in_chronological_order();
781
+		foreach ($datetimes as $datetime) {
782
+			if ($datetime instanceof EE_Datetime) {
783
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
784
+				if ($datetime->is_expired()) {
785
+					continue;
786
+				}
787
+				// if this dtt is active then we return false.
788
+				if ($datetime->is_active()) {
789
+					return false;
790
+				}
791
+				// otherwise let's check upcoming status
792
+				$upcoming = $datetime->is_upcoming();
793
+			}
794
+		}
795
+		return $upcoming;
796
+	}
797
+
798
+
799
+	/**
800
+	 * @return bool
801
+	 * @throws EE_Error
802
+	 */
803
+	public function is_active()
804
+	{
805
+		// check if event id is present and if this event is published
806
+		if ($this->is_inactive()) {
807
+			return false;
808
+		}
809
+		// set initial value
810
+		$active = false;
811
+		// next let's get all datetimes and loop through them
812
+		$datetimes = $this->datetimes_in_chronological_order();
813
+		foreach ($datetimes as $datetime) {
814
+			if ($datetime instanceof EE_Datetime) {
815
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
816
+				if ($datetime->is_expired()) {
817
+					continue;
818
+				}
819
+				// if this dtt is upcoming then we return false.
820
+				if ($datetime->is_upcoming()) {
821
+					return false;
822
+				}
823
+				// otherwise let's check active status
824
+				$active = $datetime->is_active();
825
+			}
826
+		}
827
+		return $active;
828
+	}
829
+
830
+
831
+	/**
832
+	 * @return bool
833
+	 * @throws EE_Error
834
+	 */
835
+	public function is_expired()
836
+	{
837
+		// check if event id is present and if this event is published
838
+		if ($this->is_inactive()) {
839
+			return false;
840
+		}
841
+		// set initial value
842
+		$expired = false;
843
+		// first let's get all datetimes and loop through them
844
+		$datetimes = $this->datetimes_in_chronological_order();
845
+		foreach ($datetimes as $datetime) {
846
+			if ($datetime instanceof EE_Datetime) {
847
+				// if this dtt is upcoming or active then we return false.
848
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
849
+					return false;
850
+				}
851
+				// otherwise let's check active status
852
+				$expired = $datetime->is_expired();
853
+			}
854
+		}
855
+		return $expired;
856
+	}
857
+
858
+
859
+	/**
860
+	 * @return bool
861
+	 * @throws EE_Error
862
+	 */
863
+	public function is_inactive()
864
+	{
865
+		// check if event id is present and if this event is published
866
+		if ($this->_has_ID_and_is_published()) {
867
+			return false;
868
+		}
869
+		return true;
870
+	}
871
+
872
+
873
+	/**
874
+	 * calculate spaces remaining based on "saleable" tickets
875
+	 *
876
+	 * @param array $tickets
877
+	 * @param bool  $filtered
878
+	 * @return int|float
879
+	 * @throws EE_Error
880
+	 * @throws DomainException
881
+	 * @throws UnexpectedEntityException
882
+	 */
883
+	public function spaces_remaining($tickets = array(), $filtered = true)
884
+	{
885
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
886
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
887
+		return $filtered
888
+			? apply_filters(
889
+				'FHEE_EE_Event__spaces_remaining',
890
+				$spaces_remaining,
891
+				$this,
892
+				$tickets
893
+			)
894
+			: $spaces_remaining;
895
+	}
896
+
897
+
898
+	/**
899
+	 *    perform_sold_out_status_check
900
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
901
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
902
+	 *
903
+	 * @return bool    return the ACTUAL sold out state.
904
+	 * @throws EE_Error
905
+	 * @throws DomainException
906
+	 * @throws UnexpectedEntityException
907
+	 */
908
+	public function perform_sold_out_status_check()
909
+	{
910
+		// get all tickets
911
+		$tickets = $this->tickets(
912
+			array(
913
+				'default_where_conditions' => 'none',
914
+				'order_by' => array('TKT_qty' => 'ASC'),
915
+			)
916
+		);
917
+		$all_expired = true;
918
+		foreach ($tickets as $ticket) {
919
+			if (! $ticket->is_expired()) {
920
+				$all_expired = false;
921
+				break;
922
+			}
923
+		}
924
+		// if all the tickets are just expired, then don't update the event status to sold out
925
+		if ($all_expired) {
926
+			return true;
927
+		}
928
+		$spaces_remaining = $this->spaces_remaining($tickets);
929
+		if ($spaces_remaining < 1) {
930
+			if ($this->status() !== EEM_Event::post_status_private) {
931
+				$this->set_status(EEM_Event::sold_out);
932
+				$this->save();
933
+			}
934
+			$sold_out = true;
935
+		} else {
936
+			$sold_out = false;
937
+			// was event previously marked as sold out ?
938
+			if ($this->status() === EEM_Event::sold_out) {
939
+				// revert status to previous value, if it was set
940
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
941
+				if ($previous_event_status) {
942
+					$this->set_status($previous_event_status);
943
+					$this->save();
944
+				}
945
+			}
946
+		}
947
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
948
+		return $sold_out;
949
+	}
950
+
951
+
952
+	/**
953
+	 * This returns the total remaining spaces for sale on this event.
954
+	 *
955
+	 * @uses EE_Event::total_available_spaces()
956
+	 * @return float|int
957
+	 * @throws EE_Error
958
+	 * @throws DomainException
959
+	 * @throws UnexpectedEntityException
960
+	 */
961
+	public function spaces_remaining_for_sale()
962
+	{
963
+		return $this->total_available_spaces(true);
964
+	}
965
+
966
+
967
+	/**
968
+	 * This returns the total spaces available for an event
969
+	 * while considering all the qtys on the tickets and the reg limits
970
+	 * on the datetimes attached to this event.
971
+	 *
972
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
973
+	 *                              If this is false, then we return the most tickets that could ever be sold
974
+	 *                              for this event with the datetime and tickets setup on the event under optimal
975
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
976
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
977
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
978
+	 *                              sold out, the more accurate the "live" total is.
979
+	 * @return float|int
980
+	 * @throws EE_Error
981
+	 * @throws DomainException
982
+	 * @throws UnexpectedEntityException
983
+	 */
984
+	public function total_available_spaces($consider_sold = false)
985
+	{
986
+		$spaces_available = $consider_sold
987
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
988
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
989
+		return apply_filters(
990
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
991
+			$spaces_available,
992
+			$this,
993
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
994
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
995
+		);
996
+	}
997
+
998
+
999
+	/**
1000
+	 * Checks if the event is set to sold out
1001
+	 *
1002
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
1003
+	 *                      actual status but also to flip the status if necessary to sold
1004
+	 *                      out If false, we just check the existing status of the event
1005
+	 * @return boolean
1006
+	 * @throws EE_Error
1007
+	 */
1008
+	public function is_sold_out($actual = false)
1009
+	{
1010
+		if (! $actual) {
1011
+			return $this->status() === EEM_Event::sold_out;
1012
+		}
1013
+		return $this->perform_sold_out_status_check();
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * Checks if the event is marked as postponed
1019
+	 *
1020
+	 * @return boolean
1021
+	 */
1022
+	public function is_postponed()
1023
+	{
1024
+		return $this->status() === EEM_Event::postponed;
1025
+	}
1026
+
1027
+
1028
+	/**
1029
+	 * Checks if the event is marked as cancelled
1030
+	 *
1031
+	 * @return boolean
1032
+	 */
1033
+	public function is_cancelled()
1034
+	{
1035
+		return $this->status() === EEM_Event::cancelled;
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1041
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1042
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1043
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1044
+	 * the event is considered expired.
1045
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1046
+	 * status set on the EVENT when it is not published and thus is done
1047
+	 *
1048
+	 * @param bool $reset
1049
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1050
+	 * @throws EE_Error
1051
+	 */
1052
+	public function get_active_status($reset = false)
1053
+	{
1054
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1055
+		if (! empty($this->_active_status) && ! $reset) {
1056
+			return $this->_active_status;
1057
+		}
1058
+		// first check if event id is present on this object
1059
+		if (! $this->ID()) {
1060
+			return false;
1061
+		}
1062
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1063
+		// if event is published:
1064
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1065
+			// active?
1066
+			if (
1067
+				EEM_Datetime::instance()->get_datetime_count_for_status(
1068
+					EE_Datetime::active,
1069
+					$where_params_for_event
1070
+				) > 0
1071
+			) {
1072
+				$this->_active_status = EE_Datetime::active;
1073
+			} else {
1074
+				// upcoming?
1075
+				if (
1076
+					EEM_Datetime::instance()->get_datetime_count_for_status(
1077
+						EE_Datetime::upcoming,
1078
+						$where_params_for_event
1079
+					) > 0
1080
+				) {
1081
+					$this->_active_status = EE_Datetime::upcoming;
1082
+				} else {
1083
+					// expired?
1084
+					if (
1085
+						EEM_Datetime::instance()->get_datetime_count_for_status(
1086
+							EE_Datetime::expired,
1087
+							$where_params_for_event
1088
+						) > 0
1089
+					) {
1090
+						$this->_active_status = EE_Datetime::expired;
1091
+					} else {
1092
+						// it would be odd if things make it this far because it basically means there are no datetime's
1093
+						// attached to the event.  So in this case it will just be considered inactive.
1094
+						$this->_active_status = EE_Datetime::inactive;
1095
+					}
1096
+				}
1097
+			}
1098
+		} else {
1099
+			// the event is not published, so let's just set it's active status according to its' post status
1100
+			switch ($this->status()) {
1101
+				case EEM_Event::sold_out:
1102
+					$this->_active_status = EE_Datetime::sold_out;
1103
+					break;
1104
+				case EEM_Event::cancelled:
1105
+					$this->_active_status = EE_Datetime::cancelled;
1106
+					break;
1107
+				case EEM_Event::postponed:
1108
+					$this->_active_status = EE_Datetime::postponed;
1109
+					break;
1110
+				default:
1111
+					$this->_active_status = EE_Datetime::inactive;
1112
+			}
1113
+		}
1114
+		return $this->_active_status;
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 *    pretty_active_status
1120
+	 *
1121
+	 * @access public
1122
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1123
+	 * @return mixed void|string
1124
+	 * @throws EE_Error
1125
+	 */
1126
+	public function pretty_active_status($echo = true)
1127
+	{
1128
+		$active_status = $this->get_active_status();
1129
+		$status = '<span class="ee-status event-active-status-'
1130
+				  . $active_status
1131
+				  . '">'
1132
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1133
+				  . '</span>';
1134
+		if ($echo) {
1135
+			echo $status;
1136
+			return '';
1137
+		}
1138
+		return $status;
1139
+	}
1140
+
1141
+
1142
+	/**
1143
+	 * @return bool|int
1144
+	 * @throws EE_Error
1145
+	 */
1146
+	public function get_number_of_tickets_sold()
1147
+	{
1148
+		$tkt_sold = 0;
1149
+		if (! $this->ID()) {
1150
+			return 0;
1151
+		}
1152
+		$datetimes = $this->datetimes();
1153
+		foreach ($datetimes as $datetime) {
1154
+			if ($datetime instanceof EE_Datetime) {
1155
+				$tkt_sold += $datetime->sold();
1156
+			}
1157
+		}
1158
+		return $tkt_sold;
1159
+	}
1160
+
1161
+
1162
+	/**
1163
+	 * This just returns a count of all the registrations for this event
1164
+	 *
1165
+	 * @access  public
1166
+	 * @return int
1167
+	 * @throws EE_Error
1168
+	 */
1169
+	public function get_count_of_all_registrations()
1170
+	{
1171
+		return EEM_Event::instance()->count_related($this, 'Registration');
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * This returns the ticket with the earliest start time that is
1177
+	 * available for this event (across all datetimes attached to the event)
1178
+	 *
1179
+	 * @return EE_Base_Class|EE_Ticket|null
1180
+	 * @throws EE_Error
1181
+	 */
1182
+	public function get_ticket_with_earliest_start_time()
1183
+	{
1184
+		$where['Datetime.EVT_ID'] = $this->ID();
1185
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1186
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * This returns the ticket with the latest end time that is available
1192
+	 * for this event (across all datetimes attached to the event)
1193
+	 *
1194
+	 * @return EE_Base_Class|EE_Ticket|null
1195
+	 * @throws EE_Error
1196
+	 */
1197
+	public function get_ticket_with_latest_end_time()
1198
+	{
1199
+		$where['Datetime.EVT_ID'] = $this->ID();
1200
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1201
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * This returns the number of different ticket types currently on sale for this event.
1207
+	 *
1208
+	 * @return int
1209
+	 * @throws EE_Error
1210
+	 */
1211
+	public function countTicketsOnSale()
1212
+	{
1213
+		$where = array(
1214
+			'Datetime.EVT_ID' => $this->ID(),
1215
+			'TKT_start_date'  => array('<', time()),
1216
+			'TKT_end_date'    => array('>', time()),
1217
+		);
1218
+		return EEM_Ticket::instance()->count(array($where));
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * This returns whether there are any tickets on sale for this event.
1224
+	 *
1225
+	 * @return bool true = YES tickets on sale.
1226
+	 * @throws EE_Error
1227
+	 */
1228
+	public function tickets_on_sale()
1229
+	{
1230
+		return $this->countTicketsOnSale() > 0;
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1236
+	 * to check for an external URL first
1237
+	 *
1238
+	 * @return string
1239
+	 * @throws EE_Error
1240
+	 */
1241
+	public function get_permalink()
1242
+	{
1243
+		if ($this->external_url()) {
1244
+			return $this->external_url();
1245
+		}
1246
+		return parent::get_permalink();
1247
+	}
1248
+
1249
+
1250
+	/**
1251
+	 * Gets the first term for 'espresso_event_categories' we can find
1252
+	 *
1253
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1254
+	 * @return EE_Base_Class|EE_Term|null
1255
+	 * @throws EE_Error
1256
+	 */
1257
+	public function first_event_category($query_params = array())
1258
+	{
1259
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1260
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1261
+		return EEM_Term::instance()->get_one($query_params);
1262
+	}
1263
+
1264
+
1265
+	/**
1266
+	 * Gets all terms for 'espresso_event_categories' we can find
1267
+	 *
1268
+	 * @param array $query_params
1269
+	 * @return EE_Base_Class[]|EE_Term[]
1270
+	 * @throws EE_Error
1271
+	 */
1272
+	public function get_all_event_categories($query_params = array())
1273
+	{
1274
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1275
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1276
+		return EEM_Term::instance()->get_all($query_params);
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * Adds a question group to this event
1282
+	 *
1283
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1284
+	 * @param bool $for_primary if true, the question group will be added for the primary
1285
+	 *                                           registrant, if false will be added for others. default: false
1286
+	 * @return EE_Base_Class|EE_Question_Group
1287
+	 * @throws EE_Error
1288
+	 * @throws InvalidArgumentException
1289
+	 * @throws InvalidDataTypeException
1290
+	 * @throws InvalidInterfaceException
1291
+	 * @throws ReflectionException
1292
+	 */
1293
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1294
+	{
1295
+		// If the row already exists, it will be updated. If it doesn't, it will be inserted.
1296
+		// That's in EE_HABTM_Relation::add_relation_to().
1297
+		return $this->_add_relation_to(
1298
+			$question_group_id_or_obj,
1299
+			'Question_Group',
1300
+			[
1301
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1302
+			]
1303
+		);
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * Removes a question group from the event
1309
+	 *
1310
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1311
+	 * @param bool $for_primary if true, the question group will be removed from the primary
1312
+	 *                                           registrant, if false will be removed from others. default: false
1313
+	 * @return EE_Base_Class|EE_Question_Group
1314
+	 * @throws EE_Error
1315
+	 * @throws InvalidArgumentException
1316
+	 * @throws ReflectionException
1317
+	 * @throws InvalidDataTypeException
1318
+	 * @throws InvalidInterfaceException
1319
+	 */
1320
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1321
+	{
1322
+		// If the question group is used for the other type (primary or additional)
1323
+		// then just update it. If not, delete it outright.
1324
+		$existing_relation = $this->get_first_related(
1325
+			'Event_Question_Group',
1326
+			[
1327
+				[
1328
+					'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1329
+				]
1330
+			]
1331
+		);
1332
+		$field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1333
+		$other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1334
+		if ($existing_relation->get($other_field) === false) {
1335
+			// Delete it. It's now no longer for primary or additional question groups.
1336
+			return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1337
+		}
1338
+		// Just update it. They'll still use this question group for the other category
1339
+		$existing_relation->save(
1340
+			[
1341
+				$field_to_update => false
1342
+			]
1343
+		);
1344
+	}
1345
+
1346
+
1347
+	/**
1348
+	 * Gets all the question groups, ordering them by QSG_order ascending
1349
+	 *
1350
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1351
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1352
+	 * @throws EE_Error
1353
+	 */
1354
+	public function question_groups($query_params = array())
1355
+	{
1356
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1357
+		return $this->get_many_related('Question_Group', $query_params);
1358
+	}
1359
+
1360
+
1361
+	/**
1362
+	 * Implementation for EEI_Has_Icon interface method.
1363
+	 *
1364
+	 * @see EEI_Visual_Representation for comments
1365
+	 * @return string
1366
+	 */
1367
+	public function get_icon()
1368
+	{
1369
+		return '<span class="dashicons dashicons-flag"></span>';
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * Implementation for EEI_Admin_Links interface method.
1375
+	 *
1376
+	 * @see EEI_Admin_Links for comments
1377
+	 * @return string
1378
+	 * @throws EE_Error
1379
+	 */
1380
+	public function get_admin_details_link()
1381
+	{
1382
+		return $this->get_admin_edit_link();
1383
+	}
1384
+
1385
+
1386
+	/**
1387
+	 * Implementation for EEI_Admin_Links interface method.
1388
+	 *
1389
+	 * @see EEI_Admin_Links for comments
1390
+	 * @return string
1391
+	 * @throws EE_Error
1392
+	 */
1393
+	public function get_admin_edit_link()
1394
+	{
1395
+		return EEH_URL::add_query_args_and_nonce(
1396
+			array(
1397
+				'page'   => 'espresso_events',
1398
+				'action' => 'edit',
1399
+				'post'   => $this->ID(),
1400
+			),
1401
+			admin_url('admin.php')
1402
+		);
1403
+	}
1404
+
1405
+
1406
+	/**
1407
+	 * Implementation for EEI_Admin_Links interface method.
1408
+	 *
1409
+	 * @see EEI_Admin_Links for comments
1410
+	 * @return string
1411
+	 */
1412
+	public function get_admin_settings_link()
1413
+	{
1414
+		return EEH_URL::add_query_args_and_nonce(
1415
+			array(
1416
+				'page'   => 'espresso_events',
1417
+				'action' => 'default_event_settings',
1418
+			),
1419
+			admin_url('admin.php')
1420
+		);
1421
+	}
1422
+
1423
+
1424
+	/**
1425
+	 * Implementation for EEI_Admin_Links interface method.
1426
+	 *
1427
+	 * @see EEI_Admin_Links for comments
1428
+	 * @return string
1429
+	 */
1430
+	public function get_admin_overview_link()
1431
+	{
1432
+		return EEH_URL::add_query_args_and_nonce(
1433
+			array(
1434
+				'page'   => 'espresso_events',
1435
+				'action' => 'default',
1436
+			),
1437
+			admin_url('admin.php')
1438
+		);
1439
+	}
1440
+
1441
+
1442
+	/**
1443
+	 * @return string|null
1444
+	 * @throws EE_Error
1445
+	 * @throws ReflectionException
1446
+	 */
1447
+	public function registrationFormUuid(): ?string
1448
+	{
1449
+		return $this->get('FSC_UUID');
1450
+	}
1451
+
1452
+
1453
+	/**
1454
+	 * Gets all the form sections for this event
1455
+	 *
1456
+	 * @return EE_Base_Class[]|EE_Form_Section[]
1457
+	 * @throws EE_Error
1458
+	 * @throws ReflectionException
1459
+	 */
1460
+	public function registrationForm()
1461
+	{
1462
+		$FSC_UUID = $this->registrationFormUuid();
1463
+
1464
+		if (empty($FSC_UUID)) {
1465
+			return [];
1466
+		}
1467
+
1468
+		return EEM_Form_Section::instance()->get_all([
1469
+			[
1470
+				'OR' => [
1471
+					'FSC_UUID'      => $FSC_UUID, // top level form
1472
+					'FSC_belongsTo' => $FSC_UUID, // child form sections
1473
+				]
1474
+				],
1475
+			'order_by' => ['FSC_order' => 'ASC'],
1476
+		]);
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * @param string $UUID
1482
+	 * @throws EE_Error
1483
+	 */
1484
+	public function setRegistrationFormUuid(string $UUID): void
1485
+	{
1486
+		if (! Cuid::isCuid($UUID)) {
1487
+			throw new InvalidArgumentException(
1488
+				sprintf(
1489
+				/* translators: 1: UUID value, 2: UUID generator function. */
1490
+					esc_html__(
1491
+						'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.',
1492
+						'event_espresso'
1493
+					),
1494
+					$UUID,
1495
+					'`Cuid::cuid()`'
1496
+				)
1497
+			);
1498
+		}
1499
+		$this->set('FSC_UUID', $UUID);
1500
+	}
1501 1501
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Venue_View.helper.php 1 patch
Indentation   +538 added lines, -539 removed lines patch added patch discarded remove patch
@@ -12,543 +12,542 @@
 block discarded – undo
12 12
 class EEH_Venue_View extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @access    private
17
-     * @var EE_Venue
18
-     */
19
-    private static $_venue = null;
20
-
21
-
22
-
23
-    /**
24
-     *    get_venue
25
-     *    attempts to retrieve an EE_Venue object any way it can
26
-     *
27
-     * @access    public
28
-     * @param int  $VNU_ID
29
-     * @param bool $look_in_event
30
-     * @param bool $privacy_check   Defaults to true.
31
-     *                              When false, means even if the venue is private we return it regardless of access.
32
-     * @param bool $password_check
33
-     * @return \EE_Venue|null
34
-     */
35
-    public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
36
-    {
37
-        $VNU_ID = absint($VNU_ID);
38
-        // do we already have the Venue you are looking for?
39
-        if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
40
-            // If the Venue ID matches $VNU_ID, return the venue.
41
-            if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
42
-                return EEH_Venue_View::_get_venue($privacy_check);
43
-            }
44
-            // If the Venue ID does not match, try pulling a venue using $VNU_ID.
45
-            $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
46
-            if ($venue instanceof EE_Venue) {
47
-                EEH_Venue_View::$_venue = $venue;
48
-                return EEH_Venue_View::_get_venue($privacy_check);
49
-            }
50
-        }
51
-        // international newspaper?
52
-        global $post;
53
-        if ($post instanceof WP_Post) {
54
-            switch ($post->post_type) {
55
-                // if this is being called from an EE_Venue post,
56
-                // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
57
-                // then we can try to just grab the attached EE_Venue object
58
-                case 'espresso_venues':
59
-                    // the post already contains the related EE_Venue object AND one of the following is TRUE:
60
-                    // the requested Venue ID matches the post ID OR...
61
-                    // there was no specific Venue ID requested
62
-                    if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) {
63
-                        // use existing related EE_Venue object
64
-                        EEH_Venue_View::$_venue =  $post->EE_Venue;
65
-                    } elseif ($VNU_ID) {
66
-                        // there WAS a specific Venue ID requested, but it's NOT the current post object
67
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
68
-                    } else {
69
-                        // no specific Venue ID requested, so use post ID to generate EE_Venue object
70
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
71
-                    }
72
-                    break;
73
-
74
-                case 'espresso_events':
75
-                    if ($look_in_event) {
76
-                        // grab the events related venues
77
-                        $venues = EEH_Venue_View::get_event_venues();
78
-                        // make sure the result is an array
79
-                        $venues = is_array($venues) ? $venues : [$venues];
80
-                        // do we have an ID for a specific venue?
81
-                        if ($VNU_ID) {
82
-                            // loop thru the related venues
83
-                            foreach ($venues as $venue) {
84
-                                if ($venue instanceof EE_Venue) {
85
-                                    // until we find the venue we're looking for
86
-                                    if ($venue->ID() == $VNU_ID) {
87
-                                        EEH_Venue_View::$_venue = $venue;
88
-                                        break;
89
-                                    }
90
-                                }
91
-                            }
92
-                        // no venue ID ?
93
-                        // then the global post is an events post and this function was called with no argument
94
-                        } else {
95
-                            // just grab the first related event venue
96
-                            EEH_Venue_View::$_venue = reset($venues);
97
-                        }
98
-                    }
99
-                    break;
100
-            }
101
-        }
102
-        // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
103
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
104
-            // sigh... pull it from the db
105
-            EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
106
-        }
107
-        return EEH_Venue_View::_get_venue($privacy_check, $password_check);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * return a single venue
114
-     *
115
-     * @param bool $privacy_check   Defaults to true.
116
-     *                              When false, means even if the venue is private we return it regardless of access.
117
-     * @param bool $password_check
118
-     * @return  EE_Venue
119
-     */
120
-    protected static function _get_venue($privacy_check = true, $password_check = true)
121
-    {
122
-        // check for private venues.
123
-        if (
124
-            EEH_Venue_View::$_venue instanceof EE_Venue
125
-            && EEH_Venue_View::$_venue->status() == 'private'
126
-            && $privacy_check
127
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
-        ) {
129
-            return null;
130
-        }
131
-        // check for password protected venues
132
-        if (
133
-            EEH_Venue_View::$_venue instanceof EE_Venue
134
-            && $password_check
135
-            && post_password_required(EEH_Venue_View::$_venue->ID())
136
-        ) {
137
-            return null;
138
-        }
139
-        return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     *  get_event_venues
146
-     *
147
-     *  @access     public
148
-     *  @return     EE_Venue[]
149
-     */
150
-    public static function get_event_venues()
151
-    {
152
-        global $post;
153
-        if ($post->post_type == 'espresso_events') {
154
-            if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
155
-                return $post->EE_Event->venue();
156
-            }
157
-        }
158
-        return array();
159
-    }
160
-
161
-
162
-
163
-
164
-    /**
165
-     * Simply checks whether a venue for the given ID (or the internally derived venue is private).
166
-     *
167
-     * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not
168
-     *    private.  So it is important to do explicit boolean checks when using this conditional.
169
-     *
170
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
171
-     *
172
-     * @return bool|null
173
-     */
174
-    public static function is_venue_private($VNU_ID = false)
175
-    {
176
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true);
177
-        if (! $venue instanceof EE_Venue) {
178
-            return null;
179
-        }
180
-
181
-        return $venue->status() == 'private' ? true : false;
182
-    }
183
-
184
-
185
-
186
-
187
-    /**
188
-     * returns true or false if a venue is password protected or not
189
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
-     * @return bool
191
-     */
192
-    public static function is_venue_password_protected($VNU_ID = false)
193
-    {
194
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
195
-        if (
196
-            $venue instanceof EE_Venue
197
-            && post_password_required($venue->ID())
198
-        ) {
199
-            return true;
200
-        }
201
-        return false;
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * If a venue is password protected, this will return the password form for gaining access
208
-     * returns an empty string otherwise
209
-
210
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
211
-     *
212
-     * @return string
213
-     */
214
-    public static function password_protected_venue_form($VNU_ID = false)
215
-    {
216
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
217
-        if (
218
-            $venue instanceof EE_Venue
219
-            && post_password_required($venue->ID())
220
-        ) {
221
-            return get_the_password_form($venue->ID());
222
-        }
223
-        return '';
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     *    venue_description
230
-     *
231
-     * @access    public
232
-     * @param int $VNU_ID
233
-     * @return string
234
-     */
235
-    public static function venue_description($VNU_ID = 0)
236
-    {
237
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
238
-        if ($venue instanceof EE_Venue) {
239
-            return $venue->get_pretty('VNU_desc');
240
-        }
241
-        return '';
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     *    venue_excerpt
248
-     *
249
-     * @access    public
250
-     * @param int $VNU_ID
251
-     * @return string
252
-     */
253
-    public static function venue_excerpt($VNU_ID = 0)
254
-    {
255
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
256
-        if ($venue instanceof EE_Venue) {
257
-            $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
258
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '&hellip;');
259
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
260
-        }
261
-        return '';
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     *    venue_categories
268
-     *
269
-     * @access    public
270
-     * @param int $VNU_ID
271
-     * @param bool $hide_uncategorized
272
-     * @return string
273
-     */
274
-    public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
275
-    {
276
-        $category_links = array();
277
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
278
-        if ($venue instanceof EE_Venue) {
279
-            // get category terms
280
-            if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
281
-                // loop thru terms and create links
282
-                foreach ($venue_categories as $term) {
283
-                    $url = get_term_link($term, 'espresso_venue_categories');
284
-                    if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
285
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
286
-                    }
287
-                }
288
-            }
289
-        }
290
-        return implode(', ', $category_links);
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     *    venue_address
297
-     *
298
-     * @access    public
299
-     * @param string $type
300
-     * @param int $VNU_ID
301
-     * @param bool $use_schema
302
-     * @param bool $add_wrapper
303
-     * @return string
304
-     */
305
-    public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
306
-    {
307
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
308
-        if ($venue instanceof EE_Venue) {
309
-            return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
310
-        }
311
-        return '';
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     *    venue_has_address
318
-     *
319
-     * @access    public
320
-     * @param int $VNU_ID
321
-     * @return bool|string
322
-     */
323
-    public static function venue_has_address($VNU_ID = 0)
324
-    {
325
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
326
-        if ($venue instanceof EE_Venue) {
327
-            return EEH_Address::format($venue, 'inline', false, false);
328
-        }
329
-        return false;
330
-    }
331
-
332
-
333
-
334
-    /**
335
-     *    venue_name
336
-     *
337
-     * @access    public
338
-     * @param    string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website
339
-     * @param int $VNU_ID
340
-     * @return string
341
-     */
342
-    public static function venue_name($link_to = 'details', $VNU_ID = 0)
343
-    {
344
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
345
-        if ($venue instanceof EE_Venue) {
346
-            $venue_name = apply_filters(
347
-                'FHEE__EEH_Venue__venue_name__append_private_venue_name',
348
-                EEH_Venue_View::is_venue_private()
349
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . __('(Private)', 'event_espresso')
350
-                    : EEH_Venue_View::$_venue->name(),
351
-                EEH_Venue_View::$_venue
352
-            );
353
-            $venue_name = EEH_Schema::name($venue_name);
354
-
355
-            // if venue is trashed then ignore the "link to" setting because the venue is trashed.
356
-            if ($venue->get('status') == 'trash') {
357
-                $link_to = '';
358
-            }
359
-            switch ($link_to) {
360
-                case 'details':
361
-                    return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
362
-                break;
363
-
364
-                case 'website':
365
-                    return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
366
-                break;
367
-
368
-                default:
369
-                    return $venue_name;
370
-            }
371
-        }
372
-        return '';
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     *    venue_details_link
379
-     *
380
-     * @access    public
381
-     * @param int $VNU_ID
382
-     * @param    string $text
383
-     * @return string
384
-     */
385
-    public static function venue_details_link($VNU_ID = 0, $text = '')
386
-    {
387
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
388
-        if ($venue instanceof EE_Venue) {
389
-            return EEH_Schema::url(get_permalink($venue->ID()), $text);
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     *    venue_website_link
398
-     *
399
-     * @access    public
400
-     * @param int $VNU_ID
401
-     * @param    string $text
402
-     * @return string
403
-     */
404
-    public static function venue_website_link($VNU_ID = 0, $text = '')
405
-    {
406
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
407
-        if ($venue instanceof EE_Venue) {
408
-            $url = $venue->venue_url();
409
-            $text = ! empty($text) ? $text : $url;
410
-            return ! empty($url) ? EEH_Schema::url($url, $text) : '';
411
-        }
412
-        return '';
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     *    venue_phone
419
-     *
420
-     * @access    public
421
-     * @param int $VNU_ID
422
-     * @return string
423
-     */
424
-    public static function venue_phone($VNU_ID = 0)
425
-    {
426
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
427
-        if ($venue instanceof EE_Venue) {
428
-            return EEH_Schema::telephone($venue->phone());
429
-        }
430
-        return '';
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     *    venue_gmap
437
-     *
438
-     * @access    public
439
-     * @param int $VNU_ID
440
-     * @param bool|string $map_ID a unique identifier for this map
441
-     * @param    array $gmap map options
442
-     * @return string
443
-     */
444
-    public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array())
445
-    {
446
-
447
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
448
-        if ($venue instanceof EE_Venue) {
449
-            // check for global espresso_events post and use it's ID if no map_ID is set
450
-            global $post;
451
-            $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
452
-            // grab map settings
453
-            $map_cfg = EE_Registry::instance()->CFG->map_settings;
454
-            // are maps enabled ?
455
-            if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
456
-                $details_page = is_single();
457
-                $options = array();
458
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
459
-
460
-                $options['location'] = EEH_Address::format($venue, 'inline', false, false);
461
-
462
-                $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width;
463
-                $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width'];
464
-
465
-                $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height;
466
-                $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height'];
467
-
468
-                $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom;
469
-                $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom'];
470
-
471
-                $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav;
472
-                $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display'];
473
-                ;
474
-
475
-                $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size;
476
-                $options['ee_map_nav_size'] =  isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
477
-
478
-                $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type;
479
-                $options['ee_map_type_control'] =  isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
480
-
481
-                $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align;
482
-                $options['ee_map_align'] =  isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align'];
483
-
484
-                $options['ee_static_url'] =  isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
485
-
486
-                return EEH_Maps::google_map($options);
487
-            }
488
-        }
489
-
490
-        return '';
491
-    }
492
-
493
-    /**
494
-     * Gets the HTML to display a static map of the venue
495
-     * @param EE_Venue $venue
496
-     * @param array $atts like EEH_Maps::google_map_link
497
-     * @return string
498
-     */
499
-    public static function espresso_google_static_map(EE_Venue $venue, $atts = array())
500
-    {
501
-        $state = $venue->state_obj();
502
-        $country = $venue->country_obj();
503
-        $atts = shortcode_atts(
504
-            array(
505
-                    'id' => $venue->ID(),
506
-                    'address' => $venue->get('VNU_address'),
507
-                    'city' => $venue->get('VNU_city'),
508
-                    'state' => $state instanceof EE_State ? $state->name() : '',
509
-                    'zip' => $venue->get('VNU_zip'),
510
-                    'country' => $country instanceof EE_Country ? $country->name() : '',
511
-                    'type' => 'map',
512
-                    'map_w' => 200,
513
-                    'map_h' => 200
514
-                    ),
515
-            $atts
516
-        );
517
-        return EEH_Maps::google_map_link($atts);
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     *    edit_venue_link
524
-     *
525
-     * @access    public
526
-     * @param int $VNU_ID
527
-     * @param string $link
528
-     * @param string $before
529
-     * @param string $after
530
-     * @return string
531
-     */
532
-    public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>')
533
-    {
534
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
535
-        if ($venue instanceof EE_Venue) {
536
-            // can the user edit this post ?
537
-            if (current_user_can('edit_post', $venue->ID())) {
538
-                // set link text
539
-                $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso');
540
-                // generate nonce
541
-                $nonce = wp_create_nonce('edit_nonce');
542
-                // generate url to venue editor for this venue
543
-                $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php'));
544
-                // get edit CPT text
545
-                $post_type_obj = get_post_type_object('espresso_venues');
546
-                // build final link html
547
-                $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>';
548
-                // put it all together
549
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
550
-            }
551
-        }
552
-        return '';
553
-    }
15
+	/**
16
+	 * @access    private
17
+	 * @var EE_Venue
18
+	 */
19
+	private static $_venue = null;
20
+
21
+
22
+
23
+	/**
24
+	 *    get_venue
25
+	 *    attempts to retrieve an EE_Venue object any way it can
26
+	 *
27
+	 * @access    public
28
+	 * @param int  $VNU_ID
29
+	 * @param bool $look_in_event
30
+	 * @param bool $privacy_check   Defaults to true.
31
+	 *                              When false, means even if the venue is private we return it regardless of access.
32
+	 * @param bool $password_check
33
+	 * @return \EE_Venue|null
34
+	 */
35
+	public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
36
+	{
37
+		$VNU_ID = absint($VNU_ID);
38
+		// do we already have the Venue you are looking for?
39
+		if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
40
+			// If the Venue ID matches $VNU_ID, return the venue.
41
+			if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
42
+				return EEH_Venue_View::_get_venue($privacy_check);
43
+			}
44
+			// If the Venue ID does not match, try pulling a venue using $VNU_ID.
45
+			$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
46
+			if ($venue instanceof EE_Venue) {
47
+				EEH_Venue_View::$_venue = $venue;
48
+				return EEH_Venue_View::_get_venue($privacy_check);
49
+			}
50
+		}
51
+		// international newspaper?
52
+		global $post;
53
+		if ($post instanceof WP_Post) {
54
+			switch ($post->post_type) {
55
+				// if this is being called from an EE_Venue post,
56
+				// and the EE_Venue post corresponds to the EE_Venue that is being asked for,
57
+				// then we can try to just grab the attached EE_Venue object
58
+				case 'espresso_venues':
59
+					// the post already contains the related EE_Venue object AND one of the following is TRUE:
60
+					// the requested Venue ID matches the post ID OR...
61
+					// there was no specific Venue ID requested
62
+					if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) {
63
+						// use existing related EE_Venue object
64
+						EEH_Venue_View::$_venue =  $post->EE_Venue;
65
+					} elseif ($VNU_ID) {
66
+						// there WAS a specific Venue ID requested, but it's NOT the current post object
67
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
68
+					} else {
69
+						// no specific Venue ID requested, so use post ID to generate EE_Venue object
70
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
71
+					}
72
+					break;
73
+
74
+				case 'espresso_events':
75
+					if ($look_in_event) {
76
+						// grab the events related venues
77
+						$venues = EEH_Venue_View::get_event_venues();
78
+						// make sure the result is an array
79
+						$venues = is_array($venues) ? $venues : [$venues];
80
+						// do we have an ID for a specific venue?
81
+						if ($VNU_ID) {
82
+							// loop thru the related venues
83
+							foreach ($venues as $venue) {
84
+								if ($venue instanceof EE_Venue) {
85
+									// until we find the venue we're looking for
86
+									if ($venue->ID() == $VNU_ID) {
87
+										EEH_Venue_View::$_venue = $venue;
88
+										break;
89
+									}
90
+								}
91
+							}
92
+						// no venue ID ?
93
+						// then the global post is an events post and this function was called with no argument
94
+						} else {
95
+							// just grab the first related event venue
96
+							EEH_Venue_View::$_venue = reset($venues);
97
+						}
98
+					}
99
+					break;
100
+			}
101
+		}
102
+		// now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
103
+		if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
104
+			// sigh... pull it from the db
105
+			EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
106
+		}
107
+		return EEH_Venue_View::_get_venue($privacy_check, $password_check);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * return a single venue
114
+	 *
115
+	 * @param bool $privacy_check   Defaults to true.
116
+	 *                              When false, means even if the venue is private we return it regardless of access.
117
+	 * @param bool $password_check
118
+	 * @return  EE_Venue
119
+	 */
120
+	protected static function _get_venue($privacy_check = true, $password_check = true)
121
+	{
122
+		// check for private venues.
123
+		if (
124
+			EEH_Venue_View::$_venue instanceof EE_Venue
125
+			&& EEH_Venue_View::$_venue->status() == 'private'
126
+			&& $privacy_check
127
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
+		) {
129
+			return null;
130
+		}
131
+		// check for password protected venues
132
+		if (
133
+			EEH_Venue_View::$_venue instanceof EE_Venue
134
+			&& $password_check
135
+			&& post_password_required(EEH_Venue_View::$_venue->ID())
136
+		) {
137
+			return null;
138
+		}
139
+		return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 *  get_event_venues
146
+	 *
147
+	 *  @access     public
148
+	 *  @return     EE_Venue[]
149
+	 */
150
+	public static function get_event_venues()
151
+	{
152
+		global $post;
153
+		if ($post->post_type == 'espresso_events') {
154
+			if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
155
+				return $post->EE_Event->venue();
156
+			}
157
+		}
158
+		return array();
159
+	}
160
+
161
+
162
+
163
+
164
+	/**
165
+	 * Simply checks whether a venue for the given ID (or the internally derived venue is private).
166
+	 *
167
+	 * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not
168
+	 *    private.  So it is important to do explicit boolean checks when using this conditional.
169
+	 *
170
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
171
+	 *
172
+	 * @return bool|null
173
+	 */
174
+	public static function is_venue_private($VNU_ID = false)
175
+	{
176
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true);
177
+		if (! $venue instanceof EE_Venue) {
178
+			return null;
179
+		}
180
+
181
+		return $venue->status() == 'private' ? true : false;
182
+	}
183
+
184
+
185
+
186
+
187
+	/**
188
+	 * returns true or false if a venue is password protected or not
189
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
+	 * @return bool
191
+	 */
192
+	public static function is_venue_password_protected($VNU_ID = false)
193
+	{
194
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
195
+		if (
196
+			$venue instanceof EE_Venue
197
+			&& post_password_required($venue->ID())
198
+		) {
199
+			return true;
200
+		}
201
+		return false;
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * If a venue is password protected, this will return the password form for gaining access
208
+	 * returns an empty string otherwise
209
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
210
+	 *
211
+	 * @return string
212
+	 */
213
+	public static function password_protected_venue_form($VNU_ID = false)
214
+	{
215
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
216
+		if (
217
+			$venue instanceof EE_Venue
218
+			&& post_password_required($venue->ID())
219
+		) {
220
+			return get_the_password_form($venue->ID());
221
+		}
222
+		return '';
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 *    venue_description
229
+	 *
230
+	 * @access    public
231
+	 * @param int $VNU_ID
232
+	 * @return string
233
+	 */
234
+	public static function venue_description($VNU_ID = 0)
235
+	{
236
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
237
+		if ($venue instanceof EE_Venue) {
238
+			return $venue->get_pretty('VNU_desc');
239
+		}
240
+		return '';
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 *    venue_excerpt
247
+	 *
248
+	 * @access    public
249
+	 * @param int $VNU_ID
250
+	 * @return string
251
+	 */
252
+	public static function venue_excerpt($VNU_ID = 0)
253
+	{
254
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
255
+		if ($venue instanceof EE_Venue) {
256
+			$excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
257
+			$venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '&hellip;');
258
+			return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
259
+		}
260
+		return '';
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 *    venue_categories
267
+	 *
268
+	 * @access    public
269
+	 * @param int $VNU_ID
270
+	 * @param bool $hide_uncategorized
271
+	 * @return string
272
+	 */
273
+	public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
274
+	{
275
+		$category_links = array();
276
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
277
+		if ($venue instanceof EE_Venue) {
278
+			// get category terms
279
+			if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
280
+				// loop thru terms and create links
281
+				foreach ($venue_categories as $term) {
282
+					$url = get_term_link($term, 'espresso_venue_categories');
283
+					if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) {
284
+						$category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
285
+					}
286
+				}
287
+			}
288
+		}
289
+		return implode(', ', $category_links);
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    venue_address
296
+	 *
297
+	 * @access    public
298
+	 * @param string $type
299
+	 * @param int $VNU_ID
300
+	 * @param bool $use_schema
301
+	 * @param bool $add_wrapper
302
+	 * @return string
303
+	 */
304
+	public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
305
+	{
306
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
307
+		if ($venue instanceof EE_Venue) {
308
+			return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
309
+		}
310
+		return '';
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 *    venue_has_address
317
+	 *
318
+	 * @access    public
319
+	 * @param int $VNU_ID
320
+	 * @return bool|string
321
+	 */
322
+	public static function venue_has_address($VNU_ID = 0)
323
+	{
324
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
325
+		if ($venue instanceof EE_Venue) {
326
+			return EEH_Address::format($venue, 'inline', false, false);
327
+		}
328
+		return false;
329
+	}
330
+
331
+
332
+
333
+	/**
334
+	 *    venue_name
335
+	 *
336
+	 * @access    public
337
+	 * @param    string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website
338
+	 * @param int $VNU_ID
339
+	 * @return string
340
+	 */
341
+	public static function venue_name($link_to = 'details', $VNU_ID = 0)
342
+	{
343
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
344
+		if ($venue instanceof EE_Venue) {
345
+			$venue_name = apply_filters(
346
+				'FHEE__EEH_Venue__venue_name__append_private_venue_name',
347
+				EEH_Venue_View::is_venue_private()
348
+					? EEH_Venue_View::$_venue->name() . "&nbsp;" . __('(Private)', 'event_espresso')
349
+					: EEH_Venue_View::$_venue->name(),
350
+				EEH_Venue_View::$_venue
351
+			);
352
+			$venue_name = EEH_Schema::name($venue_name);
353
+
354
+			// if venue is trashed then ignore the "link to" setting because the venue is trashed.
355
+			if ($venue->get('status') == 'trash') {
356
+				$link_to = '';
357
+			}
358
+			switch ($link_to) {
359
+				case 'details':
360
+					return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
361
+				break;
362
+
363
+				case 'website':
364
+					return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
365
+				break;
366
+
367
+				default:
368
+					return $venue_name;
369
+			}
370
+		}
371
+		return '';
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 *    venue_details_link
378
+	 *
379
+	 * @access    public
380
+	 * @param int $VNU_ID
381
+	 * @param    string $text
382
+	 * @return string
383
+	 */
384
+	public static function venue_details_link($VNU_ID = 0, $text = '')
385
+	{
386
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
387
+		if ($venue instanceof EE_Venue) {
388
+			return EEH_Schema::url(get_permalink($venue->ID()), $text);
389
+		}
390
+		return '';
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 *    venue_website_link
397
+	 *
398
+	 * @access    public
399
+	 * @param int $VNU_ID
400
+	 * @param    string $text
401
+	 * @return string
402
+	 */
403
+	public static function venue_website_link($VNU_ID = 0, $text = '')
404
+	{
405
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
406
+		if ($venue instanceof EE_Venue) {
407
+			$url = $venue->venue_url();
408
+			$text = ! empty($text) ? $text : $url;
409
+			return ! empty($url) ? EEH_Schema::url($url, $text) : '';
410
+		}
411
+		return '';
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 *    venue_phone
418
+	 *
419
+	 * @access    public
420
+	 * @param int $VNU_ID
421
+	 * @return string
422
+	 */
423
+	public static function venue_phone($VNU_ID = 0)
424
+	{
425
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
426
+		if ($venue instanceof EE_Venue) {
427
+			return EEH_Schema::telephone($venue->phone());
428
+		}
429
+		return '';
430
+	}
431
+
432
+
433
+
434
+	/**
435
+	 *    venue_gmap
436
+	 *
437
+	 * @access    public
438
+	 * @param int $VNU_ID
439
+	 * @param bool|string $map_ID a unique identifier for this map
440
+	 * @param    array $gmap map options
441
+	 * @return string
442
+	 */
443
+	public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array())
444
+	{
445
+
446
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
447
+		if ($venue instanceof EE_Venue) {
448
+			// check for global espresso_events post and use it's ID if no map_ID is set
449
+			global $post;
450
+			$map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
451
+			// grab map settings
452
+			$map_cfg = EE_Registry::instance()->CFG->map_settings;
453
+			// are maps enabled ?
454
+			if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
455
+				$details_page = is_single();
456
+				$options = array();
457
+				$options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/;
458
+
459
+				$options['location'] = EEH_Address::format($venue, 'inline', false, false);
460
+
461
+				$options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width;
462
+				$options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width'];
463
+
464
+				$options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height;
465
+				$options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height'];
466
+
467
+				$options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom;
468
+				$options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom'];
469
+
470
+				$options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav;
471
+				$options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display'];
472
+				;
473
+
474
+				$options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size;
475
+				$options['ee_map_nav_size'] =  isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size'];
476
+
477
+				$options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type;
478
+				$options['ee_map_type_control'] =  isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control'];
479
+
480
+				$options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align;
481
+				$options['ee_map_align'] =  isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align'];
482
+
483
+				$options['ee_static_url'] =  isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link();
484
+
485
+				return EEH_Maps::google_map($options);
486
+			}
487
+		}
488
+
489
+		return '';
490
+	}
491
+
492
+	/**
493
+	 * Gets the HTML to display a static map of the venue
494
+	 * @param EE_Venue $venue
495
+	 * @param array $atts like EEH_Maps::google_map_link
496
+	 * @return string
497
+	 */
498
+	public static function espresso_google_static_map(EE_Venue $venue, $atts = array())
499
+	{
500
+		$state = $venue->state_obj();
501
+		$country = $venue->country_obj();
502
+		$atts = shortcode_atts(
503
+			array(
504
+					'id' => $venue->ID(),
505
+					'address' => $venue->get('VNU_address'),
506
+					'city' => $venue->get('VNU_city'),
507
+					'state' => $state instanceof EE_State ? $state->name() : '',
508
+					'zip' => $venue->get('VNU_zip'),
509
+					'country' => $country instanceof EE_Country ? $country->name() : '',
510
+					'type' => 'map',
511
+					'map_w' => 200,
512
+					'map_h' => 200
513
+					),
514
+			$atts
515
+		);
516
+		return EEH_Maps::google_map_link($atts);
517
+	}
518
+
519
+
520
+
521
+	/**
522
+	 *    edit_venue_link
523
+	 *
524
+	 * @access    public
525
+	 * @param int $VNU_ID
526
+	 * @param string $link
527
+	 * @param string $before
528
+	 * @param string $after
529
+	 * @return string
530
+	 */
531
+	public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>')
532
+	{
533
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
534
+		if ($venue instanceof EE_Venue) {
535
+			// can the user edit this post ?
536
+			if (current_user_can('edit_post', $venue->ID())) {
537
+				// set link text
538
+				$link = ! empty($link) ? $link : __('edit this venue', 'event_espresso');
539
+				// generate nonce
540
+				$nonce = wp_create_nonce('edit_nonce');
541
+				// generate url to venue editor for this venue
542
+				$url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php'));
543
+				// get edit CPT text
544
+				$post_type_obj = get_post_type_object('espresso_venues');
545
+				// build final link html
546
+				$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>';
547
+				// put it all together
548
+				return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
549
+			}
550
+		}
551
+		return '';
552
+	}
554 553
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4112 added lines, -4112 removed lines patch added patch discarded remove patch
@@ -18,4186 +18,4186 @@
 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;
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 123
 
124
-    // set via request page and action args.
125
-    protected $_current_page;
124
+	// set via request page and action args.
125
+	protected $_current_page;
126 126
 
127
-    protected $_current_view;
127
+	protected $_current_view;
128 128
 
129
-    protected $_current_page_view_url;
129
+	protected $_current_page_view_url;
130 130
 
131
-    // sanitized request action (and nonce)
131
+	// sanitized request action (and nonce)
132 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
-     * whether or not initializePage() has run
184
-     *
185
-     * @var boolean
186
-     */
187
-    protected $initialized = false;
188
-
189
-    /**
190
-     * @var FeatureFlags
191
-     */
192
-    protected $feature;
193
-
194
-
195
-    /**
196
-     * @Constructor
197
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     * @throws ReflectionException
202
-     */
203
-    public function __construct($routing = true)
204
-    {
205
-        $this->loader = LoaderFactory::getLoader();
206
-        $this->feature = $this->loader->getShared(FeatureFlags::class);
207
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
208
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
209
-            $this->_is_caf = true;
210
-        }
211
-        $this->_yes_no_values = array(
212
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
213
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
214
-        );
215
-        // set the _req_data property.
216
-        $this->_req_data = array_merge($_GET, $_POST);
217
-        // routing enabled?
218
-        $this->_routing = $routing;
219
-    }
220
-
221
-
222
-    /**
223
-     * @return EE_Admin_Config
224
-     */
225
-    public function adminConfig(): EE_Admin_Config
226
-    {
227
-        return $this->admin_config;
228
-    }
229
-
230
-
231
-    /**
232
-     * @return FeatureFlags
233
-     */
234
-    public function feature(): FeatureFlags
235
-    {
236
-        return $this->feature;
237
-    }
238
-
239
-
240
-    /**
241
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
242
-     * for child classes that needed to set properties prior to these methods getting called,
243
-     * but also needed the parent class to have its construction completed as well.
244
-     * Bottom line is that constructors should ONLY be used for setting initial properties
245
-     * and any complex initialization logic should only run after instantiation is complete.
246
-     *
247
-     * This method gets called immediately after construction from within
248
-     *      EE_Admin_Page_Init::_initialize_admin_page()
249
-     *
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     * @throws ReflectionException
255
-     * @since $VID:$
256
-     */
257
-    public function initializePage()
258
-    {
259
-        if ($this->initialized) {
260
-            return;
261
-        }
262
-        // set initial page props (child method)
263
-        $this->_init_page_props();
264
-        // set global defaults
265
-        $this->_set_defaults();
266
-        // set early because incoming requests could be ajax related and we need to register those hooks.
267
-        $this->_global_ajax_hooks();
268
-        $this->_ajax_hooks();
269
-        // other_page_hooks have to be early too.
270
-        $this->_do_other_page_hooks();
271
-        // This just allows us to have extending classes do something specific
272
-        // before the parent constructor runs _page_setup().
273
-        if (method_exists($this, '_before_page_setup')) {
274
-            $this->_before_page_setup();
275
-        }
276
-        // set up page dependencies
277
-        $this->_page_setup();
278
-        $this->initialized = true;
279
-    }
280
-
281
-
282
-    /**
283
-     * _init_page_props
284
-     * Child classes use to set at least the following properties:
285
-     * $page_slug.
286
-     * $page_label.
287
-     *
288
-     * @abstract
289
-     * @return void
290
-     */
291
-    abstract protected function _init_page_props();
292
-
293
-
294
-    /**
295
-     * _ajax_hooks
296
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
297
-     * Note: within the ajax callback methods.
298
-     *
299
-     * @abstract
300
-     * @return void
301
-     */
302
-    abstract protected function _ajax_hooks();
303
-
304
-
305
-    /**
306
-     * _define_page_props
307
-     * child classes define page properties in here.  Must include at least:
308
-     * $_admin_base_url = base_url for all admin pages
309
-     * $_admin_page_title = default admin_page_title for admin pages
310
-     * $_labels = array of default labels for various automatically generated elements:
311
-     *    array(
312
-     *        'buttons' => array(
313
-     *            'add' => esc_html__('label for add new button'),
314
-     *            'edit' => esc_html__('label for edit button'),
315
-     *            'delete' => esc_html__('label for delete button')
316
-     *            )
317
-     *        )
318
-     *
319
-     * @abstract
320
-     * @return void
321
-     */
322
-    abstract protected function _define_page_props();
323
-
324
-
325
-    /**
326
-     * _set_page_routes
327
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
328
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
329
-     * have a 'default' route. Here's the format
330
-     * $this->_page_routes = array(
331
-     *        'default' => array(
332
-     *            'func' => '_default_method_handling_route',
333
-     *            'args' => array('array','of','args'),
334
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
335
-     *            ajax request, backend processing)
336
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
337
-     *            headers route after.  The string you enter here should match the defined route reference for a
338
-     *            headers sent route.
339
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
340
-     *            this route.
341
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
342
-     *            checks).
343
-     *        ),
344
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
345
-     *        handling method.
346
-     *        )
347
-     * )
348
-     *
349
-     * @abstract
350
-     * @return void
351
-     */
352
-    abstract protected function _set_page_routes();
353
-
354
-
355
-    /**
356
-     * _set_page_config
357
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
358
-     * array corresponds to the page_route for the loaded page. Format:
359
-     * $this->_page_config = array(
360
-     *        'default' => array(
361
-     *            'labels' => array(
362
-     *                'buttons' => array(
363
-     *                    'add' => esc_html__('label for adding item'),
364
-     *                    'edit' => esc_html__('label for editing item'),
365
-     *                    'delete' => esc_html__('label for deleting item')
366
-     *                ),
367
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
368
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
369
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
370
-     *            _define_page_props() method
371
-     *            'nav' => array(
372
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
373
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
374
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
375
-     *                'order' => 10, //required to indicate tab position.
376
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
377
-     *                displayed then add this parameter.
378
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
379
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
380
-     *            metaboxes set for eventespresso admin pages.
381
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
382
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
383
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
384
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
385
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
386
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
387
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
388
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
389
-     *            want to display.
390
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
391
-     *                'tab_id' => array(
392
-     *                    'title' => 'tab_title',
393
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
394
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
395
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
396
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
397
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
398
-     *                    attempt to use the callback which should match the name of a method in the class
399
-     *                    ),
400
-     *                'tab2_id' => array(
401
-     *                    'title' => 'tab2 title',
402
-     *                    'filename' => 'file_name_2'
403
-     *                    'callback' => 'callback_method_for_content',
404
-     *                 ),
405
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
406
-     *            help tab area on an admin page. @link
407
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
408
-     *            'help_tour' => array(
409
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
410
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
411
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
412
-     *            ),
413
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
414
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
415
-     *            just set
416
-     *            'require_nonce' to FALSE
417
-     *            )
418
-     * )
419
-     *
420
-     * @abstract
421
-     * @return void
422
-     */
423
-    abstract protected function _set_page_config();
424
-
425
-
426
-
427
-
428
-
429
-    /** end sample help_tour methods **/
430
-    /**
431
-     * _add_screen_options
432
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
433
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
434
-     * to a particular view.
435
-     *
436
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
437
-     *         see also WP_Screen object documents...
438
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
439
-     * @abstract
440
-     * @return void
441
-     */
442
-    abstract protected function _add_screen_options();
443
-
444
-
445
-    /**
446
-     * _add_feature_pointers
447
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
448
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
449
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
450
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
451
-     * extended) also see:
452
-     *
453
-     * @link   http://eamann.com/tech/wordpress-portland/
454
-     * @abstract
455
-     * @return void
456
-     */
457
-    abstract protected function _add_feature_pointers();
458
-
459
-
460
-    /**
461
-     * load_scripts_styles
462
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
463
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
464
-     * scripts/styles per view by putting them in a dynamic function in this format
465
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
466
-     *
467
-     * @abstract
468
-     * @return void
469
-     */
470
-    abstract public function load_scripts_styles();
471
-
472
-
473
-    /**
474
-     * admin_init
475
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
476
-     * all pages/views loaded by child class.
477
-     *
478
-     * @abstract
479
-     * @return void
480
-     */
481
-    abstract public function admin_init();
482
-
483
-
484
-    /**
485
-     * admin_notices
486
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
487
-     * all pages/views loaded by child class.
488
-     *
489
-     * @abstract
490
-     * @return void
491
-     */
492
-    abstract public function admin_notices();
493
-
494
-
495
-    /**
496
-     * admin_footer_scripts
497
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
498
-     * will apply to all pages/views loaded by child class.
499
-     *
500
-     * @return void
501
-     */
502
-    abstract public function admin_footer_scripts();
503
-
504
-
505
-    /**
506
-     * admin_footer
507
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
508
-     * apply to all pages/views loaded by child class.
509
-     *
510
-     * @return void
511
-     */
512
-    public function admin_footer()
513
-    {
514
-    }
515
-
516
-
517
-    /**
518
-     * _global_ajax_hooks
519
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
520
-     * Note: within the ajax callback methods.
521
-     *
522
-     * @abstract
523
-     * @return void
524
-     */
525
-    protected function _global_ajax_hooks()
526
-    {
527
-        // for lazy loading of metabox content
528
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
529
-
530
-        add_action(
531
-            'wp_ajax_espresso_hide_status_change_notice',
532
-            [$this, 'hideStatusChangeNotice']
533
-        );
534
-        add_action(
535
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
536
-            [$this, 'hideStatusChangeNotice']
537
-        );
538
-    }
539
-
540
-
541
-    public function ajax_metabox_content()
542
-    {
543
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
544
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
545
-        EE_Admin_Page::cached_rss_display($contentid, $url);
546
-        wp_die();
547
-    }
548
-
549
-
550
-    public function hideStatusChangeNotice()
551
-    {
552
-        $response = [];
553
-        try {
554
-            /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
555
-            $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
556
-            $response['success'] = $status_change_notice->dismiss() > -1;
557
-        } catch (Exception $exception) {
558
-            $response['errors'] = $exception->getMessage();
559
-        }
560
-        echo wp_json_encode($response);
561
-        exit();
562
-    }
563
-
564
-
565
-    /**
566
-     * _page_setup
567
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
568
-     * doesn't match the object.
569
-     *
570
-     * @final
571
-     * @return void
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws ReflectionException
575
-     * @throws InvalidDataTypeException
576
-     * @throws InvalidInterfaceException
577
-     */
578
-    final protected function _page_setup()
579
-    {
580
-        // requires?
581
-        // admin_init stuff - global - we're setting this REALLY early
582
-        // so if EE_Admin pages have to hook into other WP pages they can.
583
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
584
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
585
-        // next verify if we need to load anything...
586
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
587
-        $this->page_folder = strtolower(
588
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
589
-        );
590
-        global $ee_menu_slugs;
591
-        $ee_menu_slugs = (array) $ee_menu_slugs;
592
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
593
-            return;
594
-        }
595
-        // 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
596
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
597
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
598
-                ? $this->_req_data['action2']
599
-                : $this->_req_data['action'];
600
-        }
601
-        // then set blank or -1 action values to 'default'
602
-        $this->_req_action = isset($this->_req_data['action'])
603
-                             && ! empty($this->_req_data['action'])
604
-                             && $this->_req_data['action'] !== '-1'
605
-            ? sanitize_key($this->_req_data['action'])
606
-            : 'default';
607
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
608
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
609
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
610
-            ? $this->_req_data['route'] : $this->_req_action;
611
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
612
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
613
-            ? $this->_req_data['route']
614
-            : $this->_req_action;
615
-        $this->_current_view = $this->_req_action;
616
-        $this->_req_nonce = $this->_req_action . '_nonce';
617
-        $this->_define_page_props();
618
-        $this->_current_page_view_url = add_query_arg(
619
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
620
-            $this->_admin_base_url
621
-        );
622
-        // default things
623
-        $this->_default_espresso_metaboxes = array(
624
-            '_espresso_news_post_box',
625
-            '_espresso_links_post_box',
626
-            '_espresso_ratings_request',
627
-            '_espresso_sponsors_post_box',
628
-        );
629
-        // set page configs
630
-        $this->_set_page_routes();
631
-        $this->_set_page_config();
632
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
633
-        if (isset($this->_req_data['wp_referer'])) {
634
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
635
-        }
636
-        // for caffeinated and other extended functionality.
637
-        //  If there is a _extend_page_config method
638
-        // then let's run that to modify the all the various page configuration arrays
639
-        if (method_exists($this, '_extend_page_config')) {
640
-            $this->_extend_page_config();
641
-        }
642
-        // for CPT and other extended functionality.
643
-        // If there is an _extend_page_config_for_cpt
644
-        // then let's run that to modify all the various page configuration arrays.
645
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
646
-            $this->_extend_page_config_for_cpt();
647
-        }
648
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
649
-        $this->_page_routes = apply_filters(
650
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
651
-            $this->_page_routes,
652
-            $this
653
-        );
654
-        $this->_page_config = apply_filters(
655
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
656
-            $this->_page_config,
657
-            $this
658
-        );
659
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
660
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
661
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
662
-            add_action(
663
-                'AHEE__EE_Admin_Page__route_admin_request',
664
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
665
-                10,
666
-                2
667
-            );
668
-        }
669
-        // next route only if routing enabled
670
-        if ($this->_routing && ! defined('DOING_AJAX')) {
671
-            $this->_verify_routes();
672
-            // next let's just check user_access and kill if no access
673
-            $this->check_user_access();
674
-            if ($this->_is_UI_request) {
675
-                // admin_init stuff - global, all views for this page class, specific view
676
-                add_action('admin_init', array($this, 'admin_init'), 10);
677
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
678
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
679
-                }
680
-            } else {
681
-                // hijack regular WP loading and route admin request immediately
682
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
683
-                $this->route_admin_request();
684
-            }
685
-        }
686
-    }
687
-
688
-
689
-    /**
690
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
691
-     *
692
-     * @return void
693
-     * @throws EE_Error
694
-     */
695
-    private function _do_other_page_hooks()
696
-    {
697
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
698
-        foreach ($registered_pages as $page) {
699
-            // now let's setup the file name and class that should be present
700
-            $classname = str_replace('.class.php', '', $page);
701
-            // autoloaders should take care of loading file
702
-            if (! class_exists($classname)) {
703
-                $error_msg[] = sprintf(
704
-                    esc_html__(
705
-                        'Something went wrong with loading the %s admin hooks page.',
706
-                        'event_espresso'
707
-                    ),
708
-                    $page
709
-                );
710
-                $error_msg[] = $error_msg[0]
711
-                               . "\r\n"
712
-                               . sprintf(
713
-                                   esc_html__(
714
-                                       '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',
715
-                                       'event_espresso'
716
-                                   ),
717
-                                   $page,
718
-                                   '<br />',
719
-                                   '<strong>' . $classname . '</strong>'
720
-                               );
721
-                throw new EE_Error(implode('||', $error_msg));
722
-            }
723
-            // // notice we are passing the instance of this class to the hook object.
724
-            $this->loader->getShared($classname, [$this]);
725
-        }
726
-    }
727
-
728
-
729
-    /**
730
-     * @throws DomainException
731
-     * @throws EE_Error
732
-     * @throws InvalidArgumentException
733
-     * @throws InvalidDataTypeException
734
-     * @throws InvalidInterfaceException
735
-     * @throws ReflectionException
736
-     * @since $VID:$
737
-     */
738
-    public function load_page_dependencies()
739
-    {
740
-        try {
741
-            $this->_load_page_dependencies();
742
-        } catch (EE_Error $e) {
743
-            $e->get_error();
744
-        }
745
-    }
746
-
747
-
748
-    /**
749
-     * load_page_dependencies
750
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
751
-     *
752
-     * @return void
753
-     * @throws DomainException
754
-     * @throws EE_Error
755
-     * @throws InvalidArgumentException
756
-     * @throws InvalidDataTypeException
757
-     * @throws InvalidInterfaceException
758
-     * @throws ReflectionException
759
-     */
760
-    protected function _load_page_dependencies()
761
-    {
762
-        // let's set the current_screen and screen options to override what WP set
763
-        $this->_current_screen = get_current_screen();
764
-        // load admin_notices - global, page class, and view specific
765
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
766
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
767
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
768
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
769
-        }
770
-        // load network admin_notices - global, page class, and view specific
771
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
772
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
773
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
774
-        }
775
-        // this will save any per_page screen options if they are present
776
-        $this->_set_per_page_screen_options();
777
-        // setup list table properties
778
-        $this->_set_list_table();
779
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
780
-        // However in some cases the metaboxes will need to be added within a route handling callback.
781
-        $this->_add_registered_meta_boxes();
782
-        $this->_add_screen_columns();
783
-        // add screen options - global, page child class, and view specific
784
-        $this->_add_global_screen_options();
785
-        $this->_add_screen_options();
786
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
787
-        if (method_exists($this, $add_screen_options)) {
788
-            $this->{$add_screen_options}();
789
-        }
790
-        // add help tab(s) and tours- set via page_config and qtips.
791
-        // $this->_add_help_tour();
792
-        $this->_add_help_tabs();
793
-        $this->_add_qtips();
794
-        // add feature_pointers - global, page child class, and view specific
795
-        $this->_add_feature_pointers();
796
-        $this->_add_global_feature_pointers();
797
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
798
-        if (method_exists($this, $add_feature_pointer)) {
799
-            $this->{$add_feature_pointer}();
800
-        }
801
-        // enqueue scripts/styles - global, page class, and view specific
802
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
803
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
804
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
805
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
806
-        }
807
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
808
-        // admin_print_footer_scripts - global, page child class, and view specific.
809
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
810
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
811
-        // is a good use case. Notice the late priority we're giving these
812
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
813
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
814
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
815
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
816
-        }
817
-        // admin footer scripts
818
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
819
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
820
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
821
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
822
-        }
823
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
824
-        // targeted hook
825
-        do_action(
826
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
827
-        );
828
-    }
829
-
830
-
831
-    /**
832
-     * _set_defaults
833
-     * This sets some global defaults for class properties.
834
-     */
835
-    private function _set_defaults()
836
-    {
837
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
838
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
839
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
840
-        $this->_page_config = $this->_default_route_query_args = array();
841
-        $this->_default_nav_tab_name = 'overview';
842
-        // init template args
843
-        $this->_template_args = array(
844
-            'admin_page_header'  => '',
845
-            'admin_page_content' => '',
846
-            'post_body_content'  => '',
847
-            'before_list_table'  => '',
848
-            'after_list_table'   => '',
849
-        );
850
-    }
851
-
852
-
853
-    /**
854
-     * route_admin_request
855
-     *
856
-     * @see    _route_admin_request()
857
-     * @return exception|void error
858
-     * @throws InvalidArgumentException
859
-     * @throws InvalidInterfaceException
860
-     * @throws InvalidDataTypeException
861
-     * @throws EE_Error
862
-     * @throws ReflectionException
863
-     */
864
-    public function route_admin_request()
865
-    {
866
-        try {
867
-            $this->_route_admin_request();
868
-        } catch (EE_Error $e) {
869
-            $e->get_error();
870
-        }
871
-    }
872
-
873
-
874
-    public function set_wp_page_slug($wp_page_slug)
875
-    {
876
-        $this->_wp_page_slug = $wp_page_slug;
877
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
878
-        if (is_network_admin()) {
879
-            $this->_wp_page_slug .= '-network';
880
-        }
881
-    }
882
-
883
-
884
-    /**
885
-     * _verify_routes
886
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
887
-     * we know if we need to drop out.
888
-     *
889
-     * @return bool
890
-     * @throws EE_Error
891
-     */
892
-    protected function _verify_routes()
893
-    {
894
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
895
-            return false;
896
-        }
897
-        $this->_route = false;
898
-        // check that the page_routes array is not empty
899
-        if (empty($this->_page_routes)) {
900
-            // user error msg
901
-            $error_msg = sprintf(
902
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
903
-                $this->_admin_page_title
904
-            );
905
-            // developer error msg
906
-            $error_msg .= '||' . $error_msg
907
-                          . esc_html__(
908
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
909
-                              'event_espresso'
910
-                          );
911
-            throw new EE_Error($error_msg);
912
-        }
913
-        // and that the requested page route exists
914
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
915
-            $this->_route = $this->_page_routes[ $this->_req_action ];
916
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
917
-                ? $this->_page_config[ $this->_req_action ] : array();
918
-        } else {
919
-            // user error msg
920
-            $error_msg = sprintf(
921
-                esc_html__(
922
-                    'The requested page route does not exist for the %s admin page.',
923
-                    'event_espresso'
924
-                ),
925
-                $this->_admin_page_title
926
-            );
927
-            // developer error msg
928
-            $error_msg .= '||' . $error_msg
929
-                          . sprintf(
930
-                              esc_html__(
931
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
932
-                                  'event_espresso'
933
-                              ),
934
-                              $this->_req_action
935
-                          );
936
-            throw new EE_Error($error_msg);
937
-        }
938
-        // and that a default route exists
939
-        if (! array_key_exists('default', $this->_page_routes)) {
940
-            // user error msg
941
-            $error_msg = sprintf(
942
-                esc_html__(
943
-                    'A default page route has not been set for the % admin page.',
944
-                    'event_espresso'
945
-                ),
946
-                $this->_admin_page_title
947
-            );
948
-            // developer error msg
949
-            $error_msg .= '||' . $error_msg
950
-                          . esc_html__(
951
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
952
-                              'event_espresso'
953
-                          );
954
-            throw new EE_Error($error_msg);
955
-        }
956
-
957
-        // first lets' catch if the UI request has EVER been set.
958
-        if ($this->_is_UI_request === null) {
959
-            // lets set if this is a UI request or not.
960
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
961
-            // wait a minute... we might have a noheader in the route array
962
-            $this->_is_UI_request = is_array($this->_route)
963
-                                    && isset($this->_route['noheader'])
964
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
965
-        }
966
-        $this->_set_current_labels();
967
-        return true;
968
-    }
969
-
970
-
971
-    /**
972
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
973
-     *
974
-     * @param  string $route the route name we're verifying
975
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
976
-     * @throws EE_Error
977
-     */
978
-    protected function _verify_route($route)
979
-    {
980
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
981
-            return true;
982
-        }
983
-        // user error msg
984
-        $error_msg = sprintf(
985
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
986
-            $this->_admin_page_title
987
-        );
988
-        // developer error msg
989
-        $error_msg .= '||' . $error_msg
990
-                      . sprintf(
991
-                          esc_html__(
992
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
993
-                              'event_espresso'
994
-                          ),
995
-                          $route
996
-                      );
997
-        throw new EE_Error($error_msg);
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * perform nonce verification
1003
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1004
-     * using this method (and save retyping!)
1005
-     *
1006
-     * @param string $nonce     The nonce sent
1007
-     * @param string $nonce_ref The nonce reference string (name0)
1008
-     * @return void
1009
-     * @throws EE_Error
1010
-     * @throws InvalidArgumentException
1011
-     * @throws InvalidDataTypeException
1012
-     * @throws InvalidInterfaceException
1013
-     */
1014
-    protected function _verify_nonce($nonce, $nonce_ref)
1015
-    {
1016
-        // verify nonce against expected value
1017
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1018
-            // these are not the droids you are looking for !!!
1019
-            $msg = sprintf(
1020
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1021
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
1022
-                '</a>'
1023
-            );
1024
-            if (WP_DEBUG) {
1025
-                $msg .= "\n  "
1026
-                        . sprintf(
1027
-                            esc_html__(
1028
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1029
-                                'event_espresso'
1030
-                            ),
1031
-                            EE_Admin_Page::class
1032
-                        );
1033
-            }
1034
-            if (! defined('DOING_AJAX')) {
1035
-                wp_die($msg);
1036
-            } else {
1037
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1038
-                $this->_return_json();
1039
-            }
1040
-        }
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * _route_admin_request()
1046
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1047
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1048
-     * in the page routes and then will try to load the corresponding method.
1049
-     *
1050
-     * @return void
1051
-     * @throws EE_Error
1052
-     * @throws InvalidArgumentException
1053
-     * @throws InvalidDataTypeException
1054
-     * @throws InvalidInterfaceException
1055
-     * @throws ReflectionException
1056
-     */
1057
-    protected function _route_admin_request()
1058
-    {
1059
-        if (! $this->_is_UI_request) {
1060
-            $this->_verify_routes();
1061
-        }
1062
-        $nonce_check = isset($this->_route_config['require_nonce'])
1063
-            ? $this->_route_config['require_nonce']
1064
-            : true;
1065
-        if ($this->_req_action !== 'default' && $nonce_check) {
1066
-            // set nonce from post data
1067
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
1068
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1069
-                : '';
1070
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1071
-        }
1072
-        // set the nav_tabs array but ONLY if this is  UI_request
1073
-        if ($this->_is_UI_request) {
1074
-            $this->_set_nav_tabs();
1075
-        }
1076
-        // grab callback function
1077
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1078
-        // check if callback has args
1079
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1080
-        $error_msg = '';
1081
-        // action right before calling route
1082
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1083
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1084
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1085
-        }
1086
-        // right before calling the route, let's remove _wp_http_referer from the
1087
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1088
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1089
-            '_wp_http_referer',
1090
-            wp_unslash($_SERVER['REQUEST_URI'])
1091
-        );
1092
-        if (! empty($func)) {
1093
-            if (is_array($func)) {
1094
-                [$class, $method] = $func;
1095
-            } elseif (strpos($func, '::') !== false) {
1096
-                [$class, $method] = explode('::', $func);
1097
-            } else {
1098
-                $class = $this;
1099
-                $method = $func;
1100
-            }
1101
-            if (! (is_object($class) && $class === $this)) {
1102
-                // send along this admin page object for access by addons.
1103
-                $args['admin_page_object'] = $this;
1104
-            }
1105
-            // is it a method on a class that doesn't work?
1106
-            if (
1107
-                ((method_exists($class, $method)
1108
-                  && call_user_func_array(array($class, $method), $args) === false)
1109
-                 && (// is it a standalone function that doesn't work?
1110
-                     function_exists($method)
1111
-                     && call_user_func_array(
1112
-                         $func,
1113
-                         array_merge(array('admin_page_object' => $this), $args)
1114
-                     ) === false
1115
-                 )) || (// is it neither a class method NOR a standalone function?
1116
-                    ! function_exists($method)
1117
-                    && ! method_exists($class, $method)
1118
-                )
1119
-            ) {
1120
-                // user error msg
1121
-                $error_msg = esc_html__(
1122
-                    'An error occurred. The  requested page route could not be found.',
1123
-                    'event_espresso'
1124
-                );
1125
-                // developer error msg
1126
-                $error_msg .= '||';
1127
-                $error_msg .= sprintf(
1128
-                    esc_html__(
1129
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1130
-                        'event_espresso'
1131
-                    ),
1132
-                    $method
1133
-                );
1134
-            }
1135
-            if (! empty($error_msg)) {
1136
-                throw new EE_Error($error_msg);
1137
-            }
1138
-        }
1139
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1140
-        // then we need to reset the routing properties to the new route.
1141
-        // 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.
1142
-        if (
1143
-            $this->_is_UI_request === false
1144
-            && is_array($this->_route)
1145
-            && ! empty($this->_route['headers_sent_route'])
1146
-        ) {
1147
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1148
-        }
1149
-    }
1150
-
1151
-
1152
-    /**
1153
-     * This method just allows the resetting of page properties in the case where a no headers
1154
-     * route redirects to a headers route in its route config.
1155
-     *
1156
-     * @since   4.3.0
1157
-     * @param  string $new_route New (non header) route to redirect to.
1158
-     * @return   void
1159
-     * @throws ReflectionException
1160
-     * @throws InvalidArgumentException
1161
-     * @throws InvalidInterfaceException
1162
-     * @throws InvalidDataTypeException
1163
-     * @throws EE_Error
1164
-     */
1165
-    protected function _reset_routing_properties($new_route)
1166
-    {
1167
-        $this->_is_UI_request = true;
1168
-        // now we set the current route to whatever the headers_sent_route is set at
1169
-        $this->_req_data['action'] = $new_route;
1170
-        // rerun page setup
1171
-        $this->_page_setup();
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * _add_query_arg
1177
-     * adds nonce to array of arguments then calls WP add_query_arg function
1178
-     *(internally just uses EEH_URL's function with the same name)
1179
-     *
1180
-     * @param array  $args
1181
-     * @param string $url
1182
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1183
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1184
-     *                                        Example usage: If the current page is:
1185
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1186
-     *                                        &action=default&event_id=20&month_range=March%202015
1187
-     *                                        &_wpnonce=5467821
1188
-     *                                        and you call:
1189
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1190
-     *                                        array(
1191
-     *                                        'action' => 'resend_something',
1192
-     *                                        'page=>espresso_registrations'
1193
-     *                                        ),
1194
-     *                                        $some_url,
1195
-     *                                        true
1196
-     *                                        );
1197
-     *                                        It will produce a url in this structure:
1198
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1199
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1200
-     *                                        month_range]=March%202015
1201
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1202
-     * @return string
1203
-     */
1204
-    public static function add_query_args_and_nonce(
1205
-        $args = array(),
1206
-        $url = '',
1207
-        $sticky = false,
1208
-        $exclude_nonce = false
1209
-    ) {
1210
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1211
-        if ($sticky) {
1212
-            $request = $_REQUEST;
1213
-            unset($request['_wp_http_referer'], $request['wp_referer']);
1214
-            foreach ($request as $key => $value) {
1215
-                // do not add nonces
1216
-                if (strpos($key, 'nonce') !== false) {
1217
-                    continue;
1218
-                }
1219
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1220
-            }
1221
-        }
1222
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1223
-    }
1224
-
1225
-
1226
-    /**
1227
-     * This returns a generated link that will load the related help tab.
1228
-     *
1229
-     * @param  string $help_tab_id the id for the connected help tab
1230
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1231
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1232
-     * @uses EEH_Template::get_help_tab_link()
1233
-     * @return string              generated link
1234
-     */
1235
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1236
-    {
1237
-        return EEH_Template::get_help_tab_link(
1238
-            $help_tab_id,
1239
-            $this->page_slug,
1240
-            $this->_req_action,
1241
-            $icon_style,
1242
-            $help_text
1243
-        );
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * _add_help_tabs
1249
-     * Note child classes define their help tabs within the page_config array.
1250
-     *
1251
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1252
-     * @return void
1253
-     * @throws DomainException
1254
-     * @throws EE_Error
1255
-     * @throws ReflectionException
1256
-     */
1257
-    protected function _add_help_tabs()
1258
-    {
1259
-        $tour_buttons = '';
1260
-        if (isset($this->_page_config[ $this->_req_action ])) {
1261
-            $config = $this->_page_config[ $this->_req_action ];
1262
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1263
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1264
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1265
-            //     $tb = array();
1266
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1267
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1268
-            //         // if this is the end tour then we don't need to setup a button
1269
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1270
-            //             continue;
1271
-            //         }
1272
-            //         $tb[] = '<button id="trigger-tour-'
1273
-            //                 . $tour->get_slug()
1274
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1275
-            //                 . $tour->get_label()
1276
-            //                 . '</button>';
1277
-            //     }
1278
-            //     $tour_buttons .= implode('<br />', $tb);
1279
-            //     $tour_buttons .= '</div></div>';
1280
-            // }
1281
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1282
-            if (is_array($config) && isset($config['help_sidebar'])) {
1283
-                // check that the callback given is valid
1284
-                if (! method_exists($this, $config['help_sidebar'])) {
1285
-                    throw new EE_Error(
1286
-                        sprintf(
1287
-                            esc_html__(
1288
-                                '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',
1289
-                                'event_espresso'
1290
-                            ),
1291
-                            $config['help_sidebar'],
1292
-                            get_class($this)
1293
-                        )
1294
-                    );
1295
-                }
1296
-                $content = apply_filters(
1297
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1298
-                    $this->{$config['help_sidebar']}()
1299
-                );
1300
-                $content .= $tour_buttons; // add help tour buttons.
1301
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1302
-                $this->_current_screen->set_help_sidebar($content);
1303
-            }
1304
-            // if there ARE tour buttons...
1305
-            if (! empty($tour_buttons)) {
1306
-                // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1307
-                if (! isset($config['help_sidebar'])) {
1308
-                    $this->_current_screen->set_help_sidebar($tour_buttons);
1309
-                }
1310
-                // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1311
-                if (! isset($config['help_tabs'])) {
1312
-                    $_ht['id'] = $this->page_slug;
1313
-                    $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1314
-                    $_ht['content'] = '<p>'
1315
-                                      . esc_html__(
1316
-                                          'The buttons to the right allow you to start/restart any help tours available for this page',
1317
-                                          'event_espresso'
1318
-                                      ) . '</p>';
1319
-                    $this->_current_screen->add_help_tab($_ht);
1320
-                }
1321
-            }
1322
-            if (! isset($config['help_tabs'])) {
1323
-                return;
1324
-            } //no help tabs for this route
1325
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1326
-                // we're here so there ARE help tabs!
1327
-                // make sure we've got what we need
1328
-                if (! isset($cfg['title'])) {
1329
-                    throw new EE_Error(
1330
-                        esc_html__(
1331
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1332
-                            'event_espresso'
1333
-                        )
1334
-                    );
1335
-                }
1336
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1337
-                    throw new EE_Error(
1338
-                        esc_html__(
1339
-                            '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',
1340
-                            'event_espresso'
1341
-                        )
1342
-                    );
1343
-                }
1344
-                // first priority goes to content.
1345
-                if (! empty($cfg['content'])) {
1346
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1347
-                    // second priority goes to filename
1348
-                } elseif (! empty($cfg['filename'])) {
1349
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1350
-                    // 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)
1351
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1352
-                                                             . basename($this->_get_dir())
1353
-                                                             . '/help_tabs/'
1354
-                                                             . $cfg['filename']
1355
-                                                             . '.help_tab.php' : $file_path;
1356
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1357
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1358
-                        EE_Error::add_error(
1359
-                            sprintf(
1360
-                                esc_html__(
1361
-                                    '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',
1362
-                                    'event_espresso'
1363
-                                ),
1364
-                                $tab_id,
1365
-                                key($config),
1366
-                                $file_path
1367
-                            ),
1368
-                            __FILE__,
1369
-                            __FUNCTION__,
1370
-                            __LINE__
1371
-                        );
1372
-                        return;
1373
-                    }
1374
-                    $template_args['admin_page_obj'] = $this;
1375
-                    $content = EEH_Template::display_template(
1376
-                        $file_path,
1377
-                        $template_args,
1378
-                        true
1379
-                    );
1380
-                } else {
1381
-                    $content = '';
1382
-                }
1383
-                // check if callback is valid
1384
-                if (
1385
-                    empty($content) && (
1386
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1387
-                    )
1388
-                ) {
1389
-                    EE_Error::add_error(
1390
-                        sprintf(
1391
-                            esc_html__(
1392
-                                '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.',
1393
-                                'event_espresso'
1394
-                            ),
1395
-                            $cfg['title']
1396
-                        ),
1397
-                        __FILE__,
1398
-                        __FUNCTION__,
1399
-                        __LINE__
1400
-                    );
1401
-                    return;
1402
-                }
1403
-                // setup config array for help tab method
1404
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1405
-                $_ht = array(
1406
-                    'id'       => $id,
1407
-                    'title'    => $cfg['title'],
1408
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1409
-                    'content'  => $content,
1410
-                );
1411
-                $this->_current_screen->add_help_tab($_ht);
1412
-            }
1413
-        }
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1419
-     * an array with properties for setting up usage of the joyride plugin
1420
-     *
1421
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1422
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1423
-     *         _set_page_config() comments
1424
-     * @return void
1425
-     * @throws EE_Error
1426
-     * @throws InvalidArgumentException
1427
-     * @throws InvalidDataTypeException
1428
-     * @throws InvalidInterfaceException
1429
-     * @throws ReflectionException
1430
-     */
1431
-    protected function _add_help_tour()
1432
-    {
1433
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1434
-        // $tours = array();
1435
-        // $this->_help_tour = array();
1436
-        // // exit early if help tours are turned off globally
1437
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1438
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1439
-        // ) {
1440
-        //     return;
1441
-        // }
1442
-        // // loop through _page_config to find any help_tour defined
1443
-        // foreach ($this->_page_config as $route => $config) {
1444
-        //     // we're only going to set things up for this route
1445
-        //     if ($route !== $this->_req_action) {
1446
-        //         continue;
1447
-        //     }
1448
-        //     if (isset($config['help_tour'])) {
1449
-        //         foreach ($config['help_tour'] as $tour) {
1450
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1451
-        //             // let's see if we can get that file...
1452
-        //             // if not its possible this is a decaf route not set in caffeinated
1453
-        //             // so lets try and get the caffeinated equivalent
1454
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1455
-        //                                                      . basename($this->_get_dir())
1456
-        //                                                      . '/help_tours/'
1457
-        //                                                      . $tour
1458
-        //                                                      . '.class.php' : $file_path;
1459
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1460
-        //             if (! is_readable($file_path)) {
1461
-        //                 EE_Error::add_error(
1462
-        //                     sprintf(
1463
-        //                         esc_html__(
1464
-        //                             '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',
1465
-        //                             'event_espresso'
1466
-        //                         ),
1467
-        //                         $file_path,
1468
-        //                         $tour
1469
-        //                     ),
1470
-        //                     __FILE__,
1471
-        //                     __FUNCTION__,
1472
-        //                     __LINE__
1473
-        //                 );
1474
-        //                 return;
1475
-        //             }
1476
-        //             require_once $file_path;
1477
-        //             if (! class_exists($tour)) {
1478
-        //                 $error_msg[] = sprintf(
1479
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1480
-        //                     $tour
1481
-        //                 );
1482
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1483
-        //                                . sprintf(
1484
-        //                                    esc_html__(
1485
-        //                                        '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.',
1486
-        //                                        'event_espresso'
1487
-        //                                    ),
1488
-        //                                    $tour,
1489
-        //                                    '<br />',
1490
-        //                                    $tour,
1491
-        //                                    $this->_req_action,
1492
-        //                                    get_class($this)
1493
-        //                                );
1494
-        //                 throw new EE_Error(implode('||', $error_msg));
1495
-        //             }
1496
-        //             $tour_obj = new $tour($this->_is_caf);
1497
-        //             $tours[] = $tour_obj;
1498
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1499
-        //         }
1500
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1501
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1502
-        //         $tours[] = $end_stop_tour;
1503
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1504
-        //     }
1505
-        // }
1506
-        //
1507
-        // if (! empty($tours)) {
1508
-        //     $this->_help_tour['tours'] = $tours;
1509
-        // }
1510
-        // // that's it!  Now that the $_help_tours property is set (or not)
1511
-        // // the scripts and html should be taken care of automatically.
1512
-        //
1513
-        // /**
1514
-        //  * Allow extending the help tours variable.
1515
-        //  *
1516
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1517
-        //  */
1518
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * This simply sets up any qtips that have been defined in the page config
1524
-     *
1525
-     * @return void
1526
-     * @throws ReflectionException
1527
-     * @throws EE_Error
1528
-     */
1529
-    protected function _add_qtips()
1530
-    {
1531
-        if (isset($this->_route_config['qtips'])) {
1532
-            $qtips = (array) $this->_route_config['qtips'];
1533
-            // load qtip loader
1534
-            $path = array(
1535
-                $this->_get_dir() . '/qtips/',
1536
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1537
-            );
1538
-            $qtip_loader = EEH_Qtip_Loader::instance();
1539
-            if ($qtip_loader instanceof EEH_Qtip_Loader) {
1540
-                $qtip_loader->register($qtips, $path);
1541
-            }
1542
-        }
1543
-    }
1544
-
1545
-
1546
-    /**
1547
-     * _set_nav_tabs
1548
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1549
-     * wish to add additional tabs or modify accordingly.
1550
-     *
1551
-     * @return void
1552
-     * @throws InvalidArgumentException
1553
-     * @throws InvalidInterfaceException
1554
-     * @throws InvalidDataTypeException
1555
-     */
1556
-    protected function _set_nav_tabs()
1557
-    {
1558
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1559
-        $i = 0;
1560
-        foreach ($this->_page_config as $slug => $config) {
1561
-            if (
1562
-                ! is_array($config)
1563
-                || (
1564
-                    is_array($config)
1565
-                    && (
1566
-                        (isset($config['nav']) && ! $config['nav'])
1567
-                        || ! isset($config['nav'])
1568
-                    )
1569
-                )
1570
-            ) {
1571
-                continue;
1572
-            }
1573
-            // no nav tab for this config
1574
-            // check for persistent flag
1575
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1576
-                // nav tab is only to appear when route requested.
1577
-                continue;
1578
-            }
1579
-            if (! $this->check_user_access($slug, true)) {
1580
-                // no nav tab because current user does not have access.
1581
-                continue;
1582
-            }
1583
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1584
-            $this->_nav_tabs[ $slug ] = array(
1585
-                'url'       => isset($config['nav']['url'])
1586
-                    ? $config['nav']['url']
1587
-                    : EE_Admin_Page::add_query_args_and_nonce(
1588
-                        array('action' => $slug),
1589
-                        $this->_admin_base_url
1590
-                    ),
1591
-                'link_text' => isset($config['nav']['label'])
1592
-                    ? $config['nav']['label']
1593
-                    : ucwords(
1594
-                        str_replace('_', ' ', $slug)
1595
-                    ),
1596
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1597
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1598
-            );
1599
-            $i++;
1600
-        }
1601
-        // if $this->_nav_tabs is empty then lets set the default
1602
-        if (empty($this->_nav_tabs)) {
1603
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1604
-                'url'       => $this->_admin_base_url,
1605
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1606
-                'css_class' => 'nav-tab-active',
1607
-                'order'     => 10,
1608
-            );
1609
-        }
1610
-        // now let's sort the tabs according to order
1611
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1612
-    }
1613
-
1614
-
1615
-    /**
1616
-     * _set_current_labels
1617
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1618
-     * property array
1619
-     *
1620
-     * @return void
1621
-     */
1622
-    private function _set_current_labels()
1623
-    {
1624
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1625
-            foreach ($this->_route_config['labels'] as $label => $text) {
1626
-                if (is_array($text)) {
1627
-                    foreach ($text as $sublabel => $subtext) {
1628
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1629
-                    }
1630
-                } else {
1631
-                    $this->_labels[ $label ] = $text;
1632
-                }
1633
-            }
1634
-        }
1635
-    }
1636
-
1637
-
1638
-    /**
1639
-     *        verifies user access for this admin page
1640
-     *
1641
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1642
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1643
-     *                               return false if verify fail.
1644
-     * @return bool
1645
-     * @throws InvalidArgumentException
1646
-     * @throws InvalidDataTypeException
1647
-     * @throws InvalidInterfaceException
1648
-     */
1649
-    public function check_user_access($route_to_check = '', $verify_only = false)
1650
-    {
1651
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1652
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1653
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1654
-                      && is_array(
1655
-                          $this->_page_routes[ $route_to_check ]
1656
-                      )
1657
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1658
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1659
-        if (empty($capability) && empty($route_to_check)) {
1660
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1661
-                : $this->_route['capability'];
1662
-        } else {
1663
-            $capability = empty($capability) ? 'manage_options' : $capability;
1664
-        }
1665
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1666
-        if (
1667
-            ! defined('DOING_AJAX')
1668
-            && (
1669
-                ! function_exists('is_admin')
1670
-                || ! EE_Registry::instance()->CAP->current_user_can(
1671
-                    $capability,
1672
-                    $this->page_slug
1673
-                    . '_'
1674
-                    . $route_to_check,
1675
-                    $id
1676
-                )
1677
-            )
1678
-        ) {
1679
-            if ($verify_only) {
1680
-                return false;
1681
-            }
1682
-            if (is_user_logged_in()) {
1683
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1684
-            } else {
1685
-                return false;
1686
-            }
1687
-        }
1688
-        return true;
1689
-    }
1690
-
1691
-
1692
-    /**
1693
-     * admin_init_global
1694
-     * This runs all the code that we want executed within the WP admin_init hook.
1695
-     * This method executes for ALL EE Admin pages.
1696
-     *
1697
-     * @return void
1698
-     */
1699
-    public function admin_init_global()
1700
-    {
1701
-    }
1702
-
1703
-
1704
-    /**
1705
-     * wp_loaded_global
1706
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1707
-     * EE_Admin page and will execute on every EE Admin Page load
1708
-     *
1709
-     * @return void
1710
-     */
1711
-    public function wp_loaded()
1712
-    {
1713
-    }
1714
-
1715
-
1716
-    /**
1717
-     * admin_notices
1718
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1719
-     * ALL EE_Admin pages.
1720
-     *
1721
-     * @return void
1722
-     */
1723
-    public function admin_notices_global()
1724
-    {
1725
-        $this->_display_no_javascript_warning();
1726
-        $this->_display_espresso_notices();
1727
-    }
1728
-
1729
-
1730
-    public function network_admin_notices_global()
1731
-    {
1732
-        $this->_display_no_javascript_warning();
1733
-        $this->_display_espresso_notices();
1734
-    }
1735
-
1736
-
1737
-    /**
1738
-     * admin_footer_scripts_global
1739
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1740
-     * will apply on ALL EE_Admin pages.
1741
-     *
1742
-     * @return void
1743
-     */
1744
-    public function admin_footer_scripts_global()
1745
-    {
1746
-        $this->_add_admin_page_ajax_loading_img();
1747
-        $this->_add_admin_page_overlay();
1748
-        // if metaboxes are present we need to add the nonce field
1749
-        if (
1750
-            isset($this->_route_config['metaboxes'])
1751
-            || isset($this->_route_config['list_table'])
1752
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1753
-        ) {
1754
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1755
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1756
-        }
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     * admin_footer_global
1762
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1763
-     * This particular method will apply on ALL EE_Admin Pages.
1764
-     *
1765
-     * @return void
1766
-     * @throws InvalidArgumentException
1767
-     * @throws InvalidDataTypeException
1768
-     * @throws InvalidInterfaceException
1769
-     */
1770
-    public function admin_footer_global()
1771
-    {
1772
-        // dialog container for dialog helper
1773
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1774
-        $d_cont .= '<div class="ee-notices"></div>';
1775
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1776
-        $d_cont .= '</div>';
1777
-        echo $d_cont;
1778
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1779
-        // help tour stuff?
1780
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1781
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1782
-        // }
1783
-        // current set timezone for timezone js
1784
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1785
-    }
1786
-
1787
-
1788
-    /**
1789
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1790
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1791
-     * help popups then in your templates or your content you set "triggers" for the content using the
1792
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1793
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1794
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1795
-     * for the
1796
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1797
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1798
-     *    'help_trigger_id' => array(
1799
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1800
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1801
-     *    )
1802
-     * );
1803
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1804
-     *
1805
-     * @param array $help_array
1806
-     * @param bool  $display
1807
-     * @return string content
1808
-     * @throws DomainException
1809
-     * @throws EE_Error
1810
-     */
1811
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1812
-    {
1813
-        $content = '';
1814
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1815
-        // loop through the array and setup content
1816
-        foreach ($help_array as $trigger => $help) {
1817
-            // make sure the array is setup properly
1818
-            if (! isset($help['title'], $help['content'])) {
1819
-                throw new EE_Error(
1820
-                    esc_html__(
1821
-                        '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',
1822
-                        'event_espresso'
1823
-                    )
1824
-                );
1825
-            }
1826
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1827
-            $template_args = array(
1828
-                'help_popup_id'      => $trigger,
1829
-                'help_popup_title'   => $help['title'],
1830
-                'help_popup_content' => $help['content'],
1831
-            );
1832
-            $content .= EEH_Template::display_template(
1833
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1834
-                $template_args,
1835
-                true
1836
-            );
1837
-        }
1838
-        if ($display) {
1839
-            echo $content;
1840
-            return '';
1841
-        }
1842
-        return $content;
1843
-    }
1844
-
1845
-
1846
-    /**
1847
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1848
-     *
1849
-     * @return array properly formatted array for help popup content
1850
-     * @throws EE_Error
1851
-     */
1852
-    private function _get_help_content()
1853
-    {
1854
-        // what is the method we're looking for?
1855
-        $method_name = '_help_popup_content_' . $this->_req_action;
1856
-        // if method doesn't exist let's get out.
1857
-        if (! method_exists($this, $method_name)) {
1858
-            return array();
1859
-        }
1860
-        // k we're good to go let's retrieve the help array
1861
-        $help_array = $this->{$method_name}();
1862
-        // make sure we've got an array!
1863
-        if (! is_array($help_array)) {
1864
-            throw new EE_Error(
1865
-                esc_html__(
1866
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1867
-                    'event_espresso'
1868
-                )
1869
-            );
1870
-        }
1871
-        return $help_array;
1872
-    }
1873
-
1874
-
1875
-    /**
1876
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1877
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1878
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1879
-     *
1880
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1881
-     * @param boolean $display    if false then we return the trigger string
1882
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1883
-     * @return string
1884
-     * @throws DomainException
1885
-     * @throws EE_Error
1886
-     */
1887
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1888
-    {
1889
-        if (defined('DOING_AJAX')) {
1890
-            return '';
1891
-        }
1892
-        // 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
1893
-        $help_array = $this->_get_help_content();
1894
-        $help_content = '';
1895
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1896
-            $help_array[ $trigger_id ] = array(
1897
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1898
-                'content' => esc_html__(
1899
-                    '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.)',
1900
-                    'event_espresso'
1901
-                ),
1902
-            );
1903
-            $help_content = $this->_set_help_popup_content($help_array);
1904
-        }
1905
-        // let's setup the trigger
1906
-        $content = '<a class="ee-dialog" href="?height='
1907
-                   . $dimensions[0]
1908
-                   . '&width='
1909
-                   . $dimensions[1]
1910
-                   . '&inlineId='
1911
-                   . $trigger_id
1912
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1913
-        $content .= $help_content;
1914
-        if ($display) {
1915
-            echo $content;
1916
-            return '';
1917
-        }
1918
-        return $content;
1919
-    }
1920
-
1921
-
1922
-    /**
1923
-     * _add_global_screen_options
1924
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1925
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1926
-     *
1927
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1928
-     *         see also WP_Screen object documents...
1929
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1930
-     * @abstract
1931
-     * @return void
1932
-     */
1933
-    private function _add_global_screen_options()
1934
-    {
1935
-    }
1936
-
1937
-
1938
-    /**
1939
-     * _add_global_feature_pointers
1940
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1941
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1942
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1943
-     *
1944
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1945
-     *         extended) also see:
1946
-     * @link   http://eamann.com/tech/wordpress-portland/
1947
-     * @abstract
1948
-     * @return void
1949
-     */
1950
-    private function _add_global_feature_pointers()
1951
-    {
1952
-    }
1953
-
1954
-
1955
-    /**
1956
-     * load_global_scripts_styles
1957
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1958
-     *
1959
-     * @return void
1960
-     * @throws EE_Error
1961
-     */
1962
-    public function load_global_scripts_styles()
1963
-    {
1964
-        // add debugging styles
1965
-        if (WP_DEBUG) {
1966
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1967
-        }
1968
-        // taking care of metaboxes
1969
-        if (
1970
-            empty($this->_cpt_route)
1971
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1972
-        ) {
1973
-            wp_enqueue_script('dashboard');
1974
-        }
1975
-
1976
-        // LOCALIZED DATA
1977
-        // localize script for ajax lazy loading
1978
-        wp_localize_script(
1979
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1980
-            'eeLazyLoadingContainers',
1981
-            apply_filters(
1982
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1983
-                ['espresso_news_post_box_content']
1984
-            )
1985
-        );
1986
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1987
-        // /**
1988
-        //  * help tour stuff
1989
-        //  */
1990
-        // if (! empty($this->_help_tour)) {
1991
-        //     // register the js for kicking things off
1992
-        //     wp_enqueue_script(
1993
-        //         'ee-help-tour',
1994
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1995
-        //         array('jquery-joyride'),
1996
-        //         EVENT_ESPRESSO_VERSION,
1997
-        //         true
1998
-        //     );
1999
-        //     $tours = array();
2000
-        //     // setup tours for the js tour object
2001
-        //     foreach ($this->_help_tour['tours'] as $tour) {
2002
-        //         if ($tour instanceof EE_Help_Tour) {
2003
-        //             $tours[] = array(
2004
-        //                 'id'      => $tour->get_slug(),
2005
-        //                 'options' => $tour->get_options(),
2006
-        //             );
2007
-        //         }
2008
-        //     }
2009
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2010
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2011
-        // }
2012
-    }
2013
-
2014
-
2015
-    /**
2016
-     *        admin_footer_scripts_eei18n_js_strings
2017
-     *
2018
-     * @return        void
2019
-     */
2020
-    public function admin_footer_scripts_eei18n_js_strings()
2021
-    {
2022
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2023
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2024
-            '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!!!',
2025
-            'event_espresso'
2026
-        );
2027
-        EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2028
-        EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2029
-        EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2030
-        EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2031
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2032
-        EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2033
-        EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2034
-        EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2035
-        EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2036
-        EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2037
-        EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2038
-        EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2039
-        EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2040
-        EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2041
-        EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2042
-        EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2043
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2044
-        EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2045
-        EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2046
-        EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2047
-        EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2048
-        EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2049
-        EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2050
-        EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2051
-        EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2052
-        EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2053
-        EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2054
-        EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2055
-        EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2056
-        EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2057
-        EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2058
-        EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2059
-        EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2060
-        EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2061
-        EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2062
-        EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2063
-        EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2064
-        EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     *        load enhanced xdebug styles for ppl with failing eyesight
2070
-     *
2071
-     * @return        void
2072
-     */
2073
-    public function add_xdebug_style()
2074
-    {
2075
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2076
-    }
2077
-
2078
-
2079
-    /************************/
2080
-    /** LIST TABLE METHODS **/
2081
-    /************************/
2082
-    /**
2083
-     * this sets up the list table if the current view requires it.
2084
-     *
2085
-     * @return void
2086
-     * @throws EE_Error
2087
-     * @throws InvalidArgumentException
2088
-     * @throws InvalidDataTypeException
2089
-     * @throws InvalidInterfaceException
2090
-     */
2091
-    protected function _set_list_table()
2092
-    {
2093
-        // first is this a list_table view?
2094
-        if (! isset($this->_route_config['list_table'])) {
2095
-            return;
2096
-        } //not a list_table view so get out.
2097
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2098
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2099
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2100
-            // user error msg
2101
-            $error_msg = esc_html__(
2102
-                'An error occurred. The requested list table views could not be found.',
2103
-                'event_espresso'
2104
-            );
2105
-            // developer error msg
2106
-            $error_msg .= '||'
2107
-                          . sprintf(
2108
-                              esc_html__(
2109
-                                  '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.',
2110
-                                  'event_espresso'
2111
-                              ),
2112
-                              $this->_req_action,
2113
-                              $list_table_view
2114
-                          );
2115
-            throw new EE_Error($error_msg);
2116
-        }
2117
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2118
-        $this->_views = apply_filters(
2119
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2120
-            $this->_views
2121
-        );
2122
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2123
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2124
-        $this->_set_list_table_view();
2125
-        $this->_set_list_table_object();
2126
-    }
2127
-
2128
-
2129
-    /**
2130
-     * set current view for List Table
2131
-     *
2132
-     * @return void
2133
-     */
2134
-    protected function _set_list_table_view()
2135
-    {
2136
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2137
-        // looking at active items or dumpster diving ?
2138
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2139
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2140
-        } else {
2141
-            $this->_view = sanitize_key($this->_req_data['status']);
2142
-        }
2143
-    }
2144
-
2145
-
2146
-    /**
2147
-     * _set_list_table_object
2148
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2149
-     *
2150
-     * @throws InvalidInterfaceException
2151
-     * @throws InvalidArgumentException
2152
-     * @throws InvalidDataTypeException
2153
-     * @throws EE_Error
2154
-     * @throws InvalidInterfaceException
2155
-     */
2156
-    protected function _set_list_table_object()
2157
-    {
2158
-        if (isset($this->_route_config['list_table'])) {
2159
-            if (! class_exists($this->_route_config['list_table'])) {
2160
-                throw new EE_Error(
2161
-                    sprintf(
2162
-                        esc_html__(
2163
-                            '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.',
2164
-                            'event_espresso'
2165
-                        ),
2166
-                        $this->_route_config['list_table'],
2167
-                        get_class($this)
2168
-                    )
2169
-                );
2170
-            }
2171
-            $this->_list_table_object = $this->loader->getShared(
2172
-                $this->_route_config['list_table'],
2173
-                array($this)
2174
-            );
2175
-        }
2176
-    }
2177
-
2178
-
2179
-    /**
2180
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2181
-     *
2182
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2183
-     *                                                    urls.  The array should be indexed by the view it is being
2184
-     *                                                    added to.
2185
-     * @return array
2186
-     */
2187
-    public function get_list_table_view_RLs($extra_query_args = array())
2188
-    {
2189
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
-        if (empty($this->_views)) {
2191
-            $this->_views = array();
2192
-        }
2193
-        // cycle thru views
2194
-        foreach ($this->_views as $key => $view) {
2195
-            $query_args = array();
2196
-            // check for current view
2197
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2198
-            $query_args['action'] = $this->_req_action;
2199
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2200
-            $query_args['status'] = $view['slug'];
2201
-            // merge any other arguments sent in.
2202
-            if (isset($extra_query_args[ $view['slug'] ])) {
2203
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2204
-                    $query_args[] = $extra_query_arg;
2205
-                }
2206
-            }
2207
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2208
-        }
2209
-        return $this->_views;
2210
-    }
2211
-
2212
-
2213
-    /**
2214
-     * _entries_per_page_dropdown
2215
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2216
-     *
2217
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2218
-     *         WP does it.
2219
-     * @param int $max_entries total number of rows in the table
2220
-     * @return string
2221
-     */
2222
-    protected function _entries_per_page_dropdown($max_entries = 0)
2223
-    {
2224
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2225
-        $values = array(10, 25, 50, 100);
2226
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2227
-        if ($max_entries) {
2228
-            $values[] = $max_entries;
2229
-            sort($values);
2230
-        }
2231
-        $entries_per_page_dropdown = '
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
+	 * whether or not initializePage() has run
184
+	 *
185
+	 * @var boolean
186
+	 */
187
+	protected $initialized = false;
188
+
189
+	/**
190
+	 * @var FeatureFlags
191
+	 */
192
+	protected $feature;
193
+
194
+
195
+	/**
196
+	 * @Constructor
197
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 * @throws ReflectionException
202
+	 */
203
+	public function __construct($routing = true)
204
+	{
205
+		$this->loader = LoaderFactory::getLoader();
206
+		$this->feature = $this->loader->getShared(FeatureFlags::class);
207
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
208
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
209
+			$this->_is_caf = true;
210
+		}
211
+		$this->_yes_no_values = array(
212
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
213
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
214
+		);
215
+		// set the _req_data property.
216
+		$this->_req_data = array_merge($_GET, $_POST);
217
+		// routing enabled?
218
+		$this->_routing = $routing;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @return EE_Admin_Config
224
+	 */
225
+	public function adminConfig(): EE_Admin_Config
226
+	{
227
+		return $this->admin_config;
228
+	}
229
+
230
+
231
+	/**
232
+	 * @return FeatureFlags
233
+	 */
234
+	public function feature(): FeatureFlags
235
+	{
236
+		return $this->feature;
237
+	}
238
+
239
+
240
+	/**
241
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
242
+	 * for child classes that needed to set properties prior to these methods getting called,
243
+	 * but also needed the parent class to have its construction completed as well.
244
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
245
+	 * and any complex initialization logic should only run after instantiation is complete.
246
+	 *
247
+	 * This method gets called immediately after construction from within
248
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
249
+	 *
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 * @throws ReflectionException
255
+	 * @since $VID:$
256
+	 */
257
+	public function initializePage()
258
+	{
259
+		if ($this->initialized) {
260
+			return;
261
+		}
262
+		// set initial page props (child method)
263
+		$this->_init_page_props();
264
+		// set global defaults
265
+		$this->_set_defaults();
266
+		// set early because incoming requests could be ajax related and we need to register those hooks.
267
+		$this->_global_ajax_hooks();
268
+		$this->_ajax_hooks();
269
+		// other_page_hooks have to be early too.
270
+		$this->_do_other_page_hooks();
271
+		// This just allows us to have extending classes do something specific
272
+		// before the parent constructor runs _page_setup().
273
+		if (method_exists($this, '_before_page_setup')) {
274
+			$this->_before_page_setup();
275
+		}
276
+		// set up page dependencies
277
+		$this->_page_setup();
278
+		$this->initialized = true;
279
+	}
280
+
281
+
282
+	/**
283
+	 * _init_page_props
284
+	 * Child classes use to set at least the following properties:
285
+	 * $page_slug.
286
+	 * $page_label.
287
+	 *
288
+	 * @abstract
289
+	 * @return void
290
+	 */
291
+	abstract protected function _init_page_props();
292
+
293
+
294
+	/**
295
+	 * _ajax_hooks
296
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
297
+	 * Note: within the ajax callback methods.
298
+	 *
299
+	 * @abstract
300
+	 * @return void
301
+	 */
302
+	abstract protected function _ajax_hooks();
303
+
304
+
305
+	/**
306
+	 * _define_page_props
307
+	 * child classes define page properties in here.  Must include at least:
308
+	 * $_admin_base_url = base_url for all admin pages
309
+	 * $_admin_page_title = default admin_page_title for admin pages
310
+	 * $_labels = array of default labels for various automatically generated elements:
311
+	 *    array(
312
+	 *        'buttons' => array(
313
+	 *            'add' => esc_html__('label for add new button'),
314
+	 *            'edit' => esc_html__('label for edit button'),
315
+	 *            'delete' => esc_html__('label for delete button')
316
+	 *            )
317
+	 *        )
318
+	 *
319
+	 * @abstract
320
+	 * @return void
321
+	 */
322
+	abstract protected function _define_page_props();
323
+
324
+
325
+	/**
326
+	 * _set_page_routes
327
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
328
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
329
+	 * have a 'default' route. Here's the format
330
+	 * $this->_page_routes = array(
331
+	 *        'default' => array(
332
+	 *            'func' => '_default_method_handling_route',
333
+	 *            'args' => array('array','of','args'),
334
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
335
+	 *            ajax request, backend processing)
336
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
337
+	 *            headers route after.  The string you enter here should match the defined route reference for a
338
+	 *            headers sent route.
339
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
340
+	 *            this route.
341
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
342
+	 *            checks).
343
+	 *        ),
344
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
345
+	 *        handling method.
346
+	 *        )
347
+	 * )
348
+	 *
349
+	 * @abstract
350
+	 * @return void
351
+	 */
352
+	abstract protected function _set_page_routes();
353
+
354
+
355
+	/**
356
+	 * _set_page_config
357
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
358
+	 * array corresponds to the page_route for the loaded page. Format:
359
+	 * $this->_page_config = array(
360
+	 *        'default' => array(
361
+	 *            'labels' => array(
362
+	 *                'buttons' => array(
363
+	 *                    'add' => esc_html__('label for adding item'),
364
+	 *                    'edit' => esc_html__('label for editing item'),
365
+	 *                    'delete' => esc_html__('label for deleting item')
366
+	 *                ),
367
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
368
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
369
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
370
+	 *            _define_page_props() method
371
+	 *            'nav' => array(
372
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
373
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
374
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
375
+	 *                'order' => 10, //required to indicate tab position.
376
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
377
+	 *                displayed then add this parameter.
378
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
379
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
380
+	 *            metaboxes set for eventespresso admin pages.
381
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
382
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
383
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
384
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
385
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
386
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
387
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
388
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
389
+	 *            want to display.
390
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
391
+	 *                'tab_id' => array(
392
+	 *                    'title' => 'tab_title',
393
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
394
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
395
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
396
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
397
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
398
+	 *                    attempt to use the callback which should match the name of a method in the class
399
+	 *                    ),
400
+	 *                'tab2_id' => array(
401
+	 *                    'title' => 'tab2 title',
402
+	 *                    'filename' => 'file_name_2'
403
+	 *                    'callback' => 'callback_method_for_content',
404
+	 *                 ),
405
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
406
+	 *            help tab area on an admin page. @link
407
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
408
+	 *            'help_tour' => array(
409
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
410
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
411
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
412
+	 *            ),
413
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
414
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
415
+	 *            just set
416
+	 *            'require_nonce' to FALSE
417
+	 *            )
418
+	 * )
419
+	 *
420
+	 * @abstract
421
+	 * @return void
422
+	 */
423
+	abstract protected function _set_page_config();
424
+
425
+
426
+
427
+
428
+
429
+	/** end sample help_tour methods **/
430
+	/**
431
+	 * _add_screen_options
432
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
433
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
434
+	 * to a particular view.
435
+	 *
436
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
437
+	 *         see also WP_Screen object documents...
438
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
439
+	 * @abstract
440
+	 * @return void
441
+	 */
442
+	abstract protected function _add_screen_options();
443
+
444
+
445
+	/**
446
+	 * _add_feature_pointers
447
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
448
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
449
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
450
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
451
+	 * extended) also see:
452
+	 *
453
+	 * @link   http://eamann.com/tech/wordpress-portland/
454
+	 * @abstract
455
+	 * @return void
456
+	 */
457
+	abstract protected function _add_feature_pointers();
458
+
459
+
460
+	/**
461
+	 * load_scripts_styles
462
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
463
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
464
+	 * scripts/styles per view by putting them in a dynamic function in this format
465
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
466
+	 *
467
+	 * @abstract
468
+	 * @return void
469
+	 */
470
+	abstract public function load_scripts_styles();
471
+
472
+
473
+	/**
474
+	 * admin_init
475
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
476
+	 * all pages/views loaded by child class.
477
+	 *
478
+	 * @abstract
479
+	 * @return void
480
+	 */
481
+	abstract public function admin_init();
482
+
483
+
484
+	/**
485
+	 * admin_notices
486
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
487
+	 * all pages/views loaded by child class.
488
+	 *
489
+	 * @abstract
490
+	 * @return void
491
+	 */
492
+	abstract public function admin_notices();
493
+
494
+
495
+	/**
496
+	 * admin_footer_scripts
497
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
498
+	 * will apply to all pages/views loaded by child class.
499
+	 *
500
+	 * @return void
501
+	 */
502
+	abstract public function admin_footer_scripts();
503
+
504
+
505
+	/**
506
+	 * admin_footer
507
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
508
+	 * apply to all pages/views loaded by child class.
509
+	 *
510
+	 * @return void
511
+	 */
512
+	public function admin_footer()
513
+	{
514
+	}
515
+
516
+
517
+	/**
518
+	 * _global_ajax_hooks
519
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
520
+	 * Note: within the ajax callback methods.
521
+	 *
522
+	 * @abstract
523
+	 * @return void
524
+	 */
525
+	protected function _global_ajax_hooks()
526
+	{
527
+		// for lazy loading of metabox content
528
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
529
+
530
+		add_action(
531
+			'wp_ajax_espresso_hide_status_change_notice',
532
+			[$this, 'hideStatusChangeNotice']
533
+		);
534
+		add_action(
535
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
536
+			[$this, 'hideStatusChangeNotice']
537
+		);
538
+	}
539
+
540
+
541
+	public function ajax_metabox_content()
542
+	{
543
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
544
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
545
+		EE_Admin_Page::cached_rss_display($contentid, $url);
546
+		wp_die();
547
+	}
548
+
549
+
550
+	public function hideStatusChangeNotice()
551
+	{
552
+		$response = [];
553
+		try {
554
+			/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
555
+			$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
556
+			$response['success'] = $status_change_notice->dismiss() > -1;
557
+		} catch (Exception $exception) {
558
+			$response['errors'] = $exception->getMessage();
559
+		}
560
+		echo wp_json_encode($response);
561
+		exit();
562
+	}
563
+
564
+
565
+	/**
566
+	 * _page_setup
567
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
568
+	 * doesn't match the object.
569
+	 *
570
+	 * @final
571
+	 * @return void
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws ReflectionException
575
+	 * @throws InvalidDataTypeException
576
+	 * @throws InvalidInterfaceException
577
+	 */
578
+	final protected function _page_setup()
579
+	{
580
+		// requires?
581
+		// admin_init stuff - global - we're setting this REALLY early
582
+		// so if EE_Admin pages have to hook into other WP pages they can.
583
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
584
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
585
+		// next verify if we need to load anything...
586
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
587
+		$this->page_folder = strtolower(
588
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
589
+		);
590
+		global $ee_menu_slugs;
591
+		$ee_menu_slugs = (array) $ee_menu_slugs;
592
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
593
+			return;
594
+		}
595
+		// 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
596
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
597
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
598
+				? $this->_req_data['action2']
599
+				: $this->_req_data['action'];
600
+		}
601
+		// then set blank or -1 action values to 'default'
602
+		$this->_req_action = isset($this->_req_data['action'])
603
+							 && ! empty($this->_req_data['action'])
604
+							 && $this->_req_data['action'] !== '-1'
605
+			? sanitize_key($this->_req_data['action'])
606
+			: 'default';
607
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
608
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
609
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
610
+			? $this->_req_data['route'] : $this->_req_action;
611
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
612
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
613
+			? $this->_req_data['route']
614
+			: $this->_req_action;
615
+		$this->_current_view = $this->_req_action;
616
+		$this->_req_nonce = $this->_req_action . '_nonce';
617
+		$this->_define_page_props();
618
+		$this->_current_page_view_url = add_query_arg(
619
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
620
+			$this->_admin_base_url
621
+		);
622
+		// default things
623
+		$this->_default_espresso_metaboxes = array(
624
+			'_espresso_news_post_box',
625
+			'_espresso_links_post_box',
626
+			'_espresso_ratings_request',
627
+			'_espresso_sponsors_post_box',
628
+		);
629
+		// set page configs
630
+		$this->_set_page_routes();
631
+		$this->_set_page_config();
632
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
633
+		if (isset($this->_req_data['wp_referer'])) {
634
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
635
+		}
636
+		// for caffeinated and other extended functionality.
637
+		//  If there is a _extend_page_config method
638
+		// then let's run that to modify the all the various page configuration arrays
639
+		if (method_exists($this, '_extend_page_config')) {
640
+			$this->_extend_page_config();
641
+		}
642
+		// for CPT and other extended functionality.
643
+		// If there is an _extend_page_config_for_cpt
644
+		// then let's run that to modify all the various page configuration arrays.
645
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
646
+			$this->_extend_page_config_for_cpt();
647
+		}
648
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
649
+		$this->_page_routes = apply_filters(
650
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
651
+			$this->_page_routes,
652
+			$this
653
+		);
654
+		$this->_page_config = apply_filters(
655
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
656
+			$this->_page_config,
657
+			$this
658
+		);
659
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
660
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
661
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
662
+			add_action(
663
+				'AHEE__EE_Admin_Page__route_admin_request',
664
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
665
+				10,
666
+				2
667
+			);
668
+		}
669
+		// next route only if routing enabled
670
+		if ($this->_routing && ! defined('DOING_AJAX')) {
671
+			$this->_verify_routes();
672
+			// next let's just check user_access and kill if no access
673
+			$this->check_user_access();
674
+			if ($this->_is_UI_request) {
675
+				// admin_init stuff - global, all views for this page class, specific view
676
+				add_action('admin_init', array($this, 'admin_init'), 10);
677
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
678
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
679
+				}
680
+			} else {
681
+				// hijack regular WP loading and route admin request immediately
682
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
683
+				$this->route_admin_request();
684
+			}
685
+		}
686
+	}
687
+
688
+
689
+	/**
690
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
691
+	 *
692
+	 * @return void
693
+	 * @throws EE_Error
694
+	 */
695
+	private function _do_other_page_hooks()
696
+	{
697
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
698
+		foreach ($registered_pages as $page) {
699
+			// now let's setup the file name and class that should be present
700
+			$classname = str_replace('.class.php', '', $page);
701
+			// autoloaders should take care of loading file
702
+			if (! class_exists($classname)) {
703
+				$error_msg[] = sprintf(
704
+					esc_html__(
705
+						'Something went wrong with loading the %s admin hooks page.',
706
+						'event_espresso'
707
+					),
708
+					$page
709
+				);
710
+				$error_msg[] = $error_msg[0]
711
+							   . "\r\n"
712
+							   . sprintf(
713
+								   esc_html__(
714
+									   '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',
715
+									   'event_espresso'
716
+								   ),
717
+								   $page,
718
+								   '<br />',
719
+								   '<strong>' . $classname . '</strong>'
720
+							   );
721
+				throw new EE_Error(implode('||', $error_msg));
722
+			}
723
+			// // notice we are passing the instance of this class to the hook object.
724
+			$this->loader->getShared($classname, [$this]);
725
+		}
726
+	}
727
+
728
+
729
+	/**
730
+	 * @throws DomainException
731
+	 * @throws EE_Error
732
+	 * @throws InvalidArgumentException
733
+	 * @throws InvalidDataTypeException
734
+	 * @throws InvalidInterfaceException
735
+	 * @throws ReflectionException
736
+	 * @since $VID:$
737
+	 */
738
+	public function load_page_dependencies()
739
+	{
740
+		try {
741
+			$this->_load_page_dependencies();
742
+		} catch (EE_Error $e) {
743
+			$e->get_error();
744
+		}
745
+	}
746
+
747
+
748
+	/**
749
+	 * load_page_dependencies
750
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
751
+	 *
752
+	 * @return void
753
+	 * @throws DomainException
754
+	 * @throws EE_Error
755
+	 * @throws InvalidArgumentException
756
+	 * @throws InvalidDataTypeException
757
+	 * @throws InvalidInterfaceException
758
+	 * @throws ReflectionException
759
+	 */
760
+	protected function _load_page_dependencies()
761
+	{
762
+		// let's set the current_screen and screen options to override what WP set
763
+		$this->_current_screen = get_current_screen();
764
+		// load admin_notices - global, page class, and view specific
765
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
766
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
767
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
768
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
769
+		}
770
+		// load network admin_notices - global, page class, and view specific
771
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
772
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
773
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
774
+		}
775
+		// this will save any per_page screen options if they are present
776
+		$this->_set_per_page_screen_options();
777
+		// setup list table properties
778
+		$this->_set_list_table();
779
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
780
+		// However in some cases the metaboxes will need to be added within a route handling callback.
781
+		$this->_add_registered_meta_boxes();
782
+		$this->_add_screen_columns();
783
+		// add screen options - global, page child class, and view specific
784
+		$this->_add_global_screen_options();
785
+		$this->_add_screen_options();
786
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
787
+		if (method_exists($this, $add_screen_options)) {
788
+			$this->{$add_screen_options}();
789
+		}
790
+		// add help tab(s) and tours- set via page_config and qtips.
791
+		// $this->_add_help_tour();
792
+		$this->_add_help_tabs();
793
+		$this->_add_qtips();
794
+		// add feature_pointers - global, page child class, and view specific
795
+		$this->_add_feature_pointers();
796
+		$this->_add_global_feature_pointers();
797
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
798
+		if (method_exists($this, $add_feature_pointer)) {
799
+			$this->{$add_feature_pointer}();
800
+		}
801
+		// enqueue scripts/styles - global, page class, and view specific
802
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
803
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
804
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
805
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
806
+		}
807
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
808
+		// admin_print_footer_scripts - global, page child class, and view specific.
809
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
810
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
811
+		// is a good use case. Notice the late priority we're giving these
812
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
813
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
814
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
815
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
816
+		}
817
+		// admin footer scripts
818
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
819
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
820
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
821
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
822
+		}
823
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
824
+		// targeted hook
825
+		do_action(
826
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
827
+		);
828
+	}
829
+
830
+
831
+	/**
832
+	 * _set_defaults
833
+	 * This sets some global defaults for class properties.
834
+	 */
835
+	private function _set_defaults()
836
+	{
837
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
838
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
839
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
840
+		$this->_page_config = $this->_default_route_query_args = array();
841
+		$this->_default_nav_tab_name = 'overview';
842
+		// init template args
843
+		$this->_template_args = array(
844
+			'admin_page_header'  => '',
845
+			'admin_page_content' => '',
846
+			'post_body_content'  => '',
847
+			'before_list_table'  => '',
848
+			'after_list_table'   => '',
849
+		);
850
+	}
851
+
852
+
853
+	/**
854
+	 * route_admin_request
855
+	 *
856
+	 * @see    _route_admin_request()
857
+	 * @return exception|void error
858
+	 * @throws InvalidArgumentException
859
+	 * @throws InvalidInterfaceException
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws EE_Error
862
+	 * @throws ReflectionException
863
+	 */
864
+	public function route_admin_request()
865
+	{
866
+		try {
867
+			$this->_route_admin_request();
868
+		} catch (EE_Error $e) {
869
+			$e->get_error();
870
+		}
871
+	}
872
+
873
+
874
+	public function set_wp_page_slug($wp_page_slug)
875
+	{
876
+		$this->_wp_page_slug = $wp_page_slug;
877
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
878
+		if (is_network_admin()) {
879
+			$this->_wp_page_slug .= '-network';
880
+		}
881
+	}
882
+
883
+
884
+	/**
885
+	 * _verify_routes
886
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
887
+	 * we know if we need to drop out.
888
+	 *
889
+	 * @return bool
890
+	 * @throws EE_Error
891
+	 */
892
+	protected function _verify_routes()
893
+	{
894
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
895
+			return false;
896
+		}
897
+		$this->_route = false;
898
+		// check that the page_routes array is not empty
899
+		if (empty($this->_page_routes)) {
900
+			// user error msg
901
+			$error_msg = sprintf(
902
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
903
+				$this->_admin_page_title
904
+			);
905
+			// developer error msg
906
+			$error_msg .= '||' . $error_msg
907
+						  . esc_html__(
908
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
909
+							  'event_espresso'
910
+						  );
911
+			throw new EE_Error($error_msg);
912
+		}
913
+		// and that the requested page route exists
914
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
915
+			$this->_route = $this->_page_routes[ $this->_req_action ];
916
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
917
+				? $this->_page_config[ $this->_req_action ] : array();
918
+		} else {
919
+			// user error msg
920
+			$error_msg = sprintf(
921
+				esc_html__(
922
+					'The requested page route does not exist for the %s admin page.',
923
+					'event_espresso'
924
+				),
925
+				$this->_admin_page_title
926
+			);
927
+			// developer error msg
928
+			$error_msg .= '||' . $error_msg
929
+						  . sprintf(
930
+							  esc_html__(
931
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
932
+								  'event_espresso'
933
+							  ),
934
+							  $this->_req_action
935
+						  );
936
+			throw new EE_Error($error_msg);
937
+		}
938
+		// and that a default route exists
939
+		if (! array_key_exists('default', $this->_page_routes)) {
940
+			// user error msg
941
+			$error_msg = sprintf(
942
+				esc_html__(
943
+					'A default page route has not been set for the % admin page.',
944
+					'event_espresso'
945
+				),
946
+				$this->_admin_page_title
947
+			);
948
+			// developer error msg
949
+			$error_msg .= '||' . $error_msg
950
+						  . esc_html__(
951
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
952
+							  'event_espresso'
953
+						  );
954
+			throw new EE_Error($error_msg);
955
+		}
956
+
957
+		// first lets' catch if the UI request has EVER been set.
958
+		if ($this->_is_UI_request === null) {
959
+			// lets set if this is a UI request or not.
960
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
961
+			// wait a minute... we might have a noheader in the route array
962
+			$this->_is_UI_request = is_array($this->_route)
963
+									&& isset($this->_route['noheader'])
964
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
965
+		}
966
+		$this->_set_current_labels();
967
+		return true;
968
+	}
969
+
970
+
971
+	/**
972
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
973
+	 *
974
+	 * @param  string $route the route name we're verifying
975
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
976
+	 * @throws EE_Error
977
+	 */
978
+	protected function _verify_route($route)
979
+	{
980
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
981
+			return true;
982
+		}
983
+		// user error msg
984
+		$error_msg = sprintf(
985
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
986
+			$this->_admin_page_title
987
+		);
988
+		// developer error msg
989
+		$error_msg .= '||' . $error_msg
990
+					  . sprintf(
991
+						  esc_html__(
992
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
993
+							  'event_espresso'
994
+						  ),
995
+						  $route
996
+					  );
997
+		throw new EE_Error($error_msg);
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * perform nonce verification
1003
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1004
+	 * using this method (and save retyping!)
1005
+	 *
1006
+	 * @param string $nonce     The nonce sent
1007
+	 * @param string $nonce_ref The nonce reference string (name0)
1008
+	 * @return void
1009
+	 * @throws EE_Error
1010
+	 * @throws InvalidArgumentException
1011
+	 * @throws InvalidDataTypeException
1012
+	 * @throws InvalidInterfaceException
1013
+	 */
1014
+	protected function _verify_nonce($nonce, $nonce_ref)
1015
+	{
1016
+		// verify nonce against expected value
1017
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1018
+			// these are not the droids you are looking for !!!
1019
+			$msg = sprintf(
1020
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1021
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
1022
+				'</a>'
1023
+			);
1024
+			if (WP_DEBUG) {
1025
+				$msg .= "\n  "
1026
+						. sprintf(
1027
+							esc_html__(
1028
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1029
+								'event_espresso'
1030
+							),
1031
+							EE_Admin_Page::class
1032
+						);
1033
+			}
1034
+			if (! defined('DOING_AJAX')) {
1035
+				wp_die($msg);
1036
+			} else {
1037
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1038
+				$this->_return_json();
1039
+			}
1040
+		}
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * _route_admin_request()
1046
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1047
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1048
+	 * in the page routes and then will try to load the corresponding method.
1049
+	 *
1050
+	 * @return void
1051
+	 * @throws EE_Error
1052
+	 * @throws InvalidArgumentException
1053
+	 * @throws InvalidDataTypeException
1054
+	 * @throws InvalidInterfaceException
1055
+	 * @throws ReflectionException
1056
+	 */
1057
+	protected function _route_admin_request()
1058
+	{
1059
+		if (! $this->_is_UI_request) {
1060
+			$this->_verify_routes();
1061
+		}
1062
+		$nonce_check = isset($this->_route_config['require_nonce'])
1063
+			? $this->_route_config['require_nonce']
1064
+			: true;
1065
+		if ($this->_req_action !== 'default' && $nonce_check) {
1066
+			// set nonce from post data
1067
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
1068
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1069
+				: '';
1070
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1071
+		}
1072
+		// set the nav_tabs array but ONLY if this is  UI_request
1073
+		if ($this->_is_UI_request) {
1074
+			$this->_set_nav_tabs();
1075
+		}
1076
+		// grab callback function
1077
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1078
+		// check if callback has args
1079
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1080
+		$error_msg = '';
1081
+		// action right before calling route
1082
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1083
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1084
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1085
+		}
1086
+		// right before calling the route, let's remove _wp_http_referer from the
1087
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1088
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1089
+			'_wp_http_referer',
1090
+			wp_unslash($_SERVER['REQUEST_URI'])
1091
+		);
1092
+		if (! empty($func)) {
1093
+			if (is_array($func)) {
1094
+				[$class, $method] = $func;
1095
+			} elseif (strpos($func, '::') !== false) {
1096
+				[$class, $method] = explode('::', $func);
1097
+			} else {
1098
+				$class = $this;
1099
+				$method = $func;
1100
+			}
1101
+			if (! (is_object($class) && $class === $this)) {
1102
+				// send along this admin page object for access by addons.
1103
+				$args['admin_page_object'] = $this;
1104
+			}
1105
+			// is it a method on a class that doesn't work?
1106
+			if (
1107
+				((method_exists($class, $method)
1108
+				  && call_user_func_array(array($class, $method), $args) === false)
1109
+				 && (// is it a standalone function that doesn't work?
1110
+					 function_exists($method)
1111
+					 && call_user_func_array(
1112
+						 $func,
1113
+						 array_merge(array('admin_page_object' => $this), $args)
1114
+					 ) === false
1115
+				 )) || (// is it neither a class method NOR a standalone function?
1116
+					! function_exists($method)
1117
+					&& ! method_exists($class, $method)
1118
+				)
1119
+			) {
1120
+				// user error msg
1121
+				$error_msg = esc_html__(
1122
+					'An error occurred. The  requested page route could not be found.',
1123
+					'event_espresso'
1124
+				);
1125
+				// developer error msg
1126
+				$error_msg .= '||';
1127
+				$error_msg .= sprintf(
1128
+					esc_html__(
1129
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1130
+						'event_espresso'
1131
+					),
1132
+					$method
1133
+				);
1134
+			}
1135
+			if (! empty($error_msg)) {
1136
+				throw new EE_Error($error_msg);
1137
+			}
1138
+		}
1139
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1140
+		// then we need to reset the routing properties to the new route.
1141
+		// 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.
1142
+		if (
1143
+			$this->_is_UI_request === false
1144
+			&& is_array($this->_route)
1145
+			&& ! empty($this->_route['headers_sent_route'])
1146
+		) {
1147
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1148
+		}
1149
+	}
1150
+
1151
+
1152
+	/**
1153
+	 * This method just allows the resetting of page properties in the case where a no headers
1154
+	 * route redirects to a headers route in its route config.
1155
+	 *
1156
+	 * @since   4.3.0
1157
+	 * @param  string $new_route New (non header) route to redirect to.
1158
+	 * @return   void
1159
+	 * @throws ReflectionException
1160
+	 * @throws InvalidArgumentException
1161
+	 * @throws InvalidInterfaceException
1162
+	 * @throws InvalidDataTypeException
1163
+	 * @throws EE_Error
1164
+	 */
1165
+	protected function _reset_routing_properties($new_route)
1166
+	{
1167
+		$this->_is_UI_request = true;
1168
+		// now we set the current route to whatever the headers_sent_route is set at
1169
+		$this->_req_data['action'] = $new_route;
1170
+		// rerun page setup
1171
+		$this->_page_setup();
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * _add_query_arg
1177
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1178
+	 *(internally just uses EEH_URL's function with the same name)
1179
+	 *
1180
+	 * @param array  $args
1181
+	 * @param string $url
1182
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1183
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1184
+	 *                                        Example usage: If the current page is:
1185
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1186
+	 *                                        &action=default&event_id=20&month_range=March%202015
1187
+	 *                                        &_wpnonce=5467821
1188
+	 *                                        and you call:
1189
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1190
+	 *                                        array(
1191
+	 *                                        'action' => 'resend_something',
1192
+	 *                                        'page=>espresso_registrations'
1193
+	 *                                        ),
1194
+	 *                                        $some_url,
1195
+	 *                                        true
1196
+	 *                                        );
1197
+	 *                                        It will produce a url in this structure:
1198
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1199
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1200
+	 *                                        month_range]=March%202015
1201
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1202
+	 * @return string
1203
+	 */
1204
+	public static function add_query_args_and_nonce(
1205
+		$args = array(),
1206
+		$url = '',
1207
+		$sticky = false,
1208
+		$exclude_nonce = false
1209
+	) {
1210
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1211
+		if ($sticky) {
1212
+			$request = $_REQUEST;
1213
+			unset($request['_wp_http_referer'], $request['wp_referer']);
1214
+			foreach ($request as $key => $value) {
1215
+				// do not add nonces
1216
+				if (strpos($key, 'nonce') !== false) {
1217
+					continue;
1218
+				}
1219
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1220
+			}
1221
+		}
1222
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1223
+	}
1224
+
1225
+
1226
+	/**
1227
+	 * This returns a generated link that will load the related help tab.
1228
+	 *
1229
+	 * @param  string $help_tab_id the id for the connected help tab
1230
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1231
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1232
+	 * @uses EEH_Template::get_help_tab_link()
1233
+	 * @return string              generated link
1234
+	 */
1235
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1236
+	{
1237
+		return EEH_Template::get_help_tab_link(
1238
+			$help_tab_id,
1239
+			$this->page_slug,
1240
+			$this->_req_action,
1241
+			$icon_style,
1242
+			$help_text
1243
+		);
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * _add_help_tabs
1249
+	 * Note child classes define their help tabs within the page_config array.
1250
+	 *
1251
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1252
+	 * @return void
1253
+	 * @throws DomainException
1254
+	 * @throws EE_Error
1255
+	 * @throws ReflectionException
1256
+	 */
1257
+	protected function _add_help_tabs()
1258
+	{
1259
+		$tour_buttons = '';
1260
+		if (isset($this->_page_config[ $this->_req_action ])) {
1261
+			$config = $this->_page_config[ $this->_req_action ];
1262
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1263
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1264
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1265
+			//     $tb = array();
1266
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1267
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1268
+			//         // if this is the end tour then we don't need to setup a button
1269
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1270
+			//             continue;
1271
+			//         }
1272
+			//         $tb[] = '<button id="trigger-tour-'
1273
+			//                 . $tour->get_slug()
1274
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1275
+			//                 . $tour->get_label()
1276
+			//                 . '</button>';
1277
+			//     }
1278
+			//     $tour_buttons .= implode('<br />', $tb);
1279
+			//     $tour_buttons .= '</div></div>';
1280
+			// }
1281
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1282
+			if (is_array($config) && isset($config['help_sidebar'])) {
1283
+				// check that the callback given is valid
1284
+				if (! method_exists($this, $config['help_sidebar'])) {
1285
+					throw new EE_Error(
1286
+						sprintf(
1287
+							esc_html__(
1288
+								'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',
1289
+								'event_espresso'
1290
+							),
1291
+							$config['help_sidebar'],
1292
+							get_class($this)
1293
+						)
1294
+					);
1295
+				}
1296
+				$content = apply_filters(
1297
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1298
+					$this->{$config['help_sidebar']}()
1299
+				);
1300
+				$content .= $tour_buttons; // add help tour buttons.
1301
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1302
+				$this->_current_screen->set_help_sidebar($content);
1303
+			}
1304
+			// if there ARE tour buttons...
1305
+			if (! empty($tour_buttons)) {
1306
+				// if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1307
+				if (! isset($config['help_sidebar'])) {
1308
+					$this->_current_screen->set_help_sidebar($tour_buttons);
1309
+				}
1310
+				// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1311
+				if (! isset($config['help_tabs'])) {
1312
+					$_ht['id'] = $this->page_slug;
1313
+					$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1314
+					$_ht['content'] = '<p>'
1315
+									  . esc_html__(
1316
+										  'The buttons to the right allow you to start/restart any help tours available for this page',
1317
+										  'event_espresso'
1318
+									  ) . '</p>';
1319
+					$this->_current_screen->add_help_tab($_ht);
1320
+				}
1321
+			}
1322
+			if (! isset($config['help_tabs'])) {
1323
+				return;
1324
+			} //no help tabs for this route
1325
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1326
+				// we're here so there ARE help tabs!
1327
+				// make sure we've got what we need
1328
+				if (! isset($cfg['title'])) {
1329
+					throw new EE_Error(
1330
+						esc_html__(
1331
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1332
+							'event_espresso'
1333
+						)
1334
+					);
1335
+				}
1336
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1337
+					throw new EE_Error(
1338
+						esc_html__(
1339
+							'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',
1340
+							'event_espresso'
1341
+						)
1342
+					);
1343
+				}
1344
+				// first priority goes to content.
1345
+				if (! empty($cfg['content'])) {
1346
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1347
+					// second priority goes to filename
1348
+				} elseif (! empty($cfg['filename'])) {
1349
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1350
+					// 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)
1351
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1352
+															 . basename($this->_get_dir())
1353
+															 . '/help_tabs/'
1354
+															 . $cfg['filename']
1355
+															 . '.help_tab.php' : $file_path;
1356
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1357
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1358
+						EE_Error::add_error(
1359
+							sprintf(
1360
+								esc_html__(
1361
+									'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',
1362
+									'event_espresso'
1363
+								),
1364
+								$tab_id,
1365
+								key($config),
1366
+								$file_path
1367
+							),
1368
+							__FILE__,
1369
+							__FUNCTION__,
1370
+							__LINE__
1371
+						);
1372
+						return;
1373
+					}
1374
+					$template_args['admin_page_obj'] = $this;
1375
+					$content = EEH_Template::display_template(
1376
+						$file_path,
1377
+						$template_args,
1378
+						true
1379
+					);
1380
+				} else {
1381
+					$content = '';
1382
+				}
1383
+				// check if callback is valid
1384
+				if (
1385
+					empty($content) && (
1386
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1387
+					)
1388
+				) {
1389
+					EE_Error::add_error(
1390
+						sprintf(
1391
+							esc_html__(
1392
+								'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.',
1393
+								'event_espresso'
1394
+							),
1395
+							$cfg['title']
1396
+						),
1397
+						__FILE__,
1398
+						__FUNCTION__,
1399
+						__LINE__
1400
+					);
1401
+					return;
1402
+				}
1403
+				// setup config array for help tab method
1404
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1405
+				$_ht = array(
1406
+					'id'       => $id,
1407
+					'title'    => $cfg['title'],
1408
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1409
+					'content'  => $content,
1410
+				);
1411
+				$this->_current_screen->add_help_tab($_ht);
1412
+			}
1413
+		}
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1419
+	 * an array with properties for setting up usage of the joyride plugin
1420
+	 *
1421
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1422
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1423
+	 *         _set_page_config() comments
1424
+	 * @return void
1425
+	 * @throws EE_Error
1426
+	 * @throws InvalidArgumentException
1427
+	 * @throws InvalidDataTypeException
1428
+	 * @throws InvalidInterfaceException
1429
+	 * @throws ReflectionException
1430
+	 */
1431
+	protected function _add_help_tour()
1432
+	{
1433
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1434
+		// $tours = array();
1435
+		// $this->_help_tour = array();
1436
+		// // exit early if help tours are turned off globally
1437
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1438
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1439
+		// ) {
1440
+		//     return;
1441
+		// }
1442
+		// // loop through _page_config to find any help_tour defined
1443
+		// foreach ($this->_page_config as $route => $config) {
1444
+		//     // we're only going to set things up for this route
1445
+		//     if ($route !== $this->_req_action) {
1446
+		//         continue;
1447
+		//     }
1448
+		//     if (isset($config['help_tour'])) {
1449
+		//         foreach ($config['help_tour'] as $tour) {
1450
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1451
+		//             // let's see if we can get that file...
1452
+		//             // if not its possible this is a decaf route not set in caffeinated
1453
+		//             // so lets try and get the caffeinated equivalent
1454
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1455
+		//                                                      . basename($this->_get_dir())
1456
+		//                                                      . '/help_tours/'
1457
+		//                                                      . $tour
1458
+		//                                                      . '.class.php' : $file_path;
1459
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1460
+		//             if (! is_readable($file_path)) {
1461
+		//                 EE_Error::add_error(
1462
+		//                     sprintf(
1463
+		//                         esc_html__(
1464
+		//                             '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',
1465
+		//                             'event_espresso'
1466
+		//                         ),
1467
+		//                         $file_path,
1468
+		//                         $tour
1469
+		//                     ),
1470
+		//                     __FILE__,
1471
+		//                     __FUNCTION__,
1472
+		//                     __LINE__
1473
+		//                 );
1474
+		//                 return;
1475
+		//             }
1476
+		//             require_once $file_path;
1477
+		//             if (! class_exists($tour)) {
1478
+		//                 $error_msg[] = sprintf(
1479
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1480
+		//                     $tour
1481
+		//                 );
1482
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1483
+		//                                . sprintf(
1484
+		//                                    esc_html__(
1485
+		//                                        '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.',
1486
+		//                                        'event_espresso'
1487
+		//                                    ),
1488
+		//                                    $tour,
1489
+		//                                    '<br />',
1490
+		//                                    $tour,
1491
+		//                                    $this->_req_action,
1492
+		//                                    get_class($this)
1493
+		//                                );
1494
+		//                 throw new EE_Error(implode('||', $error_msg));
1495
+		//             }
1496
+		//             $tour_obj = new $tour($this->_is_caf);
1497
+		//             $tours[] = $tour_obj;
1498
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1499
+		//         }
1500
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1501
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1502
+		//         $tours[] = $end_stop_tour;
1503
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1504
+		//     }
1505
+		// }
1506
+		//
1507
+		// if (! empty($tours)) {
1508
+		//     $this->_help_tour['tours'] = $tours;
1509
+		// }
1510
+		// // that's it!  Now that the $_help_tours property is set (or not)
1511
+		// // the scripts and html should be taken care of automatically.
1512
+		//
1513
+		// /**
1514
+		//  * Allow extending the help tours variable.
1515
+		//  *
1516
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1517
+		//  */
1518
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * This simply sets up any qtips that have been defined in the page config
1524
+	 *
1525
+	 * @return void
1526
+	 * @throws ReflectionException
1527
+	 * @throws EE_Error
1528
+	 */
1529
+	protected function _add_qtips()
1530
+	{
1531
+		if (isset($this->_route_config['qtips'])) {
1532
+			$qtips = (array) $this->_route_config['qtips'];
1533
+			// load qtip loader
1534
+			$path = array(
1535
+				$this->_get_dir() . '/qtips/',
1536
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1537
+			);
1538
+			$qtip_loader = EEH_Qtip_Loader::instance();
1539
+			if ($qtip_loader instanceof EEH_Qtip_Loader) {
1540
+				$qtip_loader->register($qtips, $path);
1541
+			}
1542
+		}
1543
+	}
1544
+
1545
+
1546
+	/**
1547
+	 * _set_nav_tabs
1548
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1549
+	 * wish to add additional tabs or modify accordingly.
1550
+	 *
1551
+	 * @return void
1552
+	 * @throws InvalidArgumentException
1553
+	 * @throws InvalidInterfaceException
1554
+	 * @throws InvalidDataTypeException
1555
+	 */
1556
+	protected function _set_nav_tabs()
1557
+	{
1558
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1559
+		$i = 0;
1560
+		foreach ($this->_page_config as $slug => $config) {
1561
+			if (
1562
+				! is_array($config)
1563
+				|| (
1564
+					is_array($config)
1565
+					&& (
1566
+						(isset($config['nav']) && ! $config['nav'])
1567
+						|| ! isset($config['nav'])
1568
+					)
1569
+				)
1570
+			) {
1571
+				continue;
1572
+			}
1573
+			// no nav tab for this config
1574
+			// check for persistent flag
1575
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1576
+				// nav tab is only to appear when route requested.
1577
+				continue;
1578
+			}
1579
+			if (! $this->check_user_access($slug, true)) {
1580
+				// no nav tab because current user does not have access.
1581
+				continue;
1582
+			}
1583
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1584
+			$this->_nav_tabs[ $slug ] = array(
1585
+				'url'       => isset($config['nav']['url'])
1586
+					? $config['nav']['url']
1587
+					: EE_Admin_Page::add_query_args_and_nonce(
1588
+						array('action' => $slug),
1589
+						$this->_admin_base_url
1590
+					),
1591
+				'link_text' => isset($config['nav']['label'])
1592
+					? $config['nav']['label']
1593
+					: ucwords(
1594
+						str_replace('_', ' ', $slug)
1595
+					),
1596
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1597
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1598
+			);
1599
+			$i++;
1600
+		}
1601
+		// if $this->_nav_tabs is empty then lets set the default
1602
+		if (empty($this->_nav_tabs)) {
1603
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1604
+				'url'       => $this->_admin_base_url,
1605
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1606
+				'css_class' => 'nav-tab-active',
1607
+				'order'     => 10,
1608
+			);
1609
+		}
1610
+		// now let's sort the tabs according to order
1611
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1612
+	}
1613
+
1614
+
1615
+	/**
1616
+	 * _set_current_labels
1617
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1618
+	 * property array
1619
+	 *
1620
+	 * @return void
1621
+	 */
1622
+	private function _set_current_labels()
1623
+	{
1624
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1625
+			foreach ($this->_route_config['labels'] as $label => $text) {
1626
+				if (is_array($text)) {
1627
+					foreach ($text as $sublabel => $subtext) {
1628
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1629
+					}
1630
+				} else {
1631
+					$this->_labels[ $label ] = $text;
1632
+				}
1633
+			}
1634
+		}
1635
+	}
1636
+
1637
+
1638
+	/**
1639
+	 *        verifies user access for this admin page
1640
+	 *
1641
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1642
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1643
+	 *                               return false if verify fail.
1644
+	 * @return bool
1645
+	 * @throws InvalidArgumentException
1646
+	 * @throws InvalidDataTypeException
1647
+	 * @throws InvalidInterfaceException
1648
+	 */
1649
+	public function check_user_access($route_to_check = '', $verify_only = false)
1650
+	{
1651
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1652
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1653
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1654
+					  && is_array(
1655
+						  $this->_page_routes[ $route_to_check ]
1656
+					  )
1657
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1658
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1659
+		if (empty($capability) && empty($route_to_check)) {
1660
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1661
+				: $this->_route['capability'];
1662
+		} else {
1663
+			$capability = empty($capability) ? 'manage_options' : $capability;
1664
+		}
1665
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1666
+		if (
1667
+			! defined('DOING_AJAX')
1668
+			&& (
1669
+				! function_exists('is_admin')
1670
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1671
+					$capability,
1672
+					$this->page_slug
1673
+					. '_'
1674
+					. $route_to_check,
1675
+					$id
1676
+				)
1677
+			)
1678
+		) {
1679
+			if ($verify_only) {
1680
+				return false;
1681
+			}
1682
+			if (is_user_logged_in()) {
1683
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1684
+			} else {
1685
+				return false;
1686
+			}
1687
+		}
1688
+		return true;
1689
+	}
1690
+
1691
+
1692
+	/**
1693
+	 * admin_init_global
1694
+	 * This runs all the code that we want executed within the WP admin_init hook.
1695
+	 * This method executes for ALL EE Admin pages.
1696
+	 *
1697
+	 * @return void
1698
+	 */
1699
+	public function admin_init_global()
1700
+	{
1701
+	}
1702
+
1703
+
1704
+	/**
1705
+	 * wp_loaded_global
1706
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1707
+	 * EE_Admin page and will execute on every EE Admin Page load
1708
+	 *
1709
+	 * @return void
1710
+	 */
1711
+	public function wp_loaded()
1712
+	{
1713
+	}
1714
+
1715
+
1716
+	/**
1717
+	 * admin_notices
1718
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1719
+	 * ALL EE_Admin pages.
1720
+	 *
1721
+	 * @return void
1722
+	 */
1723
+	public function admin_notices_global()
1724
+	{
1725
+		$this->_display_no_javascript_warning();
1726
+		$this->_display_espresso_notices();
1727
+	}
1728
+
1729
+
1730
+	public function network_admin_notices_global()
1731
+	{
1732
+		$this->_display_no_javascript_warning();
1733
+		$this->_display_espresso_notices();
1734
+	}
1735
+
1736
+
1737
+	/**
1738
+	 * admin_footer_scripts_global
1739
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1740
+	 * will apply on ALL EE_Admin pages.
1741
+	 *
1742
+	 * @return void
1743
+	 */
1744
+	public function admin_footer_scripts_global()
1745
+	{
1746
+		$this->_add_admin_page_ajax_loading_img();
1747
+		$this->_add_admin_page_overlay();
1748
+		// if metaboxes are present we need to add the nonce field
1749
+		if (
1750
+			isset($this->_route_config['metaboxes'])
1751
+			|| isset($this->_route_config['list_table'])
1752
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1753
+		) {
1754
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1755
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1756
+		}
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 * admin_footer_global
1762
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1763
+	 * This particular method will apply on ALL EE_Admin Pages.
1764
+	 *
1765
+	 * @return void
1766
+	 * @throws InvalidArgumentException
1767
+	 * @throws InvalidDataTypeException
1768
+	 * @throws InvalidInterfaceException
1769
+	 */
1770
+	public function admin_footer_global()
1771
+	{
1772
+		// dialog container for dialog helper
1773
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1774
+		$d_cont .= '<div class="ee-notices"></div>';
1775
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1776
+		$d_cont .= '</div>';
1777
+		echo $d_cont;
1778
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1779
+		// help tour stuff?
1780
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1781
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1782
+		// }
1783
+		// current set timezone for timezone js
1784
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1785
+	}
1786
+
1787
+
1788
+	/**
1789
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1790
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1791
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1792
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1793
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1794
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1795
+	 * for the
1796
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1797
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1798
+	 *    'help_trigger_id' => array(
1799
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1800
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1801
+	 *    )
1802
+	 * );
1803
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1804
+	 *
1805
+	 * @param array $help_array
1806
+	 * @param bool  $display
1807
+	 * @return string content
1808
+	 * @throws DomainException
1809
+	 * @throws EE_Error
1810
+	 */
1811
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1812
+	{
1813
+		$content = '';
1814
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1815
+		// loop through the array and setup content
1816
+		foreach ($help_array as $trigger => $help) {
1817
+			// make sure the array is setup properly
1818
+			if (! isset($help['title'], $help['content'])) {
1819
+				throw new EE_Error(
1820
+					esc_html__(
1821
+						'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',
1822
+						'event_espresso'
1823
+					)
1824
+				);
1825
+			}
1826
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1827
+			$template_args = array(
1828
+				'help_popup_id'      => $trigger,
1829
+				'help_popup_title'   => $help['title'],
1830
+				'help_popup_content' => $help['content'],
1831
+			);
1832
+			$content .= EEH_Template::display_template(
1833
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1834
+				$template_args,
1835
+				true
1836
+			);
1837
+		}
1838
+		if ($display) {
1839
+			echo $content;
1840
+			return '';
1841
+		}
1842
+		return $content;
1843
+	}
1844
+
1845
+
1846
+	/**
1847
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1848
+	 *
1849
+	 * @return array properly formatted array for help popup content
1850
+	 * @throws EE_Error
1851
+	 */
1852
+	private function _get_help_content()
1853
+	{
1854
+		// what is the method we're looking for?
1855
+		$method_name = '_help_popup_content_' . $this->_req_action;
1856
+		// if method doesn't exist let's get out.
1857
+		if (! method_exists($this, $method_name)) {
1858
+			return array();
1859
+		}
1860
+		// k we're good to go let's retrieve the help array
1861
+		$help_array = $this->{$method_name}();
1862
+		// make sure we've got an array!
1863
+		if (! is_array($help_array)) {
1864
+			throw new EE_Error(
1865
+				esc_html__(
1866
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1867
+					'event_espresso'
1868
+				)
1869
+			);
1870
+		}
1871
+		return $help_array;
1872
+	}
1873
+
1874
+
1875
+	/**
1876
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1877
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1878
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1879
+	 *
1880
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1881
+	 * @param boolean $display    if false then we return the trigger string
1882
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1883
+	 * @return string
1884
+	 * @throws DomainException
1885
+	 * @throws EE_Error
1886
+	 */
1887
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1888
+	{
1889
+		if (defined('DOING_AJAX')) {
1890
+			return '';
1891
+		}
1892
+		// 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
1893
+		$help_array = $this->_get_help_content();
1894
+		$help_content = '';
1895
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1896
+			$help_array[ $trigger_id ] = array(
1897
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1898
+				'content' => esc_html__(
1899
+					'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.)',
1900
+					'event_espresso'
1901
+				),
1902
+			);
1903
+			$help_content = $this->_set_help_popup_content($help_array);
1904
+		}
1905
+		// let's setup the trigger
1906
+		$content = '<a class="ee-dialog" href="?height='
1907
+				   . $dimensions[0]
1908
+				   . '&width='
1909
+				   . $dimensions[1]
1910
+				   . '&inlineId='
1911
+				   . $trigger_id
1912
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1913
+		$content .= $help_content;
1914
+		if ($display) {
1915
+			echo $content;
1916
+			return '';
1917
+		}
1918
+		return $content;
1919
+	}
1920
+
1921
+
1922
+	/**
1923
+	 * _add_global_screen_options
1924
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1925
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1926
+	 *
1927
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1928
+	 *         see also WP_Screen object documents...
1929
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1930
+	 * @abstract
1931
+	 * @return void
1932
+	 */
1933
+	private function _add_global_screen_options()
1934
+	{
1935
+	}
1936
+
1937
+
1938
+	/**
1939
+	 * _add_global_feature_pointers
1940
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1941
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1942
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1943
+	 *
1944
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1945
+	 *         extended) also see:
1946
+	 * @link   http://eamann.com/tech/wordpress-portland/
1947
+	 * @abstract
1948
+	 * @return void
1949
+	 */
1950
+	private function _add_global_feature_pointers()
1951
+	{
1952
+	}
1953
+
1954
+
1955
+	/**
1956
+	 * load_global_scripts_styles
1957
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1958
+	 *
1959
+	 * @return void
1960
+	 * @throws EE_Error
1961
+	 */
1962
+	public function load_global_scripts_styles()
1963
+	{
1964
+		// add debugging styles
1965
+		if (WP_DEBUG) {
1966
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1967
+		}
1968
+		// taking care of metaboxes
1969
+		if (
1970
+			empty($this->_cpt_route)
1971
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1972
+		) {
1973
+			wp_enqueue_script('dashboard');
1974
+		}
1975
+
1976
+		// LOCALIZED DATA
1977
+		// localize script for ajax lazy loading
1978
+		wp_localize_script(
1979
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1980
+			'eeLazyLoadingContainers',
1981
+			apply_filters(
1982
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1983
+				['espresso_news_post_box_content']
1984
+			)
1985
+		);
1986
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1987
+		// /**
1988
+		//  * help tour stuff
1989
+		//  */
1990
+		// if (! empty($this->_help_tour)) {
1991
+		//     // register the js for kicking things off
1992
+		//     wp_enqueue_script(
1993
+		//         'ee-help-tour',
1994
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1995
+		//         array('jquery-joyride'),
1996
+		//         EVENT_ESPRESSO_VERSION,
1997
+		//         true
1998
+		//     );
1999
+		//     $tours = array();
2000
+		//     // setup tours for the js tour object
2001
+		//     foreach ($this->_help_tour['tours'] as $tour) {
2002
+		//         if ($tour instanceof EE_Help_Tour) {
2003
+		//             $tours[] = array(
2004
+		//                 'id'      => $tour->get_slug(),
2005
+		//                 'options' => $tour->get_options(),
2006
+		//             );
2007
+		//         }
2008
+		//     }
2009
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2010
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2011
+		// }
2012
+	}
2013
+
2014
+
2015
+	/**
2016
+	 *        admin_footer_scripts_eei18n_js_strings
2017
+	 *
2018
+	 * @return        void
2019
+	 */
2020
+	public function admin_footer_scripts_eei18n_js_strings()
2021
+	{
2022
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2023
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2024
+			'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!!!',
2025
+			'event_espresso'
2026
+		);
2027
+		EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2028
+		EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2029
+		EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2030
+		EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2031
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2032
+		EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2033
+		EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2034
+		EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2035
+		EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2036
+		EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2037
+		EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2038
+		EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2039
+		EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2040
+		EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2041
+		EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2042
+		EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2043
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2044
+		EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2045
+		EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2046
+		EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2047
+		EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2048
+		EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2049
+		EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2050
+		EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2051
+		EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2052
+		EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2053
+		EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2054
+		EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2055
+		EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2056
+		EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2057
+		EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2058
+		EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2059
+		EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2060
+		EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2061
+		EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2062
+		EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2063
+		EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2064
+		EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2070
+	 *
2071
+	 * @return        void
2072
+	 */
2073
+	public function add_xdebug_style()
2074
+	{
2075
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2076
+	}
2077
+
2078
+
2079
+	/************************/
2080
+	/** LIST TABLE METHODS **/
2081
+	/************************/
2082
+	/**
2083
+	 * this sets up the list table if the current view requires it.
2084
+	 *
2085
+	 * @return void
2086
+	 * @throws EE_Error
2087
+	 * @throws InvalidArgumentException
2088
+	 * @throws InvalidDataTypeException
2089
+	 * @throws InvalidInterfaceException
2090
+	 */
2091
+	protected function _set_list_table()
2092
+	{
2093
+		// first is this a list_table view?
2094
+		if (! isset($this->_route_config['list_table'])) {
2095
+			return;
2096
+		} //not a list_table view so get out.
2097
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2098
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2099
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2100
+			// user error msg
2101
+			$error_msg = esc_html__(
2102
+				'An error occurred. The requested list table views could not be found.',
2103
+				'event_espresso'
2104
+			);
2105
+			// developer error msg
2106
+			$error_msg .= '||'
2107
+						  . sprintf(
2108
+							  esc_html__(
2109
+								  '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.',
2110
+								  'event_espresso'
2111
+							  ),
2112
+							  $this->_req_action,
2113
+							  $list_table_view
2114
+						  );
2115
+			throw new EE_Error($error_msg);
2116
+		}
2117
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2118
+		$this->_views = apply_filters(
2119
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2120
+			$this->_views
2121
+		);
2122
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2123
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2124
+		$this->_set_list_table_view();
2125
+		$this->_set_list_table_object();
2126
+	}
2127
+
2128
+
2129
+	/**
2130
+	 * set current view for List Table
2131
+	 *
2132
+	 * @return void
2133
+	 */
2134
+	protected function _set_list_table_view()
2135
+	{
2136
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2137
+		// looking at active items or dumpster diving ?
2138
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2139
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2140
+		} else {
2141
+			$this->_view = sanitize_key($this->_req_data['status']);
2142
+		}
2143
+	}
2144
+
2145
+
2146
+	/**
2147
+	 * _set_list_table_object
2148
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2149
+	 *
2150
+	 * @throws InvalidInterfaceException
2151
+	 * @throws InvalidArgumentException
2152
+	 * @throws InvalidDataTypeException
2153
+	 * @throws EE_Error
2154
+	 * @throws InvalidInterfaceException
2155
+	 */
2156
+	protected function _set_list_table_object()
2157
+	{
2158
+		if (isset($this->_route_config['list_table'])) {
2159
+			if (! class_exists($this->_route_config['list_table'])) {
2160
+				throw new EE_Error(
2161
+					sprintf(
2162
+						esc_html__(
2163
+							'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.',
2164
+							'event_espresso'
2165
+						),
2166
+						$this->_route_config['list_table'],
2167
+						get_class($this)
2168
+					)
2169
+				);
2170
+			}
2171
+			$this->_list_table_object = $this->loader->getShared(
2172
+				$this->_route_config['list_table'],
2173
+				array($this)
2174
+			);
2175
+		}
2176
+	}
2177
+
2178
+
2179
+	/**
2180
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2181
+	 *
2182
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2183
+	 *                                                    urls.  The array should be indexed by the view it is being
2184
+	 *                                                    added to.
2185
+	 * @return array
2186
+	 */
2187
+	public function get_list_table_view_RLs($extra_query_args = array())
2188
+	{
2189
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
+		if (empty($this->_views)) {
2191
+			$this->_views = array();
2192
+		}
2193
+		// cycle thru views
2194
+		foreach ($this->_views as $key => $view) {
2195
+			$query_args = array();
2196
+			// check for current view
2197
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2198
+			$query_args['action'] = $this->_req_action;
2199
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2200
+			$query_args['status'] = $view['slug'];
2201
+			// merge any other arguments sent in.
2202
+			if (isset($extra_query_args[ $view['slug'] ])) {
2203
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2204
+					$query_args[] = $extra_query_arg;
2205
+				}
2206
+			}
2207
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2208
+		}
2209
+		return $this->_views;
2210
+	}
2211
+
2212
+
2213
+	/**
2214
+	 * _entries_per_page_dropdown
2215
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2216
+	 *
2217
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2218
+	 *         WP does it.
2219
+	 * @param int $max_entries total number of rows in the table
2220
+	 * @return string
2221
+	 */
2222
+	protected function _entries_per_page_dropdown($max_entries = 0)
2223
+	{
2224
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2225
+		$values = array(10, 25, 50, 100);
2226
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2227
+		if ($max_entries) {
2228
+			$values[] = $max_entries;
2229
+			sort($values);
2230
+		}
2231
+		$entries_per_page_dropdown = '
2232 2232
 			<div id="entries-per-page-dv" class="alignleft actions">
2233 2233
 				<label class="hide-if-no-js">
2234 2234
 					Show
2235 2235
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2236
-        foreach ($values as $value) {
2237
-            if ($value < $max_entries) {
2238
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2239
-                $entries_per_page_dropdown .= '
2236
+		foreach ($values as $value) {
2237
+			if ($value < $max_entries) {
2238
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2239
+				$entries_per_page_dropdown .= '
2240 2240
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2241
-            }
2242
-        }
2243
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2244
-        $entries_per_page_dropdown .= '
2241
+			}
2242
+		}
2243
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2244
+		$entries_per_page_dropdown .= '
2245 2245
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2246
-        $entries_per_page_dropdown .= '
2246
+		$entries_per_page_dropdown .= '
2247 2247
 					</select>
2248 2248
 					entries
2249 2249
 				</label>
2250 2250
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2251 2251
 			</div>
2252 2252
 		';
2253
-        return $entries_per_page_dropdown;
2254
-    }
2255
-
2256
-
2257
-    /**
2258
-     *        _set_search_attributes
2259
-     *
2260
-     * @return        void
2261
-     */
2262
-    public function _set_search_attributes()
2263
-    {
2264
-        $this->_template_args['search']['btn_label'] = sprintf(
2265
-            esc_html__('Search %s', 'event_espresso'),
2266
-            empty($this->_search_btn_label) ? $this->page_label
2267
-                : $this->_search_btn_label
2268
-        );
2269
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2270
-    }
2271
-
2272
-
2273
-
2274
-    /*** END LIST TABLE METHODS **/
2275
-
2276
-
2277
-    /**
2278
-     * _add_registered_metaboxes
2279
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2280
-     *
2281
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2282
-     * @return void
2283
-     * @throws EE_Error
2284
-     */
2285
-    private function _add_registered_meta_boxes()
2286
-    {
2287
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2288
-        // we only add meta boxes if the page_route calls for it
2289
-        if (
2290
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2291
-            && is_array(
2292
-                $this->_route_config['metaboxes']
2293
-            )
2294
-        ) {
2295
-            // this simply loops through the callbacks provided
2296
-            // and checks if there is a corresponding callback registered by the child
2297
-            // if there is then we go ahead and process the metabox loader.
2298
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2299
-                // first check for Closures
2300
-                if ($metabox_callback instanceof Closure) {
2301
-                    $result = $metabox_callback();
2302
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2303
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2304
-                } else {
2305
-                    $result = $this->{$metabox_callback}();
2306
-                }
2307
-                if ($result === false) {
2308
-                    // user error msg
2309
-                    $error_msg = esc_html__(
2310
-                        'An error occurred. The  requested metabox could not be found.',
2311
-                        'event_espresso'
2312
-                    );
2313
-                    // developer error msg
2314
-                    $error_msg .= '||'
2315
-                                  . sprintf(
2316
-                                      esc_html__(
2317
-                                          '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.',
2318
-                                          'event_espresso'
2319
-                                      ),
2320
-                                      $metabox_callback
2321
-                                  );
2322
-                    throw new EE_Error($error_msg);
2323
-                }
2324
-            }
2325
-        }
2326
-    }
2327
-
2328
-
2329
-    /**
2330
-     * _add_screen_columns
2331
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2332
-     * the dynamic column template and we'll setup the column options for the page.
2333
-     *
2334
-     * @return void
2335
-     */
2336
-    private function _add_screen_columns()
2337
-    {
2338
-        if (
2339
-            is_array($this->_route_config)
2340
-            && isset($this->_route_config['columns'])
2341
-            && is_array($this->_route_config['columns'])
2342
-            && count($this->_route_config['columns']) === 2
2343
-        ) {
2344
-            add_screen_option(
2345
-                'layout_columns',
2346
-                array(
2347
-                    'max'     => (int) $this->_route_config['columns'][0],
2348
-                    'default' => (int) $this->_route_config['columns'][1],
2349
-                )
2350
-            );
2351
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2352
-            $screen_id = $this->_current_screen->id;
2353
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2354
-            $total_columns = ! empty($screen_columns)
2355
-                ? $screen_columns
2356
-                : $this->_route_config['columns'][1];
2357
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2358
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2359
-            $this->_template_args['screen'] = $this->_current_screen;
2360
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2361
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2362
-            // finally if we don't have has_metaboxes set in the route config
2363
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2364
-            $this->_route_config['has_metaboxes'] = true;
2365
-        }
2366
-    }
2367
-
2368
-
2369
-
2370
-    /** GLOBALLY AVAILABLE METABOXES **/
2371
-
2372
-
2373
-    /**
2374
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2375
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2376
-     * these get loaded on.
2377
-     */
2378
-    private function _espresso_news_post_box()
2379
-    {
2380
-        $news_box_title = apply_filters(
2381
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2382
-            esc_html__('New @ Event Espresso', 'event_espresso')
2383
-        );
2384
-        add_meta_box(
2385
-            'espresso_news_post_box',
2386
-            $news_box_title,
2387
-            array(
2388
-                $this,
2389
-                'espresso_news_post_box',
2390
-            ),
2391
-            $this->_wp_page_slug,
2392
-            'side'
2393
-        );
2394
-    }
2395
-
2396
-
2397
-    /**
2398
-     * Code for setting up espresso ratings request metabox.
2399
-     */
2400
-    protected function _espresso_ratings_request()
2401
-    {
2402
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2403
-            return;
2404
-        }
2405
-        $ratings_box_title = apply_filters(
2406
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2407
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2408
-        );
2409
-        add_meta_box(
2410
-            'espresso_ratings_request',
2411
-            $ratings_box_title,
2412
-            array(
2413
-                $this,
2414
-                'espresso_ratings_request',
2415
-            ),
2416
-            $this->_wp_page_slug,
2417
-            'side'
2418
-        );
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     * Code for setting up espresso ratings request metabox content.
2424
-     *
2425
-     * @throws DomainException
2426
-     */
2427
-    public function espresso_ratings_request()
2428
-    {
2429
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2430
-    }
2431
-
2432
-
2433
-    public static function cached_rss_display($rss_id, $url)
2434
-    {
2435
-        $loading = '<p class="widget-loading hide-if-no-js">'
2436
-                   . __('Loading&#8230;', 'event_espresso')
2437
-                   . '</p><p class="hide-if-js">'
2438
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2439
-                   . '</p>';
2440
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2441
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2442
-        $post = '</div>' . "\n";
2443
-        $cache_key = 'ee_rss_' . md5($rss_id);
2444
-        $output = get_transient($cache_key);
2445
-        if ($output !== false) {
2446
-            echo $pre . $output . $post;
2447
-            return true;
2448
-        }
2449
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2450
-            echo $pre . $loading . $post;
2451
-            return false;
2452
-        }
2453
-        ob_start();
2454
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2455
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2456
-        return true;
2457
-    }
2458
-
2459
-
2460
-    public function espresso_news_post_box()
2461
-    {
2462
-        ?>
2253
+		return $entries_per_page_dropdown;
2254
+	}
2255
+
2256
+
2257
+	/**
2258
+	 *        _set_search_attributes
2259
+	 *
2260
+	 * @return        void
2261
+	 */
2262
+	public function _set_search_attributes()
2263
+	{
2264
+		$this->_template_args['search']['btn_label'] = sprintf(
2265
+			esc_html__('Search %s', 'event_espresso'),
2266
+			empty($this->_search_btn_label) ? $this->page_label
2267
+				: $this->_search_btn_label
2268
+		);
2269
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2270
+	}
2271
+
2272
+
2273
+
2274
+	/*** END LIST TABLE METHODS **/
2275
+
2276
+
2277
+	/**
2278
+	 * _add_registered_metaboxes
2279
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2280
+	 *
2281
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2282
+	 * @return void
2283
+	 * @throws EE_Error
2284
+	 */
2285
+	private function _add_registered_meta_boxes()
2286
+	{
2287
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2288
+		// we only add meta boxes if the page_route calls for it
2289
+		if (
2290
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2291
+			&& is_array(
2292
+				$this->_route_config['metaboxes']
2293
+			)
2294
+		) {
2295
+			// this simply loops through the callbacks provided
2296
+			// and checks if there is a corresponding callback registered by the child
2297
+			// if there is then we go ahead and process the metabox loader.
2298
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2299
+				// first check for Closures
2300
+				if ($metabox_callback instanceof Closure) {
2301
+					$result = $metabox_callback();
2302
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2303
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2304
+				} else {
2305
+					$result = $this->{$metabox_callback}();
2306
+				}
2307
+				if ($result === false) {
2308
+					// user error msg
2309
+					$error_msg = esc_html__(
2310
+						'An error occurred. The  requested metabox could not be found.',
2311
+						'event_espresso'
2312
+					);
2313
+					// developer error msg
2314
+					$error_msg .= '||'
2315
+								  . sprintf(
2316
+									  esc_html__(
2317
+										  '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.',
2318
+										  'event_espresso'
2319
+									  ),
2320
+									  $metabox_callback
2321
+								  );
2322
+					throw new EE_Error($error_msg);
2323
+				}
2324
+			}
2325
+		}
2326
+	}
2327
+
2328
+
2329
+	/**
2330
+	 * _add_screen_columns
2331
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2332
+	 * the dynamic column template and we'll setup the column options for the page.
2333
+	 *
2334
+	 * @return void
2335
+	 */
2336
+	private function _add_screen_columns()
2337
+	{
2338
+		if (
2339
+			is_array($this->_route_config)
2340
+			&& isset($this->_route_config['columns'])
2341
+			&& is_array($this->_route_config['columns'])
2342
+			&& count($this->_route_config['columns']) === 2
2343
+		) {
2344
+			add_screen_option(
2345
+				'layout_columns',
2346
+				array(
2347
+					'max'     => (int) $this->_route_config['columns'][0],
2348
+					'default' => (int) $this->_route_config['columns'][1],
2349
+				)
2350
+			);
2351
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2352
+			$screen_id = $this->_current_screen->id;
2353
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2354
+			$total_columns = ! empty($screen_columns)
2355
+				? $screen_columns
2356
+				: $this->_route_config['columns'][1];
2357
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2358
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2359
+			$this->_template_args['screen'] = $this->_current_screen;
2360
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2361
+										   . 'admin_details_metabox_column_wrapper.template.php';
2362
+			// finally if we don't have has_metaboxes set in the route config
2363
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2364
+			$this->_route_config['has_metaboxes'] = true;
2365
+		}
2366
+	}
2367
+
2368
+
2369
+
2370
+	/** GLOBALLY AVAILABLE METABOXES **/
2371
+
2372
+
2373
+	/**
2374
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2375
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2376
+	 * these get loaded on.
2377
+	 */
2378
+	private function _espresso_news_post_box()
2379
+	{
2380
+		$news_box_title = apply_filters(
2381
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2382
+			esc_html__('New @ Event Espresso', 'event_espresso')
2383
+		);
2384
+		add_meta_box(
2385
+			'espresso_news_post_box',
2386
+			$news_box_title,
2387
+			array(
2388
+				$this,
2389
+				'espresso_news_post_box',
2390
+			),
2391
+			$this->_wp_page_slug,
2392
+			'side'
2393
+		);
2394
+	}
2395
+
2396
+
2397
+	/**
2398
+	 * Code for setting up espresso ratings request metabox.
2399
+	 */
2400
+	protected function _espresso_ratings_request()
2401
+	{
2402
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2403
+			return;
2404
+		}
2405
+		$ratings_box_title = apply_filters(
2406
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2407
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2408
+		);
2409
+		add_meta_box(
2410
+			'espresso_ratings_request',
2411
+			$ratings_box_title,
2412
+			array(
2413
+				$this,
2414
+				'espresso_ratings_request',
2415
+			),
2416
+			$this->_wp_page_slug,
2417
+			'side'
2418
+		);
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 * Code for setting up espresso ratings request metabox content.
2424
+	 *
2425
+	 * @throws DomainException
2426
+	 */
2427
+	public function espresso_ratings_request()
2428
+	{
2429
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2430
+	}
2431
+
2432
+
2433
+	public static function cached_rss_display($rss_id, $url)
2434
+	{
2435
+		$loading = '<p class="widget-loading hide-if-no-js">'
2436
+				   . __('Loading&#8230;', 'event_espresso')
2437
+				   . '</p><p class="hide-if-js">'
2438
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2439
+				   . '</p>';
2440
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2441
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2442
+		$post = '</div>' . "\n";
2443
+		$cache_key = 'ee_rss_' . md5($rss_id);
2444
+		$output = get_transient($cache_key);
2445
+		if ($output !== false) {
2446
+			echo $pre . $output . $post;
2447
+			return true;
2448
+		}
2449
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2450
+			echo $pre . $loading . $post;
2451
+			return false;
2452
+		}
2453
+		ob_start();
2454
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2455
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2456
+		return true;
2457
+	}
2458
+
2459
+
2460
+	public function espresso_news_post_box()
2461
+	{
2462
+		?>
2463 2463
         <div class="padding">
2464 2464
             <div id="espresso_news_post_box_content" class="infolinks">
2465 2465
                 <?php
2466
-                // Get RSS Feed(s)
2467
-                EE_Admin_Page::cached_rss_display(
2468
-                    'espresso_news_post_box_content',
2469
-                    urlencode(
2470
-                        apply_filters(
2471
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2472
-                            'http://eventespresso.com/feed/'
2473
-                        )
2474
-                    )
2475
-                );
2476
-                ?>
2466
+				// Get RSS Feed(s)
2467
+				EE_Admin_Page::cached_rss_display(
2468
+					'espresso_news_post_box_content',
2469
+					urlencode(
2470
+						apply_filters(
2471
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2472
+							'http://eventespresso.com/feed/'
2473
+						)
2474
+					)
2475
+				);
2476
+				?>
2477 2477
             </div>
2478 2478
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2479 2479
         </div>
2480 2480
         <?php
2481
-    }
2482
-
2483
-
2484
-    private function _espresso_links_post_box()
2485
-    {
2486
-        // Hiding until we actually have content to put in here...
2487
-        // 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');
2488
-    }
2489
-
2490
-
2491
-    public function espresso_links_post_box()
2492
-    {
2493
-        // Hiding until we actually have content to put in here...
2494
-        // EEH_Template::display_template(
2495
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2496
-        // );
2497
-    }
2498
-
2499
-
2500
-    protected function _espresso_sponsors_post_box()
2501
-    {
2502
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2503
-            add_meta_box(
2504
-                'espresso_sponsors_post_box',
2505
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2506
-                array($this, 'espresso_sponsors_post_box'),
2507
-                $this->_wp_page_slug,
2508
-                'side'
2509
-            );
2510
-        }
2511
-    }
2512
-
2513
-
2514
-    public function espresso_sponsors_post_box()
2515
-    {
2516
-        EEH_Template::display_template(
2517
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2518
-        );
2519
-    }
2520
-
2521
-
2522
-    private function _publish_post_box()
2523
-    {
2524
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2525
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2526
-        // then we'll use that for the metabox label.
2527
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2528
-        if (! empty($this->_labels['publishbox'])) {
2529
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2530
-                : $this->_labels['publishbox'];
2531
-        } else {
2532
-            $box_label = esc_html__('Publish', 'event_espresso');
2533
-        }
2534
-        $box_label = apply_filters(
2535
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2536
-            $box_label,
2537
-            $this->_req_action,
2538
-            $this
2539
-        );
2540
-        add_meta_box(
2541
-            $meta_box_ref,
2542
-            $box_label,
2543
-            array($this, 'editor_overview'),
2544
-            $this->_current_screen->id,
2545
-            'side',
2546
-            'high'
2547
-        );
2548
-    }
2549
-
2550
-
2551
-    public function editor_overview()
2552
-    {
2553
-        // if we have extra content set let's add it in if not make sure its empty
2554
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2555
-            ? $this->_template_args['publish_box_extra_content']
2556
-            : '';
2557
-        echo EEH_Template::display_template(
2558
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2559
-            $this->_template_args,
2560
-            true
2561
-        );
2562
-    }
2563
-
2564
-
2565
-    /** end of globally available metaboxes section **/
2566
-
2567
-
2568
-    /**
2569
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2570
-     * protected method.
2571
-     *
2572
-     * @see   $this->_set_publish_post_box_vars for param details
2573
-     * @since 4.6.0
2574
-     * @param string $name
2575
-     * @param int    $id
2576
-     * @param bool   $delete
2577
-     * @param string $save_close_redirect_URL
2578
-     * @param bool   $both_btns
2579
-     * @throws EE_Error
2580
-     * @throws InvalidArgumentException
2581
-     * @throws InvalidDataTypeException
2582
-     * @throws InvalidInterfaceException
2583
-     */
2584
-    public function set_publish_post_box_vars(
2585
-        $name = '',
2586
-        $id = 0,
2587
-        $delete = false,
2588
-        $save_close_redirect_URL = '',
2589
-        $both_btns = true
2590
-    ) {
2591
-        $this->_set_publish_post_box_vars(
2592
-            $name,
2593
-            $id,
2594
-            $delete,
2595
-            $save_close_redirect_URL,
2596
-            $both_btns
2597
-        );
2598
-    }
2599
-
2600
-
2601
-    /**
2602
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2603
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2604
-     * save, and save and close buttons to work properly, then you will want to include a
2605
-     * values for the name and id arguments.
2606
-     *
2607
-     * @todo  Add in validation for name/id arguments.
2608
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2609
-     * @param    int     $id                      id attached to the item published
2610
-     * @param    string  $delete                  page route callback for the delete action
2611
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2612
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2613
-     *                                            the Save button
2614
-     * @throws EE_Error
2615
-     * @throws InvalidArgumentException
2616
-     * @throws InvalidDataTypeException
2617
-     * @throws InvalidInterfaceException
2618
-     */
2619
-    protected function _set_publish_post_box_vars(
2620
-        $name = '',
2621
-        $id = 0,
2622
-        $delete = '',
2623
-        $save_close_redirect_URL = '',
2624
-        $both_btns = true
2625
-    ) {
2626
-        // if Save & Close, use a custom redirect URL or default to the main page?
2627
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2628
-            ? $save_close_redirect_URL
2629
-            : $this->_admin_base_url;
2630
-        // create the Save & Close and Save buttons
2631
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2632
-        // if we have extra content set let's add it in if not make sure its empty
2633
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2634
-            ? $this->_template_args['publish_box_extra_content']
2635
-            : '';
2636
-        if ($delete && ! empty($id)) {
2637
-            // make sure we have a default if just true is sent.
2638
-            $delete = ! empty($delete) ? $delete : 'delete';
2639
-            $delete_link_args = array($name => $id);
2640
-            $delete = $this->get_action_link_or_button(
2641
-                $delete,
2642
-                $delete,
2643
-                $delete_link_args,
2644
-                'submitdelete deletion'
2645
-            );
2646
-        }
2647
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2648
-        if (! empty($name) && ! empty($id)) {
2649
-            $hidden_field_arr[ $name ] = array(
2650
-                'type'  => 'hidden',
2651
-                'value' => $id,
2652
-            );
2653
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2654
-        } else {
2655
-            $hf = '';
2656
-        }
2657
-        // add hidden field
2658
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2659
-            ? $hf[ $name ]['field']
2660
-            : $hf;
2661
-    }
2662
-
2663
-
2664
-    /**
2665
-     * displays an error message to ppl who have javascript disabled
2666
-     *
2667
-     * @return void
2668
-     */
2669
-    private function _display_no_javascript_warning()
2670
-    {
2671
-        ?>
2481
+	}
2482
+
2483
+
2484
+	private function _espresso_links_post_box()
2485
+	{
2486
+		// Hiding until we actually have content to put in here...
2487
+		// 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');
2488
+	}
2489
+
2490
+
2491
+	public function espresso_links_post_box()
2492
+	{
2493
+		// Hiding until we actually have content to put in here...
2494
+		// EEH_Template::display_template(
2495
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2496
+		// );
2497
+	}
2498
+
2499
+
2500
+	protected function _espresso_sponsors_post_box()
2501
+	{
2502
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2503
+			add_meta_box(
2504
+				'espresso_sponsors_post_box',
2505
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2506
+				array($this, 'espresso_sponsors_post_box'),
2507
+				$this->_wp_page_slug,
2508
+				'side'
2509
+			);
2510
+		}
2511
+	}
2512
+
2513
+
2514
+	public function espresso_sponsors_post_box()
2515
+	{
2516
+		EEH_Template::display_template(
2517
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2518
+		);
2519
+	}
2520
+
2521
+
2522
+	private function _publish_post_box()
2523
+	{
2524
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2525
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2526
+		// then we'll use that for the metabox label.
2527
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2528
+		if (! empty($this->_labels['publishbox'])) {
2529
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2530
+				: $this->_labels['publishbox'];
2531
+		} else {
2532
+			$box_label = esc_html__('Publish', 'event_espresso');
2533
+		}
2534
+		$box_label = apply_filters(
2535
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2536
+			$box_label,
2537
+			$this->_req_action,
2538
+			$this
2539
+		);
2540
+		add_meta_box(
2541
+			$meta_box_ref,
2542
+			$box_label,
2543
+			array($this, 'editor_overview'),
2544
+			$this->_current_screen->id,
2545
+			'side',
2546
+			'high'
2547
+		);
2548
+	}
2549
+
2550
+
2551
+	public function editor_overview()
2552
+	{
2553
+		// if we have extra content set let's add it in if not make sure its empty
2554
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2555
+			? $this->_template_args['publish_box_extra_content']
2556
+			: '';
2557
+		echo EEH_Template::display_template(
2558
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2559
+			$this->_template_args,
2560
+			true
2561
+		);
2562
+	}
2563
+
2564
+
2565
+	/** end of globally available metaboxes section **/
2566
+
2567
+
2568
+	/**
2569
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2570
+	 * protected method.
2571
+	 *
2572
+	 * @see   $this->_set_publish_post_box_vars for param details
2573
+	 * @since 4.6.0
2574
+	 * @param string $name
2575
+	 * @param int    $id
2576
+	 * @param bool   $delete
2577
+	 * @param string $save_close_redirect_URL
2578
+	 * @param bool   $both_btns
2579
+	 * @throws EE_Error
2580
+	 * @throws InvalidArgumentException
2581
+	 * @throws InvalidDataTypeException
2582
+	 * @throws InvalidInterfaceException
2583
+	 */
2584
+	public function set_publish_post_box_vars(
2585
+		$name = '',
2586
+		$id = 0,
2587
+		$delete = false,
2588
+		$save_close_redirect_URL = '',
2589
+		$both_btns = true
2590
+	) {
2591
+		$this->_set_publish_post_box_vars(
2592
+			$name,
2593
+			$id,
2594
+			$delete,
2595
+			$save_close_redirect_URL,
2596
+			$both_btns
2597
+		);
2598
+	}
2599
+
2600
+
2601
+	/**
2602
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2603
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2604
+	 * save, and save and close buttons to work properly, then you will want to include a
2605
+	 * values for the name and id arguments.
2606
+	 *
2607
+	 * @todo  Add in validation for name/id arguments.
2608
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2609
+	 * @param    int     $id                      id attached to the item published
2610
+	 * @param    string  $delete                  page route callback for the delete action
2611
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2612
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2613
+	 *                                            the Save button
2614
+	 * @throws EE_Error
2615
+	 * @throws InvalidArgumentException
2616
+	 * @throws InvalidDataTypeException
2617
+	 * @throws InvalidInterfaceException
2618
+	 */
2619
+	protected function _set_publish_post_box_vars(
2620
+		$name = '',
2621
+		$id = 0,
2622
+		$delete = '',
2623
+		$save_close_redirect_URL = '',
2624
+		$both_btns = true
2625
+	) {
2626
+		// if Save & Close, use a custom redirect URL or default to the main page?
2627
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2628
+			? $save_close_redirect_URL
2629
+			: $this->_admin_base_url;
2630
+		// create the Save & Close and Save buttons
2631
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2632
+		// if we have extra content set let's add it in if not make sure its empty
2633
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2634
+			? $this->_template_args['publish_box_extra_content']
2635
+			: '';
2636
+		if ($delete && ! empty($id)) {
2637
+			// make sure we have a default if just true is sent.
2638
+			$delete = ! empty($delete) ? $delete : 'delete';
2639
+			$delete_link_args = array($name => $id);
2640
+			$delete = $this->get_action_link_or_button(
2641
+				$delete,
2642
+				$delete,
2643
+				$delete_link_args,
2644
+				'submitdelete deletion'
2645
+			);
2646
+		}
2647
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2648
+		if (! empty($name) && ! empty($id)) {
2649
+			$hidden_field_arr[ $name ] = array(
2650
+				'type'  => 'hidden',
2651
+				'value' => $id,
2652
+			);
2653
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2654
+		} else {
2655
+			$hf = '';
2656
+		}
2657
+		// add hidden field
2658
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2659
+			? $hf[ $name ]['field']
2660
+			: $hf;
2661
+	}
2662
+
2663
+
2664
+	/**
2665
+	 * displays an error message to ppl who have javascript disabled
2666
+	 *
2667
+	 * @return void
2668
+	 */
2669
+	private function _display_no_javascript_warning()
2670
+	{
2671
+		?>
2672 2672
         <noscript>
2673 2673
             <div id="no-js-message" class="error">
2674 2674
                 <p style="font-size:1.3em;">
2675 2675
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2676 2676
                     <?php esc_html_e(
2677
-                        '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.',
2678
-                        'event_espresso'
2679
-                    ); ?>
2677
+						'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.',
2678
+						'event_espresso'
2679
+					); ?>
2680 2680
                 </p>
2681 2681
             </div>
2682 2682
         </noscript>
2683 2683
         <?php
2684
-    }
2685
-
2686
-
2687
-    /**
2688
-     * displays espresso success and/or error notices
2689
-     *
2690
-     * @return void
2691
-     */
2692
-    private function _display_espresso_notices()
2693
-    {
2694
-        $notices = $this->_get_transient(true);
2695
-        echo stripslashes($notices);
2696
-    }
2697
-
2698
-
2699
-    /**
2700
-     * spinny things pacify the masses
2701
-     *
2702
-     * @return void
2703
-     */
2704
-    protected function _add_admin_page_ajax_loading_img()
2705
-    {
2706
-        ?>
2684
+	}
2685
+
2686
+
2687
+	/**
2688
+	 * displays espresso success and/or error notices
2689
+	 *
2690
+	 * @return void
2691
+	 */
2692
+	private function _display_espresso_notices()
2693
+	{
2694
+		$notices = $this->_get_transient(true);
2695
+		echo stripslashes($notices);
2696
+	}
2697
+
2698
+
2699
+	/**
2700
+	 * spinny things pacify the masses
2701
+	 *
2702
+	 * @return void
2703
+	 */
2704
+	protected function _add_admin_page_ajax_loading_img()
2705
+	{
2706
+		?>
2707 2707
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2708 2708
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2709
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2709
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2710 2710
         </div>
2711 2711
         <?php
2712
-    }
2712
+	}
2713 2713
 
2714 2714
 
2715
-    /**
2716
-     * add admin page overlay for modal boxes
2717
-     *
2718
-     * @return void
2719
-     */
2720
-    protected function _add_admin_page_overlay()
2721
-    {
2722
-        ?>
2715
+	/**
2716
+	 * add admin page overlay for modal boxes
2717
+	 *
2718
+	 * @return void
2719
+	 */
2720
+	protected function _add_admin_page_overlay()
2721
+	{
2722
+		?>
2723 2723
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2724 2724
         <?php
2725
-    }
2726
-
2727
-
2728
-    /**
2729
-     * facade for add_meta_box
2730
-     *
2731
-     * @param string  $action        where the metabox get's displayed
2732
-     * @param string  $title         Title of Metabox (output in metabox header)
2733
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2734
-     *                               instead of the one created in here.
2735
-     * @param array   $callback_args an array of args supplied for the metabox
2736
-     * @param string  $column        what metabox column
2737
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2738
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2739
-     *                               created but just set our own callback for wp's add_meta_box.
2740
-     * @throws DomainException
2741
-     */
2742
-    public function _add_admin_page_meta_box(
2743
-        $action,
2744
-        $title,
2745
-        $callback,
2746
-        $callback_args,
2747
-        $column = 'normal',
2748
-        $priority = 'high',
2749
-        $create_func = true
2750
-    ) {
2751
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2752
-        // 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.
2753
-        if (empty($callback_args) && $create_func) {
2754
-            $callback_args = array(
2755
-                'template_path' => $this->_template_path,
2756
-                'template_args' => $this->_template_args,
2757
-            );
2758
-        }
2759
-        // 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)
2760
-        $call_back_func = $create_func
2761
-            ? static function ($post, $metabox) {
2762
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2763
-                echo EEH_Template::display_template(
2764
-                    $metabox['args']['template_path'],
2765
-                    $metabox['args']['template_args'],
2766
-                    true
2767
-                );
2768
-            }
2769
-            : $callback;
2770
-        add_meta_box(
2771
-            str_replace('_', '-', $action) . '-mbox',
2772
-            $title,
2773
-            $call_back_func,
2774
-            $this->_wp_page_slug,
2775
-            $column,
2776
-            $priority,
2777
-            $callback_args
2778
-        );
2779
-    }
2780
-
2781
-
2782
-    /**
2783
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2784
-     *
2785
-     * @throws DomainException
2786
-     * @throws EE_Error
2787
-     * @throws InvalidArgumentException
2788
-     * @throws InvalidDataTypeException
2789
-     * @throws InvalidInterfaceException
2790
-     */
2791
-    public function display_admin_page_with_metabox_columns()
2792
-    {
2793
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2794
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2795
-            $this->_column_template_path,
2796
-            $this->_template_args,
2797
-            true
2798
-        );
2799
-        // the final wrapper
2800
-        $this->admin_page_wrapper();
2801
-    }
2802
-
2803
-
2804
-    /**
2805
-     * generates  HTML wrapper for an admin details page
2806
-     *
2807
-     * @return void
2808
-     * @throws DomainException
2809
-     * @throws EE_Error
2810
-     * @throws InvalidArgumentException
2811
-     * @throws InvalidDataTypeException
2812
-     * @throws InvalidInterfaceException
2813
-     */
2814
-    public function display_admin_page_with_sidebar()
2815
-    {
2816
-        $this->_display_admin_page(true);
2817
-    }
2818
-
2819
-
2820
-    /**
2821
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2822
-     *
2823
-     * @return void
2824
-     * @throws DomainException
2825
-     * @throws EE_Error
2826
-     * @throws InvalidArgumentException
2827
-     * @throws InvalidDataTypeException
2828
-     * @throws InvalidInterfaceException
2829
-     */
2830
-    public function display_admin_page_with_no_sidebar()
2831
-    {
2832
-        $this->_display_admin_page();
2833
-    }
2834
-
2835
-
2836
-    /**
2837
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2838
-     *
2839
-     * @return void
2840
-     * @throws DomainException
2841
-     * @throws EE_Error
2842
-     * @throws InvalidArgumentException
2843
-     * @throws InvalidDataTypeException
2844
-     * @throws InvalidInterfaceException
2845
-     */
2846
-    public function display_about_admin_page()
2847
-    {
2848
-        $this->_display_admin_page(false, true);
2849
-    }
2850
-
2851
-
2852
-    /**
2853
-     * display_admin_page
2854
-     * contains the code for actually displaying an admin page
2855
-     *
2856
-     * @param boolean $sidebar true with sidebar, false without
2857
-     * @param boolean $about   use the about admin wrapper instead of the default.
2858
-     * @return void
2859
-     * @throws DomainException
2860
-     * @throws EE_Error
2861
-     * @throws InvalidArgumentException
2862
-     * @throws InvalidDataTypeException
2863
-     * @throws InvalidInterfaceException
2864
-     */
2865
-    private function _display_admin_page($sidebar = false, $about = false)
2866
-    {
2867
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2868
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2869
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2870
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2871
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2872
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2873
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2874
-            ? 'poststuff'
2875
-            : 'espresso-default-admin';
2876
-        $template_path = $sidebar
2877
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2878
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2879
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2880
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2881
-        }
2882
-        $template_path = ! empty($this->_column_template_path)
2883
-            ? $this->_column_template_path : $template_path;
2884
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2885
-            ? $this->_template_args['admin_page_content']
2886
-            : '';
2887
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2888
-            ? $this->_template_args['before_admin_page_content']
2889
-            : '';
2890
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2891
-            ? $this->_template_args['after_admin_page_content']
2892
-            : '';
2893
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2894
-            $template_path,
2895
-            $this->_template_args,
2896
-            true
2897
-        );
2898
-        // the final template wrapper
2899
-        $this->admin_page_wrapper($about);
2900
-    }
2901
-
2902
-
2903
-    /**
2904
-     * This is used to display caf preview pages.
2905
-     *
2906
-     * @since 4.3.2
2907
-     * @param string $utm_campaign_source what is the key used for google analytics link
2908
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2909
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2910
-     * @return void
2911
-     * @throws DomainException
2912
-     * @throws EE_Error
2913
-     * @throws InvalidArgumentException
2914
-     * @throws InvalidDataTypeException
2915
-     * @throws InvalidInterfaceException
2916
-     */
2917
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2918
-    {
2919
-        // let's generate a default preview action button if there isn't one already present.
2920
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2921
-            'Upgrade to Event Espresso 4 Right Now',
2922
-            'event_espresso'
2923
-        );
2924
-        $buy_now_url = add_query_arg(
2925
-            array(
2926
-                'ee_ver'       => 'ee4',
2927
-                'utm_source'   => 'ee4_plugin_admin',
2928
-                'utm_medium'   => 'link',
2929
-                'utm_campaign' => $utm_campaign_source,
2930
-                'utm_content'  => 'buy_now_button',
2931
-            ),
2932
-            'http://eventespresso.com/pricing/'
2933
-        );
2934
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2935
-            ? $this->get_action_link_or_button(
2936
-                '',
2937
-                'buy_now',
2938
-                array(),
2939
-                'button-primary button-large',
2940
-                $buy_now_url,
2941
-                true
2942
-            )
2943
-            : $this->_template_args['preview_action_button'];
2944
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2945
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2946
-            $this->_template_args,
2947
-            true
2948
-        );
2949
-        $this->_display_admin_page($display_sidebar);
2950
-    }
2951
-
2952
-
2953
-    /**
2954
-     * display_admin_list_table_page_with_sidebar
2955
-     * generates HTML wrapper for an admin_page with list_table
2956
-     *
2957
-     * @return void
2958
-     * @throws DomainException
2959
-     * @throws EE_Error
2960
-     * @throws InvalidArgumentException
2961
-     * @throws InvalidDataTypeException
2962
-     * @throws InvalidInterfaceException
2963
-     */
2964
-    public function display_admin_list_table_page_with_sidebar()
2965
-    {
2966
-        $this->_display_admin_list_table_page(true);
2967
-    }
2968
-
2969
-
2970
-    /**
2971
-     * display_admin_list_table_page_with_no_sidebar
2972
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2973
-     *
2974
-     * @return void
2975
-     * @throws DomainException
2976
-     * @throws EE_Error
2977
-     * @throws InvalidArgumentException
2978
-     * @throws InvalidDataTypeException
2979
-     * @throws InvalidInterfaceException
2980
-     */
2981
-    public function display_admin_list_table_page_with_no_sidebar()
2982
-    {
2983
-        $this->_display_admin_list_table_page();
2984
-    }
2985
-
2986
-
2987
-    /**
2988
-     * generates html wrapper for an admin_list_table page
2989
-     *
2990
-     * @param boolean $sidebar whether to display with sidebar or not.
2991
-     * @return void
2992
-     * @throws DomainException
2993
-     * @throws EE_Error
2994
-     * @throws InvalidArgumentException
2995
-     * @throws InvalidDataTypeException
2996
-     * @throws InvalidInterfaceException
2997
-     */
2998
-    private function _display_admin_list_table_page($sidebar = false)
2999
-    {
3000
-        // setup search attributes
3001
-        $this->_set_search_attributes();
3002
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
3003
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3004
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
3005
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3006
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3007
-        $this->_template_args['list_table'] = $this->_list_table_object;
3008
-        $this->_template_args['current_route'] = $this->_req_action;
3009
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3010
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
3011
-        if (! empty($ajax_sorting_callback)) {
3012
-            $sortable_list_table_form_fields = wp_nonce_field(
3013
-                $ajax_sorting_callback . '_nonce',
3014
-                $ajax_sorting_callback . '_nonce',
3015
-                false,
3016
-                false
3017
-            );
3018
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3019
-                                                . $this->page_slug
3020
-                                                . '" />';
3021
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3022
-                                                . $ajax_sorting_callback
3023
-                                                . '" />';
3024
-        } else {
3025
-            $sortable_list_table_form_fields = '';
3026
-        }
3027
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3028
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3029
-            ? $this->_template_args['list_table_hidden_fields']
3030
-            : '';
3031
-        $nonce_ref = $this->_req_action . '_nonce';
3032
-        $hidden_form_fields .= '<input type="hidden" name="'
3033
-                               . $nonce_ref
3034
-                               . '" value="'
3035
-                               . wp_create_nonce($nonce_ref)
3036
-                               . '">';
3037
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3038
-        // display message about search results?
3039
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3040
-            ? '<p class="ee-search-results">' . sprintf(
3041
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3042
-                trim($this->_req_data['s'], '%')
3043
-            ) . '</p>'
3044
-            : '';
3045
-        // filter before_list_table template arg
3046
-        $this->_template_args['before_list_table'] = apply_filters(
3047
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3048
-            $this->_template_args['before_list_table'],
3049
-            $this->page_slug,
3050
-            $this->_req_data,
3051
-            $this->_req_action
3052
-        );
3053
-        // convert to array and filter again
3054
-        // arrays are easier to inject new items in a specific location,
3055
-        // but would not be backwards compatible, so we have to add a new filter
3056
-        $this->_template_args['before_list_table'] = implode(
3057
-            " \n",
3058
-            (array) apply_filters(
3059
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3060
-                (array) $this->_template_args['before_list_table'],
3061
-                $this->page_slug,
3062
-                $this->_req_data,
3063
-                $this->_req_action
3064
-            )
3065
-        );
3066
-        // filter after_list_table template arg
3067
-        $this->_template_args['after_list_table'] = apply_filters(
3068
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3069
-            $this->_template_args['after_list_table'],
3070
-            $this->page_slug,
3071
-            $this->_req_data,
3072
-            $this->_req_action
3073
-        );
3074
-        // convert to array and filter again
3075
-        // arrays are easier to inject new items in a specific location,
3076
-        // but would not be backwards compatible, so we have to add a new filter
3077
-        $this->_template_args['after_list_table'] = implode(
3078
-            " \n",
3079
-            (array) apply_filters(
3080
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3081
-                (array) $this->_template_args['after_list_table'],
3082
-                $this->page_slug,
3083
-                $this->_req_data,
3084
-                $this->_req_action
3085
-            )
3086
-        );
3087
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3088
-            $template_path,
3089
-            $this->_template_args,
3090
-            true
3091
-        );
3092
-        // the final template wrapper
3093
-        if ($sidebar) {
3094
-            $this->display_admin_page_with_sidebar();
3095
-        } else {
3096
-            $this->display_admin_page_with_no_sidebar();
3097
-        }
3098
-    }
3099
-
3100
-
3101
-    /**
3102
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3103
-     * html string for the legend.
3104
-     * $items are expected in an array in the following format:
3105
-     * $legend_items = array(
3106
-     *        'item_id' => array(
3107
-     *            'icon' => 'http://url_to_icon_being_described.png',
3108
-     *            'desc' => esc_html__('localized description of item');
3109
-     *        )
3110
-     * );
3111
-     *
3112
-     * @param  array $items see above for format of array
3113
-     * @return string html string of legend
3114
-     * @throws DomainException
3115
-     */
3116
-    protected function _display_legend($items)
3117
-    {
3118
-        $this->_template_args['items'] = apply_filters(
3119
-            'FHEE__EE_Admin_Page___display_legend__items',
3120
-            (array) $items,
3121
-            $this
3122
-        );
3123
-        /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3124
-        $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3125
-        if (! $status_change_notice->isDismissed()) {
3126
-            $this->_template_args['status_change_notice'] = EEH_Template::display_template(
3127
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3128
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3129
-                true
3130
-            );
3131
-        }
3132
-        return EEH_Template::display_template(
3133
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3134
-            $this->_template_args,
3135
-            true
3136
-        );
3137
-    }
3138
-
3139
-
3140
-    /**
3141
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3142
-     * The returned json object is created from an array in the following format:
3143
-     * array(
3144
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3145
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3146
-     *  'notices' => '', // - contains any EE_Error formatted notices
3147
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3148
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3149
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3150
-     *  that might be included in here)
3151
-     * )
3152
-     * The json object is populated by whatever is set in the $_template_args property.
3153
-     *
3154
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3155
-     *                                 instead of displayed.
3156
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3157
-     * @return void
3158
-     * @throws EE_Error
3159
-     * @throws InvalidArgumentException
3160
-     * @throws InvalidDataTypeException
3161
-     * @throws InvalidInterfaceException
3162
-     */
3163
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3164
-    {
3165
-        // make sure any EE_Error notices have been handled.
3166
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3167
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3168
-        unset($this->_template_args['data']);
3169
-        $json = array(
3170
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3171
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3172
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3173
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3174
-            'notices'   => EE_Error::get_notices(),
3175
-            'content'   => isset($this->_template_args['admin_page_content'])
3176
-                ? $this->_template_args['admin_page_content'] : '',
3177
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3178
-            'isEEajax'  => true
3179
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3180
-        );
3181
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3182
-        if (null === error_get_last() || ! headers_sent()) {
3183
-            header('Content-Type: application/json; charset=UTF-8');
3184
-        }
3185
-        echo wp_json_encode($json);
3186
-        exit();
3187
-    }
3188
-
3189
-
3190
-    /**
3191
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3192
-     *
3193
-     * @return void
3194
-     * @throws EE_Error
3195
-     * @throws InvalidArgumentException
3196
-     * @throws InvalidDataTypeException
3197
-     * @throws InvalidInterfaceException
3198
-     */
3199
-    public function return_json()
3200
-    {
3201
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3202
-            $this->_return_json();
3203
-        } else {
3204
-            throw new EE_Error(
3205
-                sprintf(
3206
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3207
-                    __FUNCTION__
3208
-                )
3209
-            );
3210
-        }
3211
-    }
3212
-
3213
-
3214
-    /**
3215
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3216
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3217
-     *
3218
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3219
-     */
3220
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3221
-    {
3222
-        $this->_hook_obj = $hook_obj;
3223
-    }
3224
-
3225
-
3226
-    /**
3227
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3228
-     *
3229
-     * @param boolean $about whether to use the special about page wrapper or default.
3230
-     * @return void
3231
-     * @throws DomainException
3232
-     * @throws EE_Error
3233
-     * @throws InvalidArgumentException
3234
-     * @throws InvalidDataTypeException
3235
-     * @throws InvalidInterfaceException
3236
-     */
3237
-    public function admin_page_wrapper($about = false)
3238
-    {
3239
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3240
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3241
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3242
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3243
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3244
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3245
-            isset($this->_template_args['before_admin_page_content'])
3246
-                ? $this->_template_args['before_admin_page_content']
3247
-                : ''
3248
-        );
3249
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3250
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3251
-            isset($this->_template_args['after_admin_page_content'])
3252
-                ? $this->_template_args['after_admin_page_content']
3253
-                : ''
3254
-        );
3255
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3256
-        // load settings page wrapper template
3257
-        $template_path = ! defined('DOING_AJAX')
3258
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3259
-            : EE_ADMIN_TEMPLATE
3260
-              . 'admin_wrapper_ajax.template.php';
3261
-        // about page?
3262
-        $template_path = $about
3263
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3264
-            : $template_path;
3265
-        if (defined('DOING_AJAX')) {
3266
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3267
-                $template_path,
3268
-                $this->_template_args,
3269
-                true
3270
-            );
3271
-            $this->_return_json();
3272
-        } else {
3273
-            EEH_Template::display_template($template_path, $this->_template_args);
3274
-        }
3275
-    }
3276
-
3277
-
3278
-    /**
3279
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3280
-     *
3281
-     * @return string html
3282
-     * @throws EE_Error
3283
-     */
3284
-    protected function _get_main_nav_tabs()
3285
-    {
3286
-        // let's generate the html using the EEH_Tabbed_Content helper.
3287
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3288
-        // (rather than setting in the page_routes array)
3289
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3290
-    }
3291
-
3292
-
3293
-    /**
3294
-     *        sort nav tabs
3295
-     *
3296
-     * @param $a
3297
-     * @param $b
3298
-     * @return int
3299
-     */
3300
-    private function _sort_nav_tabs($a, $b)
3301
-    {
3302
-        if ($a['order'] === $b['order']) {
3303
-            return 0;
3304
-        }
3305
-        return ($a['order'] < $b['order']) ? -1 : 1;
3306
-    }
3307
-
3308
-
3309
-    /**
3310
-     * generates HTML for the forms used on admin pages
3311
-     *
3312
-     * @param array  $input_vars - array of input field details
3313
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3314
-     * @param bool   $id
3315
-     * @return array|string
3316
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3317
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3318
-     */
3319
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3320
-    {
3321
-        return $generator === 'string'
3322
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3323
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3324
-    }
3325
-
3326
-
3327
-    /**
3328
-     * generates the "Save" and "Save & Close" buttons for edit forms
3329
-     *
3330
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3331
-     *                                   Close" button.
3332
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3333
-     *                                   'Save', [1] => 'save & close')
3334
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3335
-     *                                   via the "name" value in the button).  We can also use this to just dump
3336
-     *                                   default actions by submitting some other value.
3337
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3338
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3339
-     *                                   close (normal form handling).
3340
-     */
3341
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3342
-    {
3343
-        // make sure $text and $actions are in an array
3344
-        $text = (array) $text;
3345
-        $actions = (array) $actions;
3346
-        $referrer_url = empty($referrer)
3347
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3348
-              . $_SERVER['REQUEST_URI']
3349
-              . '" />'
3350
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3351
-              . $referrer
3352
-              . '" />';
3353
-        $button_text = ! empty($text)
3354
-            ? $text
3355
-            : array(
3356
-                esc_html__('Save', 'event_espresso'),
3357
-                esc_html__('Save and Close', 'event_espresso'),
3358
-            );
3359
-        $default_names = array('save', 'save_and_close');
3360
-        // add in a hidden index for the current page (so save and close redirects properly)
3361
-        $this->_template_args['save_buttons'] = $referrer_url;
3362
-        foreach ($button_text as $key => $button) {
3363
-            $ref = $default_names[ $key ];
3364
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3365
-                                                     . $ref
3366
-                                                     . '" value="'
3367
-                                                     . $button
3368
-                                                     . '" name="'
3369
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3370
-                                                     . '" id="'
3371
-                                                     . $this->_current_view . '_' . $ref
3372
-                                                     . '" />';
3373
-            if (! $both) {
3374
-                break;
3375
-            }
3376
-        }
3377
-    }
3378
-
3379
-
3380
-    /**
3381
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3382
-     *
3383
-     * @see   $this->_set_add_edit_form_tags() for details on params
3384
-     * @since 4.6.0
3385
-     * @param string $route
3386
-     * @param array  $additional_hidden_fields
3387
-     */
3388
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3389
-    {
3390
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3391
-    }
3392
-
3393
-
3394
-    /**
3395
-     * set form open and close tags on add/edit pages.
3396
-     *
3397
-     * @param string $route                    the route you want the form to direct to
3398
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3399
-     * @return void
3400
-     */
3401
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3402
-    {
3403
-        if (empty($route)) {
3404
-            $user_msg = esc_html__(
3405
-                'An error occurred. No action was set for this page\'s form.',
3406
-                'event_espresso'
3407
-            );
3408
-            $dev_msg = $user_msg . "\n"
3409
-                       . sprintf(
3410
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3411
-                           __FUNCTION__,
3412
-                           EE_Admin_Page::class
3413
-                       );
3414
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3415
-        }
3416
-        // open form
3417
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3418
-                                                             . $this->_admin_base_url
3419
-                                                             . '" id="'
3420
-                                                             . $route
3421
-                                                             . '_event_form" >';
3422
-        // add nonce
3423
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3424
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3425
-        // add REQUIRED form action
3426
-        $hidden_fields = array(
3427
-            'action' => array('type' => 'hidden', 'value' => $route),
3428
-        );
3429
-        // merge arrays
3430
-        $hidden_fields = is_array($additional_hidden_fields)
3431
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3432
-            : $hidden_fields;
3433
-        // generate form fields
3434
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3435
-        // add fields to form
3436
-        foreach ((array) $form_fields as $field_name => $form_field) {
3437
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3438
-        }
3439
-        // close form
3440
-        $this->_template_args['after_admin_page_content'] = '</form>';
3441
-    }
3442
-
3443
-
3444
-    /**
3445
-     * Public Wrapper for _redirect_after_action() method since its
3446
-     * discovered it would be useful for external code to have access.
3447
-     *
3448
-     * @param bool   $success
3449
-     * @param string $what
3450
-     * @param string $action_desc
3451
-     * @param array  $query_args
3452
-     * @param bool   $override_overwrite
3453
-     * @throws EE_Error
3454
-     * @throws InvalidArgumentException
3455
-     * @throws InvalidDataTypeException
3456
-     * @throws InvalidInterfaceException
3457
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3458
-     * @since 4.5.0
3459
-     */
3460
-    public function redirect_after_action(
3461
-        $success = false,
3462
-        $what = 'item',
3463
-        $action_desc = 'processed',
3464
-        $query_args = array(),
3465
-        $override_overwrite = false
3466
-    ) {
3467
-        $this->_redirect_after_action(
3468
-            $success,
3469
-            $what,
3470
-            $action_desc,
3471
-            $query_args,
3472
-            $override_overwrite
3473
-        );
3474
-    }
3475
-
3476
-
3477
-    /**
3478
-     * Helper method for merging existing request data with the returned redirect url.
3479
-     *
3480
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3481
-     * filters are still applied.
3482
-     *
3483
-     * @param array $new_route_data
3484
-     * @return array
3485
-     */
3486
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3487
-    {
3488
-        foreach ($this->_req_data as $ref => $value) {
3489
-            // unset nonces
3490
-            if (strpos($ref, 'nonce') !== false) {
3491
-                unset($this->_req_data[ $ref ]);
3492
-                continue;
3493
-            }
3494
-            // urlencode values.
3495
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3496
-            $this->_req_data[ $ref ] = $value;
3497
-        }
3498
-        return array_merge($this->_req_data, $new_route_data);
3499
-    }
3500
-
3501
-
3502
-    /**
3503
-     *    _redirect_after_action
3504
-     *
3505
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3506
-     * @param string $what               - what the action was performed on
3507
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3508
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3509
-     *                                   action is completed
3510
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3511
-     *                                   override this so that they show.
3512
-     * @return void
3513
-     * @throws EE_Error
3514
-     * @throws InvalidArgumentException
3515
-     * @throws InvalidDataTypeException
3516
-     * @throws InvalidInterfaceException
3517
-     */
3518
-    protected function _redirect_after_action(
3519
-        $success = 0,
3520
-        $what = 'item',
3521
-        $action_desc = 'processed',
3522
-        $query_args = array(),
3523
-        $override_overwrite = false
3524
-    ) {
3525
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3526
-        // class name for actions/filters.
3527
-        $classname = get_class($this);
3528
-        // set redirect url.
3529
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3530
-        // otherwise we go with whatever is set as the _admin_base_url
3531
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3532
-        $notices = EE_Error::get_notices(false);
3533
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3534
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3535
-            EE_Error::overwrite_success();
3536
-        }
3537
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3538
-            // how many records affected ? more than one record ? or just one ?
3539
-            if ($success > 1) {
3540
-                // set plural msg
3541
-                EE_Error::add_success(
3542
-                    sprintf(
3543
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3544
-                        $what,
3545
-                        $action_desc
3546
-                    ),
3547
-                    __FILE__,
3548
-                    __FUNCTION__,
3549
-                    __LINE__
3550
-                );
3551
-            } elseif ($success === 1) {
3552
-                // set singular msg
3553
-                EE_Error::add_success(
3554
-                    sprintf(
3555
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3556
-                        $what,
3557
-                        $action_desc
3558
-                    ),
3559
-                    __FILE__,
3560
-                    __FUNCTION__,
3561
-                    __LINE__
3562
-                );
3563
-            }
3564
-        }
3565
-        // check that $query_args isn't something crazy
3566
-        if (! is_array($query_args)) {
3567
-            $query_args = array();
3568
-        }
3569
-        /**
3570
-         * Allow injecting actions before the query_args are modified for possible different
3571
-         * redirections on save and close actions
3572
-         *
3573
-         * @since 4.2.0
3574
-         * @param array $query_args       The original query_args array coming into the
3575
-         *                                method.
3576
-         */
3577
-        do_action(
3578
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3579
-            $query_args
3580
-        );
3581
-        // calculate where we're going (if we have a "save and close" button pushed)
3582
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3583
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3584
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3585
-            // regenerate query args array from referrer URL
3586
-            parse_str($parsed_url['query'], $query_args);
3587
-            // correct page and action will be in the query args now
3588
-            $redirect_url = admin_url('admin.php');
3589
-        }
3590
-        // merge any default query_args set in _default_route_query_args property
3591
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3592
-            $args_to_merge = array();
3593
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3594
-                // is there a wp_referer array in our _default_route_query_args property?
3595
-                if ($query_param === 'wp_referer') {
3596
-                    $query_value = (array) $query_value;
3597
-                    foreach ($query_value as $reference => $value) {
3598
-                        if (strpos($reference, 'nonce') !== false) {
3599
-                            continue;
3600
-                        }
3601
-                        // finally we will override any arguments in the referer with
3602
-                        // what might be set on the _default_route_query_args array.
3603
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3604
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3605
-                        } else {
3606
-                            $args_to_merge[ $reference ] = urlencode($value);
3607
-                        }
3608
-                    }
3609
-                    continue;
3610
-                }
3611
-                $args_to_merge[ $query_param ] = $query_value;
3612
-            }
3613
-            // now let's merge these arguments but override with what was specifically sent in to the
3614
-            // redirect.
3615
-            $query_args = array_merge($args_to_merge, $query_args);
3616
-        }
3617
-        $this->_process_notices($query_args);
3618
-        // generate redirect url
3619
-        // if redirecting to anything other than the main page, add a nonce
3620
-        if (isset($query_args['action'])) {
3621
-            // manually generate wp_nonce and merge that with the query vars
3622
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3623
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3624
-        }
3625
-        // we're adding some hooks and filters in here for processing any things just before redirects
3626
-        // (example: an admin page has done an insert or update and we want to run something after that).
3627
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3628
-        $redirect_url = apply_filters(
3629
-            'FHEE_redirect_' . $classname . $this->_req_action,
3630
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3631
-            $query_args
3632
-        );
3633
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3634
-        if (defined('DOING_AJAX')) {
3635
-            $default_data = array(
3636
-                'close'        => true,
3637
-                'redirect_url' => $redirect_url,
3638
-                'where'        => 'main',
3639
-                'what'         => 'append',
3640
-            );
3641
-            $this->_template_args['success'] = $success;
3642
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3643
-                $default_data,
3644
-                $this->_template_args['data']
3645
-            ) : $default_data;
3646
-            $this->_return_json();
3647
-        }
3648
-        wp_safe_redirect($redirect_url);
3649
-        exit();
3650
-    }
3651
-
3652
-
3653
-    /**
3654
-     * process any notices before redirecting (or returning ajax request)
3655
-     * This method sets the $this->_template_args['notices'] attribute;
3656
-     *
3657
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3658
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3659
-     *                                  page_routes haven't been defined yet.
3660
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3661
-     *                                  still save a transient for the notice.
3662
-     * @return void
3663
-     * @throws EE_Error
3664
-     * @throws InvalidArgumentException
3665
-     * @throws InvalidDataTypeException
3666
-     * @throws InvalidInterfaceException
3667
-     */
3668
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3669
-    {
3670
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3671
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3672
-            $notices = EE_Error::get_notices(false);
3673
-            if (empty($this->_template_args['success'])) {
3674
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3675
-            }
3676
-            if (empty($this->_template_args['errors'])) {
3677
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3678
-            }
3679
-            if (empty($this->_template_args['attention'])) {
3680
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3681
-            }
3682
-        }
3683
-        $this->_template_args['notices'] = EE_Error::get_notices();
3684
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3685
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3686
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3687
-            $this->_add_transient(
3688
-                $route,
3689
-                $this->_template_args['notices'],
3690
-                true,
3691
-                $skip_route_verify
3692
-            );
3693
-        }
3694
-    }
3695
-
3696
-
3697
-    /**
3698
-     * get_action_link_or_button
3699
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3700
-     *
3701
-     * @param string $action        use this to indicate which action the url is generated with.
3702
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3703
-     *                              property.
3704
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3705
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3706
-     * @param string $base_url      If this is not provided
3707
-     *                              the _admin_base_url will be used as the default for the button base_url.
3708
-     *                              Otherwise this value will be used.
3709
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3710
-     * @return string
3711
-     * @throws InvalidArgumentException
3712
-     * @throws InvalidInterfaceException
3713
-     * @throws InvalidDataTypeException
3714
-     * @throws EE_Error
3715
-     */
3716
-    public function get_action_link_or_button(
3717
-        $action,
3718
-        $type = 'add',
3719
-        $extra_request = array(),
3720
-        $class = 'button-primary',
3721
-        $base_url = '',
3722
-        $exclude_nonce = false
3723
-    ) {
3724
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3725
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3726
-            throw new EE_Error(
3727
-                sprintf(
3728
-                    esc_html__(
3729
-                        'There is no page route for given action for the button.  This action was given: %s',
3730
-                        'event_espresso'
3731
-                    ),
3732
-                    $action
3733
-                )
3734
-            );
3735
-        }
3736
-        if (! isset($this->_labels['buttons'][ $type ])) {
3737
-            throw new EE_Error(
3738
-                sprintf(
3739
-                    __(
3740
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3741
-                        'event_espresso'
3742
-                    ),
3743
-                    $type
3744
-                )
3745
-            );
3746
-        }
3747
-        // finally check user access for this button.
3748
-        $has_access = $this->check_user_access($action, true);
3749
-        if (! $has_access) {
3750
-            return '';
3751
-        }
3752
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3753
-        $query_args = array(
3754
-            'action' => $action,
3755
-        );
3756
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3757
-        if (! empty($extra_request)) {
3758
-            $query_args = array_merge($extra_request, $query_args);
3759
-        }
3760
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3761
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3762
-    }
3763
-
3764
-
3765
-    /**
3766
-     * _per_page_screen_option
3767
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3768
-     *
3769
-     * @return void
3770
-     * @throws InvalidArgumentException
3771
-     * @throws InvalidInterfaceException
3772
-     * @throws InvalidDataTypeException
3773
-     */
3774
-    protected function _per_page_screen_option()
3775
-    {
3776
-        $option = 'per_page';
3777
-        $args = array(
3778
-            'label'   => apply_filters(
3779
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3780
-                $this->_admin_page_title,
3781
-                $this
3782
-            ),
3783
-            'default' => (int) apply_filters(
3784
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3785
-                20
3786
-            ),
3787
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3788
-        );
3789
-        // ONLY add the screen option if the user has access to it.
3790
-        if ($this->check_user_access($this->_current_view, true)) {
3791
-            add_screen_option($option, $args);
3792
-        }
3793
-    }
3794
-
3795
-
3796
-    /**
3797
-     * set_per_page_screen_option
3798
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3799
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3800
-     * admin_menu.
3801
-     *
3802
-     * @return void
3803
-     */
3804
-    private function _set_per_page_screen_options()
3805
-    {
3806
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3807
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3808
-            if (! $user = wp_get_current_user()) {
3809
-                return;
3810
-            }
3811
-            $option = $_POST['wp_screen_options']['option'];
3812
-            $value = $_POST['wp_screen_options']['value'];
3813
-            if ($option !== sanitize_key($option)) {
3814
-                return;
3815
-            }
3816
-            $map_option = $option;
3817
-            $option = str_replace('-', '_', $option);
3818
-            switch ($map_option) {
3819
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3820
-                    $value = (int) $value;
3821
-                    $max_value = apply_filters(
3822
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3823
-                        999,
3824
-                        $this->_current_page,
3825
-                        $this->_current_view
3826
-                    );
3827
-                    if ($value < 1) {
3828
-                        return;
3829
-                    }
3830
-                    $value = min($value, $max_value);
3831
-                    break;
3832
-                default:
3833
-                    $value = apply_filters(
3834
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3835
-                        false,
3836
-                        $option,
3837
-                        $value
3838
-                    );
3839
-                    if (false === $value) {
3840
-                        return;
3841
-                    }
3842
-                    break;
3843
-            }
3844
-            update_user_meta($user->ID, $option, $value);
3845
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3846
-            exit;
3847
-        }
3848
-    }
3849
-
3850
-
3851
-    /**
3852
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3853
-     *
3854
-     * @param array $data array that will be assigned to template args.
3855
-     */
3856
-    public function set_template_args($data)
3857
-    {
3858
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3859
-    }
3860
-
3861
-
3862
-    /**
3863
-     * This makes available the WP transient system for temporarily moving data between routes
3864
-     *
3865
-     * @param string $route             the route that should receive the transient
3866
-     * @param array  $data              the data that gets sent
3867
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3868
-     *                                  normal route transient.
3869
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3870
-     *                                  when we are adding a transient before page_routes have been defined.
3871
-     * @return void
3872
-     * @throws EE_Error
3873
-     */
3874
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3875
-    {
3876
-        $user_id = get_current_user_id();
3877
-        if (! $skip_route_verify) {
3878
-            $this->_verify_route($route);
3879
-        }
3880
-        // now let's set the string for what kind of transient we're setting
3881
-        $transient = $notices
3882
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3883
-            : 'rte_tx_' . $route . '_' . $user_id;
3884
-        $data = $notices ? array('notices' => $data) : $data;
3885
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3886
-        $existing = is_multisite() && is_network_admin()
3887
-            ? get_site_transient($transient)
3888
-            : get_transient($transient);
3889
-        if ($existing) {
3890
-            $data = array_merge((array) $data, (array) $existing);
3891
-        }
3892
-        if (is_multisite() && is_network_admin()) {
3893
-            set_site_transient($transient, $data, 8);
3894
-        } else {
3895
-            set_transient($transient, $data, 8);
3896
-        }
3897
-    }
3898
-
3899
-
3900
-    /**
3901
-     * this retrieves the temporary transient that has been set for moving data between routes.
3902
-     *
3903
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3904
-     * @param string $route
3905
-     * @return mixed data
3906
-     */
3907
-    protected function _get_transient($notices = false, $route = '')
3908
-    {
3909
-        $user_id = get_current_user_id();
3910
-        $route = ! $route ? $this->_req_action : $route;
3911
-        $transient = $notices
3912
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3913
-            : 'rte_tx_' . $route . '_' . $user_id;
3914
-        $data = is_multisite() && is_network_admin()
3915
-            ? get_site_transient($transient)
3916
-            : get_transient($transient);
3917
-        // delete transient after retrieval (just in case it hasn't expired);
3918
-        if (is_multisite() && is_network_admin()) {
3919
-            delete_site_transient($transient);
3920
-        } else {
3921
-            delete_transient($transient);
3922
-        }
3923
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3924
-    }
3925
-
3926
-
3927
-    /**
3928
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3929
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3930
-     * default route callback on the EE_Admin page you want it run.)
3931
-     *
3932
-     * @return void
3933
-     */
3934
-    protected function _transient_garbage_collection()
3935
-    {
3936
-        global $wpdb;
3937
-        // retrieve all existing transients
3938
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3939
-        if ($results = $wpdb->get_results($query)) {
3940
-            foreach ($results as $result) {
3941
-                $transient = str_replace('_transient_', '', $result->option_name);
3942
-                get_transient($transient);
3943
-                if (is_multisite() && is_network_admin()) {
3944
-                    get_site_transient($transient);
3945
-                }
3946
-            }
3947
-        }
3948
-    }
3949
-
3950
-
3951
-    /**
3952
-     * get_view
3953
-     *
3954
-     * @return string content of _view property
3955
-     */
3956
-    public function get_view()
3957
-    {
3958
-        return $this->_view;
3959
-    }
3960
-
3961
-
3962
-    /**
3963
-     * getter for the protected $_views property
3964
-     *
3965
-     * @return array
3966
-     */
3967
-    public function get_views()
3968
-    {
3969
-        return $this->_views;
3970
-    }
3971
-
3972
-
3973
-    /**
3974
-     * get_current_page
3975
-     *
3976
-     * @return string _current_page property value
3977
-     */
3978
-    public function get_current_page()
3979
-    {
3980
-        return $this->_current_page;
3981
-    }
3982
-
3983
-
3984
-    /**
3985
-     * get_current_view
3986
-     *
3987
-     * @return string _current_view property value
3988
-     */
3989
-    public function get_current_view()
3990
-    {
3991
-        return $this->_current_view;
3992
-    }
3993
-
3994
-
3995
-    /**
3996
-     * get_current_screen
3997
-     *
3998
-     * @return object The current WP_Screen object
3999
-     */
4000
-    public function get_current_screen()
4001
-    {
4002
-        return $this->_current_screen;
4003
-    }
4004
-
4005
-
4006
-    /**
4007
-     * get_current_page_view_url
4008
-     *
4009
-     * @return string This returns the url for the current_page_view.
4010
-     */
4011
-    public function get_current_page_view_url()
4012
-    {
4013
-        return $this->_current_page_view_url;
4014
-    }
4015
-
4016
-
4017
-    /**
4018
-     * just returns the _req_data property
4019
-     *
4020
-     * @return array
4021
-     */
4022
-    public function get_request_data()
4023
-    {
4024
-        return $this->_req_data;
4025
-    }
4026
-
4027
-
4028
-    /**
4029
-     * returns the _req_data protected property
4030
-     *
4031
-     * @return string
4032
-     */
4033
-    public function get_req_action()
4034
-    {
4035
-        return $this->_req_action;
4036
-    }
4037
-
4038
-
4039
-    /**
4040
-     * @return bool  value of $_is_caf property
4041
-     */
4042
-    public function is_caf()
4043
-    {
4044
-        return $this->_is_caf;
4045
-    }
4046
-
4047
-
4048
-    /**
4049
-     * @return mixed
4050
-     */
4051
-    public function default_espresso_metaboxes()
4052
-    {
4053
-        return $this->_default_espresso_metaboxes;
4054
-    }
4055
-
4056
-
4057
-    /**
4058
-     * @return mixed
4059
-     */
4060
-    public function admin_base_url()
4061
-    {
4062
-        return $this->_admin_base_url;
4063
-    }
4064
-
4065
-
4066
-    /**
4067
-     * @return mixed
4068
-     */
4069
-    public function wp_page_slug()
4070
-    {
4071
-        return $this->_wp_page_slug;
4072
-    }
4073
-
4074
-
4075
-    /**
4076
-     * updates  espresso configuration settings
4077
-     *
4078
-     * @param string                   $tab
4079
-     * @param EE_Config_Base|EE_Config $config
4080
-     * @param string                   $file file where error occurred
4081
-     * @param string                   $func function  where error occurred
4082
-     * @param string                   $line line no where error occurred
4083
-     * @return boolean
4084
-     */
4085
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4086
-    {
4087
-        // remove any options that are NOT going to be saved with the config settings.
4088
-        if (isset($config->core->ee_ueip_optin)) {
4089
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4090
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4091
-            update_option('ee_ueip_has_notified', true);
4092
-        }
4093
-        // and save it (note we're also doing the network save here)
4094
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4095
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4096
-        if ($config_saved && $net_saved) {
4097
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4098
-            return true;
4099
-        }
4100
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4101
-        return false;
4102
-    }
4103
-
4104
-
4105
-    /**
4106
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4107
-     *
4108
-     * @return array
4109
-     */
4110
-    public function get_yes_no_values()
4111
-    {
4112
-        return $this->_yes_no_values;
4113
-    }
4114
-
4115
-
4116
-    /**
4117
-     * @return string
4118
-     * @throws ReflectionException
4119
-     * @since $VID:$
4120
-     */
4121
-    protected function _get_dir()
4122
-    {
4123
-        $reflector = new ReflectionClass(get_class($this));
4124
-        return dirname($reflector->getFileName());
4125
-    }
4126
-
4127
-
4128
-    /**
4129
-     * A helper for getting a "next link".
4130
-     *
4131
-     * @param string $url   The url to link to
4132
-     * @param string $class The class to use.
4133
-     * @return string
4134
-     */
4135
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4136
-    {
4137
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4138
-    }
4139
-
4140
-
4141
-    /**
4142
-     * A helper for getting a "previous link".
4143
-     *
4144
-     * @param string $url   The url to link to
4145
-     * @param string $class The class to use.
4146
-     * @return string
4147
-     */
4148
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4149
-    {
4150
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4151
-    }
4152
-
4153
-
4154
-
4155
-
4156
-
4157
-
4158
-
4159
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4160
-
4161
-
4162
-    /**
4163
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4164
-     * 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
4165
-     * _req_data array.
4166
-     *
4167
-     * @return bool success/fail
4168
-     * @throws EE_Error
4169
-     * @throws InvalidArgumentException
4170
-     * @throws ReflectionException
4171
-     * @throws InvalidDataTypeException
4172
-     * @throws InvalidInterfaceException
4173
-     */
4174
-    protected function _process_resend_registration()
4175
-    {
4176
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4177
-        do_action(
4178
-            'AHEE__EE_Admin_Page___process_resend_registration',
4179
-            $this->_template_args['success'],
4180
-            $this->_req_data
4181
-        );
4182
-        return $this->_template_args['success'];
4183
-    }
4184
-
4185
-
4186
-    /**
4187
-     * This automatically processes any payment message notifications when manual payment has been applied.
4188
-     *
4189
-     * @param EE_Payment $payment
4190
-     * @return bool success/fail
4191
-     */
4192
-    protected function _process_payment_notification(EE_Payment $payment)
4193
-    {
4194
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4195
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4196
-        $this->_template_args['success'] = apply_filters(
4197
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4198
-            false,
4199
-            $payment
4200
-        );
4201
-        return $this->_template_args['success'];
4202
-    }
2725
+	}
2726
+
2727
+
2728
+	/**
2729
+	 * facade for add_meta_box
2730
+	 *
2731
+	 * @param string  $action        where the metabox get's displayed
2732
+	 * @param string  $title         Title of Metabox (output in metabox header)
2733
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2734
+	 *                               instead of the one created in here.
2735
+	 * @param array   $callback_args an array of args supplied for the metabox
2736
+	 * @param string  $column        what metabox column
2737
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2738
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2739
+	 *                               created but just set our own callback for wp's add_meta_box.
2740
+	 * @throws DomainException
2741
+	 */
2742
+	public function _add_admin_page_meta_box(
2743
+		$action,
2744
+		$title,
2745
+		$callback,
2746
+		$callback_args,
2747
+		$column = 'normal',
2748
+		$priority = 'high',
2749
+		$create_func = true
2750
+	) {
2751
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2752
+		// 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.
2753
+		if (empty($callback_args) && $create_func) {
2754
+			$callback_args = array(
2755
+				'template_path' => $this->_template_path,
2756
+				'template_args' => $this->_template_args,
2757
+			);
2758
+		}
2759
+		// 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)
2760
+		$call_back_func = $create_func
2761
+			? static function ($post, $metabox) {
2762
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2763
+				echo EEH_Template::display_template(
2764
+					$metabox['args']['template_path'],
2765
+					$metabox['args']['template_args'],
2766
+					true
2767
+				);
2768
+			}
2769
+			: $callback;
2770
+		add_meta_box(
2771
+			str_replace('_', '-', $action) . '-mbox',
2772
+			$title,
2773
+			$call_back_func,
2774
+			$this->_wp_page_slug,
2775
+			$column,
2776
+			$priority,
2777
+			$callback_args
2778
+		);
2779
+	}
2780
+
2781
+
2782
+	/**
2783
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2784
+	 *
2785
+	 * @throws DomainException
2786
+	 * @throws EE_Error
2787
+	 * @throws InvalidArgumentException
2788
+	 * @throws InvalidDataTypeException
2789
+	 * @throws InvalidInterfaceException
2790
+	 */
2791
+	public function display_admin_page_with_metabox_columns()
2792
+	{
2793
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2794
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2795
+			$this->_column_template_path,
2796
+			$this->_template_args,
2797
+			true
2798
+		);
2799
+		// the final wrapper
2800
+		$this->admin_page_wrapper();
2801
+	}
2802
+
2803
+
2804
+	/**
2805
+	 * generates  HTML wrapper for an admin details page
2806
+	 *
2807
+	 * @return void
2808
+	 * @throws DomainException
2809
+	 * @throws EE_Error
2810
+	 * @throws InvalidArgumentException
2811
+	 * @throws InvalidDataTypeException
2812
+	 * @throws InvalidInterfaceException
2813
+	 */
2814
+	public function display_admin_page_with_sidebar()
2815
+	{
2816
+		$this->_display_admin_page(true);
2817
+	}
2818
+
2819
+
2820
+	/**
2821
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2822
+	 *
2823
+	 * @return void
2824
+	 * @throws DomainException
2825
+	 * @throws EE_Error
2826
+	 * @throws InvalidArgumentException
2827
+	 * @throws InvalidDataTypeException
2828
+	 * @throws InvalidInterfaceException
2829
+	 */
2830
+	public function display_admin_page_with_no_sidebar()
2831
+	{
2832
+		$this->_display_admin_page();
2833
+	}
2834
+
2835
+
2836
+	/**
2837
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2838
+	 *
2839
+	 * @return void
2840
+	 * @throws DomainException
2841
+	 * @throws EE_Error
2842
+	 * @throws InvalidArgumentException
2843
+	 * @throws InvalidDataTypeException
2844
+	 * @throws InvalidInterfaceException
2845
+	 */
2846
+	public function display_about_admin_page()
2847
+	{
2848
+		$this->_display_admin_page(false, true);
2849
+	}
2850
+
2851
+
2852
+	/**
2853
+	 * display_admin_page
2854
+	 * contains the code for actually displaying an admin page
2855
+	 *
2856
+	 * @param boolean $sidebar true with sidebar, false without
2857
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2858
+	 * @return void
2859
+	 * @throws DomainException
2860
+	 * @throws EE_Error
2861
+	 * @throws InvalidArgumentException
2862
+	 * @throws InvalidDataTypeException
2863
+	 * @throws InvalidInterfaceException
2864
+	 */
2865
+	private function _display_admin_page($sidebar = false, $about = false)
2866
+	{
2867
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2868
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2869
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2870
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2871
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2872
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2873
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2874
+			? 'poststuff'
2875
+			: 'espresso-default-admin';
2876
+		$template_path = $sidebar
2877
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2878
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2879
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2880
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2881
+		}
2882
+		$template_path = ! empty($this->_column_template_path)
2883
+			? $this->_column_template_path : $template_path;
2884
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2885
+			? $this->_template_args['admin_page_content']
2886
+			: '';
2887
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2888
+			? $this->_template_args['before_admin_page_content']
2889
+			: '';
2890
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2891
+			? $this->_template_args['after_admin_page_content']
2892
+			: '';
2893
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2894
+			$template_path,
2895
+			$this->_template_args,
2896
+			true
2897
+		);
2898
+		// the final template wrapper
2899
+		$this->admin_page_wrapper($about);
2900
+	}
2901
+
2902
+
2903
+	/**
2904
+	 * This is used to display caf preview pages.
2905
+	 *
2906
+	 * @since 4.3.2
2907
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2908
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2909
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2910
+	 * @return void
2911
+	 * @throws DomainException
2912
+	 * @throws EE_Error
2913
+	 * @throws InvalidArgumentException
2914
+	 * @throws InvalidDataTypeException
2915
+	 * @throws InvalidInterfaceException
2916
+	 */
2917
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2918
+	{
2919
+		// let's generate a default preview action button if there isn't one already present.
2920
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2921
+			'Upgrade to Event Espresso 4 Right Now',
2922
+			'event_espresso'
2923
+		);
2924
+		$buy_now_url = add_query_arg(
2925
+			array(
2926
+				'ee_ver'       => 'ee4',
2927
+				'utm_source'   => 'ee4_plugin_admin',
2928
+				'utm_medium'   => 'link',
2929
+				'utm_campaign' => $utm_campaign_source,
2930
+				'utm_content'  => 'buy_now_button',
2931
+			),
2932
+			'http://eventespresso.com/pricing/'
2933
+		);
2934
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2935
+			? $this->get_action_link_or_button(
2936
+				'',
2937
+				'buy_now',
2938
+				array(),
2939
+				'button-primary button-large',
2940
+				$buy_now_url,
2941
+				true
2942
+			)
2943
+			: $this->_template_args['preview_action_button'];
2944
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2945
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2946
+			$this->_template_args,
2947
+			true
2948
+		);
2949
+		$this->_display_admin_page($display_sidebar);
2950
+	}
2951
+
2952
+
2953
+	/**
2954
+	 * display_admin_list_table_page_with_sidebar
2955
+	 * generates HTML wrapper for an admin_page with list_table
2956
+	 *
2957
+	 * @return void
2958
+	 * @throws DomainException
2959
+	 * @throws EE_Error
2960
+	 * @throws InvalidArgumentException
2961
+	 * @throws InvalidDataTypeException
2962
+	 * @throws InvalidInterfaceException
2963
+	 */
2964
+	public function display_admin_list_table_page_with_sidebar()
2965
+	{
2966
+		$this->_display_admin_list_table_page(true);
2967
+	}
2968
+
2969
+
2970
+	/**
2971
+	 * display_admin_list_table_page_with_no_sidebar
2972
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2973
+	 *
2974
+	 * @return void
2975
+	 * @throws DomainException
2976
+	 * @throws EE_Error
2977
+	 * @throws InvalidArgumentException
2978
+	 * @throws InvalidDataTypeException
2979
+	 * @throws InvalidInterfaceException
2980
+	 */
2981
+	public function display_admin_list_table_page_with_no_sidebar()
2982
+	{
2983
+		$this->_display_admin_list_table_page();
2984
+	}
2985
+
2986
+
2987
+	/**
2988
+	 * generates html wrapper for an admin_list_table page
2989
+	 *
2990
+	 * @param boolean $sidebar whether to display with sidebar or not.
2991
+	 * @return void
2992
+	 * @throws DomainException
2993
+	 * @throws EE_Error
2994
+	 * @throws InvalidArgumentException
2995
+	 * @throws InvalidDataTypeException
2996
+	 * @throws InvalidInterfaceException
2997
+	 */
2998
+	private function _display_admin_list_table_page($sidebar = false)
2999
+	{
3000
+		// setup search attributes
3001
+		$this->_set_search_attributes();
3002
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
3003
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3004
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
3005
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3006
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3007
+		$this->_template_args['list_table'] = $this->_list_table_object;
3008
+		$this->_template_args['current_route'] = $this->_req_action;
3009
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3010
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
3011
+		if (! empty($ajax_sorting_callback)) {
3012
+			$sortable_list_table_form_fields = wp_nonce_field(
3013
+				$ajax_sorting_callback . '_nonce',
3014
+				$ajax_sorting_callback . '_nonce',
3015
+				false,
3016
+				false
3017
+			);
3018
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3019
+												. $this->page_slug
3020
+												. '" />';
3021
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3022
+												. $ajax_sorting_callback
3023
+												. '" />';
3024
+		} else {
3025
+			$sortable_list_table_form_fields = '';
3026
+		}
3027
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3028
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3029
+			? $this->_template_args['list_table_hidden_fields']
3030
+			: '';
3031
+		$nonce_ref = $this->_req_action . '_nonce';
3032
+		$hidden_form_fields .= '<input type="hidden" name="'
3033
+							   . $nonce_ref
3034
+							   . '" value="'
3035
+							   . wp_create_nonce($nonce_ref)
3036
+							   . '">';
3037
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3038
+		// display message about search results?
3039
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3040
+			? '<p class="ee-search-results">' . sprintf(
3041
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3042
+				trim($this->_req_data['s'], '%')
3043
+			) . '</p>'
3044
+			: '';
3045
+		// filter before_list_table template arg
3046
+		$this->_template_args['before_list_table'] = apply_filters(
3047
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3048
+			$this->_template_args['before_list_table'],
3049
+			$this->page_slug,
3050
+			$this->_req_data,
3051
+			$this->_req_action
3052
+		);
3053
+		// convert to array and filter again
3054
+		// arrays are easier to inject new items in a specific location,
3055
+		// but would not be backwards compatible, so we have to add a new filter
3056
+		$this->_template_args['before_list_table'] = implode(
3057
+			" \n",
3058
+			(array) apply_filters(
3059
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3060
+				(array) $this->_template_args['before_list_table'],
3061
+				$this->page_slug,
3062
+				$this->_req_data,
3063
+				$this->_req_action
3064
+			)
3065
+		);
3066
+		// filter after_list_table template arg
3067
+		$this->_template_args['after_list_table'] = apply_filters(
3068
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3069
+			$this->_template_args['after_list_table'],
3070
+			$this->page_slug,
3071
+			$this->_req_data,
3072
+			$this->_req_action
3073
+		);
3074
+		// convert to array and filter again
3075
+		// arrays are easier to inject new items in a specific location,
3076
+		// but would not be backwards compatible, so we have to add a new filter
3077
+		$this->_template_args['after_list_table'] = implode(
3078
+			" \n",
3079
+			(array) apply_filters(
3080
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3081
+				(array) $this->_template_args['after_list_table'],
3082
+				$this->page_slug,
3083
+				$this->_req_data,
3084
+				$this->_req_action
3085
+			)
3086
+		);
3087
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3088
+			$template_path,
3089
+			$this->_template_args,
3090
+			true
3091
+		);
3092
+		// the final template wrapper
3093
+		if ($sidebar) {
3094
+			$this->display_admin_page_with_sidebar();
3095
+		} else {
3096
+			$this->display_admin_page_with_no_sidebar();
3097
+		}
3098
+	}
3099
+
3100
+
3101
+	/**
3102
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3103
+	 * html string for the legend.
3104
+	 * $items are expected in an array in the following format:
3105
+	 * $legend_items = array(
3106
+	 *        'item_id' => array(
3107
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3108
+	 *            'desc' => esc_html__('localized description of item');
3109
+	 *        )
3110
+	 * );
3111
+	 *
3112
+	 * @param  array $items see above for format of array
3113
+	 * @return string html string of legend
3114
+	 * @throws DomainException
3115
+	 */
3116
+	protected function _display_legend($items)
3117
+	{
3118
+		$this->_template_args['items'] = apply_filters(
3119
+			'FHEE__EE_Admin_Page___display_legend__items',
3120
+			(array) $items,
3121
+			$this
3122
+		);
3123
+		/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3124
+		$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3125
+		if (! $status_change_notice->isDismissed()) {
3126
+			$this->_template_args['status_change_notice'] = EEH_Template::display_template(
3127
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3128
+				[ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3129
+				true
3130
+			);
3131
+		}
3132
+		return EEH_Template::display_template(
3133
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3134
+			$this->_template_args,
3135
+			true
3136
+		);
3137
+	}
3138
+
3139
+
3140
+	/**
3141
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3142
+	 * The returned json object is created from an array in the following format:
3143
+	 * array(
3144
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3145
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3146
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3147
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3148
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3149
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3150
+	 *  that might be included in here)
3151
+	 * )
3152
+	 * The json object is populated by whatever is set in the $_template_args property.
3153
+	 *
3154
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3155
+	 *                                 instead of displayed.
3156
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3157
+	 * @return void
3158
+	 * @throws EE_Error
3159
+	 * @throws InvalidArgumentException
3160
+	 * @throws InvalidDataTypeException
3161
+	 * @throws InvalidInterfaceException
3162
+	 */
3163
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3164
+	{
3165
+		// make sure any EE_Error notices have been handled.
3166
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3167
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3168
+		unset($this->_template_args['data']);
3169
+		$json = array(
3170
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3171
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3172
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3173
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3174
+			'notices'   => EE_Error::get_notices(),
3175
+			'content'   => isset($this->_template_args['admin_page_content'])
3176
+				? $this->_template_args['admin_page_content'] : '',
3177
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3178
+			'isEEajax'  => true
3179
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3180
+		);
3181
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3182
+		if (null === error_get_last() || ! headers_sent()) {
3183
+			header('Content-Type: application/json; charset=UTF-8');
3184
+		}
3185
+		echo wp_json_encode($json);
3186
+		exit();
3187
+	}
3188
+
3189
+
3190
+	/**
3191
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3192
+	 *
3193
+	 * @return void
3194
+	 * @throws EE_Error
3195
+	 * @throws InvalidArgumentException
3196
+	 * @throws InvalidDataTypeException
3197
+	 * @throws InvalidInterfaceException
3198
+	 */
3199
+	public function return_json()
3200
+	{
3201
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3202
+			$this->_return_json();
3203
+		} else {
3204
+			throw new EE_Error(
3205
+				sprintf(
3206
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3207
+					__FUNCTION__
3208
+				)
3209
+			);
3210
+		}
3211
+	}
3212
+
3213
+
3214
+	/**
3215
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3216
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3217
+	 *
3218
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3219
+	 */
3220
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3221
+	{
3222
+		$this->_hook_obj = $hook_obj;
3223
+	}
3224
+
3225
+
3226
+	/**
3227
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3228
+	 *
3229
+	 * @param boolean $about whether to use the special about page wrapper or default.
3230
+	 * @return void
3231
+	 * @throws DomainException
3232
+	 * @throws EE_Error
3233
+	 * @throws InvalidArgumentException
3234
+	 * @throws InvalidDataTypeException
3235
+	 * @throws InvalidInterfaceException
3236
+	 */
3237
+	public function admin_page_wrapper($about = false)
3238
+	{
3239
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3240
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3241
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3242
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3243
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3244
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3245
+			isset($this->_template_args['before_admin_page_content'])
3246
+				? $this->_template_args['before_admin_page_content']
3247
+				: ''
3248
+		);
3249
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3250
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3251
+			isset($this->_template_args['after_admin_page_content'])
3252
+				? $this->_template_args['after_admin_page_content']
3253
+				: ''
3254
+		);
3255
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3256
+		// load settings page wrapper template
3257
+		$template_path = ! defined('DOING_AJAX')
3258
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3259
+			: EE_ADMIN_TEMPLATE
3260
+			  . 'admin_wrapper_ajax.template.php';
3261
+		// about page?
3262
+		$template_path = $about
3263
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3264
+			: $template_path;
3265
+		if (defined('DOING_AJAX')) {
3266
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3267
+				$template_path,
3268
+				$this->_template_args,
3269
+				true
3270
+			);
3271
+			$this->_return_json();
3272
+		} else {
3273
+			EEH_Template::display_template($template_path, $this->_template_args);
3274
+		}
3275
+	}
3276
+
3277
+
3278
+	/**
3279
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3280
+	 *
3281
+	 * @return string html
3282
+	 * @throws EE_Error
3283
+	 */
3284
+	protected function _get_main_nav_tabs()
3285
+	{
3286
+		// let's generate the html using the EEH_Tabbed_Content helper.
3287
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3288
+		// (rather than setting in the page_routes array)
3289
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3290
+	}
3291
+
3292
+
3293
+	/**
3294
+	 *        sort nav tabs
3295
+	 *
3296
+	 * @param $a
3297
+	 * @param $b
3298
+	 * @return int
3299
+	 */
3300
+	private function _sort_nav_tabs($a, $b)
3301
+	{
3302
+		if ($a['order'] === $b['order']) {
3303
+			return 0;
3304
+		}
3305
+		return ($a['order'] < $b['order']) ? -1 : 1;
3306
+	}
3307
+
3308
+
3309
+	/**
3310
+	 * generates HTML for the forms used on admin pages
3311
+	 *
3312
+	 * @param array  $input_vars - array of input field details
3313
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3314
+	 * @param bool   $id
3315
+	 * @return array|string
3316
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3317
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3318
+	 */
3319
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3320
+	{
3321
+		return $generator === 'string'
3322
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3323
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3324
+	}
3325
+
3326
+
3327
+	/**
3328
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3329
+	 *
3330
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3331
+	 *                                   Close" button.
3332
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3333
+	 *                                   'Save', [1] => 'save & close')
3334
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3335
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3336
+	 *                                   default actions by submitting some other value.
3337
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3338
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3339
+	 *                                   close (normal form handling).
3340
+	 */
3341
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3342
+	{
3343
+		// make sure $text and $actions are in an array
3344
+		$text = (array) $text;
3345
+		$actions = (array) $actions;
3346
+		$referrer_url = empty($referrer)
3347
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3348
+			  . $_SERVER['REQUEST_URI']
3349
+			  . '" />'
3350
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3351
+			  . $referrer
3352
+			  . '" />';
3353
+		$button_text = ! empty($text)
3354
+			? $text
3355
+			: array(
3356
+				esc_html__('Save', 'event_espresso'),
3357
+				esc_html__('Save and Close', 'event_espresso'),
3358
+			);
3359
+		$default_names = array('save', 'save_and_close');
3360
+		// add in a hidden index for the current page (so save and close redirects properly)
3361
+		$this->_template_args['save_buttons'] = $referrer_url;
3362
+		foreach ($button_text as $key => $button) {
3363
+			$ref = $default_names[ $key ];
3364
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3365
+													 . $ref
3366
+													 . '" value="'
3367
+													 . $button
3368
+													 . '" name="'
3369
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3370
+													 . '" id="'
3371
+													 . $this->_current_view . '_' . $ref
3372
+													 . '" />';
3373
+			if (! $both) {
3374
+				break;
3375
+			}
3376
+		}
3377
+	}
3378
+
3379
+
3380
+	/**
3381
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3382
+	 *
3383
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3384
+	 * @since 4.6.0
3385
+	 * @param string $route
3386
+	 * @param array  $additional_hidden_fields
3387
+	 */
3388
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3389
+	{
3390
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3391
+	}
3392
+
3393
+
3394
+	/**
3395
+	 * set form open and close tags on add/edit pages.
3396
+	 *
3397
+	 * @param string $route                    the route you want the form to direct to
3398
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3399
+	 * @return void
3400
+	 */
3401
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3402
+	{
3403
+		if (empty($route)) {
3404
+			$user_msg = esc_html__(
3405
+				'An error occurred. No action was set for this page\'s form.',
3406
+				'event_espresso'
3407
+			);
3408
+			$dev_msg = $user_msg . "\n"
3409
+					   . sprintf(
3410
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3411
+						   __FUNCTION__,
3412
+						   EE_Admin_Page::class
3413
+					   );
3414
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3415
+		}
3416
+		// open form
3417
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3418
+															 . $this->_admin_base_url
3419
+															 . '" id="'
3420
+															 . $route
3421
+															 . '_event_form" >';
3422
+		// add nonce
3423
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3424
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3425
+		// add REQUIRED form action
3426
+		$hidden_fields = array(
3427
+			'action' => array('type' => 'hidden', 'value' => $route),
3428
+		);
3429
+		// merge arrays
3430
+		$hidden_fields = is_array($additional_hidden_fields)
3431
+			? array_merge($hidden_fields, $additional_hidden_fields)
3432
+			: $hidden_fields;
3433
+		// generate form fields
3434
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3435
+		// add fields to form
3436
+		foreach ((array) $form_fields as $field_name => $form_field) {
3437
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3438
+		}
3439
+		// close form
3440
+		$this->_template_args['after_admin_page_content'] = '</form>';
3441
+	}
3442
+
3443
+
3444
+	/**
3445
+	 * Public Wrapper for _redirect_after_action() method since its
3446
+	 * discovered it would be useful for external code to have access.
3447
+	 *
3448
+	 * @param bool   $success
3449
+	 * @param string $what
3450
+	 * @param string $action_desc
3451
+	 * @param array  $query_args
3452
+	 * @param bool   $override_overwrite
3453
+	 * @throws EE_Error
3454
+	 * @throws InvalidArgumentException
3455
+	 * @throws InvalidDataTypeException
3456
+	 * @throws InvalidInterfaceException
3457
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3458
+	 * @since 4.5.0
3459
+	 */
3460
+	public function redirect_after_action(
3461
+		$success = false,
3462
+		$what = 'item',
3463
+		$action_desc = 'processed',
3464
+		$query_args = array(),
3465
+		$override_overwrite = false
3466
+	) {
3467
+		$this->_redirect_after_action(
3468
+			$success,
3469
+			$what,
3470
+			$action_desc,
3471
+			$query_args,
3472
+			$override_overwrite
3473
+		);
3474
+	}
3475
+
3476
+
3477
+	/**
3478
+	 * Helper method for merging existing request data with the returned redirect url.
3479
+	 *
3480
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3481
+	 * filters are still applied.
3482
+	 *
3483
+	 * @param array $new_route_data
3484
+	 * @return array
3485
+	 */
3486
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3487
+	{
3488
+		foreach ($this->_req_data as $ref => $value) {
3489
+			// unset nonces
3490
+			if (strpos($ref, 'nonce') !== false) {
3491
+				unset($this->_req_data[ $ref ]);
3492
+				continue;
3493
+			}
3494
+			// urlencode values.
3495
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3496
+			$this->_req_data[ $ref ] = $value;
3497
+		}
3498
+		return array_merge($this->_req_data, $new_route_data);
3499
+	}
3500
+
3501
+
3502
+	/**
3503
+	 *    _redirect_after_action
3504
+	 *
3505
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3506
+	 * @param string $what               - what the action was performed on
3507
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3508
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3509
+	 *                                   action is completed
3510
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3511
+	 *                                   override this so that they show.
3512
+	 * @return void
3513
+	 * @throws EE_Error
3514
+	 * @throws InvalidArgumentException
3515
+	 * @throws InvalidDataTypeException
3516
+	 * @throws InvalidInterfaceException
3517
+	 */
3518
+	protected function _redirect_after_action(
3519
+		$success = 0,
3520
+		$what = 'item',
3521
+		$action_desc = 'processed',
3522
+		$query_args = array(),
3523
+		$override_overwrite = false
3524
+	) {
3525
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3526
+		// class name for actions/filters.
3527
+		$classname = get_class($this);
3528
+		// set redirect url.
3529
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3530
+		// otherwise we go with whatever is set as the _admin_base_url
3531
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3532
+		$notices = EE_Error::get_notices(false);
3533
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3534
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3535
+			EE_Error::overwrite_success();
3536
+		}
3537
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3538
+			// how many records affected ? more than one record ? or just one ?
3539
+			if ($success > 1) {
3540
+				// set plural msg
3541
+				EE_Error::add_success(
3542
+					sprintf(
3543
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3544
+						$what,
3545
+						$action_desc
3546
+					),
3547
+					__FILE__,
3548
+					__FUNCTION__,
3549
+					__LINE__
3550
+				);
3551
+			} elseif ($success === 1) {
3552
+				// set singular msg
3553
+				EE_Error::add_success(
3554
+					sprintf(
3555
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3556
+						$what,
3557
+						$action_desc
3558
+					),
3559
+					__FILE__,
3560
+					__FUNCTION__,
3561
+					__LINE__
3562
+				);
3563
+			}
3564
+		}
3565
+		// check that $query_args isn't something crazy
3566
+		if (! is_array($query_args)) {
3567
+			$query_args = array();
3568
+		}
3569
+		/**
3570
+		 * Allow injecting actions before the query_args are modified for possible different
3571
+		 * redirections on save and close actions
3572
+		 *
3573
+		 * @since 4.2.0
3574
+		 * @param array $query_args       The original query_args array coming into the
3575
+		 *                                method.
3576
+		 */
3577
+		do_action(
3578
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3579
+			$query_args
3580
+		);
3581
+		// calculate where we're going (if we have a "save and close" button pushed)
3582
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3583
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3584
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3585
+			// regenerate query args array from referrer URL
3586
+			parse_str($parsed_url['query'], $query_args);
3587
+			// correct page and action will be in the query args now
3588
+			$redirect_url = admin_url('admin.php');
3589
+		}
3590
+		// merge any default query_args set in _default_route_query_args property
3591
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3592
+			$args_to_merge = array();
3593
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3594
+				// is there a wp_referer array in our _default_route_query_args property?
3595
+				if ($query_param === 'wp_referer') {
3596
+					$query_value = (array) $query_value;
3597
+					foreach ($query_value as $reference => $value) {
3598
+						if (strpos($reference, 'nonce') !== false) {
3599
+							continue;
3600
+						}
3601
+						// finally we will override any arguments in the referer with
3602
+						// what might be set on the _default_route_query_args array.
3603
+						if (isset($this->_default_route_query_args[ $reference ])) {
3604
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3605
+						} else {
3606
+							$args_to_merge[ $reference ] = urlencode($value);
3607
+						}
3608
+					}
3609
+					continue;
3610
+				}
3611
+				$args_to_merge[ $query_param ] = $query_value;
3612
+			}
3613
+			// now let's merge these arguments but override with what was specifically sent in to the
3614
+			// redirect.
3615
+			$query_args = array_merge($args_to_merge, $query_args);
3616
+		}
3617
+		$this->_process_notices($query_args);
3618
+		// generate redirect url
3619
+		// if redirecting to anything other than the main page, add a nonce
3620
+		if (isset($query_args['action'])) {
3621
+			// manually generate wp_nonce and merge that with the query vars
3622
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3623
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3624
+		}
3625
+		// we're adding some hooks and filters in here for processing any things just before redirects
3626
+		// (example: an admin page has done an insert or update and we want to run something after that).
3627
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3628
+		$redirect_url = apply_filters(
3629
+			'FHEE_redirect_' . $classname . $this->_req_action,
3630
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3631
+			$query_args
3632
+		);
3633
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3634
+		if (defined('DOING_AJAX')) {
3635
+			$default_data = array(
3636
+				'close'        => true,
3637
+				'redirect_url' => $redirect_url,
3638
+				'where'        => 'main',
3639
+				'what'         => 'append',
3640
+			);
3641
+			$this->_template_args['success'] = $success;
3642
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3643
+				$default_data,
3644
+				$this->_template_args['data']
3645
+			) : $default_data;
3646
+			$this->_return_json();
3647
+		}
3648
+		wp_safe_redirect($redirect_url);
3649
+		exit();
3650
+	}
3651
+
3652
+
3653
+	/**
3654
+	 * process any notices before redirecting (or returning ajax request)
3655
+	 * This method sets the $this->_template_args['notices'] attribute;
3656
+	 *
3657
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3658
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3659
+	 *                                  page_routes haven't been defined yet.
3660
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3661
+	 *                                  still save a transient for the notice.
3662
+	 * @return void
3663
+	 * @throws EE_Error
3664
+	 * @throws InvalidArgumentException
3665
+	 * @throws InvalidDataTypeException
3666
+	 * @throws InvalidInterfaceException
3667
+	 */
3668
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3669
+	{
3670
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3671
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3672
+			$notices = EE_Error::get_notices(false);
3673
+			if (empty($this->_template_args['success'])) {
3674
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3675
+			}
3676
+			if (empty($this->_template_args['errors'])) {
3677
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3678
+			}
3679
+			if (empty($this->_template_args['attention'])) {
3680
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3681
+			}
3682
+		}
3683
+		$this->_template_args['notices'] = EE_Error::get_notices();
3684
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3685
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3686
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3687
+			$this->_add_transient(
3688
+				$route,
3689
+				$this->_template_args['notices'],
3690
+				true,
3691
+				$skip_route_verify
3692
+			);
3693
+		}
3694
+	}
3695
+
3696
+
3697
+	/**
3698
+	 * get_action_link_or_button
3699
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3700
+	 *
3701
+	 * @param string $action        use this to indicate which action the url is generated with.
3702
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3703
+	 *                              property.
3704
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3705
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3706
+	 * @param string $base_url      If this is not provided
3707
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3708
+	 *                              Otherwise this value will be used.
3709
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3710
+	 * @return string
3711
+	 * @throws InvalidArgumentException
3712
+	 * @throws InvalidInterfaceException
3713
+	 * @throws InvalidDataTypeException
3714
+	 * @throws EE_Error
3715
+	 */
3716
+	public function get_action_link_or_button(
3717
+		$action,
3718
+		$type = 'add',
3719
+		$extra_request = array(),
3720
+		$class = 'button-primary',
3721
+		$base_url = '',
3722
+		$exclude_nonce = false
3723
+	) {
3724
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3725
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3726
+			throw new EE_Error(
3727
+				sprintf(
3728
+					esc_html__(
3729
+						'There is no page route for given action for the button.  This action was given: %s',
3730
+						'event_espresso'
3731
+					),
3732
+					$action
3733
+				)
3734
+			);
3735
+		}
3736
+		if (! isset($this->_labels['buttons'][ $type ])) {
3737
+			throw new EE_Error(
3738
+				sprintf(
3739
+					__(
3740
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3741
+						'event_espresso'
3742
+					),
3743
+					$type
3744
+				)
3745
+			);
3746
+		}
3747
+		// finally check user access for this button.
3748
+		$has_access = $this->check_user_access($action, true);
3749
+		if (! $has_access) {
3750
+			return '';
3751
+		}
3752
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3753
+		$query_args = array(
3754
+			'action' => $action,
3755
+		);
3756
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3757
+		if (! empty($extra_request)) {
3758
+			$query_args = array_merge($extra_request, $query_args);
3759
+		}
3760
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3761
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3762
+	}
3763
+
3764
+
3765
+	/**
3766
+	 * _per_page_screen_option
3767
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3768
+	 *
3769
+	 * @return void
3770
+	 * @throws InvalidArgumentException
3771
+	 * @throws InvalidInterfaceException
3772
+	 * @throws InvalidDataTypeException
3773
+	 */
3774
+	protected function _per_page_screen_option()
3775
+	{
3776
+		$option = 'per_page';
3777
+		$args = array(
3778
+			'label'   => apply_filters(
3779
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3780
+				$this->_admin_page_title,
3781
+				$this
3782
+			),
3783
+			'default' => (int) apply_filters(
3784
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3785
+				20
3786
+			),
3787
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3788
+		);
3789
+		// ONLY add the screen option if the user has access to it.
3790
+		if ($this->check_user_access($this->_current_view, true)) {
3791
+			add_screen_option($option, $args);
3792
+		}
3793
+	}
3794
+
3795
+
3796
+	/**
3797
+	 * set_per_page_screen_option
3798
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3799
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3800
+	 * admin_menu.
3801
+	 *
3802
+	 * @return void
3803
+	 */
3804
+	private function _set_per_page_screen_options()
3805
+	{
3806
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3807
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3808
+			if (! $user = wp_get_current_user()) {
3809
+				return;
3810
+			}
3811
+			$option = $_POST['wp_screen_options']['option'];
3812
+			$value = $_POST['wp_screen_options']['value'];
3813
+			if ($option !== sanitize_key($option)) {
3814
+				return;
3815
+			}
3816
+			$map_option = $option;
3817
+			$option = str_replace('-', '_', $option);
3818
+			switch ($map_option) {
3819
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3820
+					$value = (int) $value;
3821
+					$max_value = apply_filters(
3822
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3823
+						999,
3824
+						$this->_current_page,
3825
+						$this->_current_view
3826
+					);
3827
+					if ($value < 1) {
3828
+						return;
3829
+					}
3830
+					$value = min($value, $max_value);
3831
+					break;
3832
+				default:
3833
+					$value = apply_filters(
3834
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3835
+						false,
3836
+						$option,
3837
+						$value
3838
+					);
3839
+					if (false === $value) {
3840
+						return;
3841
+					}
3842
+					break;
3843
+			}
3844
+			update_user_meta($user->ID, $option, $value);
3845
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3846
+			exit;
3847
+		}
3848
+	}
3849
+
3850
+
3851
+	/**
3852
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3853
+	 *
3854
+	 * @param array $data array that will be assigned to template args.
3855
+	 */
3856
+	public function set_template_args($data)
3857
+	{
3858
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3859
+	}
3860
+
3861
+
3862
+	/**
3863
+	 * This makes available the WP transient system for temporarily moving data between routes
3864
+	 *
3865
+	 * @param string $route             the route that should receive the transient
3866
+	 * @param array  $data              the data that gets sent
3867
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3868
+	 *                                  normal route transient.
3869
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3870
+	 *                                  when we are adding a transient before page_routes have been defined.
3871
+	 * @return void
3872
+	 * @throws EE_Error
3873
+	 */
3874
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3875
+	{
3876
+		$user_id = get_current_user_id();
3877
+		if (! $skip_route_verify) {
3878
+			$this->_verify_route($route);
3879
+		}
3880
+		// now let's set the string for what kind of transient we're setting
3881
+		$transient = $notices
3882
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3883
+			: 'rte_tx_' . $route . '_' . $user_id;
3884
+		$data = $notices ? array('notices' => $data) : $data;
3885
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3886
+		$existing = is_multisite() && is_network_admin()
3887
+			? get_site_transient($transient)
3888
+			: get_transient($transient);
3889
+		if ($existing) {
3890
+			$data = array_merge((array) $data, (array) $existing);
3891
+		}
3892
+		if (is_multisite() && is_network_admin()) {
3893
+			set_site_transient($transient, $data, 8);
3894
+		} else {
3895
+			set_transient($transient, $data, 8);
3896
+		}
3897
+	}
3898
+
3899
+
3900
+	/**
3901
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3902
+	 *
3903
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3904
+	 * @param string $route
3905
+	 * @return mixed data
3906
+	 */
3907
+	protected function _get_transient($notices = false, $route = '')
3908
+	{
3909
+		$user_id = get_current_user_id();
3910
+		$route = ! $route ? $this->_req_action : $route;
3911
+		$transient = $notices
3912
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3913
+			: 'rte_tx_' . $route . '_' . $user_id;
3914
+		$data = is_multisite() && is_network_admin()
3915
+			? get_site_transient($transient)
3916
+			: get_transient($transient);
3917
+		// delete transient after retrieval (just in case it hasn't expired);
3918
+		if (is_multisite() && is_network_admin()) {
3919
+			delete_site_transient($transient);
3920
+		} else {
3921
+			delete_transient($transient);
3922
+		}
3923
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3924
+	}
3925
+
3926
+
3927
+	/**
3928
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3929
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3930
+	 * default route callback on the EE_Admin page you want it run.)
3931
+	 *
3932
+	 * @return void
3933
+	 */
3934
+	protected function _transient_garbage_collection()
3935
+	{
3936
+		global $wpdb;
3937
+		// retrieve all existing transients
3938
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3939
+		if ($results = $wpdb->get_results($query)) {
3940
+			foreach ($results as $result) {
3941
+				$transient = str_replace('_transient_', '', $result->option_name);
3942
+				get_transient($transient);
3943
+				if (is_multisite() && is_network_admin()) {
3944
+					get_site_transient($transient);
3945
+				}
3946
+			}
3947
+		}
3948
+	}
3949
+
3950
+
3951
+	/**
3952
+	 * get_view
3953
+	 *
3954
+	 * @return string content of _view property
3955
+	 */
3956
+	public function get_view()
3957
+	{
3958
+		return $this->_view;
3959
+	}
3960
+
3961
+
3962
+	/**
3963
+	 * getter for the protected $_views property
3964
+	 *
3965
+	 * @return array
3966
+	 */
3967
+	public function get_views()
3968
+	{
3969
+		return $this->_views;
3970
+	}
3971
+
3972
+
3973
+	/**
3974
+	 * get_current_page
3975
+	 *
3976
+	 * @return string _current_page property value
3977
+	 */
3978
+	public function get_current_page()
3979
+	{
3980
+		return $this->_current_page;
3981
+	}
3982
+
3983
+
3984
+	/**
3985
+	 * get_current_view
3986
+	 *
3987
+	 * @return string _current_view property value
3988
+	 */
3989
+	public function get_current_view()
3990
+	{
3991
+		return $this->_current_view;
3992
+	}
3993
+
3994
+
3995
+	/**
3996
+	 * get_current_screen
3997
+	 *
3998
+	 * @return object The current WP_Screen object
3999
+	 */
4000
+	public function get_current_screen()
4001
+	{
4002
+		return $this->_current_screen;
4003
+	}
4004
+
4005
+
4006
+	/**
4007
+	 * get_current_page_view_url
4008
+	 *
4009
+	 * @return string This returns the url for the current_page_view.
4010
+	 */
4011
+	public function get_current_page_view_url()
4012
+	{
4013
+		return $this->_current_page_view_url;
4014
+	}
4015
+
4016
+
4017
+	/**
4018
+	 * just returns the _req_data property
4019
+	 *
4020
+	 * @return array
4021
+	 */
4022
+	public function get_request_data()
4023
+	{
4024
+		return $this->_req_data;
4025
+	}
4026
+
4027
+
4028
+	/**
4029
+	 * returns the _req_data protected property
4030
+	 *
4031
+	 * @return string
4032
+	 */
4033
+	public function get_req_action()
4034
+	{
4035
+		return $this->_req_action;
4036
+	}
4037
+
4038
+
4039
+	/**
4040
+	 * @return bool  value of $_is_caf property
4041
+	 */
4042
+	public function is_caf()
4043
+	{
4044
+		return $this->_is_caf;
4045
+	}
4046
+
4047
+
4048
+	/**
4049
+	 * @return mixed
4050
+	 */
4051
+	public function default_espresso_metaboxes()
4052
+	{
4053
+		return $this->_default_espresso_metaboxes;
4054
+	}
4055
+
4056
+
4057
+	/**
4058
+	 * @return mixed
4059
+	 */
4060
+	public function admin_base_url()
4061
+	{
4062
+		return $this->_admin_base_url;
4063
+	}
4064
+
4065
+
4066
+	/**
4067
+	 * @return mixed
4068
+	 */
4069
+	public function wp_page_slug()
4070
+	{
4071
+		return $this->_wp_page_slug;
4072
+	}
4073
+
4074
+
4075
+	/**
4076
+	 * updates  espresso configuration settings
4077
+	 *
4078
+	 * @param string                   $tab
4079
+	 * @param EE_Config_Base|EE_Config $config
4080
+	 * @param string                   $file file where error occurred
4081
+	 * @param string                   $func function  where error occurred
4082
+	 * @param string                   $line line no where error occurred
4083
+	 * @return boolean
4084
+	 */
4085
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4086
+	{
4087
+		// remove any options that are NOT going to be saved with the config settings.
4088
+		if (isset($config->core->ee_ueip_optin)) {
4089
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4090
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4091
+			update_option('ee_ueip_has_notified', true);
4092
+		}
4093
+		// and save it (note we're also doing the network save here)
4094
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4095
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4096
+		if ($config_saved && $net_saved) {
4097
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4098
+			return true;
4099
+		}
4100
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4101
+		return false;
4102
+	}
4103
+
4104
+
4105
+	/**
4106
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4107
+	 *
4108
+	 * @return array
4109
+	 */
4110
+	public function get_yes_no_values()
4111
+	{
4112
+		return $this->_yes_no_values;
4113
+	}
4114
+
4115
+
4116
+	/**
4117
+	 * @return string
4118
+	 * @throws ReflectionException
4119
+	 * @since $VID:$
4120
+	 */
4121
+	protected function _get_dir()
4122
+	{
4123
+		$reflector = new ReflectionClass(get_class($this));
4124
+		return dirname($reflector->getFileName());
4125
+	}
4126
+
4127
+
4128
+	/**
4129
+	 * A helper for getting a "next link".
4130
+	 *
4131
+	 * @param string $url   The url to link to
4132
+	 * @param string $class The class to use.
4133
+	 * @return string
4134
+	 */
4135
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4136
+	{
4137
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4138
+	}
4139
+
4140
+
4141
+	/**
4142
+	 * A helper for getting a "previous link".
4143
+	 *
4144
+	 * @param string $url   The url to link to
4145
+	 * @param string $class The class to use.
4146
+	 * @return string
4147
+	 */
4148
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4149
+	{
4150
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4151
+	}
4152
+
4153
+
4154
+
4155
+
4156
+
4157
+
4158
+
4159
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4160
+
4161
+
4162
+	/**
4163
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4164
+	 * 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
4165
+	 * _req_data array.
4166
+	 *
4167
+	 * @return bool success/fail
4168
+	 * @throws EE_Error
4169
+	 * @throws InvalidArgumentException
4170
+	 * @throws ReflectionException
4171
+	 * @throws InvalidDataTypeException
4172
+	 * @throws InvalidInterfaceException
4173
+	 */
4174
+	protected function _process_resend_registration()
4175
+	{
4176
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4177
+		do_action(
4178
+			'AHEE__EE_Admin_Page___process_resend_registration',
4179
+			$this->_template_args['success'],
4180
+			$this->_req_data
4181
+		);
4182
+		return $this->_template_args['success'];
4183
+	}
4184
+
4185
+
4186
+	/**
4187
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4188
+	 *
4189
+	 * @param EE_Payment $payment
4190
+	 * @return bool success/fail
4191
+	 */
4192
+	protected function _process_payment_notification(EE_Payment $payment)
4193
+	{
4194
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4195
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4196
+		$this->_template_args['success'] = apply_filters(
4197
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4198
+			false,
4199
+			$payment
4200
+		);
4201
+		return $this->_template_args['success'];
4202
+	}
4203 4203
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Message_Template.model.php 2 patches
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -12,134 +12,134 @@
 block discarded – undo
12 12
 class EEM_Event_Message_Template extends EEM_Base
13 13
 {
14 14
 
15
-    // private instance of the EEM_Event_Message_Template object
16
-    protected static $_instance = null;
15
+	// private instance of the EEM_Event_Message_Template object
16
+	protected static $_instance = null;
17 17
 
18 18
 
19
-    /**
20
-     * protected constructor to prevent direct creation
21
-     *
22
-     * @param null $timezone
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct($timezone = null)
26
-    {
27
-        $this->singular_item = esc_html__('Event Message Template', 'event_espresso');
28
-        $this->plural_item = esc_html__('Event Message Templates', 'event_espresso');
19
+	/**
20
+	 * protected constructor to prevent direct creation
21
+	 *
22
+	 * @param null $timezone
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct($timezone = null)
26
+	{
27
+		$this->singular_item = esc_html__('Event Message Template', 'event_espresso');
28
+		$this->plural_item = esc_html__('Event Message Templates', 'event_espresso');
29 29
 
30
-        $this->_tables = [
31
-            'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
32
-        ];
33
-        $this->_fields = [
34
-            'Event_Message_Template' => [
35
-                'EMT_ID' => new EE_Primary_Key_Int_Field(
36
-                    'EMT_ID',
37
-                    esc_html__('Event Message Template ID', 'event_espresso')
38
-                ),
39
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
40
-                    'EVT_ID',
41
-                    esc_html__('The ID to the Event', 'event_espresso'),
42
-                    false,
43
-                    0,
44
-                    'Event'
45
-                ),
46
-                'GRP_ID' => new EE_Foreign_Key_Int_Field(
47
-                    'GRP_ID',
48
-                    esc_html__('The ID to the Message Template Group', 'event_espresso'),
49
-                    false,
50
-                    0,
51
-                    'Message_Template_Group'
52
-                ),
53
-            ],
54
-        ];
55
-        $this->_model_relations = [
56
-            'Event'                  => new EE_Belongs_To_Relation(),
57
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
58
-        ];
59
-        $path_to_event = 'Event';
60
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
61
-            $path_to_event
62
-        );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
64
-            $path_to_event
65
-        );
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
67
-            $path_to_event
68
-        );
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
70
-            $path_to_event,
71
-            EEM_Base::caps_edit
72
-        );
73
-        parent::__construct($timezone);
74
-    }
30
+		$this->_tables = [
31
+			'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
32
+		];
33
+		$this->_fields = [
34
+			'Event_Message_Template' => [
35
+				'EMT_ID' => new EE_Primary_Key_Int_Field(
36
+					'EMT_ID',
37
+					esc_html__('Event Message Template ID', 'event_espresso')
38
+				),
39
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
40
+					'EVT_ID',
41
+					esc_html__('The ID to the Event', 'event_espresso'),
42
+					false,
43
+					0,
44
+					'Event'
45
+				),
46
+				'GRP_ID' => new EE_Foreign_Key_Int_Field(
47
+					'GRP_ID',
48
+					esc_html__('The ID to the Message Template Group', 'event_espresso'),
49
+					false,
50
+					0,
51
+					'Message_Template_Group'
52
+				),
53
+			],
54
+		];
55
+		$this->_model_relations = [
56
+			'Event'                  => new EE_Belongs_To_Relation(),
57
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
58
+		];
59
+		$path_to_event = 'Event';
60
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
61
+			$path_to_event
62
+		);
63
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
64
+			$path_to_event
65
+		);
66
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
67
+			$path_to_event
68
+		);
69
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
70
+			$path_to_event,
71
+			EEM_Base::caps_edit
72
+		);
73
+		parent::__construct($timezone);
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * helper method to simply return an array of event ids for events attached to the given
79
-     * message template group.
80
-     *
81
-     * @param int $GRP_ID The MTP group we want attached events for.
82
-     * @return  array               An array of event ids.
83
-     * @throws EE_Error
84
-     * @since 4.3.0
85
-     */
86
-    public function get_attached_event_ids($GRP_ID)
87
-    {
88
-        $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
89
-        $event_ids = call_user_func_array('array_merge', $event_ids);
90
-        return $event_ids;
91
-    }
77
+	/**
78
+	 * helper method to simply return an array of event ids for events attached to the given
79
+	 * message template group.
80
+	 *
81
+	 * @param int $GRP_ID The MTP group we want attached events for.
82
+	 * @return  array               An array of event ids.
83
+	 * @throws EE_Error
84
+	 * @since 4.3.0
85
+	 */
86
+	public function get_attached_event_ids($GRP_ID)
87
+	{
88
+		$event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
89
+		$event_ids = call_user_func_array('array_merge', $event_ids);
90
+		return $event_ids;
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * helper method for clearing event/group relations for the given event ids and grp ids.
96
-     *
97
-     * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
98
-     * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
99
-     * @return int             How many rows were deleted.
100
-     * @throws EE_Error
101
-     * @throws EE_Error
102
-     */
103
-    public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = [])
104
-    {
105
-        if (empty($GRP_IDs) && empty($EVT_IDs)) {
106
-            throw new EE_Error(
107
-                sprintf(
108
-                    esc_html__(
109
-                        '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
110
-                        'event_espresso'
111
-                    ),
112
-                    __METHOD__
113
-                )
114
-            );
115
-        }
94
+	/**
95
+	 * helper method for clearing event/group relations for the given event ids and grp ids.
96
+	 *
97
+	 * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
98
+	 * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
99
+	 * @return int             How many rows were deleted.
100
+	 * @throws EE_Error
101
+	 * @throws EE_Error
102
+	 */
103
+	public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = [])
104
+	{
105
+		if (empty($GRP_IDs) && empty($EVT_IDs)) {
106
+			throw new EE_Error(
107
+				sprintf(
108
+					esc_html__(
109
+						'%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
110
+						'event_espresso'
111
+					),
112
+					__METHOD__
113
+				)
114
+			);
115
+		}
116 116
 
117
-        $where = [];
118
-        if (! empty($GRP_IDs)) {
119
-            $where['GRP_ID'] = ['IN', (array) $GRP_IDs];
120
-        }
121
-        if (! empty($EVT_IDs)) {
122
-            $where['EVT_ID'] = ['IN', (array) $EVT_IDs];
123
-        }
117
+		$where = [];
118
+		if (! empty($GRP_IDs)) {
119
+			$where['GRP_ID'] = ['IN', (array) $GRP_IDs];
120
+		}
121
+		if (! empty($EVT_IDs)) {
122
+			$where['EVT_ID'] = ['IN', (array) $EVT_IDs];
123
+		}
124 124
 
125
-        return $this->delete([$where], false);
126
-    }
125
+		return $this->delete([$where], false);
126
+	}
127 127
 
128 128
 
129
-    /**
130
-     * returns a numerically indexed array
131
-     * with values that correspond to the 'GRP_ID' column
132
-     * where the 'EVT_ID' column matches that of the supplied event
133
-     *
134
-     * @param EE_Event $event
135
-     * @return array
136
-     * @throws EE_Error
137
-     * @throws ReflectionException
138
-     * @since   $VID:$
139
-     */
140
-    public function messageTemplateGroupIDsForEvent(EE_Event $event): array
141
-    {
142
-        $results = $this->get_col( [['EVT_ID' => $event->ID()]], 'GRP_ID' );
143
-        return $results !== false ? $results : [];
144
-    }
129
+	/**
130
+	 * returns a numerically indexed array
131
+	 * with values that correspond to the 'GRP_ID' column
132
+	 * where the 'EVT_ID' column matches that of the supplied event
133
+	 *
134
+	 * @param EE_Event $event
135
+	 * @return array
136
+	 * @throws EE_Error
137
+	 * @throws ReflectionException
138
+	 * @since   $VID:$
139
+	 */
140
+	public function messageTemplateGroupIDsForEvent(EE_Event $event): array
141
+	{
142
+		$results = $this->get_col( [['EVT_ID' => $event->ID()]], 'GRP_ID' );
143
+		return $results !== false ? $results : [];
144
+	}
145 145
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
             'Message_Template_Group' => new EE_Belongs_To_Relation(),
58 58
         ];
59 59
         $path_to_event = 'Event';
60
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
60
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
61 61
             $path_to_event
62 62
         );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
63
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected(
64 64
             $path_to_event
65 65
         );
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
66
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
67 67
             $path_to_event
68 68
         );
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
69
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected(
70 70
             $path_to_event,
71 71
             EEM_Base::caps_edit
72 72
         );
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
         }
116 116
 
117 117
         $where = [];
118
-        if (! empty($GRP_IDs)) {
118
+        if ( ! empty($GRP_IDs)) {
119 119
             $where['GRP_ID'] = ['IN', (array) $GRP_IDs];
120 120
         }
121
-        if (! empty($EVT_IDs)) {
121
+        if ( ! empty($EVT_IDs)) {
122 122
             $where['EVT_ID'] = ['IN', (array) $EVT_IDs];
123 123
         }
124 124
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function messageTemplateGroupIDsForEvent(EE_Event $event): array
141 141
     {
142
-        $results = $this->get_col( [['EVT_ID' => $event->ID()]], 'GRP_ID' );
142
+        $results = $this->get_col([['EVT_ID' => $event->ID()]], 'GRP_ID');
143 143
         return $results !== false ? $results : [];
144 144
     }
145 145
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2889 added lines, -2889 removed lines patch added patch discarded remove patch
@@ -16,2896 +16,2896 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
21
-     *
22
-     * @access protected
23
-     * @var EE_Event $_event
24
-     */
25
-    protected $_event;
26
-
27
-
28
-    /**
29
-     * This will hold the category object for category_details screen.
30
-     *
31
-     * @var stdClass $_category
32
-     */
33
-    protected $_category;
34
-
35
-
36
-    /**
37
-     * This will hold the event model instance
38
-     *
39
-     * @var EEM_Event $_event_model
40
-     */
41
-    protected $_event_model;
42
-
43
-
44
-    /**
45
-     * @var EE_Event
46
-     */
47
-    protected $_cpt_model_obj = false;
48
-
49
-
50
-    /**
51
-     * @var NodeGroupDao
52
-     */
53
-    protected $model_obj_node_group_persister;
54
-
55
-
56
-    /**
57
-     * Initialize page props for this admin page group.
58
-     */
59
-    protected function _init_page_props()
60
-    {
61
-        $this->page_slug        = EVENTS_PG_SLUG;
62
-        $this->page_label       = EVENTS_LABEL;
63
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
64
-        $this->_admin_base_path = EVENTS_ADMIN;
65
-        $this->_cpt_model_names = [
66
-            'create_new' => 'EEM_Event',
67
-            'edit'       => 'EEM_Event',
68
-        ];
69
-        $this->_cpt_edit_routes = [
70
-            'espresso_events' => 'edit',
71
-        ];
72
-        add_action(
73
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
74
-            [$this, 'verify_event_edit'],
75
-            10,
76
-            2
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * Sets the ajax hooks used for this admin page group.
83
-     */
84
-    protected function _ajax_hooks()
85
-    {
86
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
87
-    }
88
-
89
-
90
-    /**
91
-     * Sets the page properties for this admin page group.
92
-     */
93
-    protected function _define_page_props()
94
-    {
95
-        $this->_admin_page_title = EVENTS_LABEL;
96
-        $this->_labels           = [
97
-            'buttons'      => [
98
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
99
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
100
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
101
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
102
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
103
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
104
-            ],
105
-            'editor_title' => [
106
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
107
-            ],
108
-            'publishbox'   => [
109
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
110
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
111
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
112
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
113
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
114
-            ],
115
-        ];
116
-    }
117
-
118
-
119
-    /**
120
-     * Sets the page routes property for this admin page group.
121
-     */
122
-    protected function _set_page_routes()
123
-    {
124
-        // load formatter helper
125
-        // load field generator helper
126
-        // is there a evt_id in the request?
127
-        $evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
128
-            ? $this->_req_data['EVT_ID']
129
-            : 0;
130
-        $evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
131
-        $this->_page_routes = [
132
-            'default'                       => [
133
-                'func'       => '_events_overview_list_table',
134
-                'capability' => 'ee_read_events',
135
-            ],
136
-            'create_new'                    => [
137
-                'func'       => '_create_new_cpt_item',
138
-                'capability' => 'ee_edit_events',
139
-            ],
140
-            'edit'                          => [
141
-                'func'       => '_edit_cpt_item',
142
-                'capability' => 'ee_edit_event',
143
-                'obj_id'     => $evt_id,
144
-            ],
145
-            'copy_event'                    => [
146
-                'func'       => '_copy_events',
147
-                'capability' => 'ee_edit_event',
148
-                'obj_id'     => $evt_id,
149
-                'noheader'   => true,
150
-            ],
151
-            'trash_event'                   => [
152
-                'func'       => '_trash_or_restore_event',
153
-                'args'       => ['event_status' => 'trash'],
154
-                'capability' => 'ee_delete_event',
155
-                'obj_id'     => $evt_id,
156
-                'noheader'   => true,
157
-            ],
158
-            'trash_events'                  => [
159
-                'func'       => '_trash_or_restore_events',
160
-                'args'       => ['event_status' => 'trash'],
161
-                'capability' => 'ee_delete_events',
162
-                'noheader'   => true,
163
-            ],
164
-            'restore_event'                 => [
165
-                'func'       => '_trash_or_restore_event',
166
-                'args'       => ['event_status' => 'draft'],
167
-                'capability' => 'ee_delete_event',
168
-                'obj_id'     => $evt_id,
169
-                'noheader'   => true,
170
-            ],
171
-            'restore_events'                => [
172
-                'func'       => '_trash_or_restore_events',
173
-                'args'       => ['event_status' => 'draft'],
174
-                'capability' => 'ee_delete_events',
175
-                'noheader'   => true,
176
-            ],
177
-            'delete_event'                  => [
178
-                'func'       => '_delete_event',
179
-                'capability' => 'ee_delete_event',
180
-                'obj_id'     => $evt_id,
181
-                'noheader'   => true,
182
-            ],
183
-            'delete_events'                 => [
184
-                'func'       => '_delete_events',
185
-                'capability' => 'ee_delete_events',
186
-                'noheader'   => true,
187
-            ],
188
-            'view_report'                   => [
189
-                'func'       => '_view_report',
190
-                'capability' => 'ee_edit_events',
191
-            ],
192
-            'default_event_settings'        => [
193
-                'func'       => '_default_event_settings',
194
-                'capability' => 'manage_options',
195
-            ],
196
-            'update_default_event_settings' => [
197
-                'func'       => '_update_default_event_settings',
198
-                'capability' => 'manage_options',
199
-                'noheader'   => true,
200
-            ],
201
-            'template_settings'             => [
202
-                'func'       => '_template_settings',
203
-                'capability' => 'manage_options',
204
-            ],
205
-            // event category tab related
206
-            'add_category'                  => [
207
-                'func'       => '_category_details',
208
-                'capability' => 'ee_edit_event_category',
209
-                'args'       => ['add'],
210
-            ],
211
-            'edit_category'                 => [
212
-                'func'       => '_category_details',
213
-                'capability' => 'ee_edit_event_category',
214
-                'args'       => ['edit'],
215
-            ],
216
-            'delete_categories'             => [
217
-                'func'       => '_delete_categories',
218
-                'capability' => 'ee_delete_event_category',
219
-                'noheader'   => true,
220
-            ],
221
-            'delete_category'               => [
222
-                'func'       => '_delete_categories',
223
-                'capability' => 'ee_delete_event_category',
224
-                'noheader'   => true,
225
-            ],
226
-            'insert_category'               => [
227
-                'func'       => '_insert_or_update_category',
228
-                'args'       => ['new_category' => true],
229
-                'capability' => 'ee_edit_event_category',
230
-                'noheader'   => true,
231
-            ],
232
-            'update_category'               => [
233
-                'func'       => '_insert_or_update_category',
234
-                'args'       => ['new_category' => false],
235
-                'capability' => 'ee_edit_event_category',
236
-                'noheader'   => true,
237
-            ],
238
-            'category_list'                 => [
239
-                'func'       => '_category_list_table',
240
-                'capability' => 'ee_manage_event_categories',
241
-            ],
242
-            'preview_deletion'              => [
243
-                'func'       => 'previewDeletion',
244
-                'capability' => 'ee_delete_events',
245
-            ],
246
-            'confirm_deletion'              => [
247
-                'func'       => 'confirmDeletion',
248
-                'capability' => 'ee_delete_events',
249
-                'noheader'   => true,
250
-            ],
251
-        ];
252
-    }
253
-
254
-
255
-    /**
256
-     * Set the _page_config property for this admin page group.
257
-     */
258
-    protected function _set_page_config()
259
-    {
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
-                // 'help_tour'     => [
291
-                //     'Event_Overview_Help_Tour',
292
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
293
-                // ],
294
-                'require_nonce' => false,
295
-                'qtips'         => ['EE_Event_List_Table_Tips'],
296
-            ],
297
-            'create_new'             => [
298
-                'nav'           => [
299
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
300
-                    'order'      => 5,
301
-                    'persistent' => false,
302
-                ],
303
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
304
-                'help_tabs'     => [
305
-                    'event_editor_help_tab'                            => [
306
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
307
-                        'filename' => 'event_editor',
308
-                    ],
309
-                    'event_editor_title_richtexteditor_help_tab'       => [
310
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
311
-                        'filename' => 'event_editor_title_richtexteditor',
312
-                    ],
313
-                    'event_editor_venue_details_help_tab'              => [
314
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
315
-                        'filename' => 'event_editor_venue_details',
316
-                    ],
317
-                    'event_editor_event_datetimes_help_tab'            => [
318
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
319
-                        'filename' => 'event_editor_event_datetimes',
320
-                    ],
321
-                    'event_editor_event_tickets_help_tab'              => [
322
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_tickets',
324
-                    ],
325
-                    'event_editor_event_registration_options_help_tab' => [
326
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
327
-                        'filename' => 'event_editor_event_registration_options',
328
-                    ],
329
-                    'event_editor_tags_categories_help_tab'            => [
330
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
331
-                        'filename' => 'event_editor_tags_categories',
332
-                    ],
333
-                    'event_editor_questions_registrants_help_tab'      => [
334
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
335
-                        'filename' => 'event_editor_questions_registrants',
336
-                    ],
337
-                    'event_editor_save_new_event_help_tab'             => [
338
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
339
-                        'filename' => 'event_editor_save_new_event',
340
-                    ],
341
-                    'event_editor_other_help_tab'                      => [
342
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
343
-                        'filename' => 'event_editor_other',
344
-                    ],
345
-                ],
346
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
347
-                // 'help_tour'     => [
348
-                //     'Event_Editor_Help_Tour',
349
-                // ],
350
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
351
-                'require_nonce' => false,
352
-            ],
353
-            'edit'                   => [
354
-                'nav'           => [
355
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
356
-                    'order'      => 5,
357
-                    'persistent' => false,
358
-                    'url'        => isset($this->_req_data['post'])
359
-                        ? EE_Admin_Page::add_query_args_and_nonce(
360
-                            ['post' => $this->_req_data['post'], 'action' => 'edit'],
361
-                            $this->_current_page_view_url
362
-                        )
363
-                        : $this->_admin_base_url,
364
-                ],
365
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
366
-                'help_tabs'     => [
367
-                    'event_editor_help_tab'                            => [
368
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
369
-                        'filename' => 'event_editor',
370
-                    ],
371
-                    'event_editor_title_richtexteditor_help_tab'       => [
372
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
373
-                        'filename' => 'event_editor_title_richtexteditor',
374
-                    ],
375
-                    'event_editor_venue_details_help_tab'              => [
376
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
377
-                        'filename' => 'event_editor_venue_details',
378
-                    ],
379
-                    'event_editor_event_datetimes_help_tab'            => [
380
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
381
-                        'filename' => 'event_editor_event_datetimes',
382
-                    ],
383
-                    'event_editor_event_tickets_help_tab'              => [
384
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
385
-                        'filename' => 'event_editor_event_tickets',
386
-                    ],
387
-                    'event_editor_event_registration_options_help_tab' => [
388
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
389
-                        'filename' => 'event_editor_event_registration_options',
390
-                    ],
391
-                    'event_editor_tags_categories_help_tab'            => [
392
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
393
-                        'filename' => 'event_editor_tags_categories',
394
-                    ],
395
-                    'event_editor_questions_registrants_help_tab'      => [
396
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
397
-                        'filename' => 'event_editor_questions_registrants',
398
-                    ],
399
-                    'event_editor_save_new_event_help_tab'             => [
400
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
401
-                        'filename' => 'event_editor_save_new_event',
402
-                    ],
403
-                    'event_editor_other_help_tab'                      => [
404
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
405
-                        'filename' => 'event_editor_other',
406
-                    ],
407
-                ],
408
-                'require_nonce' => false,
409
-            ],
410
-            'default_event_settings' => [
411
-                'nav'           => [
412
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
413
-                    'order' => 40,
414
-                ],
415
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
416
-                'labels'        => [
417
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
418
-                ],
419
-                'help_tabs'     => [
420
-                    'default_settings_help_tab'        => [
421
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
422
-                        'filename' => 'events_default_settings',
423
-                    ],
424
-                    'default_settings_status_help_tab' => [
425
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
426
-                        'filename' => 'events_default_settings_status',
427
-                    ],
428
-                    'default_maximum_tickets_help_tab' => [
429
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
430
-                        'filename' => 'events_default_settings_max_tickets',
431
-                    ],
432
-                ],
433
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
434
-                // 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
435
-                'require_nonce' => false,
436
-            ],
437
-            // template settings
438
-            'template_settings'      => [
439
-                'nav'           => [
440
-                    'label' => esc_html__('Templates', 'event_espresso'),
441
-                    'order' => 30,
442
-                ],
443
-                'metaboxes'     => $this->_default_espresso_metaboxes,
444
-                'help_tabs'     => [
445
-                    'general_settings_templates_help_tab' => [
446
-                        'title'    => esc_html__('Templates', 'event_espresso'),
447
-                        'filename' => 'general_settings_templates',
448
-                    ],
449
-                ],
450
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
451
-                // 'help_tour'     => ['Templates_Help_Tour'],
452
-                'require_nonce' => false,
453
-            ],
454
-            // event category stuff
455
-            'add_category'           => [
456
-                'nav'           => [
457
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
458
-                    'order'      => 15,
459
-                    'persistent' => false,
460
-                ],
461
-                'help_tabs'     => [
462
-                    'add_category_help_tab' => [
463
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
464
-                        'filename' => 'events_add_category',
465
-                    ],
466
-                ],
467
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
468
-                // 'help_tour'     => ['Event_Add_Category_Help_Tour'],
469
-                'metaboxes'     => ['_publish_post_box'],
470
-                'require_nonce' => false,
471
-            ],
472
-            'edit_category'          => [
473
-                'nav'           => [
474
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
475
-                    'order'      => 15,
476
-                    'persistent' => false,
477
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
478
-                        ? add_query_arg(
479
-                            ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
480
-                            $this->_current_page_view_url
481
-                        )
482
-                        : $this->_admin_base_url,
483
-                ],
484
-                'help_tabs'     => [
485
-                    'edit_category_help_tab' => [
486
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
487
-                        'filename' => 'events_edit_category',
488
-                    ],
489
-                ],
490
-                /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
491
-                'metaboxes'     => ['_publish_post_box'],
492
-                'require_nonce' => false,
493
-            ],
494
-            'category_list'          => [
495
-                'nav'           => [
496
-                    'label' => esc_html__('Categories', 'event_espresso'),
497
-                    'order' => 20,
498
-                ],
499
-                'list_table'    => 'Event_Categories_Admin_List_Table',
500
-                'help_tabs'     => [
501
-                    'events_categories_help_tab'                       => [
502
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
503
-                        'filename' => 'events_categories',
504
-                    ],
505
-                    'events_categories_table_column_headings_help_tab' => [
506
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
507
-                        'filename' => 'events_categories_table_column_headings',
508
-                    ],
509
-                    'events_categories_view_help_tab'                  => [
510
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
511
-                        'filename' => 'events_categories_views',
512
-                    ],
513
-                    'events_categories_other_help_tab'                 => [
514
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
515
-                        'filename' => 'events_categories_other',
516
-                    ],
517
-                ],
518
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
519
-                // 'help_tour'     => [
520
-                //     'Event_Categories_Help_Tour',
521
-                // ],
522
-                'metaboxes'     => $this->_default_espresso_metaboxes,
523
-                'require_nonce' => false,
524
-            ],
525
-            'preview_deletion'       => [
526
-                'nav'           => [
527
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
528
-                    'order'      => 15,
529
-                    'persistent' => false,
530
-                    'url'        => '',
531
-                ],
532
-                'require_nonce' => false,
533
-            ],
534
-        ];
535
-        // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
536
-        $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
537
-        if (! $domain->isCaffeinated()) {
538
-            $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
539
-            $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
540
-        }
541
-    }
542
-
543
-
544
-    /**
545
-     * Used to register any global screen options if necessary for every route in this admin page group.
546
-     */
547
-    protected function _add_screen_options()
548
-    {
549
-    }
550
-
551
-
552
-    /**
553
-     * Implementing the screen options for the 'default' route.
554
-     *
555
-     * @throws InvalidArgumentException
556
-     * @throws InvalidDataTypeException
557
-     * @throws InvalidInterfaceException
558
-     */
559
-    protected function _add_screen_options_default()
560
-    {
561
-        $this->_per_page_screen_option();
562
-    }
563
-
564
-
565
-    /**
566
-     * Implementing screen options for the category list route.
567
-     *
568
-     * @throws InvalidArgumentException
569
-     * @throws InvalidDataTypeException
570
-     * @throws InvalidInterfaceException
571
-     */
572
-    protected function _add_screen_options_category_list()
573
-    {
574
-        $page_title              = $this->_admin_page_title;
575
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
576
-        $this->_per_page_screen_option();
577
-        $this->_admin_page_title = $page_title;
578
-    }
579
-
580
-
581
-    /**
582
-     * Used to register any global feature pointers for the admin page group.
583
-     */
584
-    protected function _add_feature_pointers()
585
-    {
586
-    }
587
-
588
-
589
-    /**
590
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
591
-     */
592
-    public function load_scripts_styles()
593
-    {
594
-        wp_register_style(
595
-            'events-admin-css',
596
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
597
-            [],
598
-            EVENT_ESPRESSO_VERSION
599
-        );
600
-        wp_register_style(
601
-            'ee-cat-admin',
602
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
603
-            [],
604
-            EVENT_ESPRESSO_VERSION
605
-        );
606
-        wp_enqueue_style('events-admin-css');
607
-        wp_enqueue_style('ee-cat-admin');
608
-        // scripts
609
-        wp_register_script(
610
-            'event_editor_js',
611
-            EVENTS_ASSETS_URL . 'event_editor.js',
612
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
613
-            EVENT_ESPRESSO_VERSION,
614
-            true
615
-        );
616
-    }
617
-
618
-
619
-    /**
620
-     * Enqueuing scripts and styles specific to this view
621
-     */
622
-    public function load_scripts_styles_create_new()
623
-    {
624
-        $this->load_scripts_styles_edit();
625
-    }
626
-
627
-
628
-    /**
629
-     * Enqueuing scripts and styles specific to this view
630
-     */
631
-    public function load_scripts_styles_edit()
632
-    {
633
-        // styles
634
-        wp_enqueue_style('espresso-ui-theme');
635
-        wp_register_style(
636
-            'event-editor-css',
637
-            EVENTS_ASSETS_URL . 'event-editor.css',
638
-            ['ee-admin-css'],
639
-            EVENT_ESPRESSO_VERSION
640
-        );
641
-        wp_enqueue_style('event-editor-css');
642
-        // scripts
643
-        if (! $this->admin_config->useAdvancedEditor()) {
644
-            wp_register_script(
645
-                'event-datetime-metabox',
646
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
647
-                ['event_editor_js', 'ee-datepicker'],
648
-                EVENT_ESPRESSO_VERSION
649
-            );
650
-            wp_enqueue_script('event-datetime-metabox');
651
-        }
652
-    }
653
-
654
-
655
-    /**
656
-     * Populating the _views property for the category list table view.
657
-     */
658
-    protected function _set_list_table_views_category_list()
659
-    {
660
-        $this->_views = [
661
-            'all' => [
662
-                'slug'        => 'all',
663
-                'label'       => esc_html__('All', 'event_espresso'),
664
-                'count'       => 0,
665
-                'bulk_action' => [
666
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
667
-                ],
668
-            ],
669
-        ];
670
-    }
671
-
672
-
673
-    /**
674
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
675
-     */
676
-    public function admin_init()
677
-    {
678
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
679
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
680
-            'event_espresso'
681
-        );
682
-    }
683
-
684
-
685
-    /**
686
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
687
-     * group.
688
-     */
689
-    public function admin_notices()
690
-    {
691
-    }
692
-
693
-
694
-    /**
695
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
696
-     * this admin page group.
697
-     */
698
-    public function admin_footer_scripts()
699
-    {
700
-    }
701
-
702
-
703
-    /**
704
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
705
-     * warning (via EE_Error::add_error());
706
-     *
707
-     * @param EE_Event $event Event object
708
-     * @param string   $req_type
709
-     * @return void
710
-     * @throws EE_Error
711
-     * @access public
712
-     */
713
-    public function verify_event_edit($event = null, $req_type = '')
714
-    {
715
-        // don't need to do this when processing
716
-        if (! empty($req_type)) {
717
-            return;
718
-        }
719
-        // no event?
720
-        if (! $event instanceof EE_Event) {
721
-            $event = $this->_cpt_model_obj;
722
-        }
723
-        // STILL no event?
724
-        if (! $event instanceof EE_Event) {
725
-            return;
726
-        }
727
-        $orig_status = $event->status();
728
-        // first check if event is active.
729
-        if (
730
-            $orig_status === EEM_Event::cancelled
731
-            || $orig_status === EEM_Event::postponed
732
-            || $event->is_expired()
733
-            || $event->is_inactive()
734
-        ) {
735
-            return;
736
-        }
737
-        // made it here so it IS active... next check that any of the tickets are sold.
738
-        if ($event->is_sold_out(true)) {
739
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
740
-                EE_Error::add_attention(
741
-                    sprintf(
742
-                        esc_html__(
743
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
744
-                            'event_espresso'
745
-                        ),
746
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
747
-                    )
748
-                );
749
-            }
750
-            return;
751
-        }
752
-        if ($orig_status === EEM_Event::sold_out) {
753
-            EE_Error::add_attention(
754
-                sprintf(
755
-                    esc_html__(
756
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
757
-                        'event_espresso'
758
-                    ),
759
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
760
-                )
761
-            );
762
-        }
763
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
764
-        if (! $event->tickets_on_sale()) {
765
-            return;
766
-        }
767
-        // made it here so show warning
768
-        $this->_edit_event_warning();
769
-    }
770
-
771
-
772
-    /**
773
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
774
-     * When needed, hook this into a EE_Error::add_error() notice.
775
-     *
776
-     * @access protected
777
-     * @return void
778
-     */
779
-    protected function _edit_event_warning()
780
-    {
781
-        // we don't want to add warnings during these requests
782
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
783
-            return;
784
-        }
785
-        EE_Error::add_attention(
786
-            sprintf(
787
-                esc_html__(
788
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
789
-                    'event_espresso'
790
-                ),
791
-                '<a class="espresso-help-tab-lnk">',
792
-                '</a>'
793
-            )
794
-        );
795
-    }
796
-
797
-
798
-    /**
799
-     * When a user is creating a new event, notify them if they haven't set their timezone.
800
-     * Otherwise, do the normal logic
801
-     *
802
-     * @return void
803
-     * @throws EE_Error
804
-     * @throws InvalidArgumentException
805
-     * @throws InvalidDataTypeException
806
-     * @throws InvalidInterfaceException
807
-     */
808
-    protected function _create_new_cpt_item()
809
-    {
810
-        $has_timezone_string = get_option('timezone_string');
811
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
812
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
813
-            EE_Error::add_attention(
814
-                sprintf(
815
-                    __(
816
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
817
-                        'event_espresso'
818
-                    ),
819
-                    '<br>',
820
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
821
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
822
-                    . '</select>',
823
-                    '<button class="button button-secondary timezone-submit">',
824
-                    '</button><span class="spinner"></span>'
825
-                ),
826
-                __FILE__,
827
-                __FUNCTION__,
828
-                __LINE__
829
-            );
830
-        }
831
-        parent::_create_new_cpt_item();
832
-    }
833
-
834
-
835
-    /**
836
-     * Sets the _views property for the default route in this admin page group.
837
-     */
838
-    protected function _set_list_table_views_default()
839
-    {
840
-        $this->_views = [
841
-            'all'   => [
842
-                'slug'        => 'all',
843
-                'label'       => esc_html__('View All Events', 'event_espresso'),
844
-                'count'       => 0,
845
-                'bulk_action' => [
846
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
847
-                ],
848
-            ],
849
-            'draft' => [
850
-                'slug'        => 'draft',
851
-                'label'       => esc_html__('Draft', 'event_espresso'),
852
-                'count'       => 0,
853
-                'bulk_action' => [
854
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
855
-                ],
856
-            ],
857
-        ];
858
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
859
-            $this->_views['trash'] = [
860
-                'slug'        => 'trash',
861
-                'label'       => esc_html__('Trash', 'event_espresso'),
862
-                'count'       => 0,
863
-                'bulk_action' => [
864
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
865
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
866
-                ],
867
-            ];
868
-        }
869
-    }
870
-
871
-
872
-    /**
873
-     * Provides the legend item array for the default list table view.
874
-     *
875
-     * @return array
876
-     */
877
-    protected function _event_legend_items()
878
-    {
879
-        $items    = [
880
-            'view_details'   => [
881
-                'class' => 'dashicons dashicons-search',
882
-                'desc'  => esc_html__('View Event', 'event_espresso'),
883
-            ],
884
-            'edit_event'     => [
885
-                'class' => 'ee-icon ee-icon-calendar-edit',
886
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
887
-            ],
888
-            'view_attendees' => [
889
-                'class' => 'dashicons dashicons-groups',
890
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
891
-            ],
892
-        ];
893
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
894
-        $statuses = [
895
-            'sold_out_status'  => [
896
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
897
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
898
-            ],
899
-            'active_status'    => [
900
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
901
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
902
-            ],
903
-            'upcoming_status'  => [
904
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
905
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
906
-            ],
907
-            'postponed_status' => [
908
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
909
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
910
-            ],
911
-            'cancelled_status' => [
912
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
913
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
914
-            ],
915
-            'expired_status'   => [
916
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
917
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
918
-            ],
919
-            'inactive_status'  => [
920
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
921
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
922
-            ],
923
-        ];
924
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
925
-        return array_merge($items, $statuses);
926
-    }
927
-
928
-
929
-    /**
930
-     * @return EEM_Event
931
-     * @throws EE_Error
932
-     * @throws InvalidArgumentException
933
-     * @throws InvalidDataTypeException
934
-     * @throws InvalidInterfaceException
935
-     * @throws ReflectionException
936
-     */
937
-    private function _event_model()
938
-    {
939
-        if (! $this->_event_model instanceof EEM_Event) {
940
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
941
-        }
942
-        return $this->_event_model;
943
-    }
944
-
945
-
946
-    /**
947
-     * Adds extra buttons to the WP CPT permalink field row.
948
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
949
-     *
950
-     * @param string $return    the current html
951
-     * @param int    $id        the post id for the page
952
-     * @param string $new_title What the title is
953
-     * @param string $new_slug  what the slug is
954
-     * @return string            The new html string for the permalink area
955
-     */
956
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
957
-    {
958
-        // make sure this is only when editing
959
-        if (! empty($id)) {
960
-            $post   = get_post($id);
961
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
962
-                       . esc_html__('Shortcode', 'event_espresso')
963
-                       . '</a> ';
964
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
965
-                       . $post->ID
966
-                       . ']">';
967
-        }
968
-        return $return;
969
-    }
970
-
971
-
972
-    /**
973
-     * _events_overview_list_table
974
-     * This contains the logic for showing the events_overview list
975
-     *
976
-     * @access protected
977
-     * @return void
978
-     * @throws DomainException
979
-     * @throws EE_Error
980
-     * @throws InvalidArgumentException
981
-     * @throws InvalidDataTypeException
982
-     * @throws InvalidInterfaceException
983
-     */
984
-    protected function _events_overview_list_table()
985
-    {
986
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
987
-        $after_list_table                           = [];
988
-        $after_list_table['view_event_list_button'] = EEH_HTML::br();
989
-        $after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
990
-            get_post_type_archive_link('espresso_events'),
991
-            esc_html__('View Event Archive Page', 'event_espresso'),
992
-            'button'
993
-        );
994
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
995
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
996
-            'create_new',
997
-            'add',
998
-            [],
999
-            'add-new-h2'
1000
-        );
1001
-        $this->_template_args['after_list_table']   = array_merge(
1002
-            (array) $this->_template_args['after_list_table'],
1003
-            $after_list_table
1004
-        );
1005
-        $this->display_admin_list_table_page_with_no_sidebar();
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * this allows for extra misc actions in the default WP publish box
1011
-     *
1012
-     * @return void
1013
-     * @throws DomainException
1014
-     * @throws EE_Error
1015
-     * @throws InvalidArgumentException
1016
-     * @throws InvalidDataTypeException
1017
-     * @throws InvalidInterfaceException
1018
-     * @throws ReflectionException
1019
-     */
1020
-    public function extra_misc_actions_publish_box()
1021
-    {
1022
-        $this->_generate_publish_box_extra_content();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1028
-     * saved.
1029
-     * Typically you would use this to save any additional data.
1030
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1031
-     * ALSO very important.  When a post transitions from scheduled to published,
1032
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1033
-     * other meta saves. So MAKE sure that you handle this accordingly.
1034
-     *
1035
-     * @access protected
1036
-     * @abstract
1037
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1038
-     * @param object $post    The post object of the cpt that was saved.
1039
-     * @return void
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    protected function _insert_update_cpt_item($post_id, $post)
1047
-    {
1048
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1049
-            // get out we're not processing an event save.
1050
-            return;
1051
-        }
1052
-        $event_values = [
1053
-            'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1054
-            'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1055
-            'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1056
-                ? sanitize_text_field($this->_req_data['timezone_string'])
1057
-                : null,
1058
-        ];
1059
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1060
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1061
-            $event_values['EVT_display_ticket_selector']     =
1062
-                ! empty($this->_req_data['display_ticket_selector'])
1063
-                    ? 1
1064
-                    : 0;
1065
-            $event_values['EVT_additional_limit']            = min(
1066
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1067
-                ! empty($this->_req_data['additional_limit'])
1068
-                    ? absint($this->_req_data['additional_limit'])
1069
-                    : null
1070
-            );
1071
-            $event_values['EVT_default_registration_status'] =
1072
-                ! empty($this->_req_data['EVT_default_registration_status'])
1073
-                    ? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1074
-                    : EE_Registry::instance()->CFG->registration->default_STS_ID;
1075
-            $event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1076
-                ? esc_url_raw($this->_req_data['externalURL'])
1077
-                : null;
1078
-            $event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1079
-                ? sanitize_text_field($this->_req_data['event_phone'])
1080
-                : null;
1081
-        }
1082
-        // update event
1083
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1084
-        // get event_object for other metaboxes...
1085
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1086
-        // i have to setup where conditions to override the filters in the model that filter out autodraft
1087
-        // and inherit statuses so we GET the inherit id!
1088
-        $get_one_where = [
1089
-            $this->_event_model()->primary_key_name() => $post_id,
1090
-            'OR'                                      => [
1091
-                'status'   => $post->post_status,
1092
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1093
-                // but the returned object here has a status of "publish", so use the original post status as well
1094
-                'status*1' => $this->_req_data['original_post_status'],
1095
-            ],
1096
-        ];
1097
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1098
-        // the following are default callbacks for event attachment updates
1099
-        // that can be overridden by caffeinated functionality and/or addons.
1100
-        $event_update_callbacks = [];
1101
-        if (! $this->admin_config->useAdvancedEditor()) {
1102
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1103
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1104
-        }
1105
-        $event_update_callbacks = apply_filters(
1106
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1107
-            $event_update_callbacks
1108
-        );
1109
-        $att_success            = true;
1110
-        foreach ($event_update_callbacks as $e_callback) {
1111
-            $results = is_callable($e_callback)
1112
-                ? $e_callback($event, $this->_req_data)
1113
-                : false;
1114
-            // if ANY of these updates fail then we want the appropriate global error message
1115
-            $att_success = $results !== false ? $att_success : false;
1116
-        }
1117
-        // any errors?
1118
-        if ($success && $att_success === false) {
1119
-            EE_Error::add_error(
1120
-                esc_html__(
1121
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1122
-                    'event_espresso'
1123
-                ),
1124
-                __FILE__,
1125
-                __FUNCTION__,
1126
-                __LINE__
1127
-            );
1128
-        } elseif ($success === false) {
1129
-            EE_Error::add_error(
1130
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1131
-                __FILE__,
1132
-                __FUNCTION__,
1133
-                __LINE__
1134
-            );
1135
-        }
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * @param int $post_id
1141
-     * @param int $revision_id
1142
-     * @throws EE_Error
1143
-     * @throws InvalidArgumentException
1144
-     * @throws InvalidDataTypeException
1145
-     * @throws InvalidInterfaceException
1146
-     * @throws ReflectionException
1147
-     * @see parent::restore_item()
1148
-     */
1149
-    protected function _restore_cpt_item($post_id, $revision_id)
1150
-    {
1151
-        // copy existing event meta to new post
1152
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1153
-        if ($post_evt instanceof EE_Event) {
1154
-            // meta revision restore
1155
-            $post_evt->restore_revision($revision_id);
1156
-            // related objs restore
1157
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1158
-        }
1159
-    }
1160
-
1161
-
1162
-    /**
1163
-     * Attach the venue to the Event
1164
-     *
1165
-     * @param EE_Event $evtobj Event Object to add the venue to
1166
-     * @param array    $data   The request data from the form
1167
-     * @return bool           Success or fail.
1168
-     * @throws EE_Error
1169
-     * @throws InvalidArgumentException
1170
-     * @throws InvalidDataTypeException
1171
-     * @throws InvalidInterfaceException
1172
-     * @throws ReflectionException
1173
-     */
1174
-    protected function _default_venue_update(EE_Event $evtobj, $data)
1175
-    {
1176
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1177
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1178
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1179
-        // very important.  If we don't have a venue name...
1180
-        // then we'll get out because not necessary to create empty venue
1181
-        if (empty($data['venue_title'])) {
1182
-            return false;
1183
-        }
1184
-        $venue_array = [
1185
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1186
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1187
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1188
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1189
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1190
-                : null,
1191
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1192
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1193
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1194
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1195
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1196
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1197
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1198
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1199
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1200
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1201
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1202
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1203
-            'status'              => 'publish',
1204
-        ];
1205
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1206
-        if (! empty($venue_id)) {
1207
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1208
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1209
-            // we've gotta make sure that the venue is always attached to a revision..
1210
-            // add_relation_to should take care of making sure that the relation is already present.
1211
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1212
-            return $rows_affected > 0;
1213
-        }
1214
-        // we insert the venue
1215
-        $venue_id = $venue_model->insert($venue_array);
1216
-        $evtobj->_add_relation_to($venue_id, 'Venue');
1217
-        return ! empty($venue_id);
1218
-        // when we have the ancestor come in it's already been handled by the revision save.
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1224
-     *
1225
-     * @param EE_Event $evtobj The Event object we're attaching data to
1226
-     * @param array    $data   The request data from the form
1227
-     * @return array
1228
-     * @throws EE_Error
1229
-     * @throws InvalidArgumentException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws InvalidInterfaceException
1232
-     * @throws ReflectionException
1233
-     * @throws Exception
1234
-     */
1235
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1236
-    {
1237
-        if ($this->admin_config->useAdvancedEditor()) {
1238
-            return [];
1239
-        }
1240
-        $success               = true;
1241
-        $saved_dtt             = null;
1242
-        $saved_tickets         = [];
1243
-        $incoming_date_formats = ['Y-m-d', 'h:i a'];
1244
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1245
-            // trim all values to ensure any excess whitespace is removed.
1246
-            $dtt                = array_map('trim', $dtt);
1247
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1248
-                : $dtt['DTT_EVT_start'];
1249
-            $datetime_values    = [
1250
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1251
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1252
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1253
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1254
-                'DTT_order'     => $row,
1255
-            ];
1256
-            // if we have an id then let's get existing object first and then set the new values.
1257
-            //  Otherwise we instantiate a new object for save.
1258
-            if (! empty($dtt['DTT_ID'])) {
1259
-                $DTM = EE_Registry::instance()
1260
-                                  ->load_model('Datetime', [$evtobj->get_timezone()])
1261
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1262
-                $DTM->set_date_format($incoming_date_formats[0]);
1263
-                $DTM->set_time_format($incoming_date_formats[1]);
1264
-                foreach ($datetime_values as $field => $value) {
1265
-                    $DTM->set($field, $value);
1266
-                }
1267
-                // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1268
-                // We need to do this so we dont' TRASH the parent DTT.
1269
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1270
-            } else {
1271
-                $DTM = EE_Registry::instance()->load_class(
1272
-                    'Datetime',
1273
-                    [$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1274
-                    false,
1275
-                    false
1276
-                );
1277
-                foreach ($datetime_values as $field => $value) {
1278
-                    $DTM->set($field, $value);
1279
-                }
1280
-            }
1281
-            $DTM->save();
1282
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1283
-            // load DTT helper
1284
-            // before going any further make sure our dates are setup correctly
1285
-            // so that the end date is always equal or greater than the start date.
1286
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1287
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1288
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1289
-                $DTT->save();
1290
-            }
1291
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array
1292
-            //  because it is possible there was a new one created for the autosave.
1293
-            $saved_dtt = $DTT;
1294
-            $success   = ! $success ? $success : $DTT;
1295
-            // if ANY of these updates fail then we want the appropriate global error message.
1296
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1297
-        }
1298
-        // no dtts get deleted so we don't do any of that logic here.
1299
-        // update tickets next
1300
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1301
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1302
-            $incoming_date_formats = ['Y-m-d', 'h:i a'];
1303
-            $update_prices         = false;
1304
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1305
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1306
-                : 0;
1307
-            // trim inputs to ensure any excess whitespace is removed.
1308
-            $tkt = array_map('trim', $tkt);
1309
-            if (empty($tkt['TKT_start_date'])) {
1310
-                // let's use now in the set timezone.
1311
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1312
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1313
-            }
1314
-            if (empty($tkt['TKT_end_date'])) {
1315
-                // use the start date of the first datetime
1316
-                $dtt                 = $evtobj->first_datetime();
1317
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1318
-                    $incoming_date_formats[0],
1319
-                    $incoming_date_formats[1]
1320
-                );
1321
-            }
1322
-            $TKT_values = [
1323
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1324
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1325
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1326
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1327
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1328
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1329
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1330
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1331
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1332
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1333
-                'TKT_row'         => $row,
1334
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1335
-                'TKT_price'       => $ticket_price,
1336
-            ];
1337
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1338
-            // which means in turn that the prices will become new prices as well.
1339
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1340
-                $TKT_values['TKT_ID']         = 0;
1341
-                $TKT_values['TKT_is_default'] = 0;
1342
-                $TKT_values['TKT_price']      = $ticket_price;
1343
-                $update_prices                = true;
1344
-            }
1345
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1346
-            // we actually do our saves a head of doing any add_relations to because its entirely possible
1347
-            // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1348
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
1349
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
-            if (! empty($tkt['TKT_ID'])) {
1351
-                $TKT = EE_Registry::instance()
1352
-                                  ->load_model('Ticket', [$evtobj->get_timezone()])
1353
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1354
-                if ($TKT instanceof EE_Ticket) {
1355
-                    $ticket_sold = $TKT->count_related(
1356
-                        'Registration',
1357
-                        [
1358
-                            [
1359
-                                'STS_ID' => [
1360
-                                    'NOT IN',
1361
-                                    [EEM_Registration::status_id_incomplete],
1362
-                                ],
1363
-                            ],
1364
-                        ]
1365
-                    ) > 0;
1366
-                    // let's just check the total price for the existing ticket and determine if it matches the new
1367
-                    // total price.  if they are different then we create a new ticket (if tickets sold)
1368
-                    // if they aren't different then we go ahead and modify existing ticket.
1369
-                    $create_new_TKT = $ticket_sold
1370
-                                      && ! $TKT->deleted()
1371
-                                      && EEH_Money::compare_floats(
1372
-                                          $ticket_price,
1373
-                                          $TKT->get('TKT_price'),
1374
-                                          '!=='
1375
-                                      );
1376
-                    $TKT->set_date_format($incoming_date_formats[0]);
1377
-                    $TKT->set_time_format($incoming_date_formats[1]);
1378
-                    // set new values
1379
-                    foreach ($TKT_values as $field => $value) {
1380
-                        if ($field === 'TKT_qty') {
1381
-                            $TKT->set_qty($value);
1382
-                        } else {
1383
-                            $TKT->set($field, $value);
1384
-                        }
1385
-                    }
1386
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
1387
-                    //  Otherwise we have to create a new ticket.
1388
-                    if ($create_new_TKT) {
1389
-                        // archive the old ticket first
1390
-                        $TKT->set('TKT_deleted', 1);
1391
-                        $TKT->save();
1392
-                        // make sure this ticket is still recorded in our saved_tkts
1393
-                        // so we don't run it through the regular trash routine.
1394
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1395
-                        // create new ticket that's a copy of the existing except a new id of course
1396
-                        // (and not archived) AND has the new TKT_price associated with it.
1397
-                        $TKT = clone $TKT;
1398
-                        $TKT->set('TKT_ID', 0);
1399
-                        $TKT->set('TKT_deleted', 0);
1400
-                        $TKT->set('TKT_price', $ticket_price);
1401
-                        $TKT->set('TKT_sold', 0);
1402
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1403
-                        $update_prices = true;
1404
-                    }
1405
-                    // make sure price is set if it hasn't been already
1406
-                    $TKT->set('TKT_price', $ticket_price);
1407
-                }
1408
-            } else {
1409
-                // no TKT_id so a new TKT
1410
-                $TKT_values['TKT_price'] = $ticket_price;
1411
-                $TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1412
-                if ($TKT instanceof EE_Ticket) {
1413
-                    // need to reset values to properly account for the date formats
1414
-                    $TKT->set_date_format($incoming_date_formats[0]);
1415
-                    $TKT->set_time_format($incoming_date_formats[1]);
1416
-                    $TKT->set_timezone($evtobj->get_timezone());
1417
-                    // set new values
1418
-                    foreach ($TKT_values as $field => $value) {
1419
-                        if ($field === 'TKT_qty') {
1420
-                            $TKT->set_qty($value);
1421
-                        } else {
1422
-                            $TKT->set($field, $value);
1423
-                        }
1424
-                    }
1425
-                    $update_prices = true;
1426
-                }
1427
-            }
1428
-            // cap ticket qty by datetime reg limits
1429
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1430
-            // update ticket.
1431
-            $TKT->save();
1432
-            // before going any further make sure our dates are setup correctly
1433
-            // so that the end date is always equal or greater than the start date.
1434
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1435
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1436
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1437
-                $TKT->save();
1438
-            }
1439
-            // initially let's add the ticket to the dtt
1440
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1441
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1442
-            // add prices to ticket
1443
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1444
-        }
1445
-        // however now we need to handle permanently deleting tickets via the ui.
1446
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1447
-        //  However, it does allow for deleting tickets that have no tickets sold,
1448
-        // in which case we want to get rid of permanently because there is no need to save in db.
1449
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1450
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1451
-        foreach ($tickets_removed as $id) {
1452
-            $id = absint($id);
1453
-            // get the ticket for this id
1454
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1455
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1456
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
1457
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1458
-            foreach ($dtts as $dtt) {
1459
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1460
-            }
1461
-            // need to do the same for prices (except these prices can also be deleted because again,
1462
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1463
-            $tkt_to_remove->delete_related_permanently('Price');
1464
-            // finally let's delete this ticket
1465
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1466
-            $tkt_to_remove->delete_permanently();
1467
-        }
1468
-        return [$saved_dtt, $saved_tickets];
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * This attaches a list of given prices to a ticket.
1474
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1475
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1476
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1477
-     *
1478
-     * @access  private
1479
-     * @param array     $prices     Array of prices from the form.
1480
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1481
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1482
-     * @return  void
1483
-     * @throws EE_Error
1484
-     * @throws InvalidArgumentException
1485
-     * @throws InvalidDataTypeException
1486
-     * @throws InvalidInterfaceException
1487
-     * @throws ReflectionException
1488
-     */
1489
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1490
-    {
1491
-        foreach ($prices as $row => $prc) {
1492
-            $PRC_values = [
1493
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1494
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1495
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1496
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1497
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1498
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1499
-                'PRC_order'      => $row,
1500
-            ];
1501
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1502
-                $PRC_values['PRC_ID'] = 0;
1503
-                $PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1504
-            } else {
1505
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1506
-                // update this price with new values
1507
-                foreach ($PRC_values as $field => $newprc) {
1508
-                    $PRC->set($field, $newprc);
1509
-                }
1510
-                $PRC->save();
1511
-            }
1512
-            $ticket->_add_relation_to($PRC, 'Price');
1513
-        }
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * Add in our autosave ajax handlers
1519
-     *
1520
-     */
1521
-    protected function _ee_autosave_create_new()
1522
-    {
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * More autosave handlers.
1528
-     */
1529
-    protected function _ee_autosave_edit()
1530
-    {
1531
-    }
1532
-
1533
-
1534
-    /**
1535
-     *    _generate_publish_box_extra_content
1536
-     *
1537
-     * @throws DomainException
1538
-     * @throws EE_Error
1539
-     * @throws InvalidArgumentException
1540
-     * @throws InvalidDataTypeException
1541
-     * @throws InvalidInterfaceException
1542
-     * @throws ReflectionException
1543
-     */
1544
-    private function _generate_publish_box_extra_content()
1545
-    {
1546
-        // load formatter helper
1547
-        // args for getting related registrations
1548
-        $approved_query_args        = [
1549
-            [
1550
-                'REG_deleted' => 0,
1551
-                'STS_ID'      => EEM_Registration::status_id_approved,
1552
-            ],
1553
-        ];
1554
-        $not_approved_query_args    = [
1555
-            [
1556
-                'REG_deleted' => 0,
1557
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1558
-            ],
1559
-        ];
1560
-        $pending_payment_query_args = [
1561
-            [
1562
-                'REG_deleted' => 0,
1563
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1564
-            ],
1565
-        ];
1566
-        // publish box
1567
-        $publish_box_extra_args = [
1568
-            'view_approved_reg_url'        => add_query_arg(
1569
-                [
1570
-                    'action'      => 'default',
1571
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1572
-                    '_reg_status' => EEM_Registration::status_id_approved,
1573
-                ],
1574
-                REG_ADMIN_URL
1575
-            ),
1576
-            'view_not_approved_reg_url'    => add_query_arg(
1577
-                [
1578
-                    'action'      => 'default',
1579
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1580
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1581
-                ],
1582
-                REG_ADMIN_URL
1583
-            ),
1584
-            'view_pending_payment_reg_url' => add_query_arg(
1585
-                [
1586
-                    'action'      => 'default',
1587
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1588
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1589
-                ],
1590
-                REG_ADMIN_URL
1591
-            ),
1592
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1593
-                'Registration',
1594
-                $approved_query_args
1595
-            ),
1596
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1597
-                'Registration',
1598
-                $not_approved_query_args
1599
-            ),
1600
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1601
-                'Registration',
1602
-                $pending_payment_query_args
1603
-            ),
1604
-            'misc_pub_section_class'       => apply_filters(
1605
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1606
-                'misc-pub-section'
1607
-            ),
1608
-        ];
1609
-        ob_start();
1610
-        do_action(
1611
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1612
-            $this->_cpt_model_obj
1613
-        );
1614
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1615
-        // load template
1616
-        EEH_Template::display_template(
1617
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1618
-            $publish_box_extra_args
1619
-        );
1620
-    }
1621
-
1622
-
1623
-    /**
1624
-     * @return EE_Event
1625
-     */
1626
-    public function get_event_object()
1627
-    {
1628
-        return $this->_cpt_model_obj;
1629
-    }
1630
-
1631
-
1632
-
1633
-
1634
-    /** METABOXES * */
1635
-    /**
1636
-     * _register_event_editor_meta_boxes
1637
-     * add all metaboxes related to the event_editor
1638
-     *
1639
-     * @return void
1640
-     * @throws EE_Error
1641
-     * @throws InvalidArgumentException
1642
-     * @throws InvalidDataTypeException
1643
-     * @throws InvalidInterfaceException
1644
-     * @throws ReflectionException
1645
-     */
1646
-    protected function _register_event_editor_meta_boxes()
1647
-    {
1648
-        $this->verify_cpt_object();
1649
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1650
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1651
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1652
-            add_meta_box(
1653
-                'espresso_event_editor_event_options',
1654
-                esc_html__('Event Registration Options', 'event_espresso'),
1655
-                [$this, 'registration_options_meta_box'],
1656
-                $this->page_slug,
1657
-                'side'
1658
-            );
1659
-        }
1660
-        if (! $use_advanced_editor) {
1661
-            add_meta_box(
1662
-                'espresso_event_editor_tickets',
1663
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1664
-                [$this, 'ticket_metabox'],
1665
-                $this->page_slug,
1666
-                'normal',
1667
-                'high'
1668
-            );
1669
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1670
-            add_action(
1671
-                'add_meta_boxes_espresso_events',
1672
-                function () {
1673
-                    global $current_screen;
1674
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1675
-                },
1676
-                99
1677
-            );
1678
-        }
1679
-        // NOTE: if you're looking for other metaboxes in here,
1680
-        // where a metabox has a related management page in the admin
1681
-        // you will find it setup in the related management page's "_Hooks" file.
1682
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1683
-    }
1684
-
1685
-
1686
-    /**
1687
-     * @throws DomainException
1688
-     * @throws EE_Error
1689
-     * @throws InvalidArgumentException
1690
-     * @throws InvalidDataTypeException
1691
-     * @throws InvalidInterfaceException
1692
-     * @throws ReflectionException
1693
-     */
1694
-    public function ticket_metabox()
1695
-    {
1696
-        $existing_datetime_ids = $existing_ticket_ids = [];
1697
-        // defaults for template args
1698
-        $template_args = [
1699
-            'existing_datetime_ids'    => '',
1700
-            'event_datetime_help_link' => '',
1701
-            'ticket_options_help_link' => '',
1702
-            'time'                     => null,
1703
-            'ticket_rows'              => '',
1704
-            'existing_ticket_ids'      => '',
1705
-            'total_ticket_rows'        => 1,
1706
-            'ticket_js_structure'      => '',
1707
-            'trash_icon'               => 'ee-lock-icon',
1708
-            'disabled'                 => '',
1709
-        ];
1710
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1711
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1712
-        /**
1713
-         * 1. Start with retrieving Datetimes
1714
-         * 2. Fore each datetime get related tickets
1715
-         * 3. For each ticket get related prices
1716
-         */
1717
-        /** @var EEM_Datetime $datetime_model */
1718
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1719
-        /** @var EEM_Ticket $datetime_model */
1720
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1721
-        $times        = $datetime_model->get_all_event_dates($event_id);
1722
-        /** @type EE_Datetime $first_datetime */
1723
-        $first_datetime = reset($times);
1724
-        // do we get related tickets?
1725
-        if (
1726
-            $first_datetime instanceof EE_Datetime
1727
-            && $first_datetime->ID() !== 0
1728
-        ) {
1729
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1730
-            $template_args['time']   = $first_datetime;
1731
-            $related_tickets         = $first_datetime->tickets(
1732
-                [
1733
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1734
-                    'default_where_conditions' => 'none',
1735
-                ]
1736
-            );
1737
-            if (! empty($related_tickets)) {
1738
-                $template_args['total_ticket_rows'] = count($related_tickets);
1739
-                $row                                = 0;
1740
-                foreach ($related_tickets as $ticket) {
1741
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1742
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743
-                    $row++;
1744
-                }
1745
-            } else {
1746
-                $template_args['total_ticket_rows'] = 1;
1747
-                /** @type EE_Ticket $ticket */
1748
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1749
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750
-            }
1751
-        } else {
1752
-            $template_args['time'] = $times[0];
1753
-            /** @type EE_Ticket[] $tickets */
1754
-            $tickets                      = $ticket_model->get_all_default_tickets();
1755
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756
-            // NOTE: we're just sending the first default row
1757
-            // (decaf can't manage default tickets so this should be sufficient);
1758
-        }
1759
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1760
-            'event_editor_event_datetimes_help_tab'
1761
-        );
1762
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1763
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1764
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1765
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1766
-            $ticket_model->create_default_object(),
1767
-            true
1768
-        );
1769
-        $template                                  = apply_filters(
1770
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1772
-        );
1773
-        EEH_Template::display_template($template, $template_args);
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     * Setup an individual ticket form for the decaf event editor page
1779
-     *
1780
-     * @access private
1781
-     * @param EE_Ticket $ticket   the ticket object
1782
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1783
-     * @param int       $row
1784
-     * @return string generated html for the ticket row.
1785
-     * @throws DomainException
1786
-     * @throws EE_Error
1787
-     * @throws InvalidArgumentException
1788
-     * @throws InvalidDataTypeException
1789
-     * @throws InvalidInterfaceException
1790
-     * @throws ReflectionException
1791
-     */
1792
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1793
-    {
1794
-        $template_args = [
1795
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1796
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1797
-                : '',
1798
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1799
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1800
-            'TKT_name'            => $ticket->get('TKT_name'),
1801
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1802
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1803
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1804
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1805
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1806
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1807
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1808
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1809
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1810
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1811
-                : ' disabled=disabled',
1812
-        ];
1813
-        $price         = $ticket->ID() !== 0
1814
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1815
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1816
-        $price_args    = [
1817
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1818
-            'PRC_amount'            => $price->get('PRC_amount'),
1819
-            'PRT_ID'                => $price->get('PRT_ID'),
1820
-            'PRC_ID'                => $price->get('PRC_ID'),
1821
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1822
-        ];
1823
-        // make sure we have default start and end dates if skeleton
1824
-        // handle rows that should NOT be empty
1825
-        if (empty($template_args['TKT_start_date'])) {
1826
-            // if empty then the start date will be now.
1827
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1828
-        }
1829
-        if (empty($template_args['TKT_end_date'])) {
1830
-            // get the earliest datetime (if present);
1831
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1832
-                ? $this->_cpt_model_obj->get_first_related(
1833
-                    'Datetime',
1834
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1835
-                )
1836
-                : null;
1837
-            if (! empty($earliest_dtt)) {
1838
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1839
-            } else {
1840
-                $template_args['TKT_end_date'] = date(
1841
-                    'Y-m-d h:i a',
1842
-                    mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1843
-                );
1844
-            }
1845
-        }
1846
-        $template_args = array_merge($template_args, $price_args);
1847
-        $template      = apply_filters(
1848
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1849
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1850
-            $ticket
1851
-        );
1852
-        return EEH_Template::display_template($template, $template_args, true);
1853
-    }
1854
-
1855
-
1856
-    /**
1857
-     * @throws DomainException
1858
-     * @throws EE_Error
1859
-     */
1860
-    public function registration_options_meta_box()
1861
-    {
1862
-        $yes_no_values             = [
1863
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1864
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1865
-        ];
1866
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1867
-            [
1868
-                EEM_Registration::status_id_cancelled,
1869
-                EEM_Registration::status_id_declined,
1870
-                EEM_Registration::status_id_incomplete,
1871
-            ],
1872
-            true
1873
-        );
1874
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1875
-        $template_args['_event']                          = $this->_cpt_model_obj;
1876
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1877
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1878
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1879
-            'default_reg_status',
1880
-            $default_reg_status_values,
1881
-            $this->_cpt_model_obj->default_registration_status()
1882
-        );
1883
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1884
-            'display_desc',
1885
-            $yes_no_values,
1886
-            $this->_cpt_model_obj->display_description()
1887
-        );
1888
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1889
-            'display_ticket_selector',
1890
-            $yes_no_values,
1891
-            $this->_cpt_model_obj->display_ticket_selector(),
1892
-            '',
1893
-            '',
1894
-            false
1895
-        );
1896
-        $template_args['additional_registration_options'] = apply_filters(
1897
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1898
-            '',
1899
-            $template_args,
1900
-            $yes_no_values,
1901
-            $default_reg_status_values
1902
-        );
1903
-        EEH_Template::display_template(
1904
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1905
-            $template_args
1906
-        );
1907
-    }
1908
-
1909
-
1910
-    /**
1911
-     * _get_events()
1912
-     * This method simply returns all the events (for the given _view and paging)
1913
-     *
1914
-     * @access public
1915
-     * @param int  $per_page     count of items per page (20 default);
1916
-     * @param int  $current_page what is the current page being viewed.
1917
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1918
-     *                           If FALSE then we return an array of event objects
1919
-     *                           that match the given _view and paging parameters.
1920
-     * @return array|int an array of event objects.
1921
-     * @throws EE_Error
1922
-     * @throws InvalidArgumentException
1923
-     * @throws InvalidDataTypeException
1924
-     * @throws InvalidInterfaceException
1925
-     * @throws ReflectionException
1926
-     * @throws Exception
1927
-     * @throws Exception
1928
-     * @throws Exception
1929
-     */
1930
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1931
-    {
1932
-        $EEME    = $this->_event_model();
1933
-        $offset  = ($current_page - 1) * $per_page;
1934
-        $limit   = $count ? null : $offset . ',' . $per_page;
1935
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1936
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1937
-        $month_r = '';
1938
-        $year_r  = '';
1939
-        if (isset($this->_req_data['month_range'])) {
1940
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1941
-            // simulate the FIRST day of the month, that fixes issues for months like February
1942
-            // where PHP doesn't know what to assume for date.
1943
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1944
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1945
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1946
-        }
1947
-        $where  = [];
1948
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1949
-        // determine what post_status our condition will have for the query.
1950
-        switch ($status) {
1951
-            case 'month':
1952
-            case 'today':
1953
-            case null:
1954
-            case 'all':
1955
-                break;
1956
-            case 'draft':
1957
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1958
-                break;
1959
-            default:
1960
-                $where['status'] = $status;
1961
-        }
1962
-        // categories?
1963
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1964
-            ? $this->_req_data['EVT_CAT'] : null;
1965
-        if (! empty($category)) {
1966
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1967
-            $where['Term_Taxonomy.term_id']  = $category;
1968
-        }
1969
-        // date where conditions
1970
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1971
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1972
-            $DateTime = new DateTime(
1973
-                $year_r . '-' . $month_r . '-01 00:00:00',
1974
-                new DateTimeZone('UTC')
1975
-            );
1976
-            $start    = $DateTime->getTimestamp();
1977
-            // set the datetime to be the end of the month
1978
-            $DateTime->setDate(
1979
-                $year_r,
1980
-                $month_r,
1981
-                $DateTime->format('t')
1982
-            )->setTime(23, 59, 59);
1983
-            $end                             = $DateTime->getTimestamp();
1984
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1985
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1986
-            $DateTime                        =
1987
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1988
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1989
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1990
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1991
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1992
-            $now                             = date('Y-m-01');
1993
-            $DateTime                        =
1994
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1995
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1996
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1997
-                                                        ->setTime(23, 59, 59)
1998
-                                                        ->format(implode(' ', $start_formats));
1999
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2000
-        }
2001
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2002
-            $where['EVT_wp_user'] = get_current_user_id();
2003
-        } elseif (
2004
-            ! isset($where['status'])
2005
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2006
-        ) {
2007
-            $where['OR'] = [
2008
-                'status*restrict_private' => ['!=', 'private'],
2009
-                'AND'                     => [
2010
-                    'status*inclusive' => ['=', 'private'],
2011
-                    'EVT_wp_user'      => get_current_user_id(),
2012
-                ],
2013
-            ];
2014
-        }
2015
-
2016
-        if (
2017
-            isset($this->_req_data['EVT_wp_user'])
2018
-            && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2019
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2020
-        ) {
2021
-            $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2022
-        }
2023
-        // search query handling
2024
-        if (isset($this->_req_data['s'])) {
2025
-            $search_string = '%' . $this->_req_data['s'] . '%';
2026
-            $where['OR']   = [
2027
-                'EVT_name'       => ['LIKE', $search_string],
2028
-                'EVT_desc'       => ['LIKE', $search_string],
2029
-                'EVT_short_desc' => ['LIKE', $search_string],
2030
-            ];
2031
-        }
2032
-        // filter events by venue.
2033
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2034
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2035
-        }
2036
-        $where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2037
-        $query_params = apply_filters(
2038
-            'FHEE__Events_Admin_Page__get_events__query_params',
2039
-            [
2040
-                $where,
2041
-                'limit'    => $limit,
2042
-                'order_by' => $orderby,
2043
-                'order'    => $order,
2044
-                'group_by' => 'EVT_ID',
2045
-            ],
2046
-            $this->_req_data
2047
-        );
2048
-
2049
-        // let's first check if we have special requests coming in.
2050
-        if (isset($this->_req_data['active_status'])) {
2051
-            switch ($this->_req_data['active_status']) {
2052
-                case 'upcoming':
2053
-                    return $EEME->get_upcoming_events($query_params, $count);
2054
-                case 'expired':
2055
-                    return $EEME->get_expired_events($query_params, $count);
2056
-                case 'active':
2057
-                    return $EEME->get_active_events($query_params, $count);
2058
-                case 'inactive':
2059
-                    return $EEME->get_inactive_events($query_params, $count);
2060
-            }
2061
-        }
2062
-
2063
-        return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2064
-    }
2065
-
2066
-
2067
-    /**
2068
-     * handling for WordPress CPT actions (trash, restore, delete)
2069
-     *
2070
-     * @param string $post_id
2071
-     * @throws EE_Error
2072
-     * @throws InvalidArgumentException
2073
-     * @throws InvalidDataTypeException
2074
-     * @throws InvalidInterfaceException
2075
-     * @throws ReflectionException
2076
-     */
2077
-    public function trash_cpt_item($post_id)
2078
-    {
2079
-        $this->_req_data['EVT_ID'] = $post_id;
2080
-        $this->_trash_or_restore_event('trash', false);
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * @param string $post_id
2086
-     * @throws EE_Error
2087
-     * @throws InvalidArgumentException
2088
-     * @throws InvalidDataTypeException
2089
-     * @throws InvalidInterfaceException
2090
-     * @throws ReflectionException
2091
-     */
2092
-    public function restore_cpt_item($post_id)
2093
-    {
2094
-        $this->_req_data['EVT_ID'] = $post_id;
2095
-        $this->_trash_or_restore_event('draft', false);
2096
-    }
2097
-
2098
-
2099
-    /**
2100
-     * @param string $post_id
2101
-     * @throws EE_Error
2102
-     * @throws InvalidArgumentException
2103
-     * @throws InvalidDataTypeException
2104
-     * @throws InvalidInterfaceException
2105
-     * @throws ReflectionException
2106
-     */
2107
-    public function delete_cpt_item($post_id)
2108
-    {
2109
-        throw new EE_Error(
2110
-            esc_html__(
2111
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2112
-                'event_espresso'
2113
-            )
2114
-        );
2115
-        $this->_req_data['EVT_ID'] = $post_id;
2116
-        $this->_delete_event();
2117
-    }
2118
-
2119
-
2120
-    /**
2121
-     * _trash_or_restore_event
2122
-     *
2123
-     * @access protected
2124
-     * @param string $event_status
2125
-     * @param bool   $redirect_after
2126
-     * @throws EE_Error
2127
-     * @throws InvalidArgumentException
2128
-     * @throws InvalidDataTypeException
2129
-     * @throws InvalidInterfaceException
2130
-     * @throws ReflectionException
2131
-     */
2132
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2133
-    {
2134
-        // determine the event id and set to array.
2135
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2136
-        // loop thru events
2137
-        if ($EVT_ID) {
2138
-            // clean status
2139
-            $event_status = sanitize_key($event_status);
2140
-            // grab status
2141
-            if (! empty($event_status)) {
2142
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2143
-            } else {
2144
-                $success = false;
2145
-                $msg     = esc_html__(
2146
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2147
-                    'event_espresso'
2148
-                );
2149
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2150
-            }
2151
-        } else {
2152
-            $success = false;
2153
-            $msg     = esc_html__(
2154
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2155
-                'event_espresso'
2156
-            );
2157
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2158
-        }
2159
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2160
-        if ($redirect_after) {
2161
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2162
-        }
2163
-    }
2164
-
2165
-
2166
-    /**
2167
-     * _trash_or_restore_events
2168
-     *
2169
-     * @access protected
2170
-     * @param string $event_status
2171
-     * @return void
2172
-     * @throws EE_Error
2173
-     * @throws InvalidArgumentException
2174
-     * @throws InvalidDataTypeException
2175
-     * @throws InvalidInterfaceException
2176
-     * @throws ReflectionException
2177
-     */
2178
-    protected function _trash_or_restore_events($event_status = 'trash')
2179
-    {
2180
-        // clean status
2181
-        $event_status = sanitize_key($event_status);
2182
-        // grab status
2183
-        if (! empty($event_status)) {
2184
-            $success = true;
2185
-            // determine the event id and set to array.
2186
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2187
-            // loop thru events
2188
-            foreach ($EVT_IDs as $EVT_ID) {
2189
-                if ($EVT_ID = absint($EVT_ID)) {
2190
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2191
-                    $success = $results !== false ? $success : false;
2192
-                } else {
2193
-                    $msg = sprintf(
2194
-                        esc_html__(
2195
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2196
-                            'event_espresso'
2197
-                        ),
2198
-                        $EVT_ID
2199
-                    );
2200
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2201
-                    $success = false;
2202
-                }
2203
-            }
2204
-        } else {
2205
-            $success = false;
2206
-            $msg     = esc_html__(
2207
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2208
-                'event_espresso'
2209
-            );
2210
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2211
-        }
2212
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2213
-        $success = $success ? 2 : false;
2214
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2215
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2216
-    }
2217
-
2218
-
2219
-    /**
2220
-     * _trash_or_restore_events
2221
-     *
2222
-     * @access  private
2223
-     * @param int    $EVT_ID
2224
-     * @param string $event_status
2225
-     * @return bool
2226
-     * @throws EE_Error
2227
-     * @throws InvalidArgumentException
2228
-     * @throws InvalidDataTypeException
2229
-     * @throws InvalidInterfaceException
2230
-     * @throws ReflectionException
2231
-     */
2232
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2233
-    {
2234
-        // grab event id
2235
-        if (! $EVT_ID) {
2236
-            $msg = esc_html__(
2237
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2238
-                'event_espresso'
2239
-            );
2240
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2241
-            return false;
2242
-        }
2243
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2244
-        // clean status
2245
-        $event_status = sanitize_key($event_status);
2246
-        // grab status
2247
-        if (empty($event_status)) {
2248
-            $msg = esc_html__(
2249
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2250
-                'event_espresso'
2251
-            );
2252
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2253
-            return false;
2254
-        }
2255
-        // was event trashed or restored ?
2256
-        switch ($event_status) {
2257
-            case 'draft':
2258
-                $action = 'restored from the trash';
2259
-                $hook   = 'AHEE_event_restored_from_trash';
2260
-                break;
2261
-            case 'trash':
2262
-                $action = 'moved to the trash';
2263
-                $hook   = 'AHEE_event_moved_to_trash';
2264
-                break;
2265
-            default:
2266
-                $action = 'updated';
2267
-                $hook   = false;
2268
-        }
2269
-        // use class to change status
2270
-        $this->_cpt_model_obj->set_status($event_status);
2271
-        $success = $this->_cpt_model_obj->save();
2272
-        if ($success === false) {
2273
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2274
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2275
-            return false;
2276
-        }
2277
-        if ($hook) {
2278
-            do_action($hook);
2279
-        }
2280
-        return true;
2281
-    }
2282
-
2283
-
2284
-    /**
2285
-     * @throws InvalidArgumentException
2286
-     * @throws InvalidDataTypeException
2287
-     * @throws InvalidInterfaceException
2288
-     */
2289
-    protected function _delete_event()
2290
-    {
2291
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2292
-    }
2293
-
2294
-
2295
-    /**
2296
-     * Gets the tree traversal batch persister.
2297
-     *
2298
-     * @return NodeGroupDao
2299
-     * @throws InvalidArgumentException
2300
-     * @throws InvalidDataTypeException
2301
-     * @throws InvalidInterfaceException
2302
-     * @since 4.10.12.p
2303
-     */
2304
-    protected function getModelObjNodeGroupPersister()
2305
-    {
2306
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2307
-            $this->model_obj_node_group_persister =
2308
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2309
-        }
2310
-        return $this->model_obj_node_group_persister;
2311
-    }
2312
-
2313
-
2314
-    /**
2315
-     * @return void
2316
-     * @throws InvalidArgumentException
2317
-     * @throws InvalidDataTypeException
2318
-     * @throws InvalidInterfaceException
2319
-     */
2320
-    protected function _delete_events()
2321
-    {
2322
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2323
-    }
2324
-
2325
-
2326
-    protected function generateDeletionPreview($event_ids)
2327
-    {
2328
-        $event_ids = (array) $event_ids;
2329
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2330
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2331
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2332
-            [
2333
-                'action'            => 'preview_deletion',
2334
-                'deletion_job_code' => $deletion_job_code,
2335
-            ],
2336
-            $this->_admin_base_url
2337
-        );
2338
-        $event_ids         = array_map(
2339
-            'intval',
2340
-            $event_ids
2341
-        );
2342
-
2343
-        EEH_URL::safeRedirectAndExit(
2344
-            EE_Admin_Page::add_query_args_and_nonce(
2345
-                [
2346
-                    'page'              => 'espresso_batch',
2347
-                    'batch'             => EED_Batch::batch_job,
2348
-                    'EVT_IDs'           => $event_ids,
2349
-                    'deletion_job_code' => $deletion_job_code,
2350
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2351
-                    'return_url'        => urlencode($return_url),
2352
-                ],
2353
-                admin_url()
2354
-            )
2355
-        );
2356
-    }
2357
-
2358
-
2359
-    /**
2360
-     * Checks for a POST submission
2361
-     *
2362
-     * @since 4.10.12.p
2363
-     */
2364
-    protected function confirmDeletion()
2365
-    {
2366
-        $deletion_redirect_logic =
2367
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2368
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2369
-    }
2370
-
2371
-
2372
-    /**
2373
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2374
-     *
2375
-     * @throws EE_Error
2376
-     * @since 4.10.12.p
2377
-     */
2378
-    protected function previewDeletion()
2379
-    {
2380
-        $preview_deletion_logic =
2381
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2382
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2383
-        $this->display_admin_page_with_no_sidebar();
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * get total number of events
2389
-     *
2390
-     * @access public
2391
-     * @return int
2392
-     * @throws EE_Error
2393
-     * @throws InvalidArgumentException
2394
-     * @throws InvalidDataTypeException
2395
-     * @throws InvalidInterfaceException
2396
-     */
2397
-    public function total_events()
2398
-    {
2399
-        return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2400
-    }
2401
-
2402
-
2403
-    /**
2404
-     * get total number of draft events
2405
-     *
2406
-     * @access public
2407
-     * @return int
2408
-     * @throws EE_Error
2409
-     * @throws InvalidArgumentException
2410
-     * @throws InvalidDataTypeException
2411
-     * @throws InvalidInterfaceException
2412
-     */
2413
-    public function total_events_draft()
2414
-    {
2415
-        $where = [
2416
-            'status' => ['IN', ['draft', 'auto-draft']],
2417
-        ];
2418
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     * get total number of trashed events
2424
-     *
2425
-     * @access public
2426
-     * @return int
2427
-     * @throws EE_Error
2428
-     * @throws InvalidArgumentException
2429
-     * @throws InvalidDataTypeException
2430
-     * @throws InvalidInterfaceException
2431
-     */
2432
-    public function total_trashed_events()
2433
-    {
2434
-        $where = [
2435
-            'status' => 'trash',
2436
-        ];
2437
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2438
-    }
2439
-
2440
-
2441
-    /**
2442
-     *    _default_event_settings
2443
-     *    This generates the Default Settings Tab
2444
-     *
2445
-     * @return void
2446
-     * @throws DomainException
2447
-     * @throws EE_Error
2448
-     * @throws InvalidArgumentException
2449
-     * @throws InvalidDataTypeException
2450
-     * @throws InvalidInterfaceException
2451
-     */
2452
-    protected function _default_event_settings()
2453
-    {
2454
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2455
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2456
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2457
-        $this->display_admin_page_with_sidebar();
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     * Return the form for event settings.
2463
-     *
2464
-     * @return EE_Form_Section_Proper
2465
-     * @throws EE_Error
2466
-     */
2467
-    protected function _default_event_settings_form()
2468
-    {
2469
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2470
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
-        // exclude
2472
-            [
2473
-                EEM_Registration::status_id_cancelled,
2474
-                EEM_Registration::status_id_declined,
2475
-                EEM_Registration::status_id_incomplete,
2476
-                EEM_Registration::status_id_wait_list,
2477
-            ],
2478
-            true
2479
-        );
2480
-        return new EE_Form_Section_Proper(
2481
-            [
2482
-                'name'            => 'update_default_event_settings',
2483
-                'html_id'         => 'update_default_event_settings',
2484
-                'html_class'      => 'form-table',
2485
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2486
-                'subsections'     => apply_filters(
2487
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2488
-                    [
2489
-                        'default_reg_status'  => new EE_Select_Input(
2490
-                            $registration_stati_for_selection,
2491
-                            [
2492
-                                'default'         => isset($registration_config->default_STS_ID)
2493
-                                                     && array_key_exists(
2494
-                                                         $registration_config->default_STS_ID,
2495
-                                                         $registration_stati_for_selection
2496
-                                                     )
2497
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2498
-                                    : EEM_Registration::status_id_pending_payment,
2499
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2500
-                                                     . EEH_Template::get_help_tab_link(
2501
-                                                         'default_settings_status_help_tab'
2502
-                                                     ),
2503
-                                'html_help_text'  => esc_html__(
2504
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2505
-                                    'event_espresso'
2506
-                                ),
2507
-                            ]
2508
-                        ),
2509
-                        'default_max_tickets' => new EE_Integer_Input(
2510
-                            [
2511
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2512
-                                    ? $registration_config->default_maximum_number_of_tickets
2513
-                                    : EEM_Event::get_default_additional_limit(),
2514
-                                'html_label_text' => esc_html__(
2515
-                                    'Default Maximum Tickets Allowed Per Order:',
2516
-                                    'event_espresso'
2517
-                                )
2518
-                                . EEH_Template::get_help_tab_link(
2519
-                                    'default_maximum_tickets_help_tab"'
2520
-                                ),
2521
-                                'html_help_text'  => esc_html__(
2522
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2523
-                                    'event_espresso'
2524
-                                ),
2525
-                            ]
2526
-                        ),
2527
-                    ]
2528
-                ),
2529
-            ]
2530
-        );
2531
-    }
2532
-
2533
-
2534
-    /**
2535
-     * @return void
2536
-     * @throws EE_Error
2537
-     * @throws InvalidArgumentException
2538
-     * @throws InvalidDataTypeException
2539
-     * @throws InvalidInterfaceException
2540
-     */
2541
-    protected function _update_default_event_settings()
2542
-    {
2543
-        $form = $this->_default_event_settings_form();
2544
-        if ($form->was_submitted()) {
2545
-            $form->receive_form_submission();
2546
-            if ($form->is_valid()) {
2547
-                $registration_config = EE_Registry::instance()->CFG->registration;
2548
-                $valid_data          = $form->valid_data();
2549
-                if (isset($valid_data['default_reg_status'])) {
2550
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2551
-                }
2552
-                if (isset($valid_data['default_max_tickets'])) {
2553
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2554
-                }
2555
-                do_action(
2556
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2557
-                    $valid_data,
2558
-                    EE_Registry::instance()->CFG,
2559
-                    $this
2560
-                );
2561
-                // update because data was valid!
2562
-                EE_Registry::instance()->CFG->update_espresso_config();
2563
-                EE_Error::overwrite_success();
2564
-                EE_Error::add_success(
2565
-                    __('Default Event Settings were updated', 'event_espresso')
2566
-                );
2567
-            }
2568
-        }
2569
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2570
-    }
2571
-
2572
-
2573
-    /*************        Templates        *************
2574
-     *
2575
-     * @throws EE_Error
2576
-     */
2577
-    protected function _template_settings()
2578
-    {
2579
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2580
-        $this->_template_args['preview_img']  = '<img src="'
2581
-                                                . EVENTS_ASSETS_URL
2582
-                                                . '/images/'
2583
-                                                . 'caffeinated_template_features.jpg" alt="'
2584
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2585
-                                                . '" />';
2586
-        $this->_template_args['preview_text'] = '<strong>'
2587
-                                                . esc_html__(
2588
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2589
-                                                    'event_espresso'
2590
-                                                ) . '</strong>';
2591
-        $this->display_admin_caf_preview_page('template_settings_tab');
2592
-    }
2593
-
2594
-
2595
-    /** Event Category Stuff **/
2596
-    /**
2597
-     * set the _category property with the category object for the loaded page.
2598
-     *
2599
-     * @access private
2600
-     * @return void
2601
-     */
2602
-    private function _set_category_object()
2603
-    {
2604
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2605
-            return;
2606
-        } //already have the category object so get out.
2607
-        // set default category object
2608
-        $this->_set_empty_category_object();
2609
-        // only set if we've got an id
2610
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2611
-            return;
2612
-        }
2613
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2614
-        $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2615
-        if (! empty($term)) {
2616
-            $this->_category->category_name       = $term->name;
2617
-            $this->_category->category_identifier = $term->slug;
2618
-            $this->_category->category_desc       = $term->description;
2619
-            $this->_category->id                  = $term->term_id;
2620
-            $this->_category->parent              = $term->parent;
2621
-        }
2622
-    }
2623
-
2624
-
2625
-    /**
2626
-     * Clears out category properties.
2627
-     */
2628
-    private function _set_empty_category_object()
2629
-    {
2630
-        $this->_category                = new stdClass();
2631
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2632
-        $this->_category->id            = $this->_category->parent = 0;
2633
-    }
2634
-
2635
-
2636
-    /**
2637
-     * @throws DomainException
2638
-     * @throws EE_Error
2639
-     * @throws InvalidArgumentException
2640
-     * @throws InvalidDataTypeException
2641
-     * @throws InvalidInterfaceException
2642
-     */
2643
-    protected function _category_list_table()
2644
-    {
2645
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2646
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2647
-        $this->_admin_page_title .= ' ';
2648
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2649
-            'add_category',
2650
-            'add_category',
2651
-            [],
2652
-            'add-new-h2'
2653
-        );
2654
-        $this->display_admin_list_table_page_with_sidebar();
2655
-    }
2656
-
2657
-
2658
-    /**
2659
-     * Output category details view.
2660
-     *
2661
-     * @param string $view
2662
-     * @throws DomainException
2663
-     * @throws EE_Error
2664
-     * @throws InvalidArgumentException
2665
-     * @throws InvalidDataTypeException
2666
-     * @throws InvalidInterfaceException
2667
-     */
2668
-    protected function _category_details($view)
2669
-    {
2670
-        // load formatter helper
2671
-        // load field generator helper
2672
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2673
-        $this->_set_add_edit_form_tags($route);
2674
-        $this->_set_category_object();
2675
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2676
-        $delete_action = 'delete_category';
2677
-        // custom redirect
2678
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2679
-            ['action' => 'category_list'],
2680
-            $this->_admin_base_url
2681
-        );
2682
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2683
-        // take care of contents
2684
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2685
-        $this->display_admin_page_with_sidebar();
2686
-    }
2687
-
2688
-
2689
-    /**
2690
-     * Output category details content.
2691
-     *
2692
-     * @throws DomainException
2693
-     */
2694
-    protected function _category_details_content()
2695
-    {
2696
-        $editor_args['category_desc'] = [
2697
-            'type'          => 'wp_editor',
2698
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2699
-            'class'         => 'my_editor_custom',
2700
-            'wpeditor_args' => ['media_buttons' => false],
2701
-        ];
2702
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2703
-        $all_terms                    = get_terms(
2704
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2705
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2706
-        );
2707
-        // setup category select for term parents.
2708
-        $category_select_values[] = [
2709
-            'text' => esc_html__('No Parent', 'event_espresso'),
2710
-            'id'   => 0,
2711
-        ];
2712
-        foreach ($all_terms as $term) {
2713
-            $category_select_values[] = [
2714
-                'text' => $term->name,
2715
-                'id'   => $term->term_id,
2716
-            ];
2717
-        }
2718
-        $category_select = EEH_Form_Fields::select_input(
2719
-            'category_parent',
2720
-            $category_select_values,
2721
-            $this->_category->parent
2722
-        );
2723
-        $template_args   = [
2724
-            'category'                 => $this->_category,
2725
-            'category_select'          => $category_select,
2726
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2727
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2728
-            'disable'                  => '',
2729
-            'disabled_message'         => false,
2730
-        ];
2731
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2732
-        return EEH_Template::display_template($template, $template_args, true);
2733
-    }
2734
-
2735
-
2736
-    /**
2737
-     * Handles deleting categories.
2738
-     *
2739
-     * @throws EE_Error
2740
-     */
2741
-    protected function _delete_categories()
2742
-    {
2743
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2744
-            : (array) $this->_req_data['category_id'];
2745
-        foreach ($cat_ids as $cat_id) {
2746
-            $this->_delete_category($cat_id);
2747
-        }
2748
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2749
-        $query_args = [
2750
-            'action' => 'category_list',
2751
-        ];
2752
-        $this->_redirect_after_action(0, '', '', $query_args);
2753
-    }
2754
-
2755
-
2756
-    /**
2757
-     * Handles deleting specific category.
2758
-     *
2759
-     * @param int $cat_id
2760
-     */
2761
-    protected function _delete_category($cat_id)
2762
-    {
2763
-        $cat_id = absint($cat_id);
2764
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2765
-    }
2766
-
2767
-
2768
-    /**
2769
-     * Handles triggering the update or insertion of a new category.
2770
-     *
2771
-     * @param bool $new_category true means we're triggering the insert of a new category.
2772
-     * @throws EE_Error
2773
-     * @throws InvalidArgumentException
2774
-     * @throws InvalidDataTypeException
2775
-     * @throws InvalidInterfaceException
2776
-     */
2777
-    protected function _insert_or_update_category($new_category)
2778
-    {
2779
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2780
-        $success = 0; // we already have a success message so lets not send another.
2781
-        if ($cat_id) {
2782
-            $query_args = [
2783
-                'action'     => 'edit_category',
2784
-                'EVT_CAT_ID' => $cat_id,
2785
-            ];
2786
-        } else {
2787
-            $query_args = ['action' => 'add_category'];
2788
-        }
2789
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2790
-    }
2791
-
2792
-
2793
-    /**
2794
-     * Inserts or updates category
2795
-     *
2796
-     * @param bool $update (true indicates we're updating a category).
2797
-     * @return bool|mixed|string
2798
-     */
2799
-    private function _insert_category($update = false)
2800
-    {
2801
-        $cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2802
-        $category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2803
-        $category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2804
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2805
-        if (empty($category_name)) {
2806
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2807
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2808
-            return false;
2809
-        }
2810
-        $term_args = [
2811
-            'name'        => $category_name,
2812
-            'description' => $category_desc,
2813
-            'parent'      => $category_parent,
2814
-        ];
2815
-        // was the category_identifier input disabled?
2816
-        if (isset($this->_req_data['category_identifier'])) {
2817
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2818
-        }
2819
-        $insert_ids = $update
2820
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2821
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2822
-        if (! is_array($insert_ids)) {
2823
-            $msg = esc_html__(
2824
-                'An error occurred and the category has not been saved to the database.',
2825
-                'event_espresso'
2826
-            );
2827
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2828
-        } else {
2829
-            $cat_id = $insert_ids['term_id'];
2830
-            $msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2831
-            EE_Error::add_success($msg);
2832
-        }
2833
-        return $cat_id;
2834
-    }
2835
-
2836
-
2837
-    /**
2838
-     * Gets categories or count of categories matching the arguments in the request.
2839
-     *
2840
-     * @param int  $per_page
2841
-     * @param int  $current_page
2842
-     * @param bool $count
2843
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2844
-     * @throws EE_Error
2845
-     * @throws InvalidArgumentException
2846
-     * @throws InvalidDataTypeException
2847
-     * @throws InvalidInterfaceException
2848
-     */
2849
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2850
-    {
2851
-        // testing term stuff
2852
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2853
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2854
-        $limit   = ($current_page - 1) * $per_page;
2855
-        $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2856
-        if (isset($this->_req_data['s'])) {
2857
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2858
-            $where['OR'] = [
2859
-                'Term.name'   => ['LIKE', $sstr],
2860
-                'description' => ['LIKE', $sstr],
2861
-            ];
2862
-        }
2863
-        $query_params = [
2864
-            $where,
2865
-            'order_by'   => [$orderby => $order],
2866
-            'limit'      => $limit . ',' . $per_page,
2867
-            'force_join' => ['Term'],
2868
-        ];
2869
-        return $count
2870
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2871
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2872
-    }
2873
-
2874
-    /* end category stuff */
2875
-
2876
-
2877
-    /**************/
2878
-
2879
-
2880
-    /**
2881
-     * Callback for the `ee_save_timezone_setting` ajax action.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @access protected
23
+	 * @var EE_Event $_event
24
+	 */
25
+	protected $_event;
26
+
27
+
28
+	/**
29
+	 * This will hold the category object for category_details screen.
30
+	 *
31
+	 * @var stdClass $_category
32
+	 */
33
+	protected $_category;
34
+
35
+
36
+	/**
37
+	 * This will hold the event model instance
38
+	 *
39
+	 * @var EEM_Event $_event_model
40
+	 */
41
+	protected $_event_model;
42
+
43
+
44
+	/**
45
+	 * @var EE_Event
46
+	 */
47
+	protected $_cpt_model_obj = false;
48
+
49
+
50
+	/**
51
+	 * @var NodeGroupDao
52
+	 */
53
+	protected $model_obj_node_group_persister;
54
+
55
+
56
+	/**
57
+	 * Initialize page props for this admin page group.
58
+	 */
59
+	protected function _init_page_props()
60
+	{
61
+		$this->page_slug        = EVENTS_PG_SLUG;
62
+		$this->page_label       = EVENTS_LABEL;
63
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
64
+		$this->_admin_base_path = EVENTS_ADMIN;
65
+		$this->_cpt_model_names = [
66
+			'create_new' => 'EEM_Event',
67
+			'edit'       => 'EEM_Event',
68
+		];
69
+		$this->_cpt_edit_routes = [
70
+			'espresso_events' => 'edit',
71
+		];
72
+		add_action(
73
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
74
+			[$this, 'verify_event_edit'],
75
+			10,
76
+			2
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * Sets the ajax hooks used for this admin page group.
83
+	 */
84
+	protected function _ajax_hooks()
85
+	{
86
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
87
+	}
88
+
89
+
90
+	/**
91
+	 * Sets the page properties for this admin page group.
92
+	 */
93
+	protected function _define_page_props()
94
+	{
95
+		$this->_admin_page_title = EVENTS_LABEL;
96
+		$this->_labels           = [
97
+			'buttons'      => [
98
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
99
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
100
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
101
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
102
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
103
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
104
+			],
105
+			'editor_title' => [
106
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
107
+			],
108
+			'publishbox'   => [
109
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
110
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
111
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
112
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
113
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
114
+			],
115
+		];
116
+	}
117
+
118
+
119
+	/**
120
+	 * Sets the page routes property for this admin page group.
121
+	 */
122
+	protected function _set_page_routes()
123
+	{
124
+		// load formatter helper
125
+		// load field generator helper
126
+		// is there a evt_id in the request?
127
+		$evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
128
+			? $this->_req_data['EVT_ID']
129
+			: 0;
130
+		$evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
131
+		$this->_page_routes = [
132
+			'default'                       => [
133
+				'func'       => '_events_overview_list_table',
134
+				'capability' => 'ee_read_events',
135
+			],
136
+			'create_new'                    => [
137
+				'func'       => '_create_new_cpt_item',
138
+				'capability' => 'ee_edit_events',
139
+			],
140
+			'edit'                          => [
141
+				'func'       => '_edit_cpt_item',
142
+				'capability' => 'ee_edit_event',
143
+				'obj_id'     => $evt_id,
144
+			],
145
+			'copy_event'                    => [
146
+				'func'       => '_copy_events',
147
+				'capability' => 'ee_edit_event',
148
+				'obj_id'     => $evt_id,
149
+				'noheader'   => true,
150
+			],
151
+			'trash_event'                   => [
152
+				'func'       => '_trash_or_restore_event',
153
+				'args'       => ['event_status' => 'trash'],
154
+				'capability' => 'ee_delete_event',
155
+				'obj_id'     => $evt_id,
156
+				'noheader'   => true,
157
+			],
158
+			'trash_events'                  => [
159
+				'func'       => '_trash_or_restore_events',
160
+				'args'       => ['event_status' => 'trash'],
161
+				'capability' => 'ee_delete_events',
162
+				'noheader'   => true,
163
+			],
164
+			'restore_event'                 => [
165
+				'func'       => '_trash_or_restore_event',
166
+				'args'       => ['event_status' => 'draft'],
167
+				'capability' => 'ee_delete_event',
168
+				'obj_id'     => $evt_id,
169
+				'noheader'   => true,
170
+			],
171
+			'restore_events'                => [
172
+				'func'       => '_trash_or_restore_events',
173
+				'args'       => ['event_status' => 'draft'],
174
+				'capability' => 'ee_delete_events',
175
+				'noheader'   => true,
176
+			],
177
+			'delete_event'                  => [
178
+				'func'       => '_delete_event',
179
+				'capability' => 'ee_delete_event',
180
+				'obj_id'     => $evt_id,
181
+				'noheader'   => true,
182
+			],
183
+			'delete_events'                 => [
184
+				'func'       => '_delete_events',
185
+				'capability' => 'ee_delete_events',
186
+				'noheader'   => true,
187
+			],
188
+			'view_report'                   => [
189
+				'func'       => '_view_report',
190
+				'capability' => 'ee_edit_events',
191
+			],
192
+			'default_event_settings'        => [
193
+				'func'       => '_default_event_settings',
194
+				'capability' => 'manage_options',
195
+			],
196
+			'update_default_event_settings' => [
197
+				'func'       => '_update_default_event_settings',
198
+				'capability' => 'manage_options',
199
+				'noheader'   => true,
200
+			],
201
+			'template_settings'             => [
202
+				'func'       => '_template_settings',
203
+				'capability' => 'manage_options',
204
+			],
205
+			// event category tab related
206
+			'add_category'                  => [
207
+				'func'       => '_category_details',
208
+				'capability' => 'ee_edit_event_category',
209
+				'args'       => ['add'],
210
+			],
211
+			'edit_category'                 => [
212
+				'func'       => '_category_details',
213
+				'capability' => 'ee_edit_event_category',
214
+				'args'       => ['edit'],
215
+			],
216
+			'delete_categories'             => [
217
+				'func'       => '_delete_categories',
218
+				'capability' => 'ee_delete_event_category',
219
+				'noheader'   => true,
220
+			],
221
+			'delete_category'               => [
222
+				'func'       => '_delete_categories',
223
+				'capability' => 'ee_delete_event_category',
224
+				'noheader'   => true,
225
+			],
226
+			'insert_category'               => [
227
+				'func'       => '_insert_or_update_category',
228
+				'args'       => ['new_category' => true],
229
+				'capability' => 'ee_edit_event_category',
230
+				'noheader'   => true,
231
+			],
232
+			'update_category'               => [
233
+				'func'       => '_insert_or_update_category',
234
+				'args'       => ['new_category' => false],
235
+				'capability' => 'ee_edit_event_category',
236
+				'noheader'   => true,
237
+			],
238
+			'category_list'                 => [
239
+				'func'       => '_category_list_table',
240
+				'capability' => 'ee_manage_event_categories',
241
+			],
242
+			'preview_deletion'              => [
243
+				'func'       => 'previewDeletion',
244
+				'capability' => 'ee_delete_events',
245
+			],
246
+			'confirm_deletion'              => [
247
+				'func'       => 'confirmDeletion',
248
+				'capability' => 'ee_delete_events',
249
+				'noheader'   => true,
250
+			],
251
+		];
252
+	}
253
+
254
+
255
+	/**
256
+	 * Set the _page_config property for this admin page group.
257
+	 */
258
+	protected function _set_page_config()
259
+	{
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
+				// 'help_tour'     => [
291
+				//     'Event_Overview_Help_Tour',
292
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
293
+				// ],
294
+				'require_nonce' => false,
295
+				'qtips'         => ['EE_Event_List_Table_Tips'],
296
+			],
297
+			'create_new'             => [
298
+				'nav'           => [
299
+					'label'      => esc_html__('Add Event', 'event_espresso'),
300
+					'order'      => 5,
301
+					'persistent' => false,
302
+				],
303
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
304
+				'help_tabs'     => [
305
+					'event_editor_help_tab'                            => [
306
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
307
+						'filename' => 'event_editor',
308
+					],
309
+					'event_editor_title_richtexteditor_help_tab'       => [
310
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
311
+						'filename' => 'event_editor_title_richtexteditor',
312
+					],
313
+					'event_editor_venue_details_help_tab'              => [
314
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
315
+						'filename' => 'event_editor_venue_details',
316
+					],
317
+					'event_editor_event_datetimes_help_tab'            => [
318
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
319
+						'filename' => 'event_editor_event_datetimes',
320
+					],
321
+					'event_editor_event_tickets_help_tab'              => [
322
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
323
+						'filename' => 'event_editor_event_tickets',
324
+					],
325
+					'event_editor_event_registration_options_help_tab' => [
326
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
327
+						'filename' => 'event_editor_event_registration_options',
328
+					],
329
+					'event_editor_tags_categories_help_tab'            => [
330
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
331
+						'filename' => 'event_editor_tags_categories',
332
+					],
333
+					'event_editor_questions_registrants_help_tab'      => [
334
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
335
+						'filename' => 'event_editor_questions_registrants',
336
+					],
337
+					'event_editor_save_new_event_help_tab'             => [
338
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
339
+						'filename' => 'event_editor_save_new_event',
340
+					],
341
+					'event_editor_other_help_tab'                      => [
342
+						'title'    => esc_html__('Event Other', 'event_espresso'),
343
+						'filename' => 'event_editor_other',
344
+					],
345
+				],
346
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
347
+				// 'help_tour'     => [
348
+				//     'Event_Editor_Help_Tour',
349
+				// ],
350
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
351
+				'require_nonce' => false,
352
+			],
353
+			'edit'                   => [
354
+				'nav'           => [
355
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
356
+					'order'      => 5,
357
+					'persistent' => false,
358
+					'url'        => isset($this->_req_data['post'])
359
+						? EE_Admin_Page::add_query_args_and_nonce(
360
+							['post' => $this->_req_data['post'], 'action' => 'edit'],
361
+							$this->_current_page_view_url
362
+						)
363
+						: $this->_admin_base_url,
364
+				],
365
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
366
+				'help_tabs'     => [
367
+					'event_editor_help_tab'                            => [
368
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
369
+						'filename' => 'event_editor',
370
+					],
371
+					'event_editor_title_richtexteditor_help_tab'       => [
372
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
373
+						'filename' => 'event_editor_title_richtexteditor',
374
+					],
375
+					'event_editor_venue_details_help_tab'              => [
376
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
377
+						'filename' => 'event_editor_venue_details',
378
+					],
379
+					'event_editor_event_datetimes_help_tab'            => [
380
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
381
+						'filename' => 'event_editor_event_datetimes',
382
+					],
383
+					'event_editor_event_tickets_help_tab'              => [
384
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
385
+						'filename' => 'event_editor_event_tickets',
386
+					],
387
+					'event_editor_event_registration_options_help_tab' => [
388
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
389
+						'filename' => 'event_editor_event_registration_options',
390
+					],
391
+					'event_editor_tags_categories_help_tab'            => [
392
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
393
+						'filename' => 'event_editor_tags_categories',
394
+					],
395
+					'event_editor_questions_registrants_help_tab'      => [
396
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
397
+						'filename' => 'event_editor_questions_registrants',
398
+					],
399
+					'event_editor_save_new_event_help_tab'             => [
400
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
401
+						'filename' => 'event_editor_save_new_event',
402
+					],
403
+					'event_editor_other_help_tab'                      => [
404
+						'title'    => esc_html__('Event Other', 'event_espresso'),
405
+						'filename' => 'event_editor_other',
406
+					],
407
+				],
408
+				'require_nonce' => false,
409
+			],
410
+			'default_event_settings' => [
411
+				'nav'           => [
412
+					'label' => esc_html__('Default Settings', 'event_espresso'),
413
+					'order' => 40,
414
+				],
415
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
416
+				'labels'        => [
417
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
418
+				],
419
+				'help_tabs'     => [
420
+					'default_settings_help_tab'        => [
421
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
422
+						'filename' => 'events_default_settings',
423
+					],
424
+					'default_settings_status_help_tab' => [
425
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
426
+						'filename' => 'events_default_settings_status',
427
+					],
428
+					'default_maximum_tickets_help_tab' => [
429
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
430
+						'filename' => 'events_default_settings_max_tickets',
431
+					],
432
+				],
433
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
434
+				// 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
435
+				'require_nonce' => false,
436
+			],
437
+			// template settings
438
+			'template_settings'      => [
439
+				'nav'           => [
440
+					'label' => esc_html__('Templates', 'event_espresso'),
441
+					'order' => 30,
442
+				],
443
+				'metaboxes'     => $this->_default_espresso_metaboxes,
444
+				'help_tabs'     => [
445
+					'general_settings_templates_help_tab' => [
446
+						'title'    => esc_html__('Templates', 'event_espresso'),
447
+						'filename' => 'general_settings_templates',
448
+					],
449
+				],
450
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
451
+				// 'help_tour'     => ['Templates_Help_Tour'],
452
+				'require_nonce' => false,
453
+			],
454
+			// event category stuff
455
+			'add_category'           => [
456
+				'nav'           => [
457
+					'label'      => esc_html__('Add Category', 'event_espresso'),
458
+					'order'      => 15,
459
+					'persistent' => false,
460
+				],
461
+				'help_tabs'     => [
462
+					'add_category_help_tab' => [
463
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
464
+						'filename' => 'events_add_category',
465
+					],
466
+				],
467
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
468
+				// 'help_tour'     => ['Event_Add_Category_Help_Tour'],
469
+				'metaboxes'     => ['_publish_post_box'],
470
+				'require_nonce' => false,
471
+			],
472
+			'edit_category'          => [
473
+				'nav'           => [
474
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
475
+					'order'      => 15,
476
+					'persistent' => false,
477
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
478
+						? add_query_arg(
479
+							['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
480
+							$this->_current_page_view_url
481
+						)
482
+						: $this->_admin_base_url,
483
+				],
484
+				'help_tabs'     => [
485
+					'edit_category_help_tab' => [
486
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
487
+						'filename' => 'events_edit_category',
488
+					],
489
+				],
490
+				/*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
491
+				'metaboxes'     => ['_publish_post_box'],
492
+				'require_nonce' => false,
493
+			],
494
+			'category_list'          => [
495
+				'nav'           => [
496
+					'label' => esc_html__('Categories', 'event_espresso'),
497
+					'order' => 20,
498
+				],
499
+				'list_table'    => 'Event_Categories_Admin_List_Table',
500
+				'help_tabs'     => [
501
+					'events_categories_help_tab'                       => [
502
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
503
+						'filename' => 'events_categories',
504
+					],
505
+					'events_categories_table_column_headings_help_tab' => [
506
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
507
+						'filename' => 'events_categories_table_column_headings',
508
+					],
509
+					'events_categories_view_help_tab'                  => [
510
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
511
+						'filename' => 'events_categories_views',
512
+					],
513
+					'events_categories_other_help_tab'                 => [
514
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
515
+						'filename' => 'events_categories_other',
516
+					],
517
+				],
518
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
519
+				// 'help_tour'     => [
520
+				//     'Event_Categories_Help_Tour',
521
+				// ],
522
+				'metaboxes'     => $this->_default_espresso_metaboxes,
523
+				'require_nonce' => false,
524
+			],
525
+			'preview_deletion'       => [
526
+				'nav'           => [
527
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
528
+					'order'      => 15,
529
+					'persistent' => false,
530
+					'url'        => '',
531
+				],
532
+				'require_nonce' => false,
533
+			],
534
+		];
535
+		// only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
536
+		$domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
537
+		if (! $domain->isCaffeinated()) {
538
+			$this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
539
+			$this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
540
+		}
541
+	}
542
+
543
+
544
+	/**
545
+	 * Used to register any global screen options if necessary for every route in this admin page group.
546
+	 */
547
+	protected function _add_screen_options()
548
+	{
549
+	}
550
+
551
+
552
+	/**
553
+	 * Implementing the screen options for the 'default' route.
554
+	 *
555
+	 * @throws InvalidArgumentException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws InvalidInterfaceException
558
+	 */
559
+	protected function _add_screen_options_default()
560
+	{
561
+		$this->_per_page_screen_option();
562
+	}
563
+
564
+
565
+	/**
566
+	 * Implementing screen options for the category list route.
567
+	 *
568
+	 * @throws InvalidArgumentException
569
+	 * @throws InvalidDataTypeException
570
+	 * @throws InvalidInterfaceException
571
+	 */
572
+	protected function _add_screen_options_category_list()
573
+	{
574
+		$page_title              = $this->_admin_page_title;
575
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
576
+		$this->_per_page_screen_option();
577
+		$this->_admin_page_title = $page_title;
578
+	}
579
+
580
+
581
+	/**
582
+	 * Used to register any global feature pointers for the admin page group.
583
+	 */
584
+	protected function _add_feature_pointers()
585
+	{
586
+	}
587
+
588
+
589
+	/**
590
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
591
+	 */
592
+	public function load_scripts_styles()
593
+	{
594
+		wp_register_style(
595
+			'events-admin-css',
596
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
597
+			[],
598
+			EVENT_ESPRESSO_VERSION
599
+		);
600
+		wp_register_style(
601
+			'ee-cat-admin',
602
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
603
+			[],
604
+			EVENT_ESPRESSO_VERSION
605
+		);
606
+		wp_enqueue_style('events-admin-css');
607
+		wp_enqueue_style('ee-cat-admin');
608
+		// scripts
609
+		wp_register_script(
610
+			'event_editor_js',
611
+			EVENTS_ASSETS_URL . 'event_editor.js',
612
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
613
+			EVENT_ESPRESSO_VERSION,
614
+			true
615
+		);
616
+	}
617
+
618
+
619
+	/**
620
+	 * Enqueuing scripts and styles specific to this view
621
+	 */
622
+	public function load_scripts_styles_create_new()
623
+	{
624
+		$this->load_scripts_styles_edit();
625
+	}
626
+
627
+
628
+	/**
629
+	 * Enqueuing scripts and styles specific to this view
630
+	 */
631
+	public function load_scripts_styles_edit()
632
+	{
633
+		// styles
634
+		wp_enqueue_style('espresso-ui-theme');
635
+		wp_register_style(
636
+			'event-editor-css',
637
+			EVENTS_ASSETS_URL . 'event-editor.css',
638
+			['ee-admin-css'],
639
+			EVENT_ESPRESSO_VERSION
640
+		);
641
+		wp_enqueue_style('event-editor-css');
642
+		// scripts
643
+		if (! $this->admin_config->useAdvancedEditor()) {
644
+			wp_register_script(
645
+				'event-datetime-metabox',
646
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
647
+				['event_editor_js', 'ee-datepicker'],
648
+				EVENT_ESPRESSO_VERSION
649
+			);
650
+			wp_enqueue_script('event-datetime-metabox');
651
+		}
652
+	}
653
+
654
+
655
+	/**
656
+	 * Populating the _views property for the category list table view.
657
+	 */
658
+	protected function _set_list_table_views_category_list()
659
+	{
660
+		$this->_views = [
661
+			'all' => [
662
+				'slug'        => 'all',
663
+				'label'       => esc_html__('All', 'event_espresso'),
664
+				'count'       => 0,
665
+				'bulk_action' => [
666
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
667
+				],
668
+			],
669
+		];
670
+	}
671
+
672
+
673
+	/**
674
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
675
+	 */
676
+	public function admin_init()
677
+	{
678
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
679
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
680
+			'event_espresso'
681
+		);
682
+	}
683
+
684
+
685
+	/**
686
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
687
+	 * group.
688
+	 */
689
+	public function admin_notices()
690
+	{
691
+	}
692
+
693
+
694
+	/**
695
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
696
+	 * this admin page group.
697
+	 */
698
+	public function admin_footer_scripts()
699
+	{
700
+	}
701
+
702
+
703
+	/**
704
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
705
+	 * warning (via EE_Error::add_error());
706
+	 *
707
+	 * @param EE_Event $event Event object
708
+	 * @param string   $req_type
709
+	 * @return void
710
+	 * @throws EE_Error
711
+	 * @access public
712
+	 */
713
+	public function verify_event_edit($event = null, $req_type = '')
714
+	{
715
+		// don't need to do this when processing
716
+		if (! empty($req_type)) {
717
+			return;
718
+		}
719
+		// no event?
720
+		if (! $event instanceof EE_Event) {
721
+			$event = $this->_cpt_model_obj;
722
+		}
723
+		// STILL no event?
724
+		if (! $event instanceof EE_Event) {
725
+			return;
726
+		}
727
+		$orig_status = $event->status();
728
+		// first check if event is active.
729
+		if (
730
+			$orig_status === EEM_Event::cancelled
731
+			|| $orig_status === EEM_Event::postponed
732
+			|| $event->is_expired()
733
+			|| $event->is_inactive()
734
+		) {
735
+			return;
736
+		}
737
+		// made it here so it IS active... next check that any of the tickets are sold.
738
+		if ($event->is_sold_out(true)) {
739
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
740
+				EE_Error::add_attention(
741
+					sprintf(
742
+						esc_html__(
743
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
744
+							'event_espresso'
745
+						),
746
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
747
+					)
748
+				);
749
+			}
750
+			return;
751
+		}
752
+		if ($orig_status === EEM_Event::sold_out) {
753
+			EE_Error::add_attention(
754
+				sprintf(
755
+					esc_html__(
756
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
757
+						'event_espresso'
758
+					),
759
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
760
+				)
761
+			);
762
+		}
763
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
764
+		if (! $event->tickets_on_sale()) {
765
+			return;
766
+		}
767
+		// made it here so show warning
768
+		$this->_edit_event_warning();
769
+	}
770
+
771
+
772
+	/**
773
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
774
+	 * When needed, hook this into a EE_Error::add_error() notice.
775
+	 *
776
+	 * @access protected
777
+	 * @return void
778
+	 */
779
+	protected function _edit_event_warning()
780
+	{
781
+		// we don't want to add warnings during these requests
782
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
783
+			return;
784
+		}
785
+		EE_Error::add_attention(
786
+			sprintf(
787
+				esc_html__(
788
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
789
+					'event_espresso'
790
+				),
791
+				'<a class="espresso-help-tab-lnk">',
792
+				'</a>'
793
+			)
794
+		);
795
+	}
796
+
797
+
798
+	/**
799
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
800
+	 * Otherwise, do the normal logic
801
+	 *
802
+	 * @return void
803
+	 * @throws EE_Error
804
+	 * @throws InvalidArgumentException
805
+	 * @throws InvalidDataTypeException
806
+	 * @throws InvalidInterfaceException
807
+	 */
808
+	protected function _create_new_cpt_item()
809
+	{
810
+		$has_timezone_string = get_option('timezone_string');
811
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
812
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
813
+			EE_Error::add_attention(
814
+				sprintf(
815
+					__(
816
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
817
+						'event_espresso'
818
+					),
819
+					'<br>',
820
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
821
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
822
+					. '</select>',
823
+					'<button class="button button-secondary timezone-submit">',
824
+					'</button><span class="spinner"></span>'
825
+				),
826
+				__FILE__,
827
+				__FUNCTION__,
828
+				__LINE__
829
+			);
830
+		}
831
+		parent::_create_new_cpt_item();
832
+	}
833
+
834
+
835
+	/**
836
+	 * Sets the _views property for the default route in this admin page group.
837
+	 */
838
+	protected function _set_list_table_views_default()
839
+	{
840
+		$this->_views = [
841
+			'all'   => [
842
+				'slug'        => 'all',
843
+				'label'       => esc_html__('View All Events', 'event_espresso'),
844
+				'count'       => 0,
845
+				'bulk_action' => [
846
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
847
+				],
848
+			],
849
+			'draft' => [
850
+				'slug'        => 'draft',
851
+				'label'       => esc_html__('Draft', 'event_espresso'),
852
+				'count'       => 0,
853
+				'bulk_action' => [
854
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
855
+				],
856
+			],
857
+		];
858
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
859
+			$this->_views['trash'] = [
860
+				'slug'        => 'trash',
861
+				'label'       => esc_html__('Trash', 'event_espresso'),
862
+				'count'       => 0,
863
+				'bulk_action' => [
864
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
865
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
866
+				],
867
+			];
868
+		}
869
+	}
870
+
871
+
872
+	/**
873
+	 * Provides the legend item array for the default list table view.
874
+	 *
875
+	 * @return array
876
+	 */
877
+	protected function _event_legend_items()
878
+	{
879
+		$items    = [
880
+			'view_details'   => [
881
+				'class' => 'dashicons dashicons-search',
882
+				'desc'  => esc_html__('View Event', 'event_espresso'),
883
+			],
884
+			'edit_event'     => [
885
+				'class' => 'ee-icon ee-icon-calendar-edit',
886
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
887
+			],
888
+			'view_attendees' => [
889
+				'class' => 'dashicons dashicons-groups',
890
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
891
+			],
892
+		];
893
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
894
+		$statuses = [
895
+			'sold_out_status'  => [
896
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
897
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
898
+			],
899
+			'active_status'    => [
900
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
901
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
902
+			],
903
+			'upcoming_status'  => [
904
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
905
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
906
+			],
907
+			'postponed_status' => [
908
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
909
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
910
+			],
911
+			'cancelled_status' => [
912
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
913
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
914
+			],
915
+			'expired_status'   => [
916
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
917
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
918
+			],
919
+			'inactive_status'  => [
920
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
921
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
922
+			],
923
+		];
924
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
925
+		return array_merge($items, $statuses);
926
+	}
927
+
928
+
929
+	/**
930
+	 * @return EEM_Event
931
+	 * @throws EE_Error
932
+	 * @throws InvalidArgumentException
933
+	 * @throws InvalidDataTypeException
934
+	 * @throws InvalidInterfaceException
935
+	 * @throws ReflectionException
936
+	 */
937
+	private function _event_model()
938
+	{
939
+		if (! $this->_event_model instanceof EEM_Event) {
940
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
941
+		}
942
+		return $this->_event_model;
943
+	}
944
+
945
+
946
+	/**
947
+	 * Adds extra buttons to the WP CPT permalink field row.
948
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
949
+	 *
950
+	 * @param string $return    the current html
951
+	 * @param int    $id        the post id for the page
952
+	 * @param string $new_title What the title is
953
+	 * @param string $new_slug  what the slug is
954
+	 * @return string            The new html string for the permalink area
955
+	 */
956
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
957
+	{
958
+		// make sure this is only when editing
959
+		if (! empty($id)) {
960
+			$post   = get_post($id);
961
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
962
+					   . esc_html__('Shortcode', 'event_espresso')
963
+					   . '</a> ';
964
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
965
+					   . $post->ID
966
+					   . ']">';
967
+		}
968
+		return $return;
969
+	}
970
+
971
+
972
+	/**
973
+	 * _events_overview_list_table
974
+	 * This contains the logic for showing the events_overview list
975
+	 *
976
+	 * @access protected
977
+	 * @return void
978
+	 * @throws DomainException
979
+	 * @throws EE_Error
980
+	 * @throws InvalidArgumentException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws InvalidInterfaceException
983
+	 */
984
+	protected function _events_overview_list_table()
985
+	{
986
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
987
+		$after_list_table                           = [];
988
+		$after_list_table['view_event_list_button'] = EEH_HTML::br();
989
+		$after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
990
+			get_post_type_archive_link('espresso_events'),
991
+			esc_html__('View Event Archive Page', 'event_espresso'),
992
+			'button'
993
+		);
994
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
995
+		$this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
996
+			'create_new',
997
+			'add',
998
+			[],
999
+			'add-new-h2'
1000
+		);
1001
+		$this->_template_args['after_list_table']   = array_merge(
1002
+			(array) $this->_template_args['after_list_table'],
1003
+			$after_list_table
1004
+		);
1005
+		$this->display_admin_list_table_page_with_no_sidebar();
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * this allows for extra misc actions in the default WP publish box
1011
+	 *
1012
+	 * @return void
1013
+	 * @throws DomainException
1014
+	 * @throws EE_Error
1015
+	 * @throws InvalidArgumentException
1016
+	 * @throws InvalidDataTypeException
1017
+	 * @throws InvalidInterfaceException
1018
+	 * @throws ReflectionException
1019
+	 */
1020
+	public function extra_misc_actions_publish_box()
1021
+	{
1022
+		$this->_generate_publish_box_extra_content();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1028
+	 * saved.
1029
+	 * Typically you would use this to save any additional data.
1030
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1031
+	 * ALSO very important.  When a post transitions from scheduled to published,
1032
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1033
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1034
+	 *
1035
+	 * @access protected
1036
+	 * @abstract
1037
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1038
+	 * @param object $post    The post object of the cpt that was saved.
1039
+	 * @return void
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	protected function _insert_update_cpt_item($post_id, $post)
1047
+	{
1048
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1049
+			// get out we're not processing an event save.
1050
+			return;
1051
+		}
1052
+		$event_values = [
1053
+			'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1054
+			'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1055
+			'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1056
+				? sanitize_text_field($this->_req_data['timezone_string'])
1057
+				: null,
1058
+		];
1059
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1060
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1061
+			$event_values['EVT_display_ticket_selector']     =
1062
+				! empty($this->_req_data['display_ticket_selector'])
1063
+					? 1
1064
+					: 0;
1065
+			$event_values['EVT_additional_limit']            = min(
1066
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1067
+				! empty($this->_req_data['additional_limit'])
1068
+					? absint($this->_req_data['additional_limit'])
1069
+					: null
1070
+			);
1071
+			$event_values['EVT_default_registration_status'] =
1072
+				! empty($this->_req_data['EVT_default_registration_status'])
1073
+					? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1074
+					: EE_Registry::instance()->CFG->registration->default_STS_ID;
1075
+			$event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1076
+				? esc_url_raw($this->_req_data['externalURL'])
1077
+				: null;
1078
+			$event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1079
+				? sanitize_text_field($this->_req_data['event_phone'])
1080
+				: null;
1081
+		}
1082
+		// update event
1083
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1084
+		// get event_object for other metaboxes...
1085
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1086
+		// i have to setup where conditions to override the filters in the model that filter out autodraft
1087
+		// and inherit statuses so we GET the inherit id!
1088
+		$get_one_where = [
1089
+			$this->_event_model()->primary_key_name() => $post_id,
1090
+			'OR'                                      => [
1091
+				'status'   => $post->post_status,
1092
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1093
+				// but the returned object here has a status of "publish", so use the original post status as well
1094
+				'status*1' => $this->_req_data['original_post_status'],
1095
+			],
1096
+		];
1097
+		$event         = $this->_event_model()->get_one([$get_one_where]);
1098
+		// the following are default callbacks for event attachment updates
1099
+		// that can be overridden by caffeinated functionality and/or addons.
1100
+		$event_update_callbacks = [];
1101
+		if (! $this->admin_config->useAdvancedEditor()) {
1102
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1103
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1104
+		}
1105
+		$event_update_callbacks = apply_filters(
1106
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1107
+			$event_update_callbacks
1108
+		);
1109
+		$att_success            = true;
1110
+		foreach ($event_update_callbacks as $e_callback) {
1111
+			$results = is_callable($e_callback)
1112
+				? $e_callback($event, $this->_req_data)
1113
+				: false;
1114
+			// if ANY of these updates fail then we want the appropriate global error message
1115
+			$att_success = $results !== false ? $att_success : false;
1116
+		}
1117
+		// any errors?
1118
+		if ($success && $att_success === false) {
1119
+			EE_Error::add_error(
1120
+				esc_html__(
1121
+					'Event Details saved successfully but something went wrong with saving attachments.',
1122
+					'event_espresso'
1123
+				),
1124
+				__FILE__,
1125
+				__FUNCTION__,
1126
+				__LINE__
1127
+			);
1128
+		} elseif ($success === false) {
1129
+			EE_Error::add_error(
1130
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1131
+				__FILE__,
1132
+				__FUNCTION__,
1133
+				__LINE__
1134
+			);
1135
+		}
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * @param int $post_id
1141
+	 * @param int $revision_id
1142
+	 * @throws EE_Error
1143
+	 * @throws InvalidArgumentException
1144
+	 * @throws InvalidDataTypeException
1145
+	 * @throws InvalidInterfaceException
1146
+	 * @throws ReflectionException
1147
+	 * @see parent::restore_item()
1148
+	 */
1149
+	protected function _restore_cpt_item($post_id, $revision_id)
1150
+	{
1151
+		// copy existing event meta to new post
1152
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1153
+		if ($post_evt instanceof EE_Event) {
1154
+			// meta revision restore
1155
+			$post_evt->restore_revision($revision_id);
1156
+			// related objs restore
1157
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1158
+		}
1159
+	}
1160
+
1161
+
1162
+	/**
1163
+	 * Attach the venue to the Event
1164
+	 *
1165
+	 * @param EE_Event $evtobj Event Object to add the venue to
1166
+	 * @param array    $data   The request data from the form
1167
+	 * @return bool           Success or fail.
1168
+	 * @throws EE_Error
1169
+	 * @throws InvalidArgumentException
1170
+	 * @throws InvalidDataTypeException
1171
+	 * @throws InvalidInterfaceException
1172
+	 * @throws ReflectionException
1173
+	 */
1174
+	protected function _default_venue_update(EE_Event $evtobj, $data)
1175
+	{
1176
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1177
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1178
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1179
+		// very important.  If we don't have a venue name...
1180
+		// then we'll get out because not necessary to create empty venue
1181
+		if (empty($data['venue_title'])) {
1182
+			return false;
1183
+		}
1184
+		$venue_array = [
1185
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1186
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1187
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1188
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1189
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1190
+				: null,
1191
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1192
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1193
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1194
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1195
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1196
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1197
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1198
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1199
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1200
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1201
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1202
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1203
+			'status'              => 'publish',
1204
+		];
1205
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1206
+		if (! empty($venue_id)) {
1207
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1208
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1209
+			// we've gotta make sure that the venue is always attached to a revision..
1210
+			// add_relation_to should take care of making sure that the relation is already present.
1211
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1212
+			return $rows_affected > 0;
1213
+		}
1214
+		// we insert the venue
1215
+		$venue_id = $venue_model->insert($venue_array);
1216
+		$evtobj->_add_relation_to($venue_id, 'Venue');
1217
+		return ! empty($venue_id);
1218
+		// when we have the ancestor come in it's already been handled by the revision save.
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1224
+	 *
1225
+	 * @param EE_Event $evtobj The Event object we're attaching data to
1226
+	 * @param array    $data   The request data from the form
1227
+	 * @return array
1228
+	 * @throws EE_Error
1229
+	 * @throws InvalidArgumentException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws InvalidInterfaceException
1232
+	 * @throws ReflectionException
1233
+	 * @throws Exception
1234
+	 */
1235
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1236
+	{
1237
+		if ($this->admin_config->useAdvancedEditor()) {
1238
+			return [];
1239
+		}
1240
+		$success               = true;
1241
+		$saved_dtt             = null;
1242
+		$saved_tickets         = [];
1243
+		$incoming_date_formats = ['Y-m-d', 'h:i a'];
1244
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1245
+			// trim all values to ensure any excess whitespace is removed.
1246
+			$dtt                = array_map('trim', $dtt);
1247
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1248
+				: $dtt['DTT_EVT_start'];
1249
+			$datetime_values    = [
1250
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1251
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1252
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1253
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1254
+				'DTT_order'     => $row,
1255
+			];
1256
+			// if we have an id then let's get existing object first and then set the new values.
1257
+			//  Otherwise we instantiate a new object for save.
1258
+			if (! empty($dtt['DTT_ID'])) {
1259
+				$DTM = EE_Registry::instance()
1260
+								  ->load_model('Datetime', [$evtobj->get_timezone()])
1261
+								  ->get_one_by_ID($dtt['DTT_ID']);
1262
+				$DTM->set_date_format($incoming_date_formats[0]);
1263
+				$DTM->set_time_format($incoming_date_formats[1]);
1264
+				foreach ($datetime_values as $field => $value) {
1265
+					$DTM->set($field, $value);
1266
+				}
1267
+				// make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1268
+				// We need to do this so we dont' TRASH the parent DTT.
1269
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1270
+			} else {
1271
+				$DTM = EE_Registry::instance()->load_class(
1272
+					'Datetime',
1273
+					[$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1274
+					false,
1275
+					false
1276
+				);
1277
+				foreach ($datetime_values as $field => $value) {
1278
+					$DTM->set($field, $value);
1279
+				}
1280
+			}
1281
+			$DTM->save();
1282
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1283
+			// load DTT helper
1284
+			// before going any further make sure our dates are setup correctly
1285
+			// so that the end date is always equal or greater than the start date.
1286
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1287
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1288
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1289
+				$DTT->save();
1290
+			}
1291
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array
1292
+			//  because it is possible there was a new one created for the autosave.
1293
+			$saved_dtt = $DTT;
1294
+			$success   = ! $success ? $success : $DTT;
1295
+			// if ANY of these updates fail then we want the appropriate global error message.
1296
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1297
+		}
1298
+		// no dtts get deleted so we don't do any of that logic here.
1299
+		// update tickets next
1300
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1301
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1302
+			$incoming_date_formats = ['Y-m-d', 'h:i a'];
1303
+			$update_prices         = false;
1304
+			$ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1305
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1306
+				: 0;
1307
+			// trim inputs to ensure any excess whitespace is removed.
1308
+			$tkt = array_map('trim', $tkt);
1309
+			if (empty($tkt['TKT_start_date'])) {
1310
+				// let's use now in the set timezone.
1311
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1312
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1313
+			}
1314
+			if (empty($tkt['TKT_end_date'])) {
1315
+				// use the start date of the first datetime
1316
+				$dtt                 = $evtobj->first_datetime();
1317
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1318
+					$incoming_date_formats[0],
1319
+					$incoming_date_formats[1]
1320
+				);
1321
+			}
1322
+			$TKT_values = [
1323
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1324
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1325
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1326
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1327
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1328
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1329
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1330
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1331
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1332
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1333
+				'TKT_row'         => $row,
1334
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1335
+				'TKT_price'       => $ticket_price,
1336
+			];
1337
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1338
+			// which means in turn that the prices will become new prices as well.
1339
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1340
+				$TKT_values['TKT_ID']         = 0;
1341
+				$TKT_values['TKT_is_default'] = 0;
1342
+				$TKT_values['TKT_price']      = $ticket_price;
1343
+				$update_prices                = true;
1344
+			}
1345
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1346
+			// we actually do our saves a head of doing any add_relations to because its entirely possible
1347
+			// that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1348
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
1349
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
+			if (! empty($tkt['TKT_ID'])) {
1351
+				$TKT = EE_Registry::instance()
1352
+								  ->load_model('Ticket', [$evtobj->get_timezone()])
1353
+								  ->get_one_by_ID($tkt['TKT_ID']);
1354
+				if ($TKT instanceof EE_Ticket) {
1355
+					$ticket_sold = $TKT->count_related(
1356
+						'Registration',
1357
+						[
1358
+							[
1359
+								'STS_ID' => [
1360
+									'NOT IN',
1361
+									[EEM_Registration::status_id_incomplete],
1362
+								],
1363
+							],
1364
+						]
1365
+					) > 0;
1366
+					// let's just check the total price for the existing ticket and determine if it matches the new
1367
+					// total price.  if they are different then we create a new ticket (if tickets sold)
1368
+					// if they aren't different then we go ahead and modify existing ticket.
1369
+					$create_new_TKT = $ticket_sold
1370
+									  && ! $TKT->deleted()
1371
+									  && EEH_Money::compare_floats(
1372
+										  $ticket_price,
1373
+										  $TKT->get('TKT_price'),
1374
+										  '!=='
1375
+									  );
1376
+					$TKT->set_date_format($incoming_date_formats[0]);
1377
+					$TKT->set_time_format($incoming_date_formats[1]);
1378
+					// set new values
1379
+					foreach ($TKT_values as $field => $value) {
1380
+						if ($field === 'TKT_qty') {
1381
+							$TKT->set_qty($value);
1382
+						} else {
1383
+							$TKT->set($field, $value);
1384
+						}
1385
+					}
1386
+					// if $create_new_TKT is false then we can safely update the existing ticket.
1387
+					//  Otherwise we have to create a new ticket.
1388
+					if ($create_new_TKT) {
1389
+						// archive the old ticket first
1390
+						$TKT->set('TKT_deleted', 1);
1391
+						$TKT->save();
1392
+						// make sure this ticket is still recorded in our saved_tkts
1393
+						// so we don't run it through the regular trash routine.
1394
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1395
+						// create new ticket that's a copy of the existing except a new id of course
1396
+						// (and not archived) AND has the new TKT_price associated with it.
1397
+						$TKT = clone $TKT;
1398
+						$TKT->set('TKT_ID', 0);
1399
+						$TKT->set('TKT_deleted', 0);
1400
+						$TKT->set('TKT_price', $ticket_price);
1401
+						$TKT->set('TKT_sold', 0);
1402
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1403
+						$update_prices = true;
1404
+					}
1405
+					// make sure price is set if it hasn't been already
1406
+					$TKT->set('TKT_price', $ticket_price);
1407
+				}
1408
+			} else {
1409
+				// no TKT_id so a new TKT
1410
+				$TKT_values['TKT_price'] = $ticket_price;
1411
+				$TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1412
+				if ($TKT instanceof EE_Ticket) {
1413
+					// need to reset values to properly account for the date formats
1414
+					$TKT->set_date_format($incoming_date_formats[0]);
1415
+					$TKT->set_time_format($incoming_date_formats[1]);
1416
+					$TKT->set_timezone($evtobj->get_timezone());
1417
+					// set new values
1418
+					foreach ($TKT_values as $field => $value) {
1419
+						if ($field === 'TKT_qty') {
1420
+							$TKT->set_qty($value);
1421
+						} else {
1422
+							$TKT->set($field, $value);
1423
+						}
1424
+					}
1425
+					$update_prices = true;
1426
+				}
1427
+			}
1428
+			// cap ticket qty by datetime reg limits
1429
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1430
+			// update ticket.
1431
+			$TKT->save();
1432
+			// before going any further make sure our dates are setup correctly
1433
+			// so that the end date is always equal or greater than the start date.
1434
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1435
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1436
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1437
+				$TKT->save();
1438
+			}
1439
+			// initially let's add the ticket to the dtt
1440
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1441
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1442
+			// add prices to ticket
1443
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1444
+		}
1445
+		// however now we need to handle permanently deleting tickets via the ui.
1446
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1447
+		//  However, it does allow for deleting tickets that have no tickets sold,
1448
+		// in which case we want to get rid of permanently because there is no need to save in db.
1449
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1450
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1451
+		foreach ($tickets_removed as $id) {
1452
+			$id = absint($id);
1453
+			// get the ticket for this id
1454
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1455
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1456
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
1457
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1458
+			foreach ($dtts as $dtt) {
1459
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1460
+			}
1461
+			// need to do the same for prices (except these prices can also be deleted because again,
1462
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1463
+			$tkt_to_remove->delete_related_permanently('Price');
1464
+			// finally let's delete this ticket
1465
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1466
+			$tkt_to_remove->delete_permanently();
1467
+		}
1468
+		return [$saved_dtt, $saved_tickets];
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * This attaches a list of given prices to a ticket.
1474
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1475
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1476
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1477
+	 *
1478
+	 * @access  private
1479
+	 * @param array     $prices     Array of prices from the form.
1480
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1481
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1482
+	 * @return  void
1483
+	 * @throws EE_Error
1484
+	 * @throws InvalidArgumentException
1485
+	 * @throws InvalidDataTypeException
1486
+	 * @throws InvalidInterfaceException
1487
+	 * @throws ReflectionException
1488
+	 */
1489
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1490
+	{
1491
+		foreach ($prices as $row => $prc) {
1492
+			$PRC_values = [
1493
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1494
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1495
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1496
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1497
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1498
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1499
+				'PRC_order'      => $row,
1500
+			];
1501
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1502
+				$PRC_values['PRC_ID'] = 0;
1503
+				$PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1504
+			} else {
1505
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1506
+				// update this price with new values
1507
+				foreach ($PRC_values as $field => $newprc) {
1508
+					$PRC->set($field, $newprc);
1509
+				}
1510
+				$PRC->save();
1511
+			}
1512
+			$ticket->_add_relation_to($PRC, 'Price');
1513
+		}
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * Add in our autosave ajax handlers
1519
+	 *
1520
+	 */
1521
+	protected function _ee_autosave_create_new()
1522
+	{
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * More autosave handlers.
1528
+	 */
1529
+	protected function _ee_autosave_edit()
1530
+	{
1531
+	}
1532
+
1533
+
1534
+	/**
1535
+	 *    _generate_publish_box_extra_content
1536
+	 *
1537
+	 * @throws DomainException
1538
+	 * @throws EE_Error
1539
+	 * @throws InvalidArgumentException
1540
+	 * @throws InvalidDataTypeException
1541
+	 * @throws InvalidInterfaceException
1542
+	 * @throws ReflectionException
1543
+	 */
1544
+	private function _generate_publish_box_extra_content()
1545
+	{
1546
+		// load formatter helper
1547
+		// args for getting related registrations
1548
+		$approved_query_args        = [
1549
+			[
1550
+				'REG_deleted' => 0,
1551
+				'STS_ID'      => EEM_Registration::status_id_approved,
1552
+			],
1553
+		];
1554
+		$not_approved_query_args    = [
1555
+			[
1556
+				'REG_deleted' => 0,
1557
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1558
+			],
1559
+		];
1560
+		$pending_payment_query_args = [
1561
+			[
1562
+				'REG_deleted' => 0,
1563
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1564
+			],
1565
+		];
1566
+		// publish box
1567
+		$publish_box_extra_args = [
1568
+			'view_approved_reg_url'        => add_query_arg(
1569
+				[
1570
+					'action'      => 'default',
1571
+					'event_id'    => $this->_cpt_model_obj->ID(),
1572
+					'_reg_status' => EEM_Registration::status_id_approved,
1573
+				],
1574
+				REG_ADMIN_URL
1575
+			),
1576
+			'view_not_approved_reg_url'    => add_query_arg(
1577
+				[
1578
+					'action'      => 'default',
1579
+					'event_id'    => $this->_cpt_model_obj->ID(),
1580
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1581
+				],
1582
+				REG_ADMIN_URL
1583
+			),
1584
+			'view_pending_payment_reg_url' => add_query_arg(
1585
+				[
1586
+					'action'      => 'default',
1587
+					'event_id'    => $this->_cpt_model_obj->ID(),
1588
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1589
+				],
1590
+				REG_ADMIN_URL
1591
+			),
1592
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1593
+				'Registration',
1594
+				$approved_query_args
1595
+			),
1596
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1597
+				'Registration',
1598
+				$not_approved_query_args
1599
+			),
1600
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1601
+				'Registration',
1602
+				$pending_payment_query_args
1603
+			),
1604
+			'misc_pub_section_class'       => apply_filters(
1605
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1606
+				'misc-pub-section'
1607
+			),
1608
+		];
1609
+		ob_start();
1610
+		do_action(
1611
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1612
+			$this->_cpt_model_obj
1613
+		);
1614
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1615
+		// load template
1616
+		EEH_Template::display_template(
1617
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1618
+			$publish_box_extra_args
1619
+		);
1620
+	}
1621
+
1622
+
1623
+	/**
1624
+	 * @return EE_Event
1625
+	 */
1626
+	public function get_event_object()
1627
+	{
1628
+		return $this->_cpt_model_obj;
1629
+	}
1630
+
1631
+
1632
+
1633
+
1634
+	/** METABOXES * */
1635
+	/**
1636
+	 * _register_event_editor_meta_boxes
1637
+	 * add all metaboxes related to the event_editor
1638
+	 *
1639
+	 * @return void
1640
+	 * @throws EE_Error
1641
+	 * @throws InvalidArgumentException
1642
+	 * @throws InvalidDataTypeException
1643
+	 * @throws InvalidInterfaceException
1644
+	 * @throws ReflectionException
1645
+	 */
1646
+	protected function _register_event_editor_meta_boxes()
1647
+	{
1648
+		$this->verify_cpt_object();
1649
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1650
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1651
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1652
+			add_meta_box(
1653
+				'espresso_event_editor_event_options',
1654
+				esc_html__('Event Registration Options', 'event_espresso'),
1655
+				[$this, 'registration_options_meta_box'],
1656
+				$this->page_slug,
1657
+				'side'
1658
+			);
1659
+		}
1660
+		if (! $use_advanced_editor) {
1661
+			add_meta_box(
1662
+				'espresso_event_editor_tickets',
1663
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1664
+				[$this, 'ticket_metabox'],
1665
+				$this->page_slug,
1666
+				'normal',
1667
+				'high'
1668
+			);
1669
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1670
+			add_action(
1671
+				'add_meta_boxes_espresso_events',
1672
+				function () {
1673
+					global $current_screen;
1674
+					remove_meta_box('authordiv', $current_screen, 'normal');
1675
+				},
1676
+				99
1677
+			);
1678
+		}
1679
+		// NOTE: if you're looking for other metaboxes in here,
1680
+		// where a metabox has a related management page in the admin
1681
+		// you will find it setup in the related management page's "_Hooks" file.
1682
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1683
+	}
1684
+
1685
+
1686
+	/**
1687
+	 * @throws DomainException
1688
+	 * @throws EE_Error
1689
+	 * @throws InvalidArgumentException
1690
+	 * @throws InvalidDataTypeException
1691
+	 * @throws InvalidInterfaceException
1692
+	 * @throws ReflectionException
1693
+	 */
1694
+	public function ticket_metabox()
1695
+	{
1696
+		$existing_datetime_ids = $existing_ticket_ids = [];
1697
+		// defaults for template args
1698
+		$template_args = [
1699
+			'existing_datetime_ids'    => '',
1700
+			'event_datetime_help_link' => '',
1701
+			'ticket_options_help_link' => '',
1702
+			'time'                     => null,
1703
+			'ticket_rows'              => '',
1704
+			'existing_ticket_ids'      => '',
1705
+			'total_ticket_rows'        => 1,
1706
+			'ticket_js_structure'      => '',
1707
+			'trash_icon'               => 'ee-lock-icon',
1708
+			'disabled'                 => '',
1709
+		];
1710
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1711
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1712
+		/**
1713
+		 * 1. Start with retrieving Datetimes
1714
+		 * 2. Fore each datetime get related tickets
1715
+		 * 3. For each ticket get related prices
1716
+		 */
1717
+		/** @var EEM_Datetime $datetime_model */
1718
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1719
+		/** @var EEM_Ticket $datetime_model */
1720
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1721
+		$times        = $datetime_model->get_all_event_dates($event_id);
1722
+		/** @type EE_Datetime $first_datetime */
1723
+		$first_datetime = reset($times);
1724
+		// do we get related tickets?
1725
+		if (
1726
+			$first_datetime instanceof EE_Datetime
1727
+			&& $first_datetime->ID() !== 0
1728
+		) {
1729
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1730
+			$template_args['time']   = $first_datetime;
1731
+			$related_tickets         = $first_datetime->tickets(
1732
+				[
1733
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1734
+					'default_where_conditions' => 'none',
1735
+				]
1736
+			);
1737
+			if (! empty($related_tickets)) {
1738
+				$template_args['total_ticket_rows'] = count($related_tickets);
1739
+				$row                                = 0;
1740
+				foreach ($related_tickets as $ticket) {
1741
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1742
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743
+					$row++;
1744
+				}
1745
+			} else {
1746
+				$template_args['total_ticket_rows'] = 1;
1747
+				/** @type EE_Ticket $ticket */
1748
+				$ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1749
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750
+			}
1751
+		} else {
1752
+			$template_args['time'] = $times[0];
1753
+			/** @type EE_Ticket[] $tickets */
1754
+			$tickets                      = $ticket_model->get_all_default_tickets();
1755
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756
+			// NOTE: we're just sending the first default row
1757
+			// (decaf can't manage default tickets so this should be sufficient);
1758
+		}
1759
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1760
+			'event_editor_event_datetimes_help_tab'
1761
+		);
1762
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1763
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1764
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1765
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1766
+			$ticket_model->create_default_object(),
1767
+			true
1768
+		);
1769
+		$template                                  = apply_filters(
1770
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1772
+		);
1773
+		EEH_Template::display_template($template, $template_args);
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 * Setup an individual ticket form for the decaf event editor page
1779
+	 *
1780
+	 * @access private
1781
+	 * @param EE_Ticket $ticket   the ticket object
1782
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1783
+	 * @param int       $row
1784
+	 * @return string generated html for the ticket row.
1785
+	 * @throws DomainException
1786
+	 * @throws EE_Error
1787
+	 * @throws InvalidArgumentException
1788
+	 * @throws InvalidDataTypeException
1789
+	 * @throws InvalidInterfaceException
1790
+	 * @throws ReflectionException
1791
+	 */
1792
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1793
+	{
1794
+		$template_args = [
1795
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1796
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1797
+				: '',
1798
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1799
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1800
+			'TKT_name'            => $ticket->get('TKT_name'),
1801
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1802
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1803
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1804
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1805
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1806
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1807
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1808
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1809
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1810
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1811
+				: ' disabled=disabled',
1812
+		];
1813
+		$price         = $ticket->ID() !== 0
1814
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1815
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1816
+		$price_args    = [
1817
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1818
+			'PRC_amount'            => $price->get('PRC_amount'),
1819
+			'PRT_ID'                => $price->get('PRT_ID'),
1820
+			'PRC_ID'                => $price->get('PRC_ID'),
1821
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1822
+		];
1823
+		// make sure we have default start and end dates if skeleton
1824
+		// handle rows that should NOT be empty
1825
+		if (empty($template_args['TKT_start_date'])) {
1826
+			// if empty then the start date will be now.
1827
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1828
+		}
1829
+		if (empty($template_args['TKT_end_date'])) {
1830
+			// get the earliest datetime (if present);
1831
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1832
+				? $this->_cpt_model_obj->get_first_related(
1833
+					'Datetime',
1834
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1835
+				)
1836
+				: null;
1837
+			if (! empty($earliest_dtt)) {
1838
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1839
+			} else {
1840
+				$template_args['TKT_end_date'] = date(
1841
+					'Y-m-d h:i a',
1842
+					mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1843
+				);
1844
+			}
1845
+		}
1846
+		$template_args = array_merge($template_args, $price_args);
1847
+		$template      = apply_filters(
1848
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1849
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1850
+			$ticket
1851
+		);
1852
+		return EEH_Template::display_template($template, $template_args, true);
1853
+	}
1854
+
1855
+
1856
+	/**
1857
+	 * @throws DomainException
1858
+	 * @throws EE_Error
1859
+	 */
1860
+	public function registration_options_meta_box()
1861
+	{
1862
+		$yes_no_values             = [
1863
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1864
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1865
+		];
1866
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1867
+			[
1868
+				EEM_Registration::status_id_cancelled,
1869
+				EEM_Registration::status_id_declined,
1870
+				EEM_Registration::status_id_incomplete,
1871
+			],
1872
+			true
1873
+		);
1874
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1875
+		$template_args['_event']                          = $this->_cpt_model_obj;
1876
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1877
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1878
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1879
+			'default_reg_status',
1880
+			$default_reg_status_values,
1881
+			$this->_cpt_model_obj->default_registration_status()
1882
+		);
1883
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1884
+			'display_desc',
1885
+			$yes_no_values,
1886
+			$this->_cpt_model_obj->display_description()
1887
+		);
1888
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1889
+			'display_ticket_selector',
1890
+			$yes_no_values,
1891
+			$this->_cpt_model_obj->display_ticket_selector(),
1892
+			'',
1893
+			'',
1894
+			false
1895
+		);
1896
+		$template_args['additional_registration_options'] = apply_filters(
1897
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1898
+			'',
1899
+			$template_args,
1900
+			$yes_no_values,
1901
+			$default_reg_status_values
1902
+		);
1903
+		EEH_Template::display_template(
1904
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1905
+			$template_args
1906
+		);
1907
+	}
1908
+
1909
+
1910
+	/**
1911
+	 * _get_events()
1912
+	 * This method simply returns all the events (for the given _view and paging)
1913
+	 *
1914
+	 * @access public
1915
+	 * @param int  $per_page     count of items per page (20 default);
1916
+	 * @param int  $current_page what is the current page being viewed.
1917
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1918
+	 *                           If FALSE then we return an array of event objects
1919
+	 *                           that match the given _view and paging parameters.
1920
+	 * @return array|int an array of event objects.
1921
+	 * @throws EE_Error
1922
+	 * @throws InvalidArgumentException
1923
+	 * @throws InvalidDataTypeException
1924
+	 * @throws InvalidInterfaceException
1925
+	 * @throws ReflectionException
1926
+	 * @throws Exception
1927
+	 * @throws Exception
1928
+	 * @throws Exception
1929
+	 */
1930
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1931
+	{
1932
+		$EEME    = $this->_event_model();
1933
+		$offset  = ($current_page - 1) * $per_page;
1934
+		$limit   = $count ? null : $offset . ',' . $per_page;
1935
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1936
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1937
+		$month_r = '';
1938
+		$year_r  = '';
1939
+		if (isset($this->_req_data['month_range'])) {
1940
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1941
+			// simulate the FIRST day of the month, that fixes issues for months like February
1942
+			// where PHP doesn't know what to assume for date.
1943
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1944
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1945
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1946
+		}
1947
+		$where  = [];
1948
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1949
+		// determine what post_status our condition will have for the query.
1950
+		switch ($status) {
1951
+			case 'month':
1952
+			case 'today':
1953
+			case null:
1954
+			case 'all':
1955
+				break;
1956
+			case 'draft':
1957
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1958
+				break;
1959
+			default:
1960
+				$where['status'] = $status;
1961
+		}
1962
+		// categories?
1963
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1964
+			? $this->_req_data['EVT_CAT'] : null;
1965
+		if (! empty($category)) {
1966
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1967
+			$where['Term_Taxonomy.term_id']  = $category;
1968
+		}
1969
+		// date where conditions
1970
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1971
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1972
+			$DateTime = new DateTime(
1973
+				$year_r . '-' . $month_r . '-01 00:00:00',
1974
+				new DateTimeZone('UTC')
1975
+			);
1976
+			$start    = $DateTime->getTimestamp();
1977
+			// set the datetime to be the end of the month
1978
+			$DateTime->setDate(
1979
+				$year_r,
1980
+				$month_r,
1981
+				$DateTime->format('t')
1982
+			)->setTime(23, 59, 59);
1983
+			$end                             = $DateTime->getTimestamp();
1984
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1985
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1986
+			$DateTime                        =
1987
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1988
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1989
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1990
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1991
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1992
+			$now                             = date('Y-m-01');
1993
+			$DateTime                        =
1994
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1995
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1996
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1997
+														->setTime(23, 59, 59)
1998
+														->format(implode(' ', $start_formats));
1999
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2000
+		}
2001
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2002
+			$where['EVT_wp_user'] = get_current_user_id();
2003
+		} elseif (
2004
+			! isset($where['status'])
2005
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2006
+		) {
2007
+			$where['OR'] = [
2008
+				'status*restrict_private' => ['!=', 'private'],
2009
+				'AND'                     => [
2010
+					'status*inclusive' => ['=', 'private'],
2011
+					'EVT_wp_user'      => get_current_user_id(),
2012
+				],
2013
+			];
2014
+		}
2015
+
2016
+		if (
2017
+			isset($this->_req_data['EVT_wp_user'])
2018
+			&& (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2019
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2020
+		) {
2021
+			$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2022
+		}
2023
+		// search query handling
2024
+		if (isset($this->_req_data['s'])) {
2025
+			$search_string = '%' . $this->_req_data['s'] . '%';
2026
+			$where['OR']   = [
2027
+				'EVT_name'       => ['LIKE', $search_string],
2028
+				'EVT_desc'       => ['LIKE', $search_string],
2029
+				'EVT_short_desc' => ['LIKE', $search_string],
2030
+			];
2031
+		}
2032
+		// filter events by venue.
2033
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2034
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2035
+		}
2036
+		$where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2037
+		$query_params = apply_filters(
2038
+			'FHEE__Events_Admin_Page__get_events__query_params',
2039
+			[
2040
+				$where,
2041
+				'limit'    => $limit,
2042
+				'order_by' => $orderby,
2043
+				'order'    => $order,
2044
+				'group_by' => 'EVT_ID',
2045
+			],
2046
+			$this->_req_data
2047
+		);
2048
+
2049
+		// let's first check if we have special requests coming in.
2050
+		if (isset($this->_req_data['active_status'])) {
2051
+			switch ($this->_req_data['active_status']) {
2052
+				case 'upcoming':
2053
+					return $EEME->get_upcoming_events($query_params, $count);
2054
+				case 'expired':
2055
+					return $EEME->get_expired_events($query_params, $count);
2056
+				case 'active':
2057
+					return $EEME->get_active_events($query_params, $count);
2058
+				case 'inactive':
2059
+					return $EEME->get_inactive_events($query_params, $count);
2060
+			}
2061
+		}
2062
+
2063
+		return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2064
+	}
2065
+
2066
+
2067
+	/**
2068
+	 * handling for WordPress CPT actions (trash, restore, delete)
2069
+	 *
2070
+	 * @param string $post_id
2071
+	 * @throws EE_Error
2072
+	 * @throws InvalidArgumentException
2073
+	 * @throws InvalidDataTypeException
2074
+	 * @throws InvalidInterfaceException
2075
+	 * @throws ReflectionException
2076
+	 */
2077
+	public function trash_cpt_item($post_id)
2078
+	{
2079
+		$this->_req_data['EVT_ID'] = $post_id;
2080
+		$this->_trash_or_restore_event('trash', false);
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * @param string $post_id
2086
+	 * @throws EE_Error
2087
+	 * @throws InvalidArgumentException
2088
+	 * @throws InvalidDataTypeException
2089
+	 * @throws InvalidInterfaceException
2090
+	 * @throws ReflectionException
2091
+	 */
2092
+	public function restore_cpt_item($post_id)
2093
+	{
2094
+		$this->_req_data['EVT_ID'] = $post_id;
2095
+		$this->_trash_or_restore_event('draft', false);
2096
+	}
2097
+
2098
+
2099
+	/**
2100
+	 * @param string $post_id
2101
+	 * @throws EE_Error
2102
+	 * @throws InvalidArgumentException
2103
+	 * @throws InvalidDataTypeException
2104
+	 * @throws InvalidInterfaceException
2105
+	 * @throws ReflectionException
2106
+	 */
2107
+	public function delete_cpt_item($post_id)
2108
+	{
2109
+		throw new EE_Error(
2110
+			esc_html__(
2111
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2112
+				'event_espresso'
2113
+			)
2114
+		);
2115
+		$this->_req_data['EVT_ID'] = $post_id;
2116
+		$this->_delete_event();
2117
+	}
2118
+
2119
+
2120
+	/**
2121
+	 * _trash_or_restore_event
2122
+	 *
2123
+	 * @access protected
2124
+	 * @param string $event_status
2125
+	 * @param bool   $redirect_after
2126
+	 * @throws EE_Error
2127
+	 * @throws InvalidArgumentException
2128
+	 * @throws InvalidDataTypeException
2129
+	 * @throws InvalidInterfaceException
2130
+	 * @throws ReflectionException
2131
+	 */
2132
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2133
+	{
2134
+		// determine the event id and set to array.
2135
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2136
+		// loop thru events
2137
+		if ($EVT_ID) {
2138
+			// clean status
2139
+			$event_status = sanitize_key($event_status);
2140
+			// grab status
2141
+			if (! empty($event_status)) {
2142
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2143
+			} else {
2144
+				$success = false;
2145
+				$msg     = esc_html__(
2146
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2147
+					'event_espresso'
2148
+				);
2149
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2150
+			}
2151
+		} else {
2152
+			$success = false;
2153
+			$msg     = esc_html__(
2154
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2155
+				'event_espresso'
2156
+			);
2157
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2158
+		}
2159
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2160
+		if ($redirect_after) {
2161
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2162
+		}
2163
+	}
2164
+
2165
+
2166
+	/**
2167
+	 * _trash_or_restore_events
2168
+	 *
2169
+	 * @access protected
2170
+	 * @param string $event_status
2171
+	 * @return void
2172
+	 * @throws EE_Error
2173
+	 * @throws InvalidArgumentException
2174
+	 * @throws InvalidDataTypeException
2175
+	 * @throws InvalidInterfaceException
2176
+	 * @throws ReflectionException
2177
+	 */
2178
+	protected function _trash_or_restore_events($event_status = 'trash')
2179
+	{
2180
+		// clean status
2181
+		$event_status = sanitize_key($event_status);
2182
+		// grab status
2183
+		if (! empty($event_status)) {
2184
+			$success = true;
2185
+			// determine the event id and set to array.
2186
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2187
+			// loop thru events
2188
+			foreach ($EVT_IDs as $EVT_ID) {
2189
+				if ($EVT_ID = absint($EVT_ID)) {
2190
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2191
+					$success = $results !== false ? $success : false;
2192
+				} else {
2193
+					$msg = sprintf(
2194
+						esc_html__(
2195
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2196
+							'event_espresso'
2197
+						),
2198
+						$EVT_ID
2199
+					);
2200
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2201
+					$success = false;
2202
+				}
2203
+			}
2204
+		} else {
2205
+			$success = false;
2206
+			$msg     = esc_html__(
2207
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2208
+				'event_espresso'
2209
+			);
2210
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2211
+		}
2212
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2213
+		$success = $success ? 2 : false;
2214
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2215
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2216
+	}
2217
+
2218
+
2219
+	/**
2220
+	 * _trash_or_restore_events
2221
+	 *
2222
+	 * @access  private
2223
+	 * @param int    $EVT_ID
2224
+	 * @param string $event_status
2225
+	 * @return bool
2226
+	 * @throws EE_Error
2227
+	 * @throws InvalidArgumentException
2228
+	 * @throws InvalidDataTypeException
2229
+	 * @throws InvalidInterfaceException
2230
+	 * @throws ReflectionException
2231
+	 */
2232
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2233
+	{
2234
+		// grab event id
2235
+		if (! $EVT_ID) {
2236
+			$msg = esc_html__(
2237
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2238
+				'event_espresso'
2239
+			);
2240
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2241
+			return false;
2242
+		}
2243
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2244
+		// clean status
2245
+		$event_status = sanitize_key($event_status);
2246
+		// grab status
2247
+		if (empty($event_status)) {
2248
+			$msg = esc_html__(
2249
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2250
+				'event_espresso'
2251
+			);
2252
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2253
+			return false;
2254
+		}
2255
+		// was event trashed or restored ?
2256
+		switch ($event_status) {
2257
+			case 'draft':
2258
+				$action = 'restored from the trash';
2259
+				$hook   = 'AHEE_event_restored_from_trash';
2260
+				break;
2261
+			case 'trash':
2262
+				$action = 'moved to the trash';
2263
+				$hook   = 'AHEE_event_moved_to_trash';
2264
+				break;
2265
+			default:
2266
+				$action = 'updated';
2267
+				$hook   = false;
2268
+		}
2269
+		// use class to change status
2270
+		$this->_cpt_model_obj->set_status($event_status);
2271
+		$success = $this->_cpt_model_obj->save();
2272
+		if ($success === false) {
2273
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2274
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2275
+			return false;
2276
+		}
2277
+		if ($hook) {
2278
+			do_action($hook);
2279
+		}
2280
+		return true;
2281
+	}
2282
+
2283
+
2284
+	/**
2285
+	 * @throws InvalidArgumentException
2286
+	 * @throws InvalidDataTypeException
2287
+	 * @throws InvalidInterfaceException
2288
+	 */
2289
+	protected function _delete_event()
2290
+	{
2291
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2292
+	}
2293
+
2294
+
2295
+	/**
2296
+	 * Gets the tree traversal batch persister.
2297
+	 *
2298
+	 * @return NodeGroupDao
2299
+	 * @throws InvalidArgumentException
2300
+	 * @throws InvalidDataTypeException
2301
+	 * @throws InvalidInterfaceException
2302
+	 * @since 4.10.12.p
2303
+	 */
2304
+	protected function getModelObjNodeGroupPersister()
2305
+	{
2306
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2307
+			$this->model_obj_node_group_persister =
2308
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2309
+		}
2310
+		return $this->model_obj_node_group_persister;
2311
+	}
2312
+
2313
+
2314
+	/**
2315
+	 * @return void
2316
+	 * @throws InvalidArgumentException
2317
+	 * @throws InvalidDataTypeException
2318
+	 * @throws InvalidInterfaceException
2319
+	 */
2320
+	protected function _delete_events()
2321
+	{
2322
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2323
+	}
2324
+
2325
+
2326
+	protected function generateDeletionPreview($event_ids)
2327
+	{
2328
+		$event_ids = (array) $event_ids;
2329
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2330
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2331
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2332
+			[
2333
+				'action'            => 'preview_deletion',
2334
+				'deletion_job_code' => $deletion_job_code,
2335
+			],
2336
+			$this->_admin_base_url
2337
+		);
2338
+		$event_ids         = array_map(
2339
+			'intval',
2340
+			$event_ids
2341
+		);
2342
+
2343
+		EEH_URL::safeRedirectAndExit(
2344
+			EE_Admin_Page::add_query_args_and_nonce(
2345
+				[
2346
+					'page'              => 'espresso_batch',
2347
+					'batch'             => EED_Batch::batch_job,
2348
+					'EVT_IDs'           => $event_ids,
2349
+					'deletion_job_code' => $deletion_job_code,
2350
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2351
+					'return_url'        => urlencode($return_url),
2352
+				],
2353
+				admin_url()
2354
+			)
2355
+		);
2356
+	}
2357
+
2358
+
2359
+	/**
2360
+	 * Checks for a POST submission
2361
+	 *
2362
+	 * @since 4.10.12.p
2363
+	 */
2364
+	protected function confirmDeletion()
2365
+	{
2366
+		$deletion_redirect_logic =
2367
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2368
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2369
+	}
2370
+
2371
+
2372
+	/**
2373
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2374
+	 *
2375
+	 * @throws EE_Error
2376
+	 * @since 4.10.12.p
2377
+	 */
2378
+	protected function previewDeletion()
2379
+	{
2380
+		$preview_deletion_logic =
2381
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2382
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2383
+		$this->display_admin_page_with_no_sidebar();
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * get total number of events
2389
+	 *
2390
+	 * @access public
2391
+	 * @return int
2392
+	 * @throws EE_Error
2393
+	 * @throws InvalidArgumentException
2394
+	 * @throws InvalidDataTypeException
2395
+	 * @throws InvalidInterfaceException
2396
+	 */
2397
+	public function total_events()
2398
+	{
2399
+		return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2400
+	}
2401
+
2402
+
2403
+	/**
2404
+	 * get total number of draft events
2405
+	 *
2406
+	 * @access public
2407
+	 * @return int
2408
+	 * @throws EE_Error
2409
+	 * @throws InvalidArgumentException
2410
+	 * @throws InvalidDataTypeException
2411
+	 * @throws InvalidInterfaceException
2412
+	 */
2413
+	public function total_events_draft()
2414
+	{
2415
+		$where = [
2416
+			'status' => ['IN', ['draft', 'auto-draft']],
2417
+		];
2418
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 * get total number of trashed events
2424
+	 *
2425
+	 * @access public
2426
+	 * @return int
2427
+	 * @throws EE_Error
2428
+	 * @throws InvalidArgumentException
2429
+	 * @throws InvalidDataTypeException
2430
+	 * @throws InvalidInterfaceException
2431
+	 */
2432
+	public function total_trashed_events()
2433
+	{
2434
+		$where = [
2435
+			'status' => 'trash',
2436
+		];
2437
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2438
+	}
2439
+
2440
+
2441
+	/**
2442
+	 *    _default_event_settings
2443
+	 *    This generates the Default Settings Tab
2444
+	 *
2445
+	 * @return void
2446
+	 * @throws DomainException
2447
+	 * @throws EE_Error
2448
+	 * @throws InvalidArgumentException
2449
+	 * @throws InvalidDataTypeException
2450
+	 * @throws InvalidInterfaceException
2451
+	 */
2452
+	protected function _default_event_settings()
2453
+	{
2454
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2455
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2456
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2457
+		$this->display_admin_page_with_sidebar();
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 * Return the form for event settings.
2463
+	 *
2464
+	 * @return EE_Form_Section_Proper
2465
+	 * @throws EE_Error
2466
+	 */
2467
+	protected function _default_event_settings_form()
2468
+	{
2469
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2470
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
+		// exclude
2472
+			[
2473
+				EEM_Registration::status_id_cancelled,
2474
+				EEM_Registration::status_id_declined,
2475
+				EEM_Registration::status_id_incomplete,
2476
+				EEM_Registration::status_id_wait_list,
2477
+			],
2478
+			true
2479
+		);
2480
+		return new EE_Form_Section_Proper(
2481
+			[
2482
+				'name'            => 'update_default_event_settings',
2483
+				'html_id'         => 'update_default_event_settings',
2484
+				'html_class'      => 'form-table',
2485
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2486
+				'subsections'     => apply_filters(
2487
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2488
+					[
2489
+						'default_reg_status'  => new EE_Select_Input(
2490
+							$registration_stati_for_selection,
2491
+							[
2492
+								'default'         => isset($registration_config->default_STS_ID)
2493
+													 && array_key_exists(
2494
+														 $registration_config->default_STS_ID,
2495
+														 $registration_stati_for_selection
2496
+													 )
2497
+									? sanitize_text_field($registration_config->default_STS_ID)
2498
+									: EEM_Registration::status_id_pending_payment,
2499
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2500
+													 . EEH_Template::get_help_tab_link(
2501
+														 'default_settings_status_help_tab'
2502
+													 ),
2503
+								'html_help_text'  => esc_html__(
2504
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2505
+									'event_espresso'
2506
+								),
2507
+							]
2508
+						),
2509
+						'default_max_tickets' => new EE_Integer_Input(
2510
+							[
2511
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2512
+									? $registration_config->default_maximum_number_of_tickets
2513
+									: EEM_Event::get_default_additional_limit(),
2514
+								'html_label_text' => esc_html__(
2515
+									'Default Maximum Tickets Allowed Per Order:',
2516
+									'event_espresso'
2517
+								)
2518
+								. EEH_Template::get_help_tab_link(
2519
+									'default_maximum_tickets_help_tab"'
2520
+								),
2521
+								'html_help_text'  => esc_html__(
2522
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2523
+									'event_espresso'
2524
+								),
2525
+							]
2526
+						),
2527
+					]
2528
+				),
2529
+			]
2530
+		);
2531
+	}
2532
+
2533
+
2534
+	/**
2535
+	 * @return void
2536
+	 * @throws EE_Error
2537
+	 * @throws InvalidArgumentException
2538
+	 * @throws InvalidDataTypeException
2539
+	 * @throws InvalidInterfaceException
2540
+	 */
2541
+	protected function _update_default_event_settings()
2542
+	{
2543
+		$form = $this->_default_event_settings_form();
2544
+		if ($form->was_submitted()) {
2545
+			$form->receive_form_submission();
2546
+			if ($form->is_valid()) {
2547
+				$registration_config = EE_Registry::instance()->CFG->registration;
2548
+				$valid_data          = $form->valid_data();
2549
+				if (isset($valid_data['default_reg_status'])) {
2550
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2551
+				}
2552
+				if (isset($valid_data['default_max_tickets'])) {
2553
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2554
+				}
2555
+				do_action(
2556
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2557
+					$valid_data,
2558
+					EE_Registry::instance()->CFG,
2559
+					$this
2560
+				);
2561
+				// update because data was valid!
2562
+				EE_Registry::instance()->CFG->update_espresso_config();
2563
+				EE_Error::overwrite_success();
2564
+				EE_Error::add_success(
2565
+					__('Default Event Settings were updated', 'event_espresso')
2566
+				);
2567
+			}
2568
+		}
2569
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2570
+	}
2571
+
2572
+
2573
+	/*************        Templates        *************
2882 2574
      *
2883 2575
      * @throws EE_Error
2884
-     * @throws InvalidArgumentException
2885
-     * @throws InvalidDataTypeException
2886
-     * @throws InvalidInterfaceException
2887 2576
      */
2888
-    public function save_timezonestring_setting()
2889
-    {
2890
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2891
-            ? $this->_req_data['timezone_selected']
2892
-            : '';
2893
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2894
-            EE_Error::add_error(
2895
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2896
-                __FILE__,
2897
-                __FUNCTION__,
2898
-                __LINE__
2899
-            );
2900
-            $this->_template_args['error'] = true;
2901
-            $this->_return_json();
2902
-        }
2903
-
2904
-        update_option('timezone_string', $timezone_string);
2905
-        EE_Error::add_success(
2906
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2907
-        );
2908
-        $this->_template_args['success'] = true;
2909
-        $this->_return_json(true, ['action' => 'create_new']);
2910
-    }
2577
+	protected function _template_settings()
2578
+	{
2579
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2580
+		$this->_template_args['preview_img']  = '<img src="'
2581
+												. EVENTS_ASSETS_URL
2582
+												. '/images/'
2583
+												. 'caffeinated_template_features.jpg" alt="'
2584
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2585
+												. '" />';
2586
+		$this->_template_args['preview_text'] = '<strong>'
2587
+												. esc_html__(
2588
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2589
+													'event_espresso'
2590
+												) . '</strong>';
2591
+		$this->display_admin_caf_preview_page('template_settings_tab');
2592
+	}
2593
+
2594
+
2595
+	/** Event Category Stuff **/
2596
+	/**
2597
+	 * set the _category property with the category object for the loaded page.
2598
+	 *
2599
+	 * @access private
2600
+	 * @return void
2601
+	 */
2602
+	private function _set_category_object()
2603
+	{
2604
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2605
+			return;
2606
+		} //already have the category object so get out.
2607
+		// set default category object
2608
+		$this->_set_empty_category_object();
2609
+		// only set if we've got an id
2610
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2611
+			return;
2612
+		}
2613
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2614
+		$term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2615
+		if (! empty($term)) {
2616
+			$this->_category->category_name       = $term->name;
2617
+			$this->_category->category_identifier = $term->slug;
2618
+			$this->_category->category_desc       = $term->description;
2619
+			$this->_category->id                  = $term->term_id;
2620
+			$this->_category->parent              = $term->parent;
2621
+		}
2622
+	}
2623
+
2624
+
2625
+	/**
2626
+	 * Clears out category properties.
2627
+	 */
2628
+	private function _set_empty_category_object()
2629
+	{
2630
+		$this->_category                = new stdClass();
2631
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2632
+		$this->_category->id            = $this->_category->parent = 0;
2633
+	}
2634
+
2635
+
2636
+	/**
2637
+	 * @throws DomainException
2638
+	 * @throws EE_Error
2639
+	 * @throws InvalidArgumentException
2640
+	 * @throws InvalidDataTypeException
2641
+	 * @throws InvalidInterfaceException
2642
+	 */
2643
+	protected function _category_list_table()
2644
+	{
2645
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2646
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2647
+		$this->_admin_page_title .= ' ';
2648
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2649
+			'add_category',
2650
+			'add_category',
2651
+			[],
2652
+			'add-new-h2'
2653
+		);
2654
+		$this->display_admin_list_table_page_with_sidebar();
2655
+	}
2656
+
2657
+
2658
+	/**
2659
+	 * Output category details view.
2660
+	 *
2661
+	 * @param string $view
2662
+	 * @throws DomainException
2663
+	 * @throws EE_Error
2664
+	 * @throws InvalidArgumentException
2665
+	 * @throws InvalidDataTypeException
2666
+	 * @throws InvalidInterfaceException
2667
+	 */
2668
+	protected function _category_details($view)
2669
+	{
2670
+		// load formatter helper
2671
+		// load field generator helper
2672
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2673
+		$this->_set_add_edit_form_tags($route);
2674
+		$this->_set_category_object();
2675
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2676
+		$delete_action = 'delete_category';
2677
+		// custom redirect
2678
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2679
+			['action' => 'category_list'],
2680
+			$this->_admin_base_url
2681
+		);
2682
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2683
+		// take care of contents
2684
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2685
+		$this->display_admin_page_with_sidebar();
2686
+	}
2687
+
2688
+
2689
+	/**
2690
+	 * Output category details content.
2691
+	 *
2692
+	 * @throws DomainException
2693
+	 */
2694
+	protected function _category_details_content()
2695
+	{
2696
+		$editor_args['category_desc'] = [
2697
+			'type'          => 'wp_editor',
2698
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2699
+			'class'         => 'my_editor_custom',
2700
+			'wpeditor_args' => ['media_buttons' => false],
2701
+		];
2702
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2703
+		$all_terms                    = get_terms(
2704
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2705
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2706
+		);
2707
+		// setup category select for term parents.
2708
+		$category_select_values[] = [
2709
+			'text' => esc_html__('No Parent', 'event_espresso'),
2710
+			'id'   => 0,
2711
+		];
2712
+		foreach ($all_terms as $term) {
2713
+			$category_select_values[] = [
2714
+				'text' => $term->name,
2715
+				'id'   => $term->term_id,
2716
+			];
2717
+		}
2718
+		$category_select = EEH_Form_Fields::select_input(
2719
+			'category_parent',
2720
+			$category_select_values,
2721
+			$this->_category->parent
2722
+		);
2723
+		$template_args   = [
2724
+			'category'                 => $this->_category,
2725
+			'category_select'          => $category_select,
2726
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2727
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2728
+			'disable'                  => '',
2729
+			'disabled_message'         => false,
2730
+		];
2731
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2732
+		return EEH_Template::display_template($template, $template_args, true);
2733
+	}
2734
+
2735
+
2736
+	/**
2737
+	 * Handles deleting categories.
2738
+	 *
2739
+	 * @throws EE_Error
2740
+	 */
2741
+	protected function _delete_categories()
2742
+	{
2743
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2744
+			: (array) $this->_req_data['category_id'];
2745
+		foreach ($cat_ids as $cat_id) {
2746
+			$this->_delete_category($cat_id);
2747
+		}
2748
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2749
+		$query_args = [
2750
+			'action' => 'category_list',
2751
+		];
2752
+		$this->_redirect_after_action(0, '', '', $query_args);
2753
+	}
2754
+
2755
+
2756
+	/**
2757
+	 * Handles deleting specific category.
2758
+	 *
2759
+	 * @param int $cat_id
2760
+	 */
2761
+	protected function _delete_category($cat_id)
2762
+	{
2763
+		$cat_id = absint($cat_id);
2764
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2765
+	}
2766
+
2767
+
2768
+	/**
2769
+	 * Handles triggering the update or insertion of a new category.
2770
+	 *
2771
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2772
+	 * @throws EE_Error
2773
+	 * @throws InvalidArgumentException
2774
+	 * @throws InvalidDataTypeException
2775
+	 * @throws InvalidInterfaceException
2776
+	 */
2777
+	protected function _insert_or_update_category($new_category)
2778
+	{
2779
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2780
+		$success = 0; // we already have a success message so lets not send another.
2781
+		if ($cat_id) {
2782
+			$query_args = [
2783
+				'action'     => 'edit_category',
2784
+				'EVT_CAT_ID' => $cat_id,
2785
+			];
2786
+		} else {
2787
+			$query_args = ['action' => 'add_category'];
2788
+		}
2789
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2790
+	}
2791
+
2792
+
2793
+	/**
2794
+	 * Inserts or updates category
2795
+	 *
2796
+	 * @param bool $update (true indicates we're updating a category).
2797
+	 * @return bool|mixed|string
2798
+	 */
2799
+	private function _insert_category($update = false)
2800
+	{
2801
+		$cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2802
+		$category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2803
+		$category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2804
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2805
+		if (empty($category_name)) {
2806
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2807
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2808
+			return false;
2809
+		}
2810
+		$term_args = [
2811
+			'name'        => $category_name,
2812
+			'description' => $category_desc,
2813
+			'parent'      => $category_parent,
2814
+		];
2815
+		// was the category_identifier input disabled?
2816
+		if (isset($this->_req_data['category_identifier'])) {
2817
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2818
+		}
2819
+		$insert_ids = $update
2820
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2821
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2822
+		if (! is_array($insert_ids)) {
2823
+			$msg = esc_html__(
2824
+				'An error occurred and the category has not been saved to the database.',
2825
+				'event_espresso'
2826
+			);
2827
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2828
+		} else {
2829
+			$cat_id = $insert_ids['term_id'];
2830
+			$msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2831
+			EE_Error::add_success($msg);
2832
+		}
2833
+		return $cat_id;
2834
+	}
2835
+
2836
+
2837
+	/**
2838
+	 * Gets categories or count of categories matching the arguments in the request.
2839
+	 *
2840
+	 * @param int  $per_page
2841
+	 * @param int  $current_page
2842
+	 * @param bool $count
2843
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2844
+	 * @throws EE_Error
2845
+	 * @throws InvalidArgumentException
2846
+	 * @throws InvalidDataTypeException
2847
+	 * @throws InvalidInterfaceException
2848
+	 */
2849
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2850
+	{
2851
+		// testing term stuff
2852
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2853
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2854
+		$limit   = ($current_page - 1) * $per_page;
2855
+		$where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2856
+		if (isset($this->_req_data['s'])) {
2857
+			$sstr        = '%' . $this->_req_data['s'] . '%';
2858
+			$where['OR'] = [
2859
+				'Term.name'   => ['LIKE', $sstr],
2860
+				'description' => ['LIKE', $sstr],
2861
+			];
2862
+		}
2863
+		$query_params = [
2864
+			$where,
2865
+			'order_by'   => [$orderby => $order],
2866
+			'limit'      => $limit . ',' . $per_page,
2867
+			'force_join' => ['Term'],
2868
+		];
2869
+		return $count
2870
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2871
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2872
+	}
2873
+
2874
+	/* end category stuff */
2875
+
2876
+
2877
+	/**************/
2878
+
2879
+
2880
+	/**
2881
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2882
+	 *
2883
+	 * @throws EE_Error
2884
+	 * @throws InvalidArgumentException
2885
+	 * @throws InvalidDataTypeException
2886
+	 * @throws InvalidInterfaceException
2887
+	 */
2888
+	public function save_timezonestring_setting()
2889
+	{
2890
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2891
+			? $this->_req_data['timezone_selected']
2892
+			: '';
2893
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2894
+			EE_Error::add_error(
2895
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2896
+				__FILE__,
2897
+				__FUNCTION__,
2898
+				__LINE__
2899
+			);
2900
+			$this->_template_args['error'] = true;
2901
+			$this->_return_json();
2902
+		}
2903
+
2904
+		update_option('timezone_string', $timezone_string);
2905
+		EE_Error::add_success(
2906
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2907
+		);
2908
+		$this->_template_args['success'] = true;
2909
+		$this->_return_json(true, ['action' => 'create_new']);
2910
+	}
2911 2911
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         ];
535 535
         // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
536 536
         $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
537
-        if (! $domain->isCaffeinated()) {
537
+        if ( ! $domain->isCaffeinated()) {
538 538
             $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
539 539
             $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
540 540
         }
@@ -593,13 +593,13 @@  discard block
 block discarded – undo
593 593
     {
594 594
         wp_register_style(
595 595
             'events-admin-css',
596
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
596
+            EVENTS_ASSETS_URL.'events-admin-page.css',
597 597
             [],
598 598
             EVENT_ESPRESSO_VERSION
599 599
         );
600 600
         wp_register_style(
601 601
             'ee-cat-admin',
602
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
602
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
603 603
             [],
604 604
             EVENT_ESPRESSO_VERSION
605 605
         );
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
         // scripts
609 609
         wp_register_script(
610 610
             'event_editor_js',
611
-            EVENTS_ASSETS_URL . 'event_editor.js',
611
+            EVENTS_ASSETS_URL.'event_editor.js',
612 612
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
613 613
             EVENT_ESPRESSO_VERSION,
614 614
             true
@@ -634,16 +634,16 @@  discard block
 block discarded – undo
634 634
         wp_enqueue_style('espresso-ui-theme');
635 635
         wp_register_style(
636 636
             'event-editor-css',
637
-            EVENTS_ASSETS_URL . 'event-editor.css',
637
+            EVENTS_ASSETS_URL.'event-editor.css',
638 638
             ['ee-admin-css'],
639 639
             EVENT_ESPRESSO_VERSION
640 640
         );
641 641
         wp_enqueue_style('event-editor-css');
642 642
         // scripts
643
-        if (! $this->admin_config->useAdvancedEditor()) {
643
+        if ( ! $this->admin_config->useAdvancedEditor()) {
644 644
             wp_register_script(
645 645
                 'event-datetime-metabox',
646
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
646
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
647 647
                 ['event_editor_js', 'ee-datepicker'],
648 648
                 EVENT_ESPRESSO_VERSION
649 649
             );
@@ -713,15 +713,15 @@  discard block
 block discarded – undo
713 713
     public function verify_event_edit($event = null, $req_type = '')
714 714
     {
715 715
         // don't need to do this when processing
716
-        if (! empty($req_type)) {
716
+        if ( ! empty($req_type)) {
717 717
             return;
718 718
         }
719 719
         // no event?
720
-        if (! $event instanceof EE_Event) {
720
+        if ( ! $event instanceof EE_Event) {
721 721
             $event = $this->_cpt_model_obj;
722 722
         }
723 723
         // STILL no event?
724
-        if (! $event instanceof EE_Event) {
724
+        if ( ! $event instanceof EE_Event) {
725 725
             return;
726 726
         }
727 727
         $orig_status = $event->status();
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
             );
762 762
         }
763 763
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
764
-        if (! $event->tickets_on_sale()) {
764
+        if ( ! $event->tickets_on_sale()) {
765 765
             return;
766 766
         }
767 767
         // made it here so show warning
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
     {
810 810
         $has_timezone_string = get_option('timezone_string');
811 811
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
812
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
812
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
813 813
             EE_Error::add_attention(
814 814
                 sprintf(
815 815
                     __(
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
      */
877 877
     protected function _event_legend_items()
878 878
     {
879
-        $items    = [
879
+        $items = [
880 880
             'view_details'   => [
881 881
                 'class' => 'dashicons dashicons-search',
882 882
                 'desc'  => esc_html__('View Event', 'event_espresso'),
@@ -893,31 +893,31 @@  discard block
 block discarded – undo
893 893
         $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
894 894
         $statuses = [
895 895
             'sold_out_status'  => [
896
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
896
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
897 897
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
898 898
             ],
899 899
             'active_status'    => [
900
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
900
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
901 901
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
902 902
             ],
903 903
             'upcoming_status'  => [
904
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
904
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
905 905
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
906 906
             ],
907 907
             'postponed_status' => [
908
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
908
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
909 909
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
910 910
             ],
911 911
             'cancelled_status' => [
912
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
912
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
913 913
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
914 914
             ],
915 915
             'expired_status'   => [
916
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
916
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
917 917
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
918 918
             ],
919 919
             'inactive_status'  => [
920
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
920
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
921 921
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
922 922
             ],
923 923
         ];
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
      */
937 937
     private function _event_model()
938 938
     {
939
-        if (! $this->_event_model instanceof EEM_Event) {
939
+        if ( ! $this->_event_model instanceof EEM_Event) {
940 940
             $this->_event_model = EE_Registry::instance()->load_model('Event');
941 941
         }
942 942
         return $this->_event_model;
@@ -956,8 +956,8 @@  discard block
 block discarded – undo
956 956
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
957 957
     {
958 958
         // make sure this is only when editing
959
-        if (! empty($id)) {
960
-            $post   = get_post($id);
959
+        if ( ! empty($id)) {
960
+            $post = get_post($id);
961 961
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
962 962
                        . esc_html__('Shortcode', 'event_espresso')
963 963
                        . '</a> ';
@@ -992,13 +992,13 @@  discard block
 block discarded – undo
992 992
             'button'
993 993
         );
994 994
         $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
995
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
995
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
996 996
             'create_new',
997 997
             'add',
998 998
             [],
999 999
             'add-new-h2'
1000 1000
         );
1001
-        $this->_template_args['after_list_table']   = array_merge(
1001
+        $this->_template_args['after_list_table'] = array_merge(
1002 1002
             (array) $this->_template_args['after_list_table'],
1003 1003
             $after_list_table
1004 1004
         );
@@ -1057,12 +1057,12 @@  discard block
 block discarded – undo
1057 1057
                 : null,
1058 1058
         ];
1059 1059
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1060
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1061
-            $event_values['EVT_display_ticket_selector']     =
1060
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1061
+            $event_values['EVT_display_ticket_selector'] =
1062 1062
                 ! empty($this->_req_data['display_ticket_selector'])
1063 1063
                     ? 1
1064 1064
                     : 0;
1065
-            $event_values['EVT_additional_limit']            = min(
1065
+            $event_values['EVT_additional_limit'] = min(
1066 1066
                 apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1067 1067
                 ! empty($this->_req_data['additional_limit'])
1068 1068
                     ? absint($this->_req_data['additional_limit'])
@@ -1094,11 +1094,11 @@  discard block
 block discarded – undo
1094 1094
                 'status*1' => $this->_req_data['original_post_status'],
1095 1095
             ],
1096 1096
         ];
1097
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1097
+        $event = $this->_event_model()->get_one([$get_one_where]);
1098 1098
         // the following are default callbacks for event attachment updates
1099 1099
         // that can be overridden by caffeinated functionality and/or addons.
1100 1100
         $event_update_callbacks = [];
1101
-        if (! $this->admin_config->useAdvancedEditor()) {
1101
+        if ( ! $this->admin_config->useAdvancedEditor()) {
1102 1102
             $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1103 1103
             $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1104 1104
         }
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
             'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1107 1107
             $event_update_callbacks
1108 1108
         );
1109
-        $att_success            = true;
1109
+        $att_success = true;
1110 1110
         foreach ($event_update_callbacks as $e_callback) {
1111 1111
             $results = is_callable($e_callback)
1112 1112
                 ? $e_callback($event, $this->_req_data)
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
      */
1174 1174
     protected function _default_venue_update(EE_Event $evtobj, $data)
1175 1175
     {
1176
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1176
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1177 1177
         $venue_model = EE_Registry::instance()->load_model('Venue');
1178 1178
         $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1179 1179
         // very important.  If we don't have a venue name...
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
             'status'              => 'publish',
1204 1204
         ];
1205 1205
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1206
-        if (! empty($venue_id)) {
1206
+        if ( ! empty($venue_id)) {
1207 1207
             $update_where  = [$venue_model->primary_key_name() => $venue_id];
1208 1208
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1209 1209
             // we've gotta make sure that the venue is always attached to a revision..
@@ -1255,7 +1255,7 @@  discard block
 block discarded – undo
1255 1255
             ];
1256 1256
             // if we have an id then let's get existing object first and then set the new values.
1257 1257
             //  Otherwise we instantiate a new object for save.
1258
-            if (! empty($dtt['DTT_ID'])) {
1258
+            if ( ! empty($dtt['DTT_ID'])) {
1259 1259
                 $DTM = EE_Registry::instance()
1260 1260
                                   ->load_model('Datetime', [$evtobj->get_timezone()])
1261 1261
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
                 }
1267 1267
                 // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1268 1268
                 // We need to do this so we dont' TRASH the parent DTT.
1269
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1269
+                $saved_dtts[$DTM->ID()] = $DTM;
1270 1270
             } else {
1271 1271
                 $DTM = EE_Registry::instance()->load_class(
1272 1272
                     'Datetime',
@@ -1301,15 +1301,15 @@  discard block
 block discarded – undo
1301 1301
         foreach ($data['edit_tickets'] as $row => $tkt) {
1302 1302
             $incoming_date_formats = ['Y-m-d', 'h:i a'];
1303 1303
             $update_prices         = false;
1304
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1305
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1304
+            $ticket_price          = isset($data['edit_prices'][$row][1]['PRC_amount'])
1305
+                ? $data['edit_prices'][$row][1]['PRC_amount']
1306 1306
                 : 0;
1307 1307
             // trim inputs to ensure any excess whitespace is removed.
1308 1308
             $tkt = array_map('trim', $tkt);
1309 1309
             if (empty($tkt['TKT_start_date'])) {
1310 1310
                 // let's use now in the set timezone.
1311 1311
                 $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1312
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1312
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1313 1313
             }
1314 1314
             if (empty($tkt['TKT_end_date'])) {
1315 1315
                 // use the start date of the first datetime
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
             // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1348 1348
             // keep in mind that if the TKT has been sold (and we have changed pricing information),
1349 1349
             // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
-            if (! empty($tkt['TKT_ID'])) {
1350
+            if ( ! empty($tkt['TKT_ID'])) {
1351 1351
                 $TKT = EE_Registry::instance()
1352 1352
                                   ->load_model('Ticket', [$evtobj->get_timezone()])
1353 1353
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
                         $TKT->save();
1392 1392
                         // make sure this ticket is still recorded in our saved_tkts
1393 1393
                         // so we don't run it through the regular trash routine.
1394
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1394
+                        $saved_tickets[$TKT->ID()] = $TKT;
1395 1395
                         // create new ticket that's a copy of the existing except a new id of course
1396 1396
                         // (and not archived) AND has the new TKT_price associated with it.
1397 1397
                         $TKT = clone $TKT;
@@ -1438,9 +1438,9 @@  discard block
 block discarded – undo
1438 1438
             }
1439 1439
             // initially let's add the ticket to the dtt
1440 1440
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1441
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1441
+            $saved_tickets[$TKT->ID()] = $TKT;
1442 1442
             // add prices to ticket
1443
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1443
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1444 1444
         }
1445 1445
         // however now we need to handle permanently deleting tickets via the ui.
1446 1446
         //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
@@ -1545,13 +1545,13 @@  discard block
 block discarded – undo
1545 1545
     {
1546 1546
         // load formatter helper
1547 1547
         // args for getting related registrations
1548
-        $approved_query_args        = [
1548
+        $approved_query_args = [
1549 1549
             [
1550 1550
                 'REG_deleted' => 0,
1551 1551
                 'STS_ID'      => EEM_Registration::status_id_approved,
1552 1552
             ],
1553 1553
         ];
1554
-        $not_approved_query_args    = [
1554
+        $not_approved_query_args = [
1555 1555
             [
1556 1556
                 'REG_deleted' => 0,
1557 1557
                 'STS_ID'      => EEM_Registration::status_id_not_approved,
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1615 1615
         // load template
1616 1616
         EEH_Template::display_template(
1617
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1617
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1618 1618
             $publish_box_extra_args
1619 1619
         );
1620 1620
     }
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
         $this->verify_cpt_object();
1649 1649
         $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1650 1650
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1651
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1651
+        if ( ! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1652 1652
             add_meta_box(
1653 1653
                 'espresso_event_editor_event_options',
1654 1654
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1657,7 +1657,7 @@  discard block
 block discarded – undo
1657 1657
                 'side'
1658 1658
             );
1659 1659
         }
1660
-        if (! $use_advanced_editor) {
1660
+        if ( ! $use_advanced_editor) {
1661 1661
             add_meta_box(
1662 1662
                 'espresso_event_editor_tickets',
1663 1663
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1669,7 +1669,7 @@  discard block
 block discarded – undo
1669 1669
         } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1670 1670
             add_action(
1671 1671
                 'add_meta_boxes_espresso_events',
1672
-                function () {
1672
+                function() {
1673 1673
                     global $current_screen;
1674 1674
                     remove_meta_box('authordiv', $current_screen, 'normal');
1675 1675
                 },
@@ -1707,7 +1707,7 @@  discard block
 block discarded – undo
1707 1707
             'trash_icon'               => 'ee-lock-icon',
1708 1708
             'disabled'                 => '',
1709 1709
         ];
1710
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1710
+        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1711 1711
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1712 1712
         /**
1713 1713
          * 1. Start with retrieving Datetimes
@@ -1734,24 +1734,24 @@  discard block
 block discarded – undo
1734 1734
                     'default_where_conditions' => 'none',
1735 1735
                 ]
1736 1736
             );
1737
-            if (! empty($related_tickets)) {
1737
+            if ( ! empty($related_tickets)) {
1738 1738
                 $template_args['total_ticket_rows'] = count($related_tickets);
1739 1739
                 $row                                = 0;
1740 1740
                 foreach ($related_tickets as $ticket) {
1741
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1741
+                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1742 1742
                     $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743 1743
                     $row++;
1744 1744
                 }
1745 1745
             } else {
1746 1746
                 $template_args['total_ticket_rows'] = 1;
1747 1747
                 /** @type EE_Ticket $ticket */
1748
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1748
+                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1749 1749
                 $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750 1750
             }
1751 1751
         } else {
1752 1752
             $template_args['time'] = $times[0];
1753 1753
             /** @type EE_Ticket[] $tickets */
1754
-            $tickets                      = $ticket_model->get_all_default_tickets();
1754
+            $tickets = $ticket_model->get_all_default_tickets();
1755 1755
             $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756 1756
             // NOTE: we're just sending the first default row
1757 1757
             // (decaf can't manage default tickets so this should be sufficient);
@@ -1766,9 +1766,9 @@  discard block
 block discarded – undo
1766 1766
             $ticket_model->create_default_object(),
1767 1767
             true
1768 1768
         );
1769
-        $template                                  = apply_filters(
1769
+        $template = apply_filters(
1770 1770
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1771
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1772 1772
         );
1773 1773
         EEH_Template::display_template($template, $template_args);
1774 1774
     }
@@ -1792,7 +1792,7 @@  discard block
 block discarded – undo
1792 1792
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1793 1793
     {
1794 1794
         $template_args = [
1795
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1795
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1796 1796
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1797 1797
                 : '',
1798 1798
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1804,10 +1804,10 @@  discard block
 block discarded – undo
1804 1804
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1805 1805
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1806 1806
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1807
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1808
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1807
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1808
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1809 1809
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1810
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1810
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1811 1811
                 : ' disabled=disabled',
1812 1812
         ];
1813 1813
         $price         = $ticket->ID() !== 0
@@ -1834,7 +1834,7 @@  discard block
 block discarded – undo
1834 1834
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1835 1835
                 )
1836 1836
                 : null;
1837
-            if (! empty($earliest_dtt)) {
1837
+            if ( ! empty($earliest_dtt)) {
1838 1838
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1839 1839
             } else {
1840 1840
                 $template_args['TKT_end_date'] = date(
@@ -1846,7 +1846,7 @@  discard block
 block discarded – undo
1846 1846
         $template_args = array_merge($template_args, $price_args);
1847 1847
         $template      = apply_filters(
1848 1848
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1849
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1849
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1850 1850
             $ticket
1851 1851
         );
1852 1852
         return EEH_Template::display_template($template, $template_args, true);
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
      */
1860 1860
     public function registration_options_meta_box()
1861 1861
     {
1862
-        $yes_no_values             = [
1862
+        $yes_no_values = [
1863 1863
             ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1864 1864
             ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1865 1865
         ];
@@ -1880,12 +1880,12 @@  discard block
 block discarded – undo
1880 1880
             $default_reg_status_values,
1881 1881
             $this->_cpt_model_obj->default_registration_status()
1882 1882
         );
1883
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1883
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1884 1884
             'display_desc',
1885 1885
             $yes_no_values,
1886 1886
             $this->_cpt_model_obj->display_description()
1887 1887
         );
1888
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1888
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1889 1889
             'display_ticket_selector',
1890 1890
             $yes_no_values,
1891 1891
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1901,7 +1901,7 @@  discard block
 block discarded – undo
1901 1901
             $default_reg_status_values
1902 1902
         );
1903 1903
         EEH_Template::display_template(
1904
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1904
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1905 1905
             $template_args
1906 1906
         );
1907 1907
     }
@@ -1931,7 +1931,7 @@  discard block
 block discarded – undo
1931 1931
     {
1932 1932
         $EEME    = $this->_event_model();
1933 1933
         $offset  = ($current_page - 1) * $per_page;
1934
-        $limit   = $count ? null : $offset . ',' . $per_page;
1934
+        $limit   = $count ? null : $offset.','.$per_page;
1935 1935
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1936 1936
         $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1937 1937
         $month_r = '';
@@ -1962,7 +1962,7 @@  discard block
 block discarded – undo
1962 1962
         // categories?
1963 1963
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1964 1964
             ? $this->_req_data['EVT_CAT'] : null;
1965
-        if (! empty($category)) {
1965
+        if ( ! empty($category)) {
1966 1966
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1967 1967
             $where['Term_Taxonomy.term_id']  = $category;
1968 1968
         }
@@ -1970,10 +1970,10 @@  discard block
 block discarded – undo
1970 1970
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1971 1971
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1972 1972
             $DateTime = new DateTime(
1973
-                $year_r . '-' . $month_r . '-01 00:00:00',
1973
+                $year_r.'-'.$month_r.'-01 00:00:00',
1974 1974
                 new DateTimeZone('UTC')
1975 1975
             );
1976
-            $start    = $DateTime->getTimestamp();
1976
+            $start = $DateTime->getTimestamp();
1977 1977
             // set the datetime to be the end of the month
1978 1978
             $DateTime->setDate(
1979 1979
                 $year_r,
@@ -1998,7 +1998,7 @@  discard block
 block discarded – undo
1998 1998
                                                         ->format(implode(' ', $start_formats));
1999 1999
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2000 2000
         }
2001
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2001
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2002 2002
             $where['EVT_wp_user'] = get_current_user_id();
2003 2003
         } elseif (
2004 2004
             ! isset($where['status'])
@@ -2022,7 +2022,7 @@  discard block
 block discarded – undo
2022 2022
         }
2023 2023
         // search query handling
2024 2024
         if (isset($this->_req_data['s'])) {
2025
-            $search_string = '%' . $this->_req_data['s'] . '%';
2025
+            $search_string = '%'.$this->_req_data['s'].'%';
2026 2026
             $where['OR']   = [
2027 2027
                 'EVT_name'       => ['LIKE', $search_string],
2028 2028
                 'EVT_desc'       => ['LIKE', $search_string],
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
             // clean status
2139 2139
             $event_status = sanitize_key($event_status);
2140 2140
             // grab status
2141
-            if (! empty($event_status)) {
2141
+            if ( ! empty($event_status)) {
2142 2142
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2143 2143
             } else {
2144 2144
                 $success = false;
@@ -2180,7 +2180,7 @@  discard block
 block discarded – undo
2180 2180
         // clean status
2181 2181
         $event_status = sanitize_key($event_status);
2182 2182
         // grab status
2183
-        if (! empty($event_status)) {
2183
+        if ( ! empty($event_status)) {
2184 2184
             $success = true;
2185 2185
             // determine the event id and set to array.
2186 2186
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
@@ -2232,7 +2232,7 @@  discard block
 block discarded – undo
2232 2232
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2233 2233
     {
2234 2234
         // grab event id
2235
-        if (! $EVT_ID) {
2235
+        if ( ! $EVT_ID) {
2236 2236
             $msg = esc_html__(
2237 2237
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2238 2238
                 'event_espresso'
@@ -2303,7 +2303,7 @@  discard block
 block discarded – undo
2303 2303
      */
2304 2304
     protected function getModelObjNodeGroupPersister()
2305 2305
     {
2306
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2306
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2307 2307
             $this->model_obj_node_group_persister =
2308 2308
                 $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2309 2309
         }
@@ -2335,7 +2335,7 @@  discard block
 block discarded – undo
2335 2335
             ],
2336 2336
             $this->_admin_base_url
2337 2337
         );
2338
-        $event_ids         = array_map(
2338
+        $event_ids = array_map(
2339 2339
             'intval',
2340 2340
             $event_ids
2341 2341
         );
@@ -2587,7 +2587,7 @@  discard block
 block discarded – undo
2587 2587
                                                 . esc_html__(
2588 2588
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2589 2589
                                                     'event_espresso'
2590
-                                                ) . '</strong>';
2590
+                                                ).'</strong>';
2591 2591
         $this->display_admin_caf_preview_page('template_settings_tab');
2592 2592
     }
2593 2593
 
@@ -2607,12 +2607,12 @@  discard block
 block discarded – undo
2607 2607
         // set default category object
2608 2608
         $this->_set_empty_category_object();
2609 2609
         // only set if we've got an id
2610
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2610
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2611 2611
             return;
2612 2612
         }
2613 2613
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2614 2614
         $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2615
-        if (! empty($term)) {
2615
+        if ( ! empty($term)) {
2616 2616
             $this->_category->category_name       = $term->name;
2617 2617
             $this->_category->category_identifier = $term->slug;
2618 2618
             $this->_category->category_desc       = $term->description;
@@ -2720,7 +2720,7 @@  discard block
 block discarded – undo
2720 2720
             $category_select_values,
2721 2721
             $this->_category->parent
2722 2722
         );
2723
-        $template_args   = [
2723
+        $template_args = [
2724 2724
             'category'                 => $this->_category,
2725 2725
             'category_select'          => $category_select,
2726 2726
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -2728,7 +2728,7 @@  discard block
 block discarded – undo
2728 2728
             'disable'                  => '',
2729 2729
             'disabled_message'         => false,
2730 2730
         ];
2731
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2731
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2732 2732
         return EEH_Template::display_template($template, $template_args, true);
2733 2733
     }
2734 2734
 
@@ -2819,7 +2819,7 @@  discard block
 block discarded – undo
2819 2819
         $insert_ids = $update
2820 2820
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2821 2821
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2822
-        if (! is_array($insert_ids)) {
2822
+        if ( ! is_array($insert_ids)) {
2823 2823
             $msg = esc_html__(
2824 2824
                 'An error occurred and the category has not been saved to the database.',
2825 2825
                 'event_espresso'
@@ -2854,7 +2854,7 @@  discard block
 block discarded – undo
2854 2854
         $limit   = ($current_page - 1) * $per_page;
2855 2855
         $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2856 2856
         if (isset($this->_req_data['s'])) {
2857
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2857
+            $sstr        = '%'.$this->_req_data['s'].'%';
2858 2858
             $where['OR'] = [
2859 2859
                 'Term.name'   => ['LIKE', $sstr],
2860 2860
                 'description' => ['LIKE', $sstr],
@@ -2863,7 +2863,7 @@  discard block
 block discarded – undo
2863 2863
         $query_params = [
2864 2864
             $where,
2865 2865
             'order_by'   => [$orderby => $order],
2866
-            'limit'      => $limit . ',' . $per_page,
2866
+            'limit'      => $limit.','.$per_page,
2867 2867
             'force_join' => ['Term'],
2868 2868
         ];
2869 2869
         return $count
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks.class.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -16,217 +16,217 @@
 block discarded – undo
16 16
 class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Event|null
21
-     */
22
-    protected $_event;
23
-
24
-
25
-    protected function _set_hooks_properties()
26
-    {
27
-        $this->_name = 'registration_form';
28
-        if (
29
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
30
-            && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
31
-        ) {
32
-            $this->_metaboxes      = [];
33
-            $this->_scripts_styles = [];
34
-            return;
35
-        }
36
-        $this->_metaboxes = array(
37
-            0 => array(
38
-                'page_route' => array('edit', 'create_new'),
39
-                'func'       => 'primary_questions',
40
-                'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
41
-                'priority'   => 'default',
42
-                'context'    => 'side',
43
-            ),
44
-        );
45
-
46
-        // hook into the handler for saving question groups
47
-        add_filter(
48
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
49
-            array($this, 'modify_callbacks'),
50
-            10
51
-        );
52
-
53
-        // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
54
-        // restricted by page)
55
-        add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2);
56
-    }
57
-
58
-
59
-    /**
60
-     * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
61
-     *
62
-     * @param $callbacks
63
-     * @return array
64
-     */
65
-    public function modify_callbacks($callbacks)
66
-    {
67
-        // now let's add the question group callback
68
-        $callbacks['primary_question_group_update'] = array($this, 'primary_question_group_update');
69
-        return $callbacks;
70
-    }
71
-
72
-
73
-    /**
74
-     * Hooked into revision restores.
75
-     *
76
-     * @param $post_id
77
-     * @param $revision_id
78
-     * @return EE_Base_Class
79
-     * @throws EE_Error
80
-     * @throws InvalidArgumentException
81
-     * @throws ReflectionException
82
-     * @throws InvalidDataTypeException
83
-     * @throws InvalidInterfaceException
84
-     */
85
-    public function restore_revision($post_id, $revision_id)
86
-    {
87
-        $EVT_MDL = EE_Registry::instance()->load_model('Event');
88
-        $post_evt = $EVT_MDL->get_one_by_ID($post_id);
89
-        // restore revision for primary questions
90
-        $post_evt->restore_revision(
91
-            $revision_id,
92
-            ['Question_Group'],
93
-            ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
94
-        );
95
-        return $post_evt;
96
-    }
97
-
98
-
99
-    /**
100
-     * Content of metabox.
101
-     *
102
-     * @param $post_id
103
-     * @param $post
104
-     * @throws EE_Error
105
-     * @throws InvalidArgumentException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     */
109
-    public function primary_questions($post_id, $post)
110
-    {
111
-        $this->_event = $this->_adminpage_obj->get_event_object();
112
-        $event_id = $this->_event->ID();
113
-        ?>
19
+	/**
20
+	 * @var EE_Event|null
21
+	 */
22
+	protected $_event;
23
+
24
+
25
+	protected function _set_hooks_properties()
26
+	{
27
+		$this->_name = 'registration_form';
28
+		if (
29
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
30
+			&& $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
31
+		) {
32
+			$this->_metaboxes      = [];
33
+			$this->_scripts_styles = [];
34
+			return;
35
+		}
36
+		$this->_metaboxes = array(
37
+			0 => array(
38
+				'page_route' => array('edit', 'create_new'),
39
+				'func'       => 'primary_questions',
40
+				'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
41
+				'priority'   => 'default',
42
+				'context'    => 'side',
43
+			),
44
+		);
45
+
46
+		// hook into the handler for saving question groups
47
+		add_filter(
48
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
49
+			array($this, 'modify_callbacks'),
50
+			10
51
+		);
52
+
53
+		// hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
54
+		// restricted by page)
55
+		add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2);
56
+	}
57
+
58
+
59
+	/**
60
+	 * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
61
+	 *
62
+	 * @param $callbacks
63
+	 * @return array
64
+	 */
65
+	public function modify_callbacks($callbacks)
66
+	{
67
+		// now let's add the question group callback
68
+		$callbacks['primary_question_group_update'] = array($this, 'primary_question_group_update');
69
+		return $callbacks;
70
+	}
71
+
72
+
73
+	/**
74
+	 * Hooked into revision restores.
75
+	 *
76
+	 * @param $post_id
77
+	 * @param $revision_id
78
+	 * @return EE_Base_Class
79
+	 * @throws EE_Error
80
+	 * @throws InvalidArgumentException
81
+	 * @throws ReflectionException
82
+	 * @throws InvalidDataTypeException
83
+	 * @throws InvalidInterfaceException
84
+	 */
85
+	public function restore_revision($post_id, $revision_id)
86
+	{
87
+		$EVT_MDL = EE_Registry::instance()->load_model('Event');
88
+		$post_evt = $EVT_MDL->get_one_by_ID($post_id);
89
+		// restore revision for primary questions
90
+		$post_evt->restore_revision(
91
+			$revision_id,
92
+			['Question_Group'],
93
+			['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
94
+		);
95
+		return $post_evt;
96
+	}
97
+
98
+
99
+	/**
100
+	 * Content of metabox.
101
+	 *
102
+	 * @param $post_id
103
+	 * @param $post
104
+	 * @throws EE_Error
105
+	 * @throws InvalidArgumentException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 */
109
+	public function primary_questions($post_id, $post)
110
+	{
111
+		$this->_event = $this->_adminpage_obj->get_event_object();
112
+		$event_id = $this->_event->ID();
113
+		?>
114 114
         <div class="inside">
115 115
             <p><strong>
116 116
                     <?php _e('Question Groups', 'event_espresso'); ?>
117 117
                 </strong><br/>
118 118
                 <?php
119
-                printf(
120
-                    esc_html__(
121
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
122
-                        'event_espresso'
123
-                    ),
124
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
125
-                    '</a>'
126
-                )
127
-                ?>
119
+				printf(
120
+					esc_html__(
121
+						'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
122
+						'event_espresso'
123
+					),
124
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
125
+					'</a>'
126
+				)
127
+				?>
128 128
             </p>
129 129
             <?php
130 130
 
131
-            $qsg_where['QSG_deleted'] = false;
132
-            $query_params = apply_filters(
133
-                'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
134
-                array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
135
-            );
136
-            $QSGs = EEM_Question_Group::instance()->get_all($query_params);
137
-            $EQGs = ! empty($event_id)
138
-                ? $this->_event->get_many_related(
139
-                    'Question_Group',
140
-                    [['Event_Question_Group.EQG_primary' => true]]
141
-                )
142
-                : array();
143
-            $EQGids = array_keys($EQGs);
144
-
145
-            if (! empty($QSGs)) {
146
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
147
-                foreach ($QSGs as $QSG) {
148
-                    $checked = in_array($QSG->ID(), $EQGids, true)
149
-                               || $QSG->get('QSG_system') === 1
150
-                        ? ' checked="checked"'
151
-                        : '';
152
-                    $visibility = $QSG->get('QSG_system') === 1
153
-                        ? ' style="visibility:hidden"'
154
-                        : '';
155
-                    $edit_query_args = $this->_adminpage_obj->is_caf() ? array(
156
-                        'action' => 'edit_question_group',
157
-                        'QSG_ID' => $QSG->ID(),
158
-                    ) : array('action' => 'question_groups');
159
-                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
160
-                        $edit_query_args,
161
-                        EE_FORMS_ADMIN_URL
162
-                    );
163
-
164
-                    $html .= '
131
+			$qsg_where['QSG_deleted'] = false;
132
+			$query_params = apply_filters(
133
+				'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
134
+				array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
135
+			);
136
+			$QSGs = EEM_Question_Group::instance()->get_all($query_params);
137
+			$EQGs = ! empty($event_id)
138
+				? $this->_event->get_many_related(
139
+					'Question_Group',
140
+					[['Event_Question_Group.EQG_primary' => true]]
141
+				)
142
+				: array();
143
+			$EQGids = array_keys($EQGs);
144
+
145
+			if (! empty($QSGs)) {
146
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
147
+				foreach ($QSGs as $QSG) {
148
+					$checked = in_array($QSG->ID(), $EQGids, true)
149
+							   || $QSG->get('QSG_system') === 1
150
+						? ' checked="checked"'
151
+						: '';
152
+					$visibility = $QSG->get('QSG_system') === 1
153
+						? ' style="visibility:hidden"'
154
+						: '';
155
+					$edit_query_args = $this->_adminpage_obj->is_caf() ? array(
156
+						'action' => 'edit_question_group',
157
+						'QSG_ID' => $QSG->ID(),
158
+					) : array('action' => 'question_groups');
159
+					$edit_link = EE_Admin_Page::add_query_args_and_nonce(
160
+						$edit_query_args,
161
+						EE_FORMS_ADMIN_URL
162
+					);
163
+
164
+					$html .= '
165 165
 					<p id="event-question-group-' . $QSG->ID() . '">
166 166
 						<input value="' . $QSG->ID() . '" type="checkbox"'
167
-                             . $visibility
168
-                             . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' />
167
+							 . $visibility
168
+							 . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' />
169 169
 						<a href="' . $edit_link . '" title="'
170
-                             . sprintf(
171
-                                 esc_attr__('Edit %s Group', 'event_espresso'),
172
-                                 $QSG->get('QSG_name')
173
-                             )
174
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
170
+							 . sprintf(
171
+								 esc_attr__('Edit %s Group', 'event_espresso'),
172
+								 $QSG->get('QSG_name')
173
+							 )
174
+							 . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
175 175
 					</p>';
176
-                }
177
-                $html .= count($QSGs) > 10 ? '</div>' : '';
178
-
179
-                echo $html;
180
-            } else {
181
-                esc_html_e(
182
-                    'There seems to be a problem with your questions. Please contact [email protected]',
183
-                    'event_espresso'
184
-                );
185
-            }
186
-            do_action('AHEE_event_editor_questions_notice');
187
-            ?>
176
+				}
177
+				$html .= count($QSGs) > 10 ? '</div>' : '';
178
+
179
+				echo $html;
180
+			} else {
181
+				esc_html_e(
182
+					'There seems to be a problem with your questions. Please contact [email protected]',
183
+					'event_espresso'
184
+				);
185
+			}
186
+			do_action('AHEE_event_editor_questions_notice');
187
+			?>
188 188
         </div>
189 189
         <?php
190
-    }
191
-
192
-
193
-    /**
194
-     * @param EE_Event $evtobj
195
-     * @param array    $data
196
-     * @return bool
197
-     * @throws EE_Error
198
-     */
199
-    public function primary_question_group_update($evtobj, $data)
200
-    {
201
-        $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array();
202
-        $added_qgs = array_keys($question_groups);
203
-        $success = array();
204
-
205
-        // let's get all current question groups associated with this event.
206
-        $current_qgs = $evtobj->get_many_related(
207
-            'Question_Group',
208
-            [['Event_Question_Group.EQG_primary' => true]]
209
-        );
210
-        $current_qgs = array_keys($current_qgs); // we just want the ids
211
-
212
-        // now let's get the groups selected in the editor and update (IF we have data)
213
-        if (! empty($question_groups)) {
214
-            foreach ($question_groups as $id => $val) {
215
-                // add to event
216
-                if ($val) {
217
-                    $qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]);
218
-                }
219
-                $success[] = ! empty($qg) ? 1 : 0;
220
-            }
221
-        }
222
-
223
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
224
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
225
-
226
-        foreach ($removed_qgs as $qgid) {
227
-            $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]);
228
-            $success[] = ! empty($qg) ? 1 : 0;
229
-        }
230
-        return in_array(0, $success, true) ? false : true;
231
-    }
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param EE_Event $evtobj
195
+	 * @param array    $data
196
+	 * @return bool
197
+	 * @throws EE_Error
198
+	 */
199
+	public function primary_question_group_update($evtobj, $data)
200
+	{
201
+		$question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array();
202
+		$added_qgs = array_keys($question_groups);
203
+		$success = array();
204
+
205
+		// let's get all current question groups associated with this event.
206
+		$current_qgs = $evtobj->get_many_related(
207
+			'Question_Group',
208
+			[['Event_Question_Group.EQG_primary' => true]]
209
+		);
210
+		$current_qgs = array_keys($current_qgs); // we just want the ids
211
+
212
+		// now let's get the groups selected in the editor and update (IF we have data)
213
+		if (! empty($question_groups)) {
214
+			foreach ($question_groups as $id => $val) {
215
+				// add to event
216
+				if ($val) {
217
+					$qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]);
218
+				}
219
+				$success[] = ! empty($qg) ? 1 : 0;
220
+			}
221
+		}
222
+
223
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
224
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
225
+
226
+		foreach ($removed_qgs as $qgid) {
227
+			$qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]);
228
+			$success[] = ! empty($qg) ? 1 : 0;
229
+		}
230
+		return in_array(0, $success, true) ? false : true;
231
+	}
232 232
 }
Please login to merge, or discard this patch.
admin_pages/venues/espresso_events_Venues_Hooks.class.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -15,210 +15,210 @@
 block discarded – undo
15 15
 class espresso_events_Venues_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Event
20
-     */
21
-    protected $_event;
22
-
23
-
24
-    public function __construct(EE_Admin_Page $admin_page)
25
-    {
26
-        parent::__construct($admin_page);
27
-    }
28
-
29
-
30
-    protected function _set_hooks_properties()
31
-    {
32
-        $this->_name = 'venues';
33
-        if ($this->_adminpage_obj->adminConfig()->useAdvancedEditor()) {
34
-            $this->_metaboxes      = [];
35
-            $this->_scripts_styles = [];
36
-            return;
37
-        }
38
-
39
-        $this->_metaboxes = array(
40
-            0 => array(
41
-                'page_route' => array('edit', 'create_new'),
42
-                'func'       => 'venue_metabox',
43
-                'label'      => __('Venue Details', 'event_espresso'),
44
-                'priority'   => 'high',
45
-                'context'    => 'normal',
46
-            ),
47
-        );
48
-
49
-        $this->_scripts_styles = array(
50
-            'registers' => array(
51
-                'ee_event_venues'     => array(
52
-                    'type'    => 'js',
53
-                    'url'     => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.js',
54
-                    'depends' => array('jquery'),
55
-                ),
56
-                'ee_event_venues_css' => array(
57
-                    'type' => 'css',
58
-                    'url'  => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.css',
59
-                ),
60
-            ),
61
-            'enqueues'  => array(
62
-                'ee_event_venues'     => array('edit', 'create_new'),
63
-                'ee_event_venues_css' => array('edit', 'create_new'),
64
-            ),
65
-        );
66
-
67
-        // hook into the handler for saving venue
68
-        add_filter(
69
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
-            array($this, 'modify_callbacks'),
71
-            10
72
-        );
73
-
74
-        // remove default ee_autosave returns for DECAF venues (not needed for CAF venues cause we have a dropdown selector)
75
-        add_filter('FHEE__Events_Admin_Page__ee_autosave_edit_do_decaf_venue_save', '__return_false');
76
-    }
77
-
78
-
79
-    public function modify_callbacks($callbacks)
80
-    {
81
-        // first remove default venue callback
82
-        unset($callbacks['_default_venue_update' ]);
83
-        // now let's add the caf version
84
-        $callbacks['caf_venue_update'] = array($this, 'caf_venue_update');
85
-        return $callbacks;
86
-    }
87
-
88
-
89
-    public function venue_metabox()
90
-    {
91
-        $evt_obj = $this->_adminpage_obj->get_event_object();
92
-        $evt_id = $evt_obj->ID();
93
-
94
-        // first let's see if we have a venue already
95
-        $evt_venues = ! empty($evt_id) ? $evt_obj->venues() : array();
96
-        $evt_venue = $evt_venues && is_array($evt_venues) ? reset($evt_venues) : null;
97
-        $evt_venue_id = $evt_venue instanceof EE_Venue ? $evt_venue->ID() : null;
98
-
99
-        // possibly private venues.
100
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
101
-            $vnu_where['status'] = array('IN', array('publish', 'private'));
102
-        } else {
103
-            $vnu_where['status'] = 'publish';
104
-        }
105
-
106
-        // cap checks
107
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
108
-            $vnu_where['VNU_wp_user'] = get_current_user_id();
109
-        }
110
-
111
-        $vnumdl = EE_Registry::instance()->load_model('Venue');
112
-        $venues = $vnumdl->get_all(array($vnu_where, 'order_by' => array('VNU_name' => 'ASC')));
113
-
114
-        $ven_select = array();
115
-        $ven_select[0] = __('Select a Venue', 'event_espresso');
116
-        // setup venues for selector
117
-        foreach ($venues as $venue) {
118
-            $ven_select[ $venue->ID() ] = $venue->name();
119
-        }
120
-
121
-        // if $ven_select does not have the existing venue attached to event then let's add that because we'll always
122
-        // show existing attached venues even if it's trashed (or some other restricted status).
123
-
124
-        if ($evt_venue_id && ! isset($ven_select[ $evt_venue_id ])) {
125
-            $ven_select[ $evt_venue_id ] = $evt_venue->name();
126
-            $venues = array_merge($venues, array($evt_venue));
127
-        }
128
-
129
-        $template_args['venues'] = $venues;
130
-        $template_args['evt_venue_id'] = $evt_venue_id;
131
-        $venue_selector = new EE_Select_Input(
132
-            $ven_select,
133
-            array(
134
-                'html_name'  => 'venue_id',
135
-                'html_id'    => 'venue_id',
136
-                'html_class' => 'wide',
137
-                'default'    => $evt_venue_id ? $evt_venue_id : '0'
138
-            )
139
-        );
140
-        $template_args['venue_selector'] = $venue_selector->get_html_for_input();
141
-        $enable_for_gmap = new EE_Yes_No_Input(
142
-            array(
143
-                'html_name'  => 'enable_for_gmap',
144
-                'html_id'    => 'enable_for_gmap',
145
-                'default'    => $evt_venue instanceof EE_Venue ? $evt_venue->enable_for_gmap() : false
146
-            )
147
-        );
148
-        $template_args['enable_for_gmap'] = $enable_for_gmap->get_html_for_input();
149
-        $template_args['new_venue_link'] = EEH_HTML::link(
150
-            EE_Admin_Page::add_query_args_and_nonce(
151
-                array('action' => 'create_new'),
152
-                EE_VENUES_ADMIN_URL
153
-            ),
154
-            esc_html_x('Add new Venue', 'a link to add a new venue', 'event_espresso'),
155
-            esc_html_x('Add new Venue', 'a link to add a new venue', 'event_espresso'),
156
-            'ev_new_venue_link',
157
-            'button',
158
-            'margin-left:10px;',
159
-            'target="_blank"'
160
-        );
161
-
162
-        // Decide on an info text when there are no venues to display.
163
-        $no_venues_info_txt = esc_html_x(
164
-            'You have not created any venues yet.',
165
-            'Information text displayed in the venues metabox when there are no venues to display',
166
-            'event_espresso'
167
-        );
168
-        if (empty($venues)) {
169
-            $unpublished_where = $vnu_where;
170
-            $unpublished_where['status'] = 'draft';
171
-            $unpublished_venues = $vnumdl->get_all(array($unpublished_where, 'order_by' => array('VNU_name' => 'ASC')));
172
-            if (count($unpublished_venues) > 0) {
173
-                $no_venues_info_txt = esc_html_x(
174
-                // @codingStandardsIgnoreStart
175
-                    'Use the link below to publish your venue through the venue editor so it appears here for selection.',
176
-                    // @codingStandardsIgnoreEnd
177
-                    'Information text displayed in the venues metabox when there are no venues to display',
178
-                    'event_espresso'
179
-                );
180
-            }
181
-        }
182
-        $template_args['no_venues_info'] = EEH_HTML::p(
183
-            EEH_HTML::strong($no_venues_info_txt),
184
-            'no_venues_info',
185
-            'info'
186
-        );
187
-
188
-        $template_path = empty($venues) ? EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content.template.php'
189
-            : EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content_from_manager.template.php';
190
-
191
-        // Allow events venue metabox template args filtering.
192
-        $template_args = apply_filters(
193
-            'FHEE__espresso_events_Venues_Hooks___venue_metabox__template_args',
194
-            $template_args,
195
-            $template_path
196
-        );
197
-
198
-        EEH_Template::display_template($template_path, $template_args);
199
-    }
200
-
201
-
202
-    public function caf_venue_update($evtobj, $data)
203
-    {
204
-        EE_Registry::instance()->load_model('Venue');
205
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
206
-
207
-
208
-        // first let's check if the selected venue matches any existing venue attached to the event
209
-        $evt_venue = $evtobj->venues();
210
-        $evt_venue = ! empty($evt_venue) ? array_shift($evt_venue) : null;
211
-
212
-        if (! empty($evt_venue) && $evt_venue->ID() != $venue_id) {
213
-            $evtobj->_remove_relation_to($evt_venue->ID(), 'Venue');
214
-        }
215
-
216
-        if (empty($venue_id)) {
217
-            return true;
218
-        } //no venue to attach
219
-
220
-        // this should take care of adding to revisions as well as main post object
221
-        $success = $evtobj->_add_relation_to($venue_id, 'Venue');
222
-        return ! empty($success) ? true : false;
223
-    }
18
+	/**
19
+	 * @var EE_Event
20
+	 */
21
+	protected $_event;
22
+
23
+
24
+	public function __construct(EE_Admin_Page $admin_page)
25
+	{
26
+		parent::__construct($admin_page);
27
+	}
28
+
29
+
30
+	protected function _set_hooks_properties()
31
+	{
32
+		$this->_name = 'venues';
33
+		if ($this->_adminpage_obj->adminConfig()->useAdvancedEditor()) {
34
+			$this->_metaboxes      = [];
35
+			$this->_scripts_styles = [];
36
+			return;
37
+		}
38
+
39
+		$this->_metaboxes = array(
40
+			0 => array(
41
+				'page_route' => array('edit', 'create_new'),
42
+				'func'       => 'venue_metabox',
43
+				'label'      => __('Venue Details', 'event_espresso'),
44
+				'priority'   => 'high',
45
+				'context'    => 'normal',
46
+			),
47
+		);
48
+
49
+		$this->_scripts_styles = array(
50
+			'registers' => array(
51
+				'ee_event_venues'     => array(
52
+					'type'    => 'js',
53
+					'url'     => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.js',
54
+					'depends' => array('jquery'),
55
+				),
56
+				'ee_event_venues_css' => array(
57
+					'type' => 'css',
58
+					'url'  => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.css',
59
+				),
60
+			),
61
+			'enqueues'  => array(
62
+				'ee_event_venues'     => array('edit', 'create_new'),
63
+				'ee_event_venues_css' => array('edit', 'create_new'),
64
+			),
65
+		);
66
+
67
+		// hook into the handler for saving venue
68
+		add_filter(
69
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
+			array($this, 'modify_callbacks'),
71
+			10
72
+		);
73
+
74
+		// remove default ee_autosave returns for DECAF venues (not needed for CAF venues cause we have a dropdown selector)
75
+		add_filter('FHEE__Events_Admin_Page__ee_autosave_edit_do_decaf_venue_save', '__return_false');
76
+	}
77
+
78
+
79
+	public function modify_callbacks($callbacks)
80
+	{
81
+		// first remove default venue callback
82
+		unset($callbacks['_default_venue_update' ]);
83
+		// now let's add the caf version
84
+		$callbacks['caf_venue_update'] = array($this, 'caf_venue_update');
85
+		return $callbacks;
86
+	}
87
+
88
+
89
+	public function venue_metabox()
90
+	{
91
+		$evt_obj = $this->_adminpage_obj->get_event_object();
92
+		$evt_id = $evt_obj->ID();
93
+
94
+		// first let's see if we have a venue already
95
+		$evt_venues = ! empty($evt_id) ? $evt_obj->venues() : array();
96
+		$evt_venue = $evt_venues && is_array($evt_venues) ? reset($evt_venues) : null;
97
+		$evt_venue_id = $evt_venue instanceof EE_Venue ? $evt_venue->ID() : null;
98
+
99
+		// possibly private venues.
100
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
101
+			$vnu_where['status'] = array('IN', array('publish', 'private'));
102
+		} else {
103
+			$vnu_where['status'] = 'publish';
104
+		}
105
+
106
+		// cap checks
107
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
108
+			$vnu_where['VNU_wp_user'] = get_current_user_id();
109
+		}
110
+
111
+		$vnumdl = EE_Registry::instance()->load_model('Venue');
112
+		$venues = $vnumdl->get_all(array($vnu_where, 'order_by' => array('VNU_name' => 'ASC')));
113
+
114
+		$ven_select = array();
115
+		$ven_select[0] = __('Select a Venue', 'event_espresso');
116
+		// setup venues for selector
117
+		foreach ($venues as $venue) {
118
+			$ven_select[ $venue->ID() ] = $venue->name();
119
+		}
120
+
121
+		// if $ven_select does not have the existing venue attached to event then let's add that because we'll always
122
+		// show existing attached venues even if it's trashed (or some other restricted status).
123
+
124
+		if ($evt_venue_id && ! isset($ven_select[ $evt_venue_id ])) {
125
+			$ven_select[ $evt_venue_id ] = $evt_venue->name();
126
+			$venues = array_merge($venues, array($evt_venue));
127
+		}
128
+
129
+		$template_args['venues'] = $venues;
130
+		$template_args['evt_venue_id'] = $evt_venue_id;
131
+		$venue_selector = new EE_Select_Input(
132
+			$ven_select,
133
+			array(
134
+				'html_name'  => 'venue_id',
135
+				'html_id'    => 'venue_id',
136
+				'html_class' => 'wide',
137
+				'default'    => $evt_venue_id ? $evt_venue_id : '0'
138
+			)
139
+		);
140
+		$template_args['venue_selector'] = $venue_selector->get_html_for_input();
141
+		$enable_for_gmap = new EE_Yes_No_Input(
142
+			array(
143
+				'html_name'  => 'enable_for_gmap',
144
+				'html_id'    => 'enable_for_gmap',
145
+				'default'    => $evt_venue instanceof EE_Venue ? $evt_venue->enable_for_gmap() : false
146
+			)
147
+		);
148
+		$template_args['enable_for_gmap'] = $enable_for_gmap->get_html_for_input();
149
+		$template_args['new_venue_link'] = EEH_HTML::link(
150
+			EE_Admin_Page::add_query_args_and_nonce(
151
+				array('action' => 'create_new'),
152
+				EE_VENUES_ADMIN_URL
153
+			),
154
+			esc_html_x('Add new Venue', 'a link to add a new venue', 'event_espresso'),
155
+			esc_html_x('Add new Venue', 'a link to add a new venue', 'event_espresso'),
156
+			'ev_new_venue_link',
157
+			'button',
158
+			'margin-left:10px;',
159
+			'target="_blank"'
160
+		);
161
+
162
+		// Decide on an info text when there are no venues to display.
163
+		$no_venues_info_txt = esc_html_x(
164
+			'You have not created any venues yet.',
165
+			'Information text displayed in the venues metabox when there are no venues to display',
166
+			'event_espresso'
167
+		);
168
+		if (empty($venues)) {
169
+			$unpublished_where = $vnu_where;
170
+			$unpublished_where['status'] = 'draft';
171
+			$unpublished_venues = $vnumdl->get_all(array($unpublished_where, 'order_by' => array('VNU_name' => 'ASC')));
172
+			if (count($unpublished_venues) > 0) {
173
+				$no_venues_info_txt = esc_html_x(
174
+				// @codingStandardsIgnoreStart
175
+					'Use the link below to publish your venue through the venue editor so it appears here for selection.',
176
+					// @codingStandardsIgnoreEnd
177
+					'Information text displayed in the venues metabox when there are no venues to display',
178
+					'event_espresso'
179
+				);
180
+			}
181
+		}
182
+		$template_args['no_venues_info'] = EEH_HTML::p(
183
+			EEH_HTML::strong($no_venues_info_txt),
184
+			'no_venues_info',
185
+			'info'
186
+		);
187
+
188
+		$template_path = empty($venues) ? EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content.template.php'
189
+			: EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content_from_manager.template.php';
190
+
191
+		// Allow events venue metabox template args filtering.
192
+		$template_args = apply_filters(
193
+			'FHEE__espresso_events_Venues_Hooks___venue_metabox__template_args',
194
+			$template_args,
195
+			$template_path
196
+		);
197
+
198
+		EEH_Template::display_template($template_path, $template_args);
199
+	}
200
+
201
+
202
+	public function caf_venue_update($evtobj, $data)
203
+	{
204
+		EE_Registry::instance()->load_model('Venue');
205
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
206
+
207
+
208
+		// first let's check if the selected venue matches any existing venue attached to the event
209
+		$evt_venue = $evtobj->venues();
210
+		$evt_venue = ! empty($evt_venue) ? array_shift($evt_venue) : null;
211
+
212
+		if (! empty($evt_venue) && $evt_venue->ID() != $venue_id) {
213
+			$evtobj->_remove_relation_to($evt_venue->ID(), 'Venue');
214
+		}
215
+
216
+		if (empty($venue_id)) {
217
+			return true;
218
+		} //no venue to attach
219
+
220
+		// this should take care of adding to revisions as well as main post object
221
+		$success = $evtobj->_add_relation_to($venue_id, 'Venue');
222
+		return ! empty($success) ? true : false;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
             'registers' => array(
51 51
                 'ee_event_venues'     => array(
52 52
                     'type'    => 'js',
53
-                    'url'     => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.js',
53
+                    'url'     => EE_VENUES_ASSETS_URL.'ee-event-venues-admin.js',
54 54
                     'depends' => array('jquery'),
55 55
                 ),
56 56
                 'ee_event_venues_css' => array(
57 57
                     'type' => 'css',
58
-                    'url'  => EE_VENUES_ASSETS_URL . 'ee-event-venues-admin.css',
58
+                    'url'  => EE_VENUES_ASSETS_URL.'ee-event-venues-admin.css',
59 59
                 ),
60 60
             ),
61 61
             'enqueues'  => array(
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     public function modify_callbacks($callbacks)
80 80
     {
81 81
         // first remove default venue callback
82
-        unset($callbacks['_default_venue_update' ]);
82
+        unset($callbacks['_default_venue_update']);
83 83
         // now let's add the caf version
84 84
         $callbacks['caf_venue_update'] = array($this, 'caf_venue_update');
85 85
         return $callbacks;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         }
105 105
 
106 106
         // cap checks
107
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
107
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
108 108
             $vnu_where['VNU_wp_user'] = get_current_user_id();
109 109
         }
110 110
 
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
         $ven_select[0] = __('Select a Venue', 'event_espresso');
116 116
         // setup venues for selector
117 117
         foreach ($venues as $venue) {
118
-            $ven_select[ $venue->ID() ] = $venue->name();
118
+            $ven_select[$venue->ID()] = $venue->name();
119 119
         }
120 120
 
121 121
         // if $ven_select does not have the existing venue attached to event then let's add that because we'll always
122 122
         // show existing attached venues even if it's trashed (or some other restricted status).
123 123
 
124
-        if ($evt_venue_id && ! isset($ven_select[ $evt_venue_id ])) {
125
-            $ven_select[ $evt_venue_id ] = $evt_venue->name();
124
+        if ($evt_venue_id && ! isset($ven_select[$evt_venue_id])) {
125
+            $ven_select[$evt_venue_id] = $evt_venue->name();
126 126
             $venues = array_merge($venues, array($evt_venue));
127 127
         }
128 128
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         );
187 187
 
188 188
         $template_path = empty($venues) ? EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content.template.php'
189
-            : EE_VENUES_TEMPLATE_PATH . 'event_venues_metabox_content_from_manager.template.php';
189
+            : EE_VENUES_TEMPLATE_PATH.'event_venues_metabox_content_from_manager.template.php';
190 190
 
191 191
         // Allow events venue metabox template args filtering.
192 192
         $template_args = apply_filters(
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         $evt_venue = $evtobj->venues();
210 210
         $evt_venue = ! empty($evt_venue) ? array_shift($evt_venue) : null;
211 211
 
212
-        if (! empty($evt_venue) && $evt_venue->ID() != $venue_id) {
212
+        if ( ! empty($evt_venue) && $evt_venue->ID() != $venue_id) {
213 213
             $evtobj->_remove_relation_to($evt_venue->ID(), 'Venue');
214 214
         }
215 215
 
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 2 patches
Indentation   +2153 added lines, -2153 removed lines patch added patch discarded remove patch
@@ -15,2215 +15,2215 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (
52
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
53
-            || ! EE_Registry::instance()->CAP->current_user_can(
54
-                'ee_read_default_prices',
55
-                'advanced_ticket_datetime_metabox'
56
-            )
57
-        ) {
58
-            $this->_metaboxes      = [];
59
-            $this->_scripts_styles = [];
60
-            return;
61
-        }
62
-        $this->_setup_metaboxes();
63
-        $this->_set_date_time_formats();
64
-        $this->_validate_format_strings();
65
-        $this->_set_scripts_styles();
66
-        // commented out temporarily until logic is implemented in callback
67
-        // add_action(
68
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
69
-        //     array($this, 'autosave_handling')
70
-        // );
71
-        add_filter(
72
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
73
-            array($this, 'caf_updates')
74
-        );
75
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (
52
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
53
+			|| ! EE_Registry::instance()->CAP->current_user_can(
54
+				'ee_read_default_prices',
55
+				'advanced_ticket_datetime_metabox'
56
+			)
57
+		) {
58
+			$this->_metaboxes      = [];
59
+			$this->_scripts_styles = [];
60
+			return;
61
+		}
62
+		$this->_setup_metaboxes();
63
+		$this->_set_date_time_formats();
64
+		$this->_validate_format_strings();
65
+		$this->_set_scripts_styles();
66
+		// commented out temporarily until logic is implemented in callback
67
+		// add_action(
68
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
69
+		//     array($this, 'autosave_handling')
70
+		// );
71
+		add_filter(
72
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
73
+			array($this, 'caf_updates')
74
+		);
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @return void
80
-     */
81
-    protected function _setup_metaboxes()
82
-    {
83
-        // if we were going to add our own metaboxes we'd use the below.
84
-        $this->_metaboxes = array(
85
-            0 => array(
86
-                'page_route' => array('edit', 'create_new'),
87
-                'func'       => 'pricing_metabox',
88
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
89
-                'priority'   => 'high',
90
-                'context'    => 'normal',
91
-            ),
92
-        );
93
-        $this->_remove_metaboxes = array(
94
-            0 => array(
95
-                'page_route' => array('edit', 'create_new'),
96
-                'id'         => 'espresso_event_editor_tickets',
97
-                'context'    => 'normal',
98
-            ),
99
-        );
100
-    }
78
+	/**
79
+	 * @return void
80
+	 */
81
+	protected function _setup_metaboxes()
82
+	{
83
+		// if we were going to add our own metaboxes we'd use the below.
84
+		$this->_metaboxes = array(
85
+			0 => array(
86
+				'page_route' => array('edit', 'create_new'),
87
+				'func'       => 'pricing_metabox',
88
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
89
+				'priority'   => 'high',
90
+				'context'    => 'normal',
91
+			),
92
+		);
93
+		$this->_remove_metaboxes = array(
94
+			0 => array(
95
+				'page_route' => array('edit', 'create_new'),
96
+				'id'         => 'espresso_event_editor_tickets',
97
+				'context'    => 'normal',
98
+			),
99
+		);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * @return void
105
-     */
106
-    protected function _set_date_time_formats()
107
-    {
108
-        /**
109
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
110
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
111
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
112
-         *
113
-         * @since 4.6.7
114
-         * @var array  Expected an array returned with 'date' and 'time' keys.
115
-         */
116
-        $this->_date_format_strings = apply_filters(
117
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
118
-            array(
119
-                'date' => 'Y-m-d',
120
-                'time' => 'h:i a',
121
-            )
122
-        );
123
-        // validate
124
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
125
-            ? $this->_date_format_strings['date']
126
-            : null;
127
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
128
-            ? $this->_date_format_strings['time']
129
-            : null;
130
-        $this->_date_time_format = $this->_date_format_strings['date']
131
-                                   . ' '
132
-                                   . $this->_date_format_strings['time'];
133
-    }
103
+	/**
104
+	 * @return void
105
+	 */
106
+	protected function _set_date_time_formats()
107
+	{
108
+		/**
109
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
110
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
111
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
112
+		 *
113
+		 * @since 4.6.7
114
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
115
+		 */
116
+		$this->_date_format_strings = apply_filters(
117
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
118
+			array(
119
+				'date' => 'Y-m-d',
120
+				'time' => 'h:i a',
121
+			)
122
+		);
123
+		// validate
124
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
125
+			? $this->_date_format_strings['date']
126
+			: null;
127
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
128
+			? $this->_date_format_strings['time']
129
+			: null;
130
+		$this->_date_time_format = $this->_date_format_strings['date']
131
+								   . ' '
132
+								   . $this->_date_format_strings['time'];
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * @return void
138
-     */
139
-    protected function _validate_format_strings()
140
-    {
141
-        // validate format strings
142
-        $format_validation = EEH_DTT_Helper::validate_format_string(
143
-            $this->_date_time_format
144
-        );
145
-        if (is_array($format_validation)) {
146
-            $msg = '<p>';
147
-            $msg .= sprintf(
148
-                esc_html__(
149
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
150
-                    'event_espresso'
151
-                ),
152
-                $this->_date_time_format
153
-            );
154
-            $msg .= '</p><ul>';
155
-            foreach ($format_validation as $error) {
156
-                $msg .= '<li>' . $error . '</li>';
157
-            }
158
-            $msg .= '</ul><p>';
159
-            $msg .= sprintf(
160
-                esc_html__(
161
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
162
-                    'event_espresso'
163
-                ),
164
-                '<span style="color:#D54E21;">',
165
-                '</span>'
166
-            );
167
-            $msg .= '</p>';
168
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
169
-            $this->_date_format_strings = array(
170
-                'date' => 'Y-m-d',
171
-                'time' => 'h:i a',
172
-            );
173
-        }
174
-    }
136
+	/**
137
+	 * @return void
138
+	 */
139
+	protected function _validate_format_strings()
140
+	{
141
+		// validate format strings
142
+		$format_validation = EEH_DTT_Helper::validate_format_string(
143
+			$this->_date_time_format
144
+		);
145
+		if (is_array($format_validation)) {
146
+			$msg = '<p>';
147
+			$msg .= sprintf(
148
+				esc_html__(
149
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
150
+					'event_espresso'
151
+				),
152
+				$this->_date_time_format
153
+			);
154
+			$msg .= '</p><ul>';
155
+			foreach ($format_validation as $error) {
156
+				$msg .= '<li>' . $error . '</li>';
157
+			}
158
+			$msg .= '</ul><p>';
159
+			$msg .= sprintf(
160
+				esc_html__(
161
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
162
+					'event_espresso'
163
+				),
164
+				'<span style="color:#D54E21;">',
165
+				'</span>'
166
+			);
167
+			$msg .= '</p>';
168
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
169
+			$this->_date_format_strings = array(
170
+				'date' => 'Y-m-d',
171
+				'time' => 'h:i a',
172
+			);
173
+		}
174
+	}
175 175
 
176 176
 
177
-    /**
178
-     * @return void
179
-     */
180
-    protected function _set_scripts_styles()
181
-    {
182
-        $this->_scripts_styles = array(
183
-            'registers'   => array(
184
-                'ee-tickets-datetimes-css' => array(
185
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
186
-                    'type' => 'css',
187
-                ),
188
-                'ee-dtt-ticket-metabox'    => array(
189
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
190
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
191
-                ),
192
-            ),
193
-            'deregisters' => array(
194
-                'event-editor-css'       => array('type' => 'css'),
195
-                'event-datetime-metabox' => array('type' => 'js'),
196
-            ),
197
-            'enqueues'    => array(
198
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
199
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
200
-            ),
201
-            'localize'    => array(
202
-                'ee-dtt-ticket-metabox' => array(
203
-                    'DTT_TRASH_BLOCK'       => array(
204
-                        'main_warning'            => esc_html__(
205
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
206
-                            'event_espresso'
207
-                        ),
208
-                        'after_warning'           => esc_html__(
209
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
210
-                            'event_espresso'
211
-                        ),
212
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
213
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
214
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
215
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
216
-                        'single_warning_from_tkt' => esc_html__(
217
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
218
-                            'event_espresso'
219
-                        ),
220
-                        'single_warning_from_dtt' => esc_html__(
221
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
222
-                            'event_espresso'
223
-                        ),
224
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
225
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
226
-                    ),
227
-                    'DTT_ERROR_MSG'         => array(
228
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
229
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
230
-                                            . '<button class="button-secondary ee-modal-cancel">'
231
-                                            . esc_html__('Dismiss', 'event_espresso')
232
-                                            . '</button></div>',
233
-                    ),
234
-                    'DTT_OVERSELL_WARNING'  => array(
235
-                        'datetime_ticket' => esc_html__(
236
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
237
-                            'event_espresso'
238
-                        ),
239
-                        'ticket_datetime' => esc_html__(
240
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
241
-                            'event_espresso'
242
-                        ),
243
-                    ),
244
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
245
-                        $this->_date_format_strings['date'],
246
-                        $this->_date_format_strings['time']
247
-                    ),
248
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
249
-                ),
250
-            ),
251
-        );
252
-    }
177
+	/**
178
+	 * @return void
179
+	 */
180
+	protected function _set_scripts_styles()
181
+	{
182
+		$this->_scripts_styles = array(
183
+			'registers'   => array(
184
+				'ee-tickets-datetimes-css' => array(
185
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
186
+					'type' => 'css',
187
+				),
188
+				'ee-dtt-ticket-metabox'    => array(
189
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
190
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
191
+				),
192
+			),
193
+			'deregisters' => array(
194
+				'event-editor-css'       => array('type' => 'css'),
195
+				'event-datetime-metabox' => array('type' => 'js'),
196
+			),
197
+			'enqueues'    => array(
198
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
199
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
200
+			),
201
+			'localize'    => array(
202
+				'ee-dtt-ticket-metabox' => array(
203
+					'DTT_TRASH_BLOCK'       => array(
204
+						'main_warning'            => esc_html__(
205
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
206
+							'event_espresso'
207
+						),
208
+						'after_warning'           => esc_html__(
209
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
210
+							'event_espresso'
211
+						),
212
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
213
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
214
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
215
+													 . esc_html__('Close', 'event_espresso') . '</button>',
216
+						'single_warning_from_tkt' => esc_html__(
217
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
218
+							'event_espresso'
219
+						),
220
+						'single_warning_from_dtt' => esc_html__(
221
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
222
+							'event_espresso'
223
+						),
224
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
225
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
226
+					),
227
+					'DTT_ERROR_MSG'         => array(
228
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
229
+						'dismiss_button' => '<div class="save-cancel-button-container">'
230
+											. '<button class="button-secondary ee-modal-cancel">'
231
+											. esc_html__('Dismiss', 'event_espresso')
232
+											. '</button></div>',
233
+					),
234
+					'DTT_OVERSELL_WARNING'  => array(
235
+						'datetime_ticket' => esc_html__(
236
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
237
+							'event_espresso'
238
+						),
239
+						'ticket_datetime' => esc_html__(
240
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
241
+							'event_espresso'
242
+						),
243
+					),
244
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
245
+						$this->_date_format_strings['date'],
246
+						$this->_date_format_strings['time']
247
+					),
248
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
249
+				),
250
+			),
251
+		);
252
+	}
253 253
 
254 254
 
255
-    /**
256
-     * @param array $update_callbacks
257
-     * @return array
258
-     */
259
-    public function caf_updates(array $update_callbacks)
260
-    {
261
-        unset($update_callbacks['_default_tickets_update']);
262
-        $update_callbacks['datetime_and_tickets_caf_update'] = array($this, 'datetime_and_tickets_caf_update');
263
-        return $update_callbacks;
264
-    }
255
+	/**
256
+	 * @param array $update_callbacks
257
+	 * @return array
258
+	 */
259
+	public function caf_updates(array $update_callbacks)
260
+	{
261
+		unset($update_callbacks['_default_tickets_update']);
262
+		$update_callbacks['datetime_and_tickets_caf_update'] = array($this, 'datetime_and_tickets_caf_update');
263
+		return $update_callbacks;
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
-     *
270
-     * @param  EE_Event $event The Event object we're attaching data to
271
-     * @param  array    $data  The request data from the form
272
-     * @throws ReflectionException
273
-     * @throws Exception
274
-     * @throws InvalidInterfaceException
275
-     * @throws InvalidDataTypeException
276
-     * @throws EE_Error
277
-     * @throws InvalidArgumentException
278
-     */
279
-    public function datetime_and_tickets_caf_update($event, $data)
280
-    {
281
-        // first we need to start with datetimes cause they are the "root" items attached to events.
282
-        $saved_datetimes = $this->_update_datetimes($event, $data);
283
-        // next tackle the tickets (and prices?)
284
-        $this->_update_tickets($event, $saved_datetimes, $data);
285
-    }
267
+	/**
268
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
+	 *
270
+	 * @param  EE_Event $event The Event object we're attaching data to
271
+	 * @param  array    $data  The request data from the form
272
+	 * @throws ReflectionException
273
+	 * @throws Exception
274
+	 * @throws InvalidInterfaceException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws EE_Error
277
+	 * @throws InvalidArgumentException
278
+	 */
279
+	public function datetime_and_tickets_caf_update($event, $data)
280
+	{
281
+		// first we need to start with datetimes cause they are the "root" items attached to events.
282
+		$saved_datetimes = $this->_update_datetimes($event, $data);
283
+		// next tackle the tickets (and prices?)
284
+		$this->_update_tickets($event, $saved_datetimes, $data);
285
+	}
286 286
 
287 287
 
288
-    /**
289
-     * update event_datetimes
290
-     *
291
-     * @param  EE_Event $event Event being updated
292
-     * @param  array    $data  the request data from the form
293
-     * @return EE_Datetime[]
294
-     * @throws Exception
295
-     * @throws ReflectionException
296
-     * @throws InvalidInterfaceException
297
-     * @throws InvalidDataTypeException
298
-     * @throws InvalidArgumentException
299
-     * @throws EE_Error
300
-     */
301
-    protected function _update_datetimes($event, $data)
302
-    {
303
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
-        $saved_dtt_ids = array();
305
-        $saved_dtt_objs = array();
306
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
-            throw new InvalidArgumentException(
308
-                esc_html__(
309
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
-                    'event_espresso'
311
-                )
312
-            );
313
-        }
314
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
-            // trim all values to ensure any excess whitespace is removed.
316
-            $datetime_data = array_map(
317
-                function ($datetime_data) {
318
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
-                },
320
-                $datetime_data
321
-            );
322
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
-                                            && ! empty($datetime_data['DTT_EVT_end'])
324
-                ? $datetime_data['DTT_EVT_end']
325
-                : $datetime_data['DTT_EVT_start'];
326
-            $datetime_values = array(
327
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
-                    ? $datetime_data['DTT_ID']
329
-                    : null,
330
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
-                    ? $datetime_data['DTT_name']
332
-                    : '',
333
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
334
-                    ? $datetime_data['DTT_description']
335
-                    : '',
336
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
-                    ? EE_INF
340
-                    : $datetime_data['DTT_reg_limit'],
341
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
-                    ? $row
343
-                    : $datetime_data['DTT_order'],
344
-            );
345
-            // if we have an id then let's get existing object first and then set the new values.
346
-            // Otherwise we instantiate a new object for save.
347
-            if (! empty($datetime_data['DTT_ID'])) {
348
-                $datetime = EE_Registry::instance()
349
-                                       ->load_model('Datetime', array($timezone))
350
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
351
-                // set date and time format according to what is set in this class.
352
-                $datetime->set_date_format($this->_date_format_strings['date']);
353
-                $datetime->set_time_format($this->_date_format_strings['time']);
354
-                foreach ($datetime_values as $field => $value) {
355
-                    $datetime->set($field, $value);
356
-                }
357
-                // make sure the $dtt_id here is saved just in case
358
-                // after the add_relation_to() the autosave replaces it.
359
-                // We need to do this so we dont' TRASH the parent DTT.
360
-                // (save the ID for both key and value to avoid duplications)
361
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
-            } else {
363
-                $datetime = EE_Registry::instance()->load_class(
364
-                    'Datetime',
365
-                    array(
366
-                        $datetime_values,
367
-                        $timezone,
368
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
-                    ),
370
-                    false,
371
-                    false
372
-                );
373
-                foreach ($datetime_values as $field => $value) {
374
-                    $datetime->set($field, $value);
375
-                }
376
-            }
377
-            $datetime->save();
378
-            do_action(
379
-                'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
-                $datetime,
381
-                $row,
382
-                $datetime_data,
383
-                $data
384
-            );
385
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
386
-            // before going any further make sure our dates are setup correctly
387
-            // so that the end date is always equal or greater than the start date.
388
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
-                $datetime->save();
392
-            }
393
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
-            // because it is possible there was a new one created for the autosave.
395
-            // (save the ID for both key and value to avoid duplications)
396
-            $DTT_ID = $datetime->ID();
397
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
-            $saved_dtt_objs[ $row ] = $datetime;
399
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
400
-        }
401
-        $event->save();
402
-        // now we need to REMOVE any datetimes that got deleted.
403
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
-        // So its safe to permanently delete at this point.
405
-        $old_datetimes = explode(',', $data['datetime_IDs']);
406
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
-        if (is_array($old_datetimes)) {
408
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
-            foreach ($datetimes_to_delete as $id) {
410
-                $id = absint($id);
411
-                if (empty($id)) {
412
-                    continue;
413
-                }
414
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
415
-                // remove tkt relationships.
416
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
417
-                foreach ($related_tickets as $tkt) {
418
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
419
-                }
420
-                $event->_remove_relation_to($id, 'Datetime');
421
-                $dtt_to_remove->refresh_cache_of_related_objects();
422
-            }
423
-        }
424
-        return $saved_dtt_objs;
425
-    }
288
+	/**
289
+	 * update event_datetimes
290
+	 *
291
+	 * @param  EE_Event $event Event being updated
292
+	 * @param  array    $data  the request data from the form
293
+	 * @return EE_Datetime[]
294
+	 * @throws Exception
295
+	 * @throws ReflectionException
296
+	 * @throws InvalidInterfaceException
297
+	 * @throws InvalidDataTypeException
298
+	 * @throws InvalidArgumentException
299
+	 * @throws EE_Error
300
+	 */
301
+	protected function _update_datetimes($event, $data)
302
+	{
303
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
+		$saved_dtt_ids = array();
305
+		$saved_dtt_objs = array();
306
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
+			throw new InvalidArgumentException(
308
+				esc_html__(
309
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
+					'event_espresso'
311
+				)
312
+			);
313
+		}
314
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
+			// trim all values to ensure any excess whitespace is removed.
316
+			$datetime_data = array_map(
317
+				function ($datetime_data) {
318
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
+				},
320
+				$datetime_data
321
+			);
322
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
+											&& ! empty($datetime_data['DTT_EVT_end'])
324
+				? $datetime_data['DTT_EVT_end']
325
+				: $datetime_data['DTT_EVT_start'];
326
+			$datetime_values = array(
327
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
+					? $datetime_data['DTT_ID']
329
+					: null,
330
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
+					? $datetime_data['DTT_name']
332
+					: '',
333
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
334
+					? $datetime_data['DTT_description']
335
+					: '',
336
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
+					? EE_INF
340
+					: $datetime_data['DTT_reg_limit'],
341
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
+					? $row
343
+					: $datetime_data['DTT_order'],
344
+			);
345
+			// if we have an id then let's get existing object first and then set the new values.
346
+			// Otherwise we instantiate a new object for save.
347
+			if (! empty($datetime_data['DTT_ID'])) {
348
+				$datetime = EE_Registry::instance()
349
+									   ->load_model('Datetime', array($timezone))
350
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
351
+				// set date and time format according to what is set in this class.
352
+				$datetime->set_date_format($this->_date_format_strings['date']);
353
+				$datetime->set_time_format($this->_date_format_strings['time']);
354
+				foreach ($datetime_values as $field => $value) {
355
+					$datetime->set($field, $value);
356
+				}
357
+				// make sure the $dtt_id here is saved just in case
358
+				// after the add_relation_to() the autosave replaces it.
359
+				// We need to do this so we dont' TRASH the parent DTT.
360
+				// (save the ID for both key and value to avoid duplications)
361
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
+			} else {
363
+				$datetime = EE_Registry::instance()->load_class(
364
+					'Datetime',
365
+					array(
366
+						$datetime_values,
367
+						$timezone,
368
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
+					),
370
+					false,
371
+					false
372
+				);
373
+				foreach ($datetime_values as $field => $value) {
374
+					$datetime->set($field, $value);
375
+				}
376
+			}
377
+			$datetime->save();
378
+			do_action(
379
+				'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
+				$datetime,
381
+				$row,
382
+				$datetime_data,
383
+				$data
384
+			);
385
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
386
+			// before going any further make sure our dates are setup correctly
387
+			// so that the end date is always equal or greater than the start date.
388
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
+				$datetime->save();
392
+			}
393
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
+			// because it is possible there was a new one created for the autosave.
395
+			// (save the ID for both key and value to avoid duplications)
396
+			$DTT_ID = $datetime->ID();
397
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
+			$saved_dtt_objs[ $row ] = $datetime;
399
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
400
+		}
401
+		$event->save();
402
+		// now we need to REMOVE any datetimes that got deleted.
403
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
+		// So its safe to permanently delete at this point.
405
+		$old_datetimes = explode(',', $data['datetime_IDs']);
406
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
+		if (is_array($old_datetimes)) {
408
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
+			foreach ($datetimes_to_delete as $id) {
410
+				$id = absint($id);
411
+				if (empty($id)) {
412
+					continue;
413
+				}
414
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
415
+				// remove tkt relationships.
416
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
417
+				foreach ($related_tickets as $tkt) {
418
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
419
+				}
420
+				$event->_remove_relation_to($id, 'Datetime');
421
+				$dtt_to_remove->refresh_cache_of_related_objects();
422
+			}
423
+		}
424
+		return $saved_dtt_objs;
425
+	}
426 426
 
427 427
 
428
-    /**
429
-     * update tickets
430
-     *
431
-     * @param  EE_Event      $event           Event object being updated
432
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
433
-     * @param  array         $data            incoming request data
434
-     * @return EE_Ticket[]
435
-     * @throws Exception
436
-     * @throws ReflectionException
437
-     * @throws InvalidInterfaceException
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidArgumentException
440
-     * @throws EE_Error
441
-     */
442
-    protected function _update_tickets($event, $saved_datetimes, $data)
443
-    {
444
-        $new_tkt = null;
445
-        $new_default = null;
446
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
447
-        $data = stripslashes_deep($data);
448
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
449
-        $saved_tickets = $datetimes_on_existing = array();
450
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
451
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
452
-            throw new InvalidArgumentException(
453
-                esc_html__(
454
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
455
-                    'event_espresso'
456
-                )
457
-            );
458
-        }
459
-        foreach ($data['edit_tickets'] as $row => $tkt) {
460
-            $update_prices = $create_new_TKT = false;
461
-            // figure out what datetimes were added to the ticket
462
-            // and what datetimes were removed from the ticket in the session.
463
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
464
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
465
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
466
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
467
-            // trim inputs to ensure any excess whitespace is removed.
468
-            $tkt = array_map(
469
-                function ($ticket_data) {
470
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
471
-                },
472
-                $tkt
473
-            );
474
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
475
-            // because we're doing calculations prior to using the models.
476
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
477
-            $ticket_price = isset($tkt['TKT_price'])
478
-                ? round((float) $tkt['TKT_price'], 3)
479
-                : 0;
480
-            // note incoming base price needs converted from localized value.
481
-            $base_price = isset($tkt['TKT_base_price'])
482
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
483
-                : 0;
484
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
485
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
486
-                ? $base_price
487
-                : $ticket_price;
488
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
489
-                ? $tkt['TKT_base_price_ID']
490
-                : 0;
491
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
492
-                ? $data['edit_prices'][ $row ]
493
-                : array();
494
-            $now = null;
495
-            if (empty($tkt['TKT_start_date'])) {
496
-                // lets' use now in the set timezone.
497
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
498
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
499
-            }
500
-            if (empty($tkt['TKT_end_date'])) {
501
-                /**
502
-                 * set the TKT_end_date to the first datetime attached to the ticket.
503
-                 */
504
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
505
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
506
-            }
507
-            $TKT_values = array(
508
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
509
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
510
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
511
-                'TKT_description' => ! empty($tkt['TKT_description'])
512
-                                     && $tkt['TKT_description'] !== esc_html__(
513
-                                         'You can modify this description',
514
-                                         'event_espresso'
515
-                                     )
516
-                    ? $tkt['TKT_description']
517
-                    : '',
518
-                'TKT_start_date'  => $tkt['TKT_start_date'],
519
-                'TKT_end_date'    => $tkt['TKT_end_date'],
520
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
521
-                    ? EE_INF
522
-                    : $tkt['TKT_qty'],
523
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
524
-                    ? EE_INF
525
-                    : $tkt['TKT_uses'],
526
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
527
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
528
-                'TKT_row'         => $row,
529
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
530
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
531
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
532
-                'TKT_price'       => $ticket_price,
533
-            );
534
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
535
-            // which means in turn that the prices will become new prices as well.
536
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
537
-                $TKT_values['TKT_ID'] = 0;
538
-                $TKT_values['TKT_is_default'] = 0;
539
-                $update_prices = true;
540
-            }
541
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
542
-            // we actually do our saves ahead of doing any add_relations to
543
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
544
-            // but DID have it's items modified.
545
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
546
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
547
-            if (absint($TKT_values['TKT_ID'])) {
548
-                $ticket = EE_Registry::instance()
549
-                                     ->load_model('Ticket', array($timezone))
550
-                                     ->get_one_by_ID($tkt['TKT_ID']);
551
-                if ($ticket instanceof EE_Ticket) {
552
-                    $ticket = $this->_update_ticket_datetimes(
553
-                        $ticket,
554
-                        $saved_datetimes,
555
-                        $datetimes_added,
556
-                        $datetimes_removed
557
-                    );
558
-                    // are there any registrations using this ticket ?
559
-                    $tickets_sold = $ticket->count_related(
560
-                        'Registration',
561
-                        array(
562
-                            array(
563
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
564
-                            ),
565
-                        )
566
-                    );
567
-                    // set ticket formats
568
-                    $ticket->set_date_format($this->_date_format_strings['date']);
569
-                    $ticket->set_time_format($this->_date_format_strings['time']);
570
-                    // let's just check the total price for the existing ticket
571
-                    // and determine if it matches the new total price.
572
-                    // if they are different then we create a new ticket (if tickets sold)
573
-                    // if they aren't different then we go ahead and modify existing ticket.
574
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
575
-                    // set new values
576
-                    foreach ($TKT_values as $field => $value) {
577
-                        if ($field === 'TKT_qty') {
578
-                            $ticket->set_qty($value);
579
-                        } else {
580
-                            $ticket->set($field, $value);
581
-                        }
582
-                    }
583
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
584
-                    // Otherwise we have to create a new ticket.
585
-                    if ($create_new_TKT) {
586
-                        $new_tkt = $this->_duplicate_ticket(
587
-                            $ticket,
588
-                            $price_rows,
589
-                            $ticket_price,
590
-                            $base_price,
591
-                            $base_price_id
592
-                        );
593
-                    }
594
-                }
595
-            } else {
596
-                // no TKT_id so a new TKT
597
-                $ticket = EE_Ticket::new_instance(
598
-                    $TKT_values,
599
-                    $timezone,
600
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
601
-                );
602
-                if ($ticket instanceof EE_Ticket) {
603
-                    // make sure ticket has an ID of setting relations won't work
604
-                    $ticket->save();
605
-                    $ticket = $this->_update_ticket_datetimes(
606
-                        $ticket,
607
-                        $saved_datetimes,
608
-                        $datetimes_added,
609
-                        $datetimes_removed
610
-                    );
611
-                    $update_prices = true;
612
-                }
613
-            }
614
-            // make sure any current values have been saved.
615
-            // $ticket->save();
616
-            // before going any further make sure our dates are setup correctly
617
-            // so that the end date is always equal or greater than the start date.
618
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
619
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
620
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
621
-            }
622
-            // let's make sure the base price is handled
623
-            $ticket = ! $create_new_TKT
624
-                ? $this->_add_prices_to_ticket(
625
-                    array(),
626
-                    $ticket,
627
-                    $update_prices,
628
-                    $base_price,
629
-                    $base_price_id
630
-                )
631
-                : $ticket;
632
-            // add/update price_modifiers
633
-            $ticket = ! $create_new_TKT
634
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
635
-                : $ticket;
636
-            // need to make sue that the TKT_price is accurate after saving the prices.
637
-            $ticket->ensure_TKT_Price_correct();
638
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
639
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
640
-                $update_prices = true;
641
-                $new_default = clone $ticket;
642
-                $new_default->set('TKT_ID', 0);
643
-                $new_default->set('TKT_is_default', 1);
644
-                $new_default->set('TKT_row', 1);
645
-                $new_default->set('TKT_price', $ticket_price);
646
-                // remove any dtt relations cause we DON'T want dtt relations attached
647
-                // (note this is just removing the cached relations in the object)
648
-                $new_default->_remove_relations('Datetime');
649
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
650
-                $new_default = $this->_add_prices_to_ticket(
651
-                    $price_rows,
652
-                    $new_default,
653
-                    $update_prices
654
-                );
655
-                // don't forget the base price!
656
-                $new_default = $this->_add_prices_to_ticket(
657
-                    array(),
658
-                    $new_default,
659
-                    $update_prices,
660
-                    $base_price,
661
-                    $base_price_id
662
-                );
663
-                $new_default->save();
664
-                do_action(
665
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
666
-                    $new_default,
667
-                    $row,
668
-                    $ticket,
669
-                    $data
670
-                );
671
-            }
672
-            // DO ALL dtt relationships for both current tickets and any archived tickets
673
-            // for the given dtt that are related to the current ticket.
674
-            // TODO... not sure exactly how we're going to do this considering we don't know
675
-            // what current ticket the archived tickets are related to
676
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
677
-            // let's assign any tickets that have been setup to the saved_tickets tracker
678
-            // save existing TKT
679
-            $ticket->save();
680
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
681
-                // save new TKT
682
-                $new_tkt->save();
683
-                // add new ticket to array
684
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
685
-                do_action(
686
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
687
-                    $new_tkt,
688
-                    $row,
689
-                    $tkt,
690
-                    $data
691
-                );
692
-            } else {
693
-                // add tkt to saved tkts
694
-                $saved_tickets[ $ticket->ID() ] = $ticket;
695
-                do_action(
696
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
697
-                    $ticket,
698
-                    $row,
699
-                    $tkt,
700
-                    $data
701
-                );
702
-            }
703
-        }
704
-        // now we need to handle tickets actually "deleted permanently".
705
-        // There are cases where we'd want this to happen
706
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
707
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
708
-        // No sense in keeping all the related data in the db!
709
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
710
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
711
-        foreach ($tickets_removed as $id) {
712
-            $id = absint($id);
713
-            // get the ticket for this id
714
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
715
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
716
-            if ($tkt_to_remove->get('TKT_is_default')) {
717
-                continue;
718
-            }
719
-            // if this tkt has any registrations attached so then we just ARCHIVE
720
-            // because we don't actually permanently delete these tickets.
721
-            if ($tkt_to_remove->count_related('Registration') > 0) {
722
-                $tkt_to_remove->delete();
723
-                continue;
724
-            }
725
-            // need to get all the related datetimes on this ticket and remove from every single one of them
726
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
727
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
728
-            foreach ($datetimes as $datetime) {
729
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
730
-            }
731
-            // need to do the same for prices (except these prices can also be deleted because again,
732
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
733
-            $tkt_to_remove->delete_related_permanently('Price');
734
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
735
-            // finally let's delete this ticket
736
-            // (which should not be blocked at this point b/c we've removed all our relationships)
737
-            $tkt_to_remove->delete_permanently();
738
-        }
739
-        return $saved_tickets;
740
-    }
428
+	/**
429
+	 * update tickets
430
+	 *
431
+	 * @param  EE_Event      $event           Event object being updated
432
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
433
+	 * @param  array         $data            incoming request data
434
+	 * @return EE_Ticket[]
435
+	 * @throws Exception
436
+	 * @throws ReflectionException
437
+	 * @throws InvalidInterfaceException
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidArgumentException
440
+	 * @throws EE_Error
441
+	 */
442
+	protected function _update_tickets($event, $saved_datetimes, $data)
443
+	{
444
+		$new_tkt = null;
445
+		$new_default = null;
446
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
447
+		$data = stripslashes_deep($data);
448
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
449
+		$saved_tickets = $datetimes_on_existing = array();
450
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
451
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
452
+			throw new InvalidArgumentException(
453
+				esc_html__(
454
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
455
+					'event_espresso'
456
+				)
457
+			);
458
+		}
459
+		foreach ($data['edit_tickets'] as $row => $tkt) {
460
+			$update_prices = $create_new_TKT = false;
461
+			// figure out what datetimes were added to the ticket
462
+			// and what datetimes were removed from the ticket in the session.
463
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
464
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
465
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
466
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
467
+			// trim inputs to ensure any excess whitespace is removed.
468
+			$tkt = array_map(
469
+				function ($ticket_data) {
470
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
471
+				},
472
+				$tkt
473
+			);
474
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
475
+			// because we're doing calculations prior to using the models.
476
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
477
+			$ticket_price = isset($tkt['TKT_price'])
478
+				? round((float) $tkt['TKT_price'], 3)
479
+				: 0;
480
+			// note incoming base price needs converted from localized value.
481
+			$base_price = isset($tkt['TKT_base_price'])
482
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
483
+				: 0;
484
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
485
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
486
+				? $base_price
487
+				: $ticket_price;
488
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
489
+				? $tkt['TKT_base_price_ID']
490
+				: 0;
491
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
492
+				? $data['edit_prices'][ $row ]
493
+				: array();
494
+			$now = null;
495
+			if (empty($tkt['TKT_start_date'])) {
496
+				// lets' use now in the set timezone.
497
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
498
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
499
+			}
500
+			if (empty($tkt['TKT_end_date'])) {
501
+				/**
502
+				 * set the TKT_end_date to the first datetime attached to the ticket.
503
+				 */
504
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
505
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
506
+			}
507
+			$TKT_values = array(
508
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
509
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
510
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
511
+				'TKT_description' => ! empty($tkt['TKT_description'])
512
+									 && $tkt['TKT_description'] !== esc_html__(
513
+										 'You can modify this description',
514
+										 'event_espresso'
515
+									 )
516
+					? $tkt['TKT_description']
517
+					: '',
518
+				'TKT_start_date'  => $tkt['TKT_start_date'],
519
+				'TKT_end_date'    => $tkt['TKT_end_date'],
520
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
521
+					? EE_INF
522
+					: $tkt['TKT_qty'],
523
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
524
+					? EE_INF
525
+					: $tkt['TKT_uses'],
526
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
527
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
528
+				'TKT_row'         => $row,
529
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
530
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
531
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
532
+				'TKT_price'       => $ticket_price,
533
+			);
534
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
535
+			// which means in turn that the prices will become new prices as well.
536
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
537
+				$TKT_values['TKT_ID'] = 0;
538
+				$TKT_values['TKT_is_default'] = 0;
539
+				$update_prices = true;
540
+			}
541
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
542
+			// we actually do our saves ahead of doing any add_relations to
543
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
544
+			// but DID have it's items modified.
545
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
546
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
547
+			if (absint($TKT_values['TKT_ID'])) {
548
+				$ticket = EE_Registry::instance()
549
+									 ->load_model('Ticket', array($timezone))
550
+									 ->get_one_by_ID($tkt['TKT_ID']);
551
+				if ($ticket instanceof EE_Ticket) {
552
+					$ticket = $this->_update_ticket_datetimes(
553
+						$ticket,
554
+						$saved_datetimes,
555
+						$datetimes_added,
556
+						$datetimes_removed
557
+					);
558
+					// are there any registrations using this ticket ?
559
+					$tickets_sold = $ticket->count_related(
560
+						'Registration',
561
+						array(
562
+							array(
563
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
564
+							),
565
+						)
566
+					);
567
+					// set ticket formats
568
+					$ticket->set_date_format($this->_date_format_strings['date']);
569
+					$ticket->set_time_format($this->_date_format_strings['time']);
570
+					// let's just check the total price for the existing ticket
571
+					// and determine if it matches the new total price.
572
+					// if they are different then we create a new ticket (if tickets sold)
573
+					// if they aren't different then we go ahead and modify existing ticket.
574
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
575
+					// set new values
576
+					foreach ($TKT_values as $field => $value) {
577
+						if ($field === 'TKT_qty') {
578
+							$ticket->set_qty($value);
579
+						} else {
580
+							$ticket->set($field, $value);
581
+						}
582
+					}
583
+					// if $create_new_TKT is false then we can safely update the existing ticket.
584
+					// Otherwise we have to create a new ticket.
585
+					if ($create_new_TKT) {
586
+						$new_tkt = $this->_duplicate_ticket(
587
+							$ticket,
588
+							$price_rows,
589
+							$ticket_price,
590
+							$base_price,
591
+							$base_price_id
592
+						);
593
+					}
594
+				}
595
+			} else {
596
+				// no TKT_id so a new TKT
597
+				$ticket = EE_Ticket::new_instance(
598
+					$TKT_values,
599
+					$timezone,
600
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
601
+				);
602
+				if ($ticket instanceof EE_Ticket) {
603
+					// make sure ticket has an ID of setting relations won't work
604
+					$ticket->save();
605
+					$ticket = $this->_update_ticket_datetimes(
606
+						$ticket,
607
+						$saved_datetimes,
608
+						$datetimes_added,
609
+						$datetimes_removed
610
+					);
611
+					$update_prices = true;
612
+				}
613
+			}
614
+			// make sure any current values have been saved.
615
+			// $ticket->save();
616
+			// before going any further make sure our dates are setup correctly
617
+			// so that the end date is always equal or greater than the start date.
618
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
619
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
620
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
621
+			}
622
+			// let's make sure the base price is handled
623
+			$ticket = ! $create_new_TKT
624
+				? $this->_add_prices_to_ticket(
625
+					array(),
626
+					$ticket,
627
+					$update_prices,
628
+					$base_price,
629
+					$base_price_id
630
+				)
631
+				: $ticket;
632
+			// add/update price_modifiers
633
+			$ticket = ! $create_new_TKT
634
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
635
+				: $ticket;
636
+			// need to make sue that the TKT_price is accurate after saving the prices.
637
+			$ticket->ensure_TKT_Price_correct();
638
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
639
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
640
+				$update_prices = true;
641
+				$new_default = clone $ticket;
642
+				$new_default->set('TKT_ID', 0);
643
+				$new_default->set('TKT_is_default', 1);
644
+				$new_default->set('TKT_row', 1);
645
+				$new_default->set('TKT_price', $ticket_price);
646
+				// remove any dtt relations cause we DON'T want dtt relations attached
647
+				// (note this is just removing the cached relations in the object)
648
+				$new_default->_remove_relations('Datetime');
649
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
650
+				$new_default = $this->_add_prices_to_ticket(
651
+					$price_rows,
652
+					$new_default,
653
+					$update_prices
654
+				);
655
+				// don't forget the base price!
656
+				$new_default = $this->_add_prices_to_ticket(
657
+					array(),
658
+					$new_default,
659
+					$update_prices,
660
+					$base_price,
661
+					$base_price_id
662
+				);
663
+				$new_default->save();
664
+				do_action(
665
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
666
+					$new_default,
667
+					$row,
668
+					$ticket,
669
+					$data
670
+				);
671
+			}
672
+			// DO ALL dtt relationships for both current tickets and any archived tickets
673
+			// for the given dtt that are related to the current ticket.
674
+			// TODO... not sure exactly how we're going to do this considering we don't know
675
+			// what current ticket the archived tickets are related to
676
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
677
+			// let's assign any tickets that have been setup to the saved_tickets tracker
678
+			// save existing TKT
679
+			$ticket->save();
680
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
681
+				// save new TKT
682
+				$new_tkt->save();
683
+				// add new ticket to array
684
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
685
+				do_action(
686
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
687
+					$new_tkt,
688
+					$row,
689
+					$tkt,
690
+					$data
691
+				);
692
+			} else {
693
+				// add tkt to saved tkts
694
+				$saved_tickets[ $ticket->ID() ] = $ticket;
695
+				do_action(
696
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
697
+					$ticket,
698
+					$row,
699
+					$tkt,
700
+					$data
701
+				);
702
+			}
703
+		}
704
+		// now we need to handle tickets actually "deleted permanently".
705
+		// There are cases where we'd want this to happen
706
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
707
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
708
+		// No sense in keeping all the related data in the db!
709
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
710
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
711
+		foreach ($tickets_removed as $id) {
712
+			$id = absint($id);
713
+			// get the ticket for this id
714
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
715
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
716
+			if ($tkt_to_remove->get('TKT_is_default')) {
717
+				continue;
718
+			}
719
+			// if this tkt has any registrations attached so then we just ARCHIVE
720
+			// because we don't actually permanently delete these tickets.
721
+			if ($tkt_to_remove->count_related('Registration') > 0) {
722
+				$tkt_to_remove->delete();
723
+				continue;
724
+			}
725
+			// need to get all the related datetimes on this ticket and remove from every single one of them
726
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
727
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
728
+			foreach ($datetimes as $datetime) {
729
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
730
+			}
731
+			// need to do the same for prices (except these prices can also be deleted because again,
732
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
733
+			$tkt_to_remove->delete_related_permanently('Price');
734
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
735
+			// finally let's delete this ticket
736
+			// (which should not be blocked at this point b/c we've removed all our relationships)
737
+			$tkt_to_remove->delete_permanently();
738
+		}
739
+		return $saved_tickets;
740
+	}
741 741
 
742 742
 
743
-    /**
744
-     * @access  protected
745
-     * @param EE_Ticket      $ticket
746
-     * @param \EE_Datetime[] $saved_datetimes
747
-     * @param \EE_Datetime[] $added_datetimes
748
-     * @param \EE_Datetime[] $removed_datetimes
749
-     * @return EE_Ticket
750
-     * @throws EE_Error
751
-     */
752
-    protected function _update_ticket_datetimes(
753
-        EE_Ticket $ticket,
754
-        $saved_datetimes = array(),
755
-        $added_datetimes = array(),
756
-        $removed_datetimes = array()
757
-    ) {
758
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
759
-        // and removing the ticket from datetimes it got removed from.
760
-        // first let's add datetimes
761
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
762
-            foreach ($added_datetimes as $row_id) {
763
-                $row_id = (int) $row_id;
764
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
765
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
766
-                    // Is this an existing ticket (has an ID) and does it have any sold?
767
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
768
-                    if ($ticket->ID() && $ticket->sold() > 0) {
769
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
770
-                    }
771
-                }
772
-            }
773
-        }
774
-        // then remove datetimes
775
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
776
-            foreach ($removed_datetimes as $row_id) {
777
-                $row_id = (int) $row_id;
778
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
779
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
780
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
781
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
782
-                    // Is this an existing ticket (has an ID) and does it have any sold?
783
-                    // If so, then we need to remove it's sold from the DTT_sold.
784
-                    if ($ticket->ID() && $ticket->sold() > 0) {
785
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
786
-                    }
787
-                }
788
-            }
789
-        }
790
-        // cap ticket qty by datetime reg limits
791
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
792
-        return $ticket;
793
-    }
743
+	/**
744
+	 * @access  protected
745
+	 * @param EE_Ticket      $ticket
746
+	 * @param \EE_Datetime[] $saved_datetimes
747
+	 * @param \EE_Datetime[] $added_datetimes
748
+	 * @param \EE_Datetime[] $removed_datetimes
749
+	 * @return EE_Ticket
750
+	 * @throws EE_Error
751
+	 */
752
+	protected function _update_ticket_datetimes(
753
+		EE_Ticket $ticket,
754
+		$saved_datetimes = array(),
755
+		$added_datetimes = array(),
756
+		$removed_datetimes = array()
757
+	) {
758
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
759
+		// and removing the ticket from datetimes it got removed from.
760
+		// first let's add datetimes
761
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
762
+			foreach ($added_datetimes as $row_id) {
763
+				$row_id = (int) $row_id;
764
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
765
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
766
+					// Is this an existing ticket (has an ID) and does it have any sold?
767
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
768
+					if ($ticket->ID() && $ticket->sold() > 0) {
769
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
770
+					}
771
+				}
772
+			}
773
+		}
774
+		// then remove datetimes
775
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
776
+			foreach ($removed_datetimes as $row_id) {
777
+				$row_id = (int) $row_id;
778
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
779
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
780
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
781
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
782
+					// Is this an existing ticket (has an ID) and does it have any sold?
783
+					// If so, then we need to remove it's sold from the DTT_sold.
784
+					if ($ticket->ID() && $ticket->sold() > 0) {
785
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
786
+					}
787
+				}
788
+			}
789
+		}
790
+		// cap ticket qty by datetime reg limits
791
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
792
+		return $ticket;
793
+	}
794 794
 
795 795
 
796
-    /**
797
-     * @access  protected
798
-     * @param EE_Ticket $ticket
799
-     * @param array     $price_rows
800
-     * @param int       $ticket_price
801
-     * @param int       $base_price
802
-     * @param int       $base_price_id
803
-     * @return EE_Ticket
804
-     * @throws ReflectionException
805
-     * @throws InvalidArgumentException
806
-     * @throws InvalidInterfaceException
807
-     * @throws InvalidDataTypeException
808
-     * @throws EE_Error
809
-     */
810
-    protected function _duplicate_ticket(
811
-        EE_Ticket $ticket,
812
-        $price_rows = array(),
813
-        $ticket_price = 0,
814
-        $base_price = 0,
815
-        $base_price_id = 0
816
-    ) {
817
-        // create new ticket that's a copy of the existing
818
-        // except a new id of course (and not archived)
819
-        // AND has the new TKT_price associated with it.
820
-        $new_ticket = clone $ticket;
821
-        $new_ticket->set('TKT_ID', 0);
822
-        $new_ticket->set_deleted(0);
823
-        $new_ticket->set_price($ticket_price);
824
-        $new_ticket->set_sold(0);
825
-        // let's get a new ID for this ticket
826
-        $new_ticket->save();
827
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
828
-        $datetimes_on_existing = $ticket->datetimes();
829
-        $new_ticket = $this->_update_ticket_datetimes(
830
-            $new_ticket,
831
-            $datetimes_on_existing,
832
-            array_keys($datetimes_on_existing)
833
-        );
834
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
835
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
836
-        // available.
837
-        if ($ticket->sold() > 0) {
838
-            $new_qty = $ticket->qty() - $ticket->sold();
839
-            $new_ticket->set_qty($new_qty);
840
-        }
841
-        // now we update the prices just for this ticket
842
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
843
-        // and we update the base price
844
-        $new_ticket = $this->_add_prices_to_ticket(
845
-            array(),
846
-            $new_ticket,
847
-            true,
848
-            $base_price,
849
-            $base_price_id
850
-        );
851
-        return $new_ticket;
852
-    }
796
+	/**
797
+	 * @access  protected
798
+	 * @param EE_Ticket $ticket
799
+	 * @param array     $price_rows
800
+	 * @param int       $ticket_price
801
+	 * @param int       $base_price
802
+	 * @param int       $base_price_id
803
+	 * @return EE_Ticket
804
+	 * @throws ReflectionException
805
+	 * @throws InvalidArgumentException
806
+	 * @throws InvalidInterfaceException
807
+	 * @throws InvalidDataTypeException
808
+	 * @throws EE_Error
809
+	 */
810
+	protected function _duplicate_ticket(
811
+		EE_Ticket $ticket,
812
+		$price_rows = array(),
813
+		$ticket_price = 0,
814
+		$base_price = 0,
815
+		$base_price_id = 0
816
+	) {
817
+		// create new ticket that's a copy of the existing
818
+		// except a new id of course (and not archived)
819
+		// AND has the new TKT_price associated with it.
820
+		$new_ticket = clone $ticket;
821
+		$new_ticket->set('TKT_ID', 0);
822
+		$new_ticket->set_deleted(0);
823
+		$new_ticket->set_price($ticket_price);
824
+		$new_ticket->set_sold(0);
825
+		// let's get a new ID for this ticket
826
+		$new_ticket->save();
827
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
828
+		$datetimes_on_existing = $ticket->datetimes();
829
+		$new_ticket = $this->_update_ticket_datetimes(
830
+			$new_ticket,
831
+			$datetimes_on_existing,
832
+			array_keys($datetimes_on_existing)
833
+		);
834
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
835
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
836
+		// available.
837
+		if ($ticket->sold() > 0) {
838
+			$new_qty = $ticket->qty() - $ticket->sold();
839
+			$new_ticket->set_qty($new_qty);
840
+		}
841
+		// now we update the prices just for this ticket
842
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
843
+		// and we update the base price
844
+		$new_ticket = $this->_add_prices_to_ticket(
845
+			array(),
846
+			$new_ticket,
847
+			true,
848
+			$base_price,
849
+			$base_price_id
850
+		);
851
+		return $new_ticket;
852
+	}
853 853
 
854 854
 
855
-    /**
856
-     * This attaches a list of given prices to a ticket.
857
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
858
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
859
-     * price info and prices are automatically "archived" via the ticket.
860
-     *
861
-     * @access  private
862
-     * @param array     $prices        Array of prices from the form.
863
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
864
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
865
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
866
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
867
-     * @return EE_Ticket
868
-     * @throws ReflectionException
869
-     * @throws InvalidArgumentException
870
-     * @throws InvalidInterfaceException
871
-     * @throws InvalidDataTypeException
872
-     * @throws EE_Error
873
-     */
874
-    protected function _add_prices_to_ticket(
875
-        $prices = array(),
876
-        EE_Ticket $ticket,
877
-        $new_prices = false,
878
-        $base_price = false,
879
-        $base_price_id = false
880
-    ) {
881
-        // let's just get any current prices that may exist on the given ticket
882
-        // so we can remove any prices that got trashed in this session.
883
-        $current_prices_on_ticket = $base_price !== false
884
-            ? $ticket->base_price(true)
885
-            : $ticket->price_modifiers();
886
-        $updated_prices = array();
887
-        // if $base_price ! FALSE then updating a base price.
888
-        if ($base_price !== false) {
889
-            $prices[1] = array(
890
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
891
-                'PRT_ID'     => 1,
892
-                'PRC_amount' => $base_price,
893
-                'PRC_name'   => $ticket->get('TKT_name'),
894
-                'PRC_desc'   => $ticket->get('TKT_description'),
895
-            );
896
-        }
897
-        // possibly need to save tkt
898
-        if (! $ticket->ID()) {
899
-            $ticket->save();
900
-        }
901
-        foreach ($prices as $row => $prc) {
902
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
903
-            if (empty($prt_id)) {
904
-                continue;
905
-            } //prices MUST have a price type id.
906
-            $PRC_values = array(
907
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
908
-                'PRT_ID'         => $prt_id,
909
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
910
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
911
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
912
-                'PRC_is_default' => false,
913
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
914
-                'PRC_order'      => $row,
915
-            );
916
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
917
-                $PRC_values['PRC_ID'] = 0;
918
-                $price = EE_Registry::instance()->load_class(
919
-                    'Price',
920
-                    array($PRC_values),
921
-                    false,
922
-                    false
923
-                );
924
-            } else {
925
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
926
-                // update this price with new values
927
-                foreach ($PRC_values as $field => $value) {
928
-                    $price->set($field, $value);
929
-                }
930
-            }
931
-            $price->save();
932
-            $updated_prices[ $price->ID() ] = $price;
933
-            $ticket->_add_relation_to($price, 'Price');
934
-        }
935
-        // now let's remove any prices that got removed from the ticket
936
-        if (! empty($current_prices_on_ticket)) {
937
-            $current = array_keys($current_prices_on_ticket);
938
-            $updated = array_keys($updated_prices);
939
-            $prices_to_remove = array_diff($current, $updated);
940
-            if (! empty($prices_to_remove)) {
941
-                foreach ($prices_to_remove as $prc_id) {
942
-                    $p = $current_prices_on_ticket[ $prc_id ];
943
-                    $ticket->_remove_relation_to($p, 'Price');
944
-                    // delete permanently the price
945
-                    $p->delete_permanently();
946
-                }
947
-            }
948
-        }
949
-        return $ticket;
950
-    }
855
+	/**
856
+	 * This attaches a list of given prices to a ticket.
857
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
858
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
859
+	 * price info and prices are automatically "archived" via the ticket.
860
+	 *
861
+	 * @access  private
862
+	 * @param array     $prices        Array of prices from the form.
863
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
864
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
865
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
866
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
867
+	 * @return EE_Ticket
868
+	 * @throws ReflectionException
869
+	 * @throws InvalidArgumentException
870
+	 * @throws InvalidInterfaceException
871
+	 * @throws InvalidDataTypeException
872
+	 * @throws EE_Error
873
+	 */
874
+	protected function _add_prices_to_ticket(
875
+		$prices = array(),
876
+		EE_Ticket $ticket,
877
+		$new_prices = false,
878
+		$base_price = false,
879
+		$base_price_id = false
880
+	) {
881
+		// let's just get any current prices that may exist on the given ticket
882
+		// so we can remove any prices that got trashed in this session.
883
+		$current_prices_on_ticket = $base_price !== false
884
+			? $ticket->base_price(true)
885
+			: $ticket->price_modifiers();
886
+		$updated_prices = array();
887
+		// if $base_price ! FALSE then updating a base price.
888
+		if ($base_price !== false) {
889
+			$prices[1] = array(
890
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
891
+				'PRT_ID'     => 1,
892
+				'PRC_amount' => $base_price,
893
+				'PRC_name'   => $ticket->get('TKT_name'),
894
+				'PRC_desc'   => $ticket->get('TKT_description'),
895
+			);
896
+		}
897
+		// possibly need to save tkt
898
+		if (! $ticket->ID()) {
899
+			$ticket->save();
900
+		}
901
+		foreach ($prices as $row => $prc) {
902
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
903
+			if (empty($prt_id)) {
904
+				continue;
905
+			} //prices MUST have a price type id.
906
+			$PRC_values = array(
907
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
908
+				'PRT_ID'         => $prt_id,
909
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
910
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
911
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
912
+				'PRC_is_default' => false,
913
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
914
+				'PRC_order'      => $row,
915
+			);
916
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
917
+				$PRC_values['PRC_ID'] = 0;
918
+				$price = EE_Registry::instance()->load_class(
919
+					'Price',
920
+					array($PRC_values),
921
+					false,
922
+					false
923
+				);
924
+			} else {
925
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
926
+				// update this price with new values
927
+				foreach ($PRC_values as $field => $value) {
928
+					$price->set($field, $value);
929
+				}
930
+			}
931
+			$price->save();
932
+			$updated_prices[ $price->ID() ] = $price;
933
+			$ticket->_add_relation_to($price, 'Price');
934
+		}
935
+		// now let's remove any prices that got removed from the ticket
936
+		if (! empty($current_prices_on_ticket)) {
937
+			$current = array_keys($current_prices_on_ticket);
938
+			$updated = array_keys($updated_prices);
939
+			$prices_to_remove = array_diff($current, $updated);
940
+			if (! empty($prices_to_remove)) {
941
+				foreach ($prices_to_remove as $prc_id) {
942
+					$p = $current_prices_on_ticket[ $prc_id ];
943
+					$ticket->_remove_relation_to($p, 'Price');
944
+					// delete permanently the price
945
+					$p->delete_permanently();
946
+				}
947
+			}
948
+		}
949
+		return $ticket;
950
+	}
951 951
 
952 952
 
953
-    /**
954
-     * @param Events_Admin_Page $event_admin_obj
955
-     * @return Events_Admin_Page
956
-     */
957
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
958
-    {
959
-        return $event_admin_obj;
960
-        // doing nothing for the moment.
961
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
962
-        // (use the set_template_args() method)
963
-        /**
964
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
965
-         * 1. TKT_is_default_selector (visible)
966
-         * 2. TKT_is_default (hidden)
967
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
968
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
969
-         * this ticket to be saved as a default.
970
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
971
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
972
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
973
-         * the TKT HAS been saved as a default..
974
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
975
-         * On Autosave:
976
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
977
-         * then set the TKT_is_default to false.
978
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
979
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
980
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
981
-         */
982
-    }
953
+	/**
954
+	 * @param Events_Admin_Page $event_admin_obj
955
+	 * @return Events_Admin_Page
956
+	 */
957
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
958
+	{
959
+		return $event_admin_obj;
960
+		// doing nothing for the moment.
961
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
962
+		// (use the set_template_args() method)
963
+		/**
964
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
965
+		 * 1. TKT_is_default_selector (visible)
966
+		 * 2. TKT_is_default (hidden)
967
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
968
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
969
+		 * this ticket to be saved as a default.
970
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
971
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
972
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
973
+		 * the TKT HAS been saved as a default..
974
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
975
+		 * On Autosave:
976
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
977
+		 * then set the TKT_is_default to false.
978
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
979
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
980
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
981
+		 */
982
+	}
983 983
 
984 984
 
985
-    /**
986
-     * @throws ReflectionException
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidInterfaceException
989
-     * @throws InvalidDataTypeException
990
-     * @throws DomainException
991
-     * @throws EE_Error
992
-     */
993
-    public function pricing_metabox()
994
-    {
995
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
996
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
997
-        // set is_creating_event property.
998
-        $EVT_ID = $event->ID();
999
-        $this->_is_creating_event = empty($this->_req_data['post']);
1000
-        // default main template args
1001
-        $main_template_args = array(
1002
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1003
-                'event_editor_event_datetimes_help_tab',
1004
-                $this->_adminpage_obj->page_slug,
1005
-                $this->_adminpage_obj->get_req_action(),
1006
-                false,
1007
-                false
1008
-            ),
1009
-            // todo need to add a filter to the template for the help text
1010
-            // in the Events_Admin_Page core file so we can add further help
1011
-            'existing_datetime_ids'    => '',
1012
-            'total_dtt_rows'           => 1,
1013
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1014
-                'add_new_dtt_info',
1015
-                $this->_adminpage_obj->page_slug,
1016
-                $this->_adminpage_obj->get_req_action(),
1017
-                false,
1018
-                false
1019
-            ),
1020
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1021
-            'datetime_rows'            => '',
1022
-            'show_tickets_container'   => '',
1023
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1024
-            'ticket_rows'              => '',
1025
-            'existing_ticket_ids'      => '',
1026
-            'total_ticket_rows'        => 1,
1027
-            'ticket_js_structure'      => '',
1028
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1029
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1030
-        );
1031
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1032
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1033
-        /**
1034
-         * 1. Start with retrieving Datetimes
1035
-         * 2. For each datetime get related tickets
1036
-         * 3. For each ticket get related prices
1037
-         */
1038
-        /** @var EEM_Datetime $datetime_model */
1039
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1040
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1041
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1042
-        /**
1043
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1044
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1045
-         */
1046
-        $datetime_row = 1;
1047
-        foreach ($datetimes as $datetime) {
1048
-            $DTT_ID = $datetime->get('DTT_ID');
1049
-            $datetime->set('DTT_order', $datetime_row);
1050
-            $existing_datetime_ids[] = $DTT_ID;
1051
-            // tickets attached
1052
-            $related_tickets = $datetime->ID() > 0
1053
-                ? $datetime->get_many_related(
1054
-                    'Ticket',
1055
-                    array(
1056
-                        array(
1057
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1058
-                        ),
1059
-                        'default_where_conditions' => 'none',
1060
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1061
-                    )
1062
-                )
1063
-                : array();
1064
-            // if there are no related tickets this is likely a new event OR autodraft
1065
-            // event so we need to generate the default tickets because datetimes
1066
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1067
-            // datetime on the event.
1068
-            if (empty($related_tickets) && count($datetimes) < 2) {
1069
-                /** @var EEM_Ticket $ticket_model */
1070
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1071
-                $related_tickets = $ticket_model->get_all_default_tickets();
1072
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1073
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1074
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1075
-                $main_default_ticket = reset($related_tickets);
1076
-                if ($main_default_ticket instanceof EE_Ticket) {
1077
-                    foreach ($default_prices as $default_price) {
1078
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1079
-                            continue;
1080
-                        }
1081
-                        $main_default_ticket->cache('Price', $default_price);
1082
-                    }
1083
-                }
1084
-            }
1085
-            // we can't actually setup rows in this loop yet cause we don't know all
1086
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1087
-            // So we're going to temporarily cache some of that information.
1088
-            // loop through and setup the ticket rows and make sure the order is set.
1089
-            foreach ($related_tickets as $ticket) {
1090
-                $TKT_ID = $ticket->get('TKT_ID');
1091
-                $ticket_row = $ticket->get('TKT_row');
1092
-                // we only want unique tickets in our final display!!
1093
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094
-                    $existing_ticket_ids[] = $TKT_ID;
1095
-                    $all_tickets[] = $ticket;
1096
-                }
1097
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1098
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1099
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1100
-                if (
1101
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1102
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
-                ) {
1104
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
-                }
1106
-            }
1107
-            $datetime_row++;
1108
-        }
1109
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1110
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1111
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
-        // sort $all_tickets by order
1113
-        usort(
1114
-            $all_tickets,
1115
-            function (EE_Ticket $a, EE_Ticket $b) {
1116
-                $a_order = (int) $a->get('TKT_order');
1117
-                $b_order = (int) $b->get('TKT_order');
1118
-                if ($a_order === $b_order) {
1119
-                    return 0;
1120
-                }
1121
-                return ($a_order < $b_order) ? -1 : 1;
1122
-            }
1123
-        );
1124
-        // k NOW we have all the data we need for setting up the dtt rows
1125
-        // and ticket rows so we start our dtt loop again.
1126
-        $datetime_row = 1;
1127
-        foreach ($datetimes as $datetime) {
1128
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1129
-                $datetime_row,
1130
-                $datetime,
1131
-                $datetime_tickets,
1132
-                $all_tickets,
1133
-                false,
1134
-                $datetimes
1135
-            );
1136
-            $datetime_row++;
1137
-        }
1138
-        // then loop through all tickets for the ticket rows.
1139
-        $ticket_row = 1;
1140
-        foreach ($all_tickets as $ticket) {
1141
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1142
-                $ticket_row,
1143
-                $ticket,
1144
-                $ticket_datetimes,
1145
-                $datetimes,
1146
-                false,
1147
-                $all_tickets
1148
-            );
1149
-            $ticket_row++;
1150
-        }
1151
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
985
+	/**
986
+	 * @throws ReflectionException
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidInterfaceException
989
+	 * @throws InvalidDataTypeException
990
+	 * @throws DomainException
991
+	 * @throws EE_Error
992
+	 */
993
+	public function pricing_metabox()
994
+	{
995
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
996
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
997
+		// set is_creating_event property.
998
+		$EVT_ID = $event->ID();
999
+		$this->_is_creating_event = empty($this->_req_data['post']);
1000
+		// default main template args
1001
+		$main_template_args = array(
1002
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1003
+				'event_editor_event_datetimes_help_tab',
1004
+				$this->_adminpage_obj->page_slug,
1005
+				$this->_adminpage_obj->get_req_action(),
1006
+				false,
1007
+				false
1008
+			),
1009
+			// todo need to add a filter to the template for the help text
1010
+			// in the Events_Admin_Page core file so we can add further help
1011
+			'existing_datetime_ids'    => '',
1012
+			'total_dtt_rows'           => 1,
1013
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1014
+				'add_new_dtt_info',
1015
+				$this->_adminpage_obj->page_slug,
1016
+				$this->_adminpage_obj->get_req_action(),
1017
+				false,
1018
+				false
1019
+			),
1020
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1021
+			'datetime_rows'            => '',
1022
+			'show_tickets_container'   => '',
1023
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1024
+			'ticket_rows'              => '',
1025
+			'existing_ticket_ids'      => '',
1026
+			'total_ticket_rows'        => 1,
1027
+			'ticket_js_structure'      => '',
1028
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1029
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1030
+		);
1031
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1032
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1033
+		/**
1034
+		 * 1. Start with retrieving Datetimes
1035
+		 * 2. For each datetime get related tickets
1036
+		 * 3. For each ticket get related prices
1037
+		 */
1038
+		/** @var EEM_Datetime $datetime_model */
1039
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1040
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1041
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1042
+		/**
1043
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1044
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1045
+		 */
1046
+		$datetime_row = 1;
1047
+		foreach ($datetimes as $datetime) {
1048
+			$DTT_ID = $datetime->get('DTT_ID');
1049
+			$datetime->set('DTT_order', $datetime_row);
1050
+			$existing_datetime_ids[] = $DTT_ID;
1051
+			// tickets attached
1052
+			$related_tickets = $datetime->ID() > 0
1053
+				? $datetime->get_many_related(
1054
+					'Ticket',
1055
+					array(
1056
+						array(
1057
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1058
+						),
1059
+						'default_where_conditions' => 'none',
1060
+						'order_by'                 => array('TKT_order' => 'ASC'),
1061
+					)
1062
+				)
1063
+				: array();
1064
+			// if there are no related tickets this is likely a new event OR autodraft
1065
+			// event so we need to generate the default tickets because datetimes
1066
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1067
+			// datetime on the event.
1068
+			if (empty($related_tickets) && count($datetimes) < 2) {
1069
+				/** @var EEM_Ticket $ticket_model */
1070
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1071
+				$related_tickets = $ticket_model->get_all_default_tickets();
1072
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1073
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1074
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1075
+				$main_default_ticket = reset($related_tickets);
1076
+				if ($main_default_ticket instanceof EE_Ticket) {
1077
+					foreach ($default_prices as $default_price) {
1078
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1079
+							continue;
1080
+						}
1081
+						$main_default_ticket->cache('Price', $default_price);
1082
+					}
1083
+				}
1084
+			}
1085
+			// we can't actually setup rows in this loop yet cause we don't know all
1086
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1087
+			// So we're going to temporarily cache some of that information.
1088
+			// loop through and setup the ticket rows and make sure the order is set.
1089
+			foreach ($related_tickets as $ticket) {
1090
+				$TKT_ID = $ticket->get('TKT_ID');
1091
+				$ticket_row = $ticket->get('TKT_row');
1092
+				// we only want unique tickets in our final display!!
1093
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094
+					$existing_ticket_ids[] = $TKT_ID;
1095
+					$all_tickets[] = $ticket;
1096
+				}
1097
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1098
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1099
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1100
+				if (
1101
+					! isset($ticket_datetimes[ $TKT_ID ])
1102
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
+				) {
1104
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
+				}
1106
+			}
1107
+			$datetime_row++;
1108
+		}
1109
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1110
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1111
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
+		// sort $all_tickets by order
1113
+		usort(
1114
+			$all_tickets,
1115
+			function (EE_Ticket $a, EE_Ticket $b) {
1116
+				$a_order = (int) $a->get('TKT_order');
1117
+				$b_order = (int) $b->get('TKT_order');
1118
+				if ($a_order === $b_order) {
1119
+					return 0;
1120
+				}
1121
+				return ($a_order < $b_order) ? -1 : 1;
1122
+			}
1123
+		);
1124
+		// k NOW we have all the data we need for setting up the dtt rows
1125
+		// and ticket rows so we start our dtt loop again.
1126
+		$datetime_row = 1;
1127
+		foreach ($datetimes as $datetime) {
1128
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1129
+				$datetime_row,
1130
+				$datetime,
1131
+				$datetime_tickets,
1132
+				$all_tickets,
1133
+				false,
1134
+				$datetimes
1135
+			);
1136
+			$datetime_row++;
1137
+		}
1138
+		// then loop through all tickets for the ticket rows.
1139
+		$ticket_row = 1;
1140
+		foreach ($all_tickets as $ticket) {
1141
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1142
+				$ticket_row,
1143
+				$ticket,
1144
+				$ticket_datetimes,
1145
+				$datetimes,
1146
+				false,
1147
+				$all_tickets
1148
+			);
1149
+			$ticket_row++;
1150
+		}
1151
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1152 1152
 
1153
-        $status_change_notice = EventEspresso\core\services\loaders\LoaderFactory::getLoader()->getShared(
1154
-            'EventEspresso\core\admin\StatusChangeNotice'
1155
-        );
1156
-        if (! $status_change_notice->isDismissed()) {
1157
-            $main_template_args['status_change_notice'] = EEH_Template::display_template(
1158
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
1159
-                ['context' => '__event-editor', 'page_slug' => 'espresso-events'],
1160
-                true
1161
-            );
1162
-        }
1153
+		$status_change_notice = EventEspresso\core\services\loaders\LoaderFactory::getLoader()->getShared(
1154
+			'EventEspresso\core\admin\StatusChangeNotice'
1155
+		);
1156
+		if (! $status_change_notice->isDismissed()) {
1157
+			$main_template_args['status_change_notice'] = EEH_Template::display_template(
1158
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
1159
+				['context' => '__event-editor', 'page_slug' => 'espresso-events'],
1160
+				true
1161
+			);
1162
+		}
1163 1163
 
1164
-        EEH_Template::display_template(
1165
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1166
-            $main_template_args
1167
-        );
1168
-    }
1164
+		EEH_Template::display_template(
1165
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1166
+			$main_template_args
1167
+		);
1168
+	}
1169 1169
 
1170 1170
 
1171
-    /**
1172
-     * @param int         $datetime_row
1173
-     * @param EE_Datetime $datetime
1174
-     * @param array       $datetime_tickets
1175
-     * @param array       $all_tickets
1176
-     * @param bool        $default
1177
-     * @param array       $all_datetimes
1178
-     * @return mixed
1179
-     * @throws DomainException
1180
-     * @throws EE_Error
1181
-     */
1182
-    protected function _get_datetime_row(
1183
-        $datetime_row,
1184
-        EE_Datetime $datetime,
1185
-        $datetime_tickets = array(),
1186
-        $all_tickets = array(),
1187
-        $default = false,
1188
-        $all_datetimes = array()
1189
-    ) {
1190
-        $dtt_display_template_args = array(
1191
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1192
-                $datetime_row,
1193
-                $datetime,
1194
-                $default,
1195
-                $all_datetimes
1196
-            ),
1197
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1198
-                $datetime_row,
1199
-                $datetime,
1200
-                $datetime_tickets,
1201
-                $all_tickets,
1202
-                $default
1203
-            ),
1204
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1205
-        );
1206
-        return EEH_Template::display_template(
1207
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1208
-            $dtt_display_template_args,
1209
-            true
1210
-        );
1211
-    }
1171
+	/**
1172
+	 * @param int         $datetime_row
1173
+	 * @param EE_Datetime $datetime
1174
+	 * @param array       $datetime_tickets
1175
+	 * @param array       $all_tickets
1176
+	 * @param bool        $default
1177
+	 * @param array       $all_datetimes
1178
+	 * @return mixed
1179
+	 * @throws DomainException
1180
+	 * @throws EE_Error
1181
+	 */
1182
+	protected function _get_datetime_row(
1183
+		$datetime_row,
1184
+		EE_Datetime $datetime,
1185
+		$datetime_tickets = array(),
1186
+		$all_tickets = array(),
1187
+		$default = false,
1188
+		$all_datetimes = array()
1189
+	) {
1190
+		$dtt_display_template_args = array(
1191
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1192
+				$datetime_row,
1193
+				$datetime,
1194
+				$default,
1195
+				$all_datetimes
1196
+			),
1197
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1198
+				$datetime_row,
1199
+				$datetime,
1200
+				$datetime_tickets,
1201
+				$all_tickets,
1202
+				$default
1203
+			),
1204
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1205
+		);
1206
+		return EEH_Template::display_template(
1207
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1208
+			$dtt_display_template_args,
1209
+			true
1210
+		);
1211
+	}
1212 1212
 
1213 1213
 
1214
-    /**
1215
-     * This method is used to generate a dtt fields  edit row.
1216
-     * The same row is used to generate a row with valid DTT objects
1217
-     * and the default row that is used as the skeleton by the js.
1218
-     *
1219
-     * @param int           $datetime_row  The row number for the row being generated.
1220
-     * @param EE_Datetime   $datetime
1221
-     * @param bool          $default       Whether a default row is being generated or not.
1222
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1223
-     * @return string
1224
-     * @throws DomainException
1225
-     * @throws EE_Error
1226
-     */
1227
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1228
-    {
1229
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1230
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1231
-        $template_args = array(
1232
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1233
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1234
-            'edit_dtt_expanded'    => '',
1235
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1236
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1237
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1238
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1239
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1240
-            'DTT_reg_limit'        => $default
1241
-                ? ''
1242
-                : $datetime->get_pretty(
1243
-                    'DTT_reg_limit',
1244
-                    'input'
1245
-                ),
1246
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1247
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1248
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1249
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1250
-                ? ''
1251
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1252
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1253
-                ? 'ee-lock-icon'
1254
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1255
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1256
-                ? ''
1257
-                : EE_Admin_Page::add_query_args_and_nonce(
1258
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1259
-                    REG_ADMIN_URL
1260
-                ),
1261
-        );
1262
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1263
-            ? ' style="display:none"'
1264
-            : '';
1265
-        // allow filtering of template args at this point.
1266
-        $template_args = apply_filters(
1267
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1268
-            $template_args,
1269
-            $datetime_row,
1270
-            $datetime,
1271
-            $default,
1272
-            $all_datetimes,
1273
-            $this->_is_creating_event
1274
-        );
1275
-        return EEH_Template::display_template(
1276
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1277
-            $template_args,
1278
-            true
1279
-        );
1280
-    }
1214
+	/**
1215
+	 * This method is used to generate a dtt fields  edit row.
1216
+	 * The same row is used to generate a row with valid DTT objects
1217
+	 * and the default row that is used as the skeleton by the js.
1218
+	 *
1219
+	 * @param int           $datetime_row  The row number for the row being generated.
1220
+	 * @param EE_Datetime   $datetime
1221
+	 * @param bool          $default       Whether a default row is being generated or not.
1222
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1223
+	 * @return string
1224
+	 * @throws DomainException
1225
+	 * @throws EE_Error
1226
+	 */
1227
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1228
+	{
1229
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1230
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1231
+		$template_args = array(
1232
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1233
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1234
+			'edit_dtt_expanded'    => '',
1235
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1236
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1237
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1238
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1239
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1240
+			'DTT_reg_limit'        => $default
1241
+				? ''
1242
+				: $datetime->get_pretty(
1243
+					'DTT_reg_limit',
1244
+					'input'
1245
+				),
1246
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1247
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1248
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1249
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1250
+				? ''
1251
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1252
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1253
+				? 'ee-lock-icon'
1254
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1255
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1256
+				? ''
1257
+				: EE_Admin_Page::add_query_args_and_nonce(
1258
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1259
+					REG_ADMIN_URL
1260
+				),
1261
+		);
1262
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1263
+			? ' style="display:none"'
1264
+			: '';
1265
+		// allow filtering of template args at this point.
1266
+		$template_args = apply_filters(
1267
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1268
+			$template_args,
1269
+			$datetime_row,
1270
+			$datetime,
1271
+			$default,
1272
+			$all_datetimes,
1273
+			$this->_is_creating_event
1274
+		);
1275
+		return EEH_Template::display_template(
1276
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1277
+			$template_args,
1278
+			true
1279
+		);
1280
+	}
1281 1281
 
1282 1282
 
1283
-    /**
1284
-     * @param int         $datetime_row
1285
-     * @param EE_Datetime $datetime
1286
-     * @param array       $datetime_tickets
1287
-     * @param array       $all_tickets
1288
-     * @param bool        $default
1289
-     * @return mixed
1290
-     * @throws DomainException
1291
-     * @throws EE_Error
1292
-     */
1293
-    protected function _get_dtt_attached_tickets_row(
1294
-        $datetime_row,
1295
-        $datetime,
1296
-        $datetime_tickets = array(),
1297
-        $all_tickets = array(),
1298
-        $default
1299
-    ) {
1300
-        $template_args = array(
1301
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1302
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1303
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1304
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1305
-            'show_tickets_row'                  => ' style="display:none;"',
1306
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1307
-                'add_new_ticket_via_datetime',
1308
-                $this->_adminpage_obj->page_slug,
1309
-                $this->_adminpage_obj->get_req_action(),
1310
-                false,
1311
-                false
1312
-            ),
1313
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1314
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1315
-        );
1316
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1317
-        if (! $default) {
1318
-            $ticket_row = 1;
1319
-            foreach ($all_tickets as $ticket) {
1320
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1321
-                    $datetime_row,
1322
-                    $ticket_row,
1323
-                    $datetime,
1324
-                    $ticket,
1325
-                    $datetime_tickets,
1326
-                    $default
1327
-                );
1328
-                $ticket_row++;
1329
-            }
1330
-        }
1331
-        // filter template args at this point
1332
-        $template_args = apply_filters(
1333
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1334
-            $template_args,
1335
-            $datetime_row,
1336
-            $datetime,
1337
-            $datetime_tickets,
1338
-            $all_tickets,
1339
-            $default,
1340
-            $this->_is_creating_event
1341
-        );
1342
-        return EEH_Template::display_template(
1343
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1344
-            $template_args,
1345
-            true
1346
-        );
1347
-    }
1283
+	/**
1284
+	 * @param int         $datetime_row
1285
+	 * @param EE_Datetime $datetime
1286
+	 * @param array       $datetime_tickets
1287
+	 * @param array       $all_tickets
1288
+	 * @param bool        $default
1289
+	 * @return mixed
1290
+	 * @throws DomainException
1291
+	 * @throws EE_Error
1292
+	 */
1293
+	protected function _get_dtt_attached_tickets_row(
1294
+		$datetime_row,
1295
+		$datetime,
1296
+		$datetime_tickets = array(),
1297
+		$all_tickets = array(),
1298
+		$default
1299
+	) {
1300
+		$template_args = array(
1301
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1302
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1303
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1304
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1305
+			'show_tickets_row'                  => ' style="display:none;"',
1306
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1307
+				'add_new_ticket_via_datetime',
1308
+				$this->_adminpage_obj->page_slug,
1309
+				$this->_adminpage_obj->get_req_action(),
1310
+				false,
1311
+				false
1312
+			),
1313
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1314
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1315
+		);
1316
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1317
+		if (! $default) {
1318
+			$ticket_row = 1;
1319
+			foreach ($all_tickets as $ticket) {
1320
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1321
+					$datetime_row,
1322
+					$ticket_row,
1323
+					$datetime,
1324
+					$ticket,
1325
+					$datetime_tickets,
1326
+					$default
1327
+				);
1328
+				$ticket_row++;
1329
+			}
1330
+		}
1331
+		// filter template args at this point
1332
+		$template_args = apply_filters(
1333
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1334
+			$template_args,
1335
+			$datetime_row,
1336
+			$datetime,
1337
+			$datetime_tickets,
1338
+			$all_tickets,
1339
+			$default,
1340
+			$this->_is_creating_event
1341
+		);
1342
+		return EEH_Template::display_template(
1343
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1344
+			$template_args,
1345
+			true
1346
+		);
1347
+	}
1348 1348
 
1349 1349
 
1350
-    /**
1351
-     * @param int         $datetime_row
1352
-     * @param int         $ticket_row
1353
-     * @param EE_Datetime $datetime
1354
-     * @param EE_Ticket   $ticket
1355
-     * @param array       $datetime_tickets
1356
-     * @param bool        $default
1357
-     * @return mixed
1358
-     * @throws DomainException
1359
-     * @throws EE_Error
1360
-     */
1361
-    protected function _get_datetime_tickets_list_item(
1362
-        $datetime_row,
1363
-        $ticket_row,
1364
-        $datetime,
1365
-        $ticket,
1366
-        $datetime_tickets = array(),
1367
-        $default
1368
-    ) {
1369
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1370
-            ? $datetime_tickets[ $datetime->ID() ]
1371
-            : array();
1372
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1373
-        $no_ticket = $default && empty($ticket);
1374
-        $template_args = array(
1375
-            'dtt_row'                 => $default
1376
-                ? 'DTTNUM'
1377
-                : $datetime_row,
1378
-            'tkt_row'                 => $no_ticket
1379
-                ? 'TICKETNUM'
1380
-                : $ticket_row,
1381
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1382
-                ? ' checked="checked"'
1383
-                : '',
1384
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1385
-                ? ' ticket-selected'
1386
-                : '',
1387
-            'TKT_name'                => $no_ticket
1388
-                ? 'TKTNAME'
1389
-                : $ticket->get('TKT_name'),
1390
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1391
-                ? ' tkt-status-' . EE_Ticket::onsale
1392
-                : ' tkt-status-' . $ticket->ticket_status(),
1393
-        );
1394
-        // filter template args
1395
-        $template_args = apply_filters(
1396
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1397
-            $template_args,
1398
-            $datetime_row,
1399
-            $ticket_row,
1400
-            $datetime,
1401
-            $ticket,
1402
-            $datetime_tickets,
1403
-            $default,
1404
-            $this->_is_creating_event
1405
-        );
1406
-        return EEH_Template::display_template(
1407
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1408
-            $template_args,
1409
-            true
1410
-        );
1411
-    }
1350
+	/**
1351
+	 * @param int         $datetime_row
1352
+	 * @param int         $ticket_row
1353
+	 * @param EE_Datetime $datetime
1354
+	 * @param EE_Ticket   $ticket
1355
+	 * @param array       $datetime_tickets
1356
+	 * @param bool        $default
1357
+	 * @return mixed
1358
+	 * @throws DomainException
1359
+	 * @throws EE_Error
1360
+	 */
1361
+	protected function _get_datetime_tickets_list_item(
1362
+		$datetime_row,
1363
+		$ticket_row,
1364
+		$datetime,
1365
+		$ticket,
1366
+		$datetime_tickets = array(),
1367
+		$default
1368
+	) {
1369
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1370
+			? $datetime_tickets[ $datetime->ID() ]
1371
+			: array();
1372
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1373
+		$no_ticket = $default && empty($ticket);
1374
+		$template_args = array(
1375
+			'dtt_row'                 => $default
1376
+				? 'DTTNUM'
1377
+				: $datetime_row,
1378
+			'tkt_row'                 => $no_ticket
1379
+				? 'TICKETNUM'
1380
+				: $ticket_row,
1381
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1382
+				? ' checked="checked"'
1383
+				: '',
1384
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1385
+				? ' ticket-selected'
1386
+				: '',
1387
+			'TKT_name'                => $no_ticket
1388
+				? 'TKTNAME'
1389
+				: $ticket->get('TKT_name'),
1390
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1391
+				? ' tkt-status-' . EE_Ticket::onsale
1392
+				: ' tkt-status-' . $ticket->ticket_status(),
1393
+		);
1394
+		// filter template args
1395
+		$template_args = apply_filters(
1396
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1397
+			$template_args,
1398
+			$datetime_row,
1399
+			$ticket_row,
1400
+			$datetime,
1401
+			$ticket,
1402
+			$datetime_tickets,
1403
+			$default,
1404
+			$this->_is_creating_event
1405
+		);
1406
+		return EEH_Template::display_template(
1407
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1408
+			$template_args,
1409
+			true
1410
+		);
1411
+	}
1412 1412
 
1413 1413
 
1414
-    /**
1415
-     * This generates the ticket row for tickets.
1416
-     * This same method is used to generate both the actual rows and the js skeleton row
1417
-     * (when default === true)
1418
-     *
1419
-     * @param int           $ticket_row       Represents the row number being generated.
1420
-     * @param               $ticket
1421
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1422
-     *                                        or empty for default
1423
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1424
-     * @param bool          $default          Whether default row being generated or not.
1425
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1426
-     *                                        (or empty in the case of defaults)
1427
-     * @return mixed
1428
-     * @throws InvalidArgumentException
1429
-     * @throws InvalidInterfaceException
1430
-     * @throws InvalidDataTypeException
1431
-     * @throws DomainException
1432
-     * @throws EE_Error
1433
-     * @throws ReflectionException
1434
-     */
1435
-    protected function _get_ticket_row(
1436
-        $ticket_row,
1437
-        $ticket,
1438
-        $ticket_datetimes,
1439
-        $all_datetimes,
1440
-        $default = false,
1441
-        $all_tickets = array()
1442
-    ) {
1443
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1444
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1445
-        $prices = ! empty($ticket) && ! $default
1446
-            ? $ticket->get_many_related(
1447
-                'Price',
1448
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1449
-            )
1450
-            : array();
1451
-        // if there is only one price (which would be the base price)
1452
-        // or NO prices and this ticket is a default ticket,
1453
-        // let's just make sure there are no cached default prices on the object.
1454
-        // This is done by not including any query_params.
1455
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1456
-            $prices = $ticket->prices();
1457
-        }
1458
-        // check if we're dealing with a default ticket in which case
1459
-        // we don't want any starting_ticket_datetime_row values set
1460
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1461
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1462
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1463
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1464
-            ? $ticket_datetimes[ $ticket->ID() ]
1465
-            : array();
1466
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1467
-        $base_price = $default ? null : $ticket->base_price();
1468
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1469
-        // breaking out complicated condition for ticket_status
1470
-        if ($default) {
1471
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1472
-        } else {
1473
-            $ticket_status_class = $ticket->is_default()
1474
-                ? ' tkt-status-' . EE_Ticket::onsale
1475
-                : ' tkt-status-' . $ticket->ticket_status();
1476
-        }
1477
-        // breaking out complicated condition for TKT_taxable
1478
-        if ($default) {
1479
-            $TKT_taxable = '';
1480
-        } else {
1481
-            $TKT_taxable = $ticket->taxable()
1482
-                ? ' checked="checked"'
1483
-                : '';
1484
-        }
1485
-        if ($default) {
1486
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1487
-        } elseif ($ticket->is_default()) {
1488
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1489
-        } else {
1490
-            $TKT_status = $ticket->ticket_status(true);
1491
-        }
1492
-        if ($default) {
1493
-            $TKT_min = '';
1494
-        } else {
1495
-            $TKT_min = $ticket->min();
1496
-            if ($TKT_min === -1 || $TKT_min === 0) {
1497
-                $TKT_min = '';
1498
-            }
1499
-        }
1500
-        $template_args = array(
1501
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1502
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1503
-            // on initial page load this will always be the correct order.
1504
-            'tkt_status_class'              => $ticket_status_class,
1505
-            'display_edit_tkt_row'          => ' style="display:none;"',
1506
-            'edit_tkt_expanded'             => '',
1507
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1508
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1509
-            'TKT_start_date'                => $default
1510
-                ? ''
1511
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1512
-            'TKT_end_date'                  => $default
1513
-                ? ''
1514
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1515
-            'TKT_status'                    => $TKT_status,
1516
-            'TKT_price'                     => $default
1517
-                ? ''
1518
-                : EEH_Template::format_currency(
1519
-                    $ticket->get_ticket_total_with_taxes(),
1520
-                    false,
1521
-                    false
1522
-                ),
1523
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1524
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1525
-            'TKT_qty'                       => $default
1526
-                ? ''
1527
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1528
-            'TKT_qty_for_input'             => $default
1529
-                ? ''
1530
-                : $ticket->get_pretty('TKT_qty', 'input'),
1531
-            'TKT_uses'                      => $default
1532
-                ? ''
1533
-                : $ticket->get_pretty('TKT_uses', 'input'),
1534
-            'TKT_min'                       => $TKT_min,
1535
-            'TKT_max'                       => $default
1536
-                ? ''
1537
-                : $ticket->get_pretty('TKT_max', 'input'),
1538
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1539
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1540
-            'TKT_registrations'             => $default
1541
-                ? 0
1542
-                : $ticket->count_registrations(
1543
-                    array(
1544
-                        array(
1545
-                            'STS_ID' => array(
1546
-                                '!=',
1547
-                                EEM_Registration::status_id_incomplete,
1548
-                            ),
1549
-                        ),
1550
-                    )
1551
-                ),
1552
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1553
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1554
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1555
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1556
-            'TKT_is_default_selector'       => '',
1557
-            'ticket_price_rows'             => '',
1558
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1559
-                ? ''
1560
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1561
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1562
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1563
-                ? ''
1564
-                : ' style="display:none;"',
1565
-            'show_price_mod_button'         => count($prices) > 1
1566
-                                               || ($default && $count_price_mods > 0)
1567
-                                               || (! $default && $ticket->deleted())
1568
-                ? ' style="display:none;"'
1569
-                : '',
1570
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1571
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1572
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1573
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1574
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1575
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1576
-            'TKT_taxable'                   => $TKT_taxable,
1577
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1578
-                ? ''
1579
-                : ' style="display:none"',
1580
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1581
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1582
-                $ticket_subtotal,
1583
-                false,
1584
-                false
1585
-            ),
1586
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1587
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1588
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1589
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1590
-                ? ' ticket-archived'
1591
-                : '',
1592
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1593
-                                               && $ticket->deleted()
1594
-                                               && ! $ticket->is_permanently_deleteable()
1595
-                ? 'ee-lock-icon '
1596
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1597
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1598
-                ? ''
1599
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1600
-        );
1601
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1602
-            ? ' style="display:none"'
1603
-            : '';
1604
-        // handle rows that should NOT be empty
1605
-        if (empty($template_args['TKT_start_date'])) {
1606
-            // if empty then the start date will be now.
1607
-            $template_args['TKT_start_date'] = date(
1608
-                $this->_date_time_format,
1609
-                current_time('timestamp')
1610
-            );
1611
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1612
-        }
1613
-        if (empty($template_args['TKT_end_date'])) {
1614
-            // get the earliest datetime (if present);
1615
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1616
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1617
-                    'Datetime',
1618
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1619
-                )
1620
-                : null;
1621
-            if (! empty($earliest_dtt)) {
1622
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1623
-                    'DTT_EVT_start',
1624
-                    $this->_date_time_format
1625
-                );
1626
-            } else {
1627
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1628
-                $template_args['TKT_end_date'] = date(
1629
-                    $this->_date_time_format,
1630
-                    mktime(
1631
-                        24,
1632
-                        0,
1633
-                        0,
1634
-                        date('m'),
1635
-                        date('d') + 29,
1636
-                        date('Y')
1637
-                    )
1638
-                );
1639
-            }
1640
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1641
-        }
1642
-        // generate ticket_datetime items
1643
-        if (! $default) {
1644
-            $datetime_row = 1;
1645
-            foreach ($all_datetimes as $datetime) {
1646
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1647
-                    $datetime_row,
1648
-                    $ticket_row,
1649
-                    $datetime,
1650
-                    $ticket,
1651
-                    $ticket_datetimes,
1652
-                    $default
1653
-                );
1654
-                $datetime_row++;
1655
-            }
1656
-        }
1657
-        $price_row = 1;
1658
-        foreach ($prices as $price) {
1659
-            if (! $price instanceof EE_Price) {
1660
-                continue;
1661
-            }
1662
-            if ($price->is_base_price()) {
1663
-                $price_row++;
1664
-                continue;
1665
-            }
1666
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1667
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1668
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1669
-                $ticket_row,
1670
-                $price_row,
1671
-                $price,
1672
-                $default,
1673
-                $ticket,
1674
-                $show_trash,
1675
-                $show_create
1676
-            );
1677
-            $price_row++;
1678
-        }
1679
-        // filter $template_args
1680
-        $template_args = apply_filters(
1681
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1682
-            $template_args,
1683
-            $ticket_row,
1684
-            $ticket,
1685
-            $ticket_datetimes,
1686
-            $all_datetimes,
1687
-            $default,
1688
-            $all_tickets,
1689
-            $this->_is_creating_event
1690
-        );
1691
-        return EEH_Template::display_template(
1692
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1693
-            $template_args,
1694
-            true
1695
-        );
1696
-    }
1414
+	/**
1415
+	 * This generates the ticket row for tickets.
1416
+	 * This same method is used to generate both the actual rows and the js skeleton row
1417
+	 * (when default === true)
1418
+	 *
1419
+	 * @param int           $ticket_row       Represents the row number being generated.
1420
+	 * @param               $ticket
1421
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1422
+	 *                                        or empty for default
1423
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1424
+	 * @param bool          $default          Whether default row being generated or not.
1425
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1426
+	 *                                        (or empty in the case of defaults)
1427
+	 * @return mixed
1428
+	 * @throws InvalidArgumentException
1429
+	 * @throws InvalidInterfaceException
1430
+	 * @throws InvalidDataTypeException
1431
+	 * @throws DomainException
1432
+	 * @throws EE_Error
1433
+	 * @throws ReflectionException
1434
+	 */
1435
+	protected function _get_ticket_row(
1436
+		$ticket_row,
1437
+		$ticket,
1438
+		$ticket_datetimes,
1439
+		$all_datetimes,
1440
+		$default = false,
1441
+		$all_tickets = array()
1442
+	) {
1443
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1444
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1445
+		$prices = ! empty($ticket) && ! $default
1446
+			? $ticket->get_many_related(
1447
+				'Price',
1448
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1449
+			)
1450
+			: array();
1451
+		// if there is only one price (which would be the base price)
1452
+		// or NO prices and this ticket is a default ticket,
1453
+		// let's just make sure there are no cached default prices on the object.
1454
+		// This is done by not including any query_params.
1455
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1456
+			$prices = $ticket->prices();
1457
+		}
1458
+		// check if we're dealing with a default ticket in which case
1459
+		// we don't want any starting_ticket_datetime_row values set
1460
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1461
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1462
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1463
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1464
+			? $ticket_datetimes[ $ticket->ID() ]
1465
+			: array();
1466
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1467
+		$base_price = $default ? null : $ticket->base_price();
1468
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1469
+		// breaking out complicated condition for ticket_status
1470
+		if ($default) {
1471
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1472
+		} else {
1473
+			$ticket_status_class = $ticket->is_default()
1474
+				? ' tkt-status-' . EE_Ticket::onsale
1475
+				: ' tkt-status-' . $ticket->ticket_status();
1476
+		}
1477
+		// breaking out complicated condition for TKT_taxable
1478
+		if ($default) {
1479
+			$TKT_taxable = '';
1480
+		} else {
1481
+			$TKT_taxable = $ticket->taxable()
1482
+				? ' checked="checked"'
1483
+				: '';
1484
+		}
1485
+		if ($default) {
1486
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1487
+		} elseif ($ticket->is_default()) {
1488
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1489
+		} else {
1490
+			$TKT_status = $ticket->ticket_status(true);
1491
+		}
1492
+		if ($default) {
1493
+			$TKT_min = '';
1494
+		} else {
1495
+			$TKT_min = $ticket->min();
1496
+			if ($TKT_min === -1 || $TKT_min === 0) {
1497
+				$TKT_min = '';
1498
+			}
1499
+		}
1500
+		$template_args = array(
1501
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1502
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1503
+			// on initial page load this will always be the correct order.
1504
+			'tkt_status_class'              => $ticket_status_class,
1505
+			'display_edit_tkt_row'          => ' style="display:none;"',
1506
+			'edit_tkt_expanded'             => '',
1507
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1508
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1509
+			'TKT_start_date'                => $default
1510
+				? ''
1511
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1512
+			'TKT_end_date'                  => $default
1513
+				? ''
1514
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1515
+			'TKT_status'                    => $TKT_status,
1516
+			'TKT_price'                     => $default
1517
+				? ''
1518
+				: EEH_Template::format_currency(
1519
+					$ticket->get_ticket_total_with_taxes(),
1520
+					false,
1521
+					false
1522
+				),
1523
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1524
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1525
+			'TKT_qty'                       => $default
1526
+				? ''
1527
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1528
+			'TKT_qty_for_input'             => $default
1529
+				? ''
1530
+				: $ticket->get_pretty('TKT_qty', 'input'),
1531
+			'TKT_uses'                      => $default
1532
+				? ''
1533
+				: $ticket->get_pretty('TKT_uses', 'input'),
1534
+			'TKT_min'                       => $TKT_min,
1535
+			'TKT_max'                       => $default
1536
+				? ''
1537
+				: $ticket->get_pretty('TKT_max', 'input'),
1538
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1539
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1540
+			'TKT_registrations'             => $default
1541
+				? 0
1542
+				: $ticket->count_registrations(
1543
+					array(
1544
+						array(
1545
+							'STS_ID' => array(
1546
+								'!=',
1547
+								EEM_Registration::status_id_incomplete,
1548
+							),
1549
+						),
1550
+					)
1551
+				),
1552
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1553
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1554
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1555
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1556
+			'TKT_is_default_selector'       => '',
1557
+			'ticket_price_rows'             => '',
1558
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1559
+				? ''
1560
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1561
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1562
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1563
+				? ''
1564
+				: ' style="display:none;"',
1565
+			'show_price_mod_button'         => count($prices) > 1
1566
+											   || ($default && $count_price_mods > 0)
1567
+											   || (! $default && $ticket->deleted())
1568
+				? ' style="display:none;"'
1569
+				: '',
1570
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1571
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1572
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1573
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1574
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1575
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1576
+			'TKT_taxable'                   => $TKT_taxable,
1577
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1578
+				? ''
1579
+				: ' style="display:none"',
1580
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1581
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1582
+				$ticket_subtotal,
1583
+				false,
1584
+				false
1585
+			),
1586
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1587
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1588
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1589
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1590
+				? ' ticket-archived'
1591
+				: '',
1592
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1593
+											   && $ticket->deleted()
1594
+											   && ! $ticket->is_permanently_deleteable()
1595
+				? 'ee-lock-icon '
1596
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1597
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1598
+				? ''
1599
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1600
+		);
1601
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1602
+			? ' style="display:none"'
1603
+			: '';
1604
+		// handle rows that should NOT be empty
1605
+		if (empty($template_args['TKT_start_date'])) {
1606
+			// if empty then the start date will be now.
1607
+			$template_args['TKT_start_date'] = date(
1608
+				$this->_date_time_format,
1609
+				current_time('timestamp')
1610
+			);
1611
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1612
+		}
1613
+		if (empty($template_args['TKT_end_date'])) {
1614
+			// get the earliest datetime (if present);
1615
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1616
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1617
+					'Datetime',
1618
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1619
+				)
1620
+				: null;
1621
+			if (! empty($earliest_dtt)) {
1622
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1623
+					'DTT_EVT_start',
1624
+					$this->_date_time_format
1625
+				);
1626
+			} else {
1627
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1628
+				$template_args['TKT_end_date'] = date(
1629
+					$this->_date_time_format,
1630
+					mktime(
1631
+						24,
1632
+						0,
1633
+						0,
1634
+						date('m'),
1635
+						date('d') + 29,
1636
+						date('Y')
1637
+					)
1638
+				);
1639
+			}
1640
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1641
+		}
1642
+		// generate ticket_datetime items
1643
+		if (! $default) {
1644
+			$datetime_row = 1;
1645
+			foreach ($all_datetimes as $datetime) {
1646
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1647
+					$datetime_row,
1648
+					$ticket_row,
1649
+					$datetime,
1650
+					$ticket,
1651
+					$ticket_datetimes,
1652
+					$default
1653
+				);
1654
+				$datetime_row++;
1655
+			}
1656
+		}
1657
+		$price_row = 1;
1658
+		foreach ($prices as $price) {
1659
+			if (! $price instanceof EE_Price) {
1660
+				continue;
1661
+			}
1662
+			if ($price->is_base_price()) {
1663
+				$price_row++;
1664
+				continue;
1665
+			}
1666
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1667
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1668
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1669
+				$ticket_row,
1670
+				$price_row,
1671
+				$price,
1672
+				$default,
1673
+				$ticket,
1674
+				$show_trash,
1675
+				$show_create
1676
+			);
1677
+			$price_row++;
1678
+		}
1679
+		// filter $template_args
1680
+		$template_args = apply_filters(
1681
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1682
+			$template_args,
1683
+			$ticket_row,
1684
+			$ticket,
1685
+			$ticket_datetimes,
1686
+			$all_datetimes,
1687
+			$default,
1688
+			$all_tickets,
1689
+			$this->_is_creating_event
1690
+		);
1691
+		return EEH_Template::display_template(
1692
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1693
+			$template_args,
1694
+			true
1695
+		);
1696
+	}
1697 1697
 
1698 1698
 
1699
-    /**
1700
-     * @param int            $ticket_row
1701
-     * @param EE_Ticket|null $ticket
1702
-     * @return string
1703
-     * @throws DomainException
1704
-     * @throws EE_Error
1705
-     */
1706
-    protected function _get_tax_rows($ticket_row, $ticket)
1707
-    {
1708
-        $tax_rows = '';
1709
-        /** @var EE_Price[] $taxes */
1710
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1711
-        foreach ($taxes as $tax) {
1712
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1713
-            $template_args = array(
1714
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1715
-                    ? ''
1716
-                    : ' style="display:none;"',
1717
-                'tax_id'            => $tax->ID(),
1718
-                'tkt_row'           => $ticket_row,
1719
-                'tax_label'         => $tax->get('PRC_name'),
1720
-                'tax_added'         => $tax_added,
1721
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1722
-                'tax_amount'        => $tax->get('PRC_amount'),
1723
-            );
1724
-            $template_args = apply_filters(
1725
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1726
-                $template_args,
1727
-                $ticket_row,
1728
-                $ticket,
1729
-                $this->_is_creating_event
1730
-            );
1731
-            $tax_rows .= EEH_Template::display_template(
1732
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1733
-                $template_args,
1734
-                true
1735
-            );
1736
-        }
1737
-        return $tax_rows;
1738
-    }
1699
+	/**
1700
+	 * @param int            $ticket_row
1701
+	 * @param EE_Ticket|null $ticket
1702
+	 * @return string
1703
+	 * @throws DomainException
1704
+	 * @throws EE_Error
1705
+	 */
1706
+	protected function _get_tax_rows($ticket_row, $ticket)
1707
+	{
1708
+		$tax_rows = '';
1709
+		/** @var EE_Price[] $taxes */
1710
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1711
+		foreach ($taxes as $tax) {
1712
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1713
+			$template_args = array(
1714
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1715
+					? ''
1716
+					: ' style="display:none;"',
1717
+				'tax_id'            => $tax->ID(),
1718
+				'tkt_row'           => $ticket_row,
1719
+				'tax_label'         => $tax->get('PRC_name'),
1720
+				'tax_added'         => $tax_added,
1721
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1722
+				'tax_amount'        => $tax->get('PRC_amount'),
1723
+			);
1724
+			$template_args = apply_filters(
1725
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1726
+				$template_args,
1727
+				$ticket_row,
1728
+				$ticket,
1729
+				$this->_is_creating_event
1730
+			);
1731
+			$tax_rows .= EEH_Template::display_template(
1732
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1733
+				$template_args,
1734
+				true
1735
+			);
1736
+		}
1737
+		return $tax_rows;
1738
+	}
1739 1739
 
1740 1740
 
1741
-    /**
1742
-     * @param EE_Price       $tax
1743
-     * @param EE_Ticket|null $ticket
1744
-     * @return float|int
1745
-     * @throws EE_Error
1746
-     */
1747
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1748
-    {
1749
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1750
-        return $subtotal * $tax->get('PRC_amount') / 100;
1751
-    }
1741
+	/**
1742
+	 * @param EE_Price       $tax
1743
+	 * @param EE_Ticket|null $ticket
1744
+	 * @return float|int
1745
+	 * @throws EE_Error
1746
+	 */
1747
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1748
+	{
1749
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1750
+		return $subtotal * $tax->get('PRC_amount') / 100;
1751
+	}
1752 1752
 
1753 1753
 
1754
-    /**
1755
-     * @param int            $ticket_row
1756
-     * @param int            $price_row
1757
-     * @param EE_Price|null  $price
1758
-     * @param bool           $default
1759
-     * @param EE_Ticket|null $ticket
1760
-     * @param bool           $show_trash
1761
-     * @param bool           $show_create
1762
-     * @return mixed
1763
-     * @throws InvalidArgumentException
1764
-     * @throws InvalidInterfaceException
1765
-     * @throws InvalidDataTypeException
1766
-     * @throws DomainException
1767
-     * @throws EE_Error
1768
-     * @throws ReflectionException
1769
-     */
1770
-    protected function _get_ticket_price_row(
1771
-        $ticket_row,
1772
-        $price_row,
1773
-        $price,
1774
-        $default,
1775
-        $ticket,
1776
-        $show_trash = true,
1777
-        $show_create = true
1778
-    ) {
1779
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1780
-        $template_args = array(
1781
-            'tkt_row'               => $default && empty($ticket)
1782
-                ? 'TICKETNUM'
1783
-                : $ticket_row,
1784
-            'PRC_order'             => $default && empty($price)
1785
-                ? 'PRICENUM'
1786
-                : $price_row,
1787
-            'edit_prices_name'      => $default && empty($price)
1788
-                ? 'PRICENAMEATTR'
1789
-                : 'edit_prices',
1790
-            'price_type_selector'   => $default && empty($price)
1791
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1792
-                : $this->_get_price_type_selector(
1793
-                    $ticket_row,
1794
-                    $price_row,
1795
-                    $price,
1796
-                    $default,
1797
-                    $send_disabled
1798
-                ),
1799
-            'PRC_ID'                => $default && empty($price)
1800
-                ? 0
1801
-                : $price->ID(),
1802
-            'PRC_is_default'        => $default && empty($price)
1803
-                ? 0
1804
-                : $price->get('PRC_is_default'),
1805
-            'PRC_name'              => $default && empty($price)
1806
-                ? ''
1807
-                : $price->get('PRC_name'),
1808
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
-            'show_plus_or_minus'    => $default && empty($price)
1810
-                ? ''
1811
-                : ' style="display:none;"',
1812
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1813
-                ? ' style="display:none;"'
1814
-                : '',
1815
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1816
-                ? ' style="display:none;"'
1817
-                : '',
1818
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1819
-                ? ' style="display:none"'
1820
-                : '',
1821
-            'PRC_amount'            => $default && empty($price)
1822
-                ? 0
1823
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1824
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1825
-                ? ' style="display:none;"'
1826
-                : '',
1827
-            'show_trash_icon'       => $show_trash
1828
-                ? ''
1829
-                : ' style="display:none;"',
1830
-            'show_create_button'    => $show_create
1831
-                ? ''
1832
-                : ' style="display:none;"',
1833
-            'PRC_desc'              => $default && empty($price)
1834
-                ? ''
1835
-                : $price->get('PRC_desc'),
1836
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1837
-        );
1838
-        $template_args = apply_filters(
1839
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1840
-            $template_args,
1841
-            $ticket_row,
1842
-            $price_row,
1843
-            $price,
1844
-            $default,
1845
-            $ticket,
1846
-            $show_trash,
1847
-            $show_create,
1848
-            $this->_is_creating_event
1849
-        );
1850
-        return EEH_Template::display_template(
1851
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1852
-            $template_args,
1853
-            true
1854
-        );
1855
-    }
1754
+	/**
1755
+	 * @param int            $ticket_row
1756
+	 * @param int            $price_row
1757
+	 * @param EE_Price|null  $price
1758
+	 * @param bool           $default
1759
+	 * @param EE_Ticket|null $ticket
1760
+	 * @param bool           $show_trash
1761
+	 * @param bool           $show_create
1762
+	 * @return mixed
1763
+	 * @throws InvalidArgumentException
1764
+	 * @throws InvalidInterfaceException
1765
+	 * @throws InvalidDataTypeException
1766
+	 * @throws DomainException
1767
+	 * @throws EE_Error
1768
+	 * @throws ReflectionException
1769
+	 */
1770
+	protected function _get_ticket_price_row(
1771
+		$ticket_row,
1772
+		$price_row,
1773
+		$price,
1774
+		$default,
1775
+		$ticket,
1776
+		$show_trash = true,
1777
+		$show_create = true
1778
+	) {
1779
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1780
+		$template_args = array(
1781
+			'tkt_row'               => $default && empty($ticket)
1782
+				? 'TICKETNUM'
1783
+				: $ticket_row,
1784
+			'PRC_order'             => $default && empty($price)
1785
+				? 'PRICENUM'
1786
+				: $price_row,
1787
+			'edit_prices_name'      => $default && empty($price)
1788
+				? 'PRICENAMEATTR'
1789
+				: 'edit_prices',
1790
+			'price_type_selector'   => $default && empty($price)
1791
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1792
+				: $this->_get_price_type_selector(
1793
+					$ticket_row,
1794
+					$price_row,
1795
+					$price,
1796
+					$default,
1797
+					$send_disabled
1798
+				),
1799
+			'PRC_ID'                => $default && empty($price)
1800
+				? 0
1801
+				: $price->ID(),
1802
+			'PRC_is_default'        => $default && empty($price)
1803
+				? 0
1804
+				: $price->get('PRC_is_default'),
1805
+			'PRC_name'              => $default && empty($price)
1806
+				? ''
1807
+				: $price->get('PRC_name'),
1808
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
+			'show_plus_or_minus'    => $default && empty($price)
1810
+				? ''
1811
+				: ' style="display:none;"',
1812
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1813
+				? ' style="display:none;"'
1814
+				: '',
1815
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1816
+				? ' style="display:none;"'
1817
+				: '',
1818
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1819
+				? ' style="display:none"'
1820
+				: '',
1821
+			'PRC_amount'            => $default && empty($price)
1822
+				? 0
1823
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1824
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1825
+				? ' style="display:none;"'
1826
+				: '',
1827
+			'show_trash_icon'       => $show_trash
1828
+				? ''
1829
+				: ' style="display:none;"',
1830
+			'show_create_button'    => $show_create
1831
+				? ''
1832
+				: ' style="display:none;"',
1833
+			'PRC_desc'              => $default && empty($price)
1834
+				? ''
1835
+				: $price->get('PRC_desc'),
1836
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1837
+		);
1838
+		$template_args = apply_filters(
1839
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1840
+			$template_args,
1841
+			$ticket_row,
1842
+			$price_row,
1843
+			$price,
1844
+			$default,
1845
+			$ticket,
1846
+			$show_trash,
1847
+			$show_create,
1848
+			$this->_is_creating_event
1849
+		);
1850
+		return EEH_Template::display_template(
1851
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1852
+			$template_args,
1853
+			true
1854
+		);
1855
+	}
1856 1856
 
1857 1857
 
1858
-    /**
1859
-     * @param int      $ticket_row
1860
-     * @param int      $price_row
1861
-     * @param EE_Price $price
1862
-     * @param bool     $default
1863
-     * @param bool     $disabled
1864
-     * @return mixed
1865
-     * @throws ReflectionException
1866
-     * @throws InvalidArgumentException
1867
-     * @throws InvalidInterfaceException
1868
-     * @throws InvalidDataTypeException
1869
-     * @throws DomainException
1870
-     * @throws EE_Error
1871
-     */
1872
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1873
-    {
1874
-        if ($price->is_base_price()) {
1875
-            return $this->_get_base_price_template(
1876
-                $ticket_row,
1877
-                $price_row,
1878
-                $price,
1879
-                $default
1880
-            );
1881
-        }
1882
-        return $this->_get_price_modifier_template(
1883
-            $ticket_row,
1884
-            $price_row,
1885
-            $price,
1886
-            $default,
1887
-            $disabled
1888
-        );
1889
-    }
1858
+	/**
1859
+	 * @param int      $ticket_row
1860
+	 * @param int      $price_row
1861
+	 * @param EE_Price $price
1862
+	 * @param bool     $default
1863
+	 * @param bool     $disabled
1864
+	 * @return mixed
1865
+	 * @throws ReflectionException
1866
+	 * @throws InvalidArgumentException
1867
+	 * @throws InvalidInterfaceException
1868
+	 * @throws InvalidDataTypeException
1869
+	 * @throws DomainException
1870
+	 * @throws EE_Error
1871
+	 */
1872
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1873
+	{
1874
+		if ($price->is_base_price()) {
1875
+			return $this->_get_base_price_template(
1876
+				$ticket_row,
1877
+				$price_row,
1878
+				$price,
1879
+				$default
1880
+			);
1881
+		}
1882
+		return $this->_get_price_modifier_template(
1883
+			$ticket_row,
1884
+			$price_row,
1885
+			$price,
1886
+			$default,
1887
+			$disabled
1888
+		);
1889
+	}
1890 1890
 
1891 1891
 
1892
-    /**
1893
-     * @param int      $ticket_row
1894
-     * @param int      $price_row
1895
-     * @param EE_Price $price
1896
-     * @param bool     $default
1897
-     * @return mixed
1898
-     * @throws DomainException
1899
-     * @throws EE_Error
1900
-     */
1901
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1902
-    {
1903
-        $template_args = array(
1904
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1905
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1906
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1907
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1908
-            'price_selected_operator'   => '+',
1909
-            'price_selected_is_percent' => 0,
1910
-        );
1911
-        $template_args = apply_filters(
1912
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1913
-            $template_args,
1914
-            $ticket_row,
1915
-            $price_row,
1916
-            $price,
1917
-            $default,
1918
-            $this->_is_creating_event
1919
-        );
1920
-        return EEH_Template::display_template(
1921
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1922
-            $template_args,
1923
-            true
1924
-        );
1925
-    }
1892
+	/**
1893
+	 * @param int      $ticket_row
1894
+	 * @param int      $price_row
1895
+	 * @param EE_Price $price
1896
+	 * @param bool     $default
1897
+	 * @return mixed
1898
+	 * @throws DomainException
1899
+	 * @throws EE_Error
1900
+	 */
1901
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1902
+	{
1903
+		$template_args = array(
1904
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1905
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1906
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1907
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1908
+			'price_selected_operator'   => '+',
1909
+			'price_selected_is_percent' => 0,
1910
+		);
1911
+		$template_args = apply_filters(
1912
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1913
+			$template_args,
1914
+			$ticket_row,
1915
+			$price_row,
1916
+			$price,
1917
+			$default,
1918
+			$this->_is_creating_event
1919
+		);
1920
+		return EEH_Template::display_template(
1921
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1922
+			$template_args,
1923
+			true
1924
+		);
1925
+	}
1926 1926
 
1927 1927
 
1928
-    /**
1929
-     * @param int      $ticket_row
1930
-     * @param int      $price_row
1931
-     * @param EE_Price $price
1932
-     * @param bool     $default
1933
-     * @param bool     $disabled
1934
-     * @return mixed
1935
-     * @throws ReflectionException
1936
-     * @throws InvalidArgumentException
1937
-     * @throws InvalidInterfaceException
1938
-     * @throws InvalidDataTypeException
1939
-     * @throws DomainException
1940
-     * @throws EE_Error
1941
-     */
1942
-    protected function _get_price_modifier_template(
1943
-        $ticket_row,
1944
-        $price_row,
1945
-        $price,
1946
-        $default,
1947
-        $disabled = false
1948
-    ) {
1949
-        $select_name = $default && ! $price instanceof EE_Price
1950
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1951
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1952
-        /** @var EEM_Price_Type $price_type_model */
1953
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1954
-        $price_types = $price_type_model->get_all(array(
1955
-            array(
1956
-                'OR' => array(
1957
-                    'PBT_ID'  => '2',
1958
-                    'PBT_ID*' => '3',
1959
-                ),
1960
-            ),
1961
-        ));
1962
-        $all_price_types = $default && ! $price instanceof EE_Price
1963
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1964
-            : array();
1965
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1966
-        $price_option_spans = '';
1967
-        // setup price types for selector
1968
-        foreach ($price_types as $price_type) {
1969
-            if (! $price_type instanceof EE_Price_Type) {
1970
-                continue;
1971
-            }
1972
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1973
-            // while we're in the loop let's setup the option spans used by js
1974
-            $span_args = array(
1975
-                'PRT_ID'         => $price_type->ID(),
1976
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1977
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1978
-            );
1979
-            $price_option_spans .= EEH_Template::display_template(
1980
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1981
-                $span_args,
1982
-                true
1983
-            );
1984
-        }
1985
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1986
-            : $select_name;
1987
-        $select_input = new EE_Select_Input(
1988
-            $all_price_types,
1989
-            array(
1990
-                'default'               => $selected_price_type_id,
1991
-                'html_name'             => $select_name,
1992
-                'html_class'            => 'edit-price-PRT_ID',
1993
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1994
-            )
1995
-        );
1996
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1997
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1998
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1999
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
2000
-        $template_args = array(
2001
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
2002
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
2003
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
2004
-            'main_name'                 => $select_name,
2005
-            'selected_price_type_id'    => $selected_price_type_id,
2006
-            'price_option_spans'        => $price_option_spans,
2007
-            'price_selected_operator'   => $price_selected_operator,
2008
-            'price_selected_is_percent' => $price_selected_is_percent,
2009
-            'disabled'                  => $disabled,
2010
-        );
2011
-        $template_args = apply_filters(
2012
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2013
-            $template_args,
2014
-            $ticket_row,
2015
-            $price_row,
2016
-            $price,
2017
-            $default,
2018
-            $disabled,
2019
-            $this->_is_creating_event
2020
-        );
2021
-        return EEH_Template::display_template(
2022
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2023
-            $template_args,
2024
-            true
2025
-        );
2026
-    }
1928
+	/**
1929
+	 * @param int      $ticket_row
1930
+	 * @param int      $price_row
1931
+	 * @param EE_Price $price
1932
+	 * @param bool     $default
1933
+	 * @param bool     $disabled
1934
+	 * @return mixed
1935
+	 * @throws ReflectionException
1936
+	 * @throws InvalidArgumentException
1937
+	 * @throws InvalidInterfaceException
1938
+	 * @throws InvalidDataTypeException
1939
+	 * @throws DomainException
1940
+	 * @throws EE_Error
1941
+	 */
1942
+	protected function _get_price_modifier_template(
1943
+		$ticket_row,
1944
+		$price_row,
1945
+		$price,
1946
+		$default,
1947
+		$disabled = false
1948
+	) {
1949
+		$select_name = $default && ! $price instanceof EE_Price
1950
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1951
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1952
+		/** @var EEM_Price_Type $price_type_model */
1953
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1954
+		$price_types = $price_type_model->get_all(array(
1955
+			array(
1956
+				'OR' => array(
1957
+					'PBT_ID'  => '2',
1958
+					'PBT_ID*' => '3',
1959
+				),
1960
+			),
1961
+		));
1962
+		$all_price_types = $default && ! $price instanceof EE_Price
1963
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1964
+			: array();
1965
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1966
+		$price_option_spans = '';
1967
+		// setup price types for selector
1968
+		foreach ($price_types as $price_type) {
1969
+			if (! $price_type instanceof EE_Price_Type) {
1970
+				continue;
1971
+			}
1972
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1973
+			// while we're in the loop let's setup the option spans used by js
1974
+			$span_args = array(
1975
+				'PRT_ID'         => $price_type->ID(),
1976
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1977
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1978
+			);
1979
+			$price_option_spans .= EEH_Template::display_template(
1980
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1981
+				$span_args,
1982
+				true
1983
+			);
1984
+		}
1985
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1986
+			: $select_name;
1987
+		$select_input = new EE_Select_Input(
1988
+			$all_price_types,
1989
+			array(
1990
+				'default'               => $selected_price_type_id,
1991
+				'html_name'             => $select_name,
1992
+				'html_class'            => 'edit-price-PRT_ID',
1993
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1994
+			)
1995
+		);
1996
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1997
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1998
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1999
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
2000
+		$template_args = array(
2001
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
2002
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
2003
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
2004
+			'main_name'                 => $select_name,
2005
+			'selected_price_type_id'    => $selected_price_type_id,
2006
+			'price_option_spans'        => $price_option_spans,
2007
+			'price_selected_operator'   => $price_selected_operator,
2008
+			'price_selected_is_percent' => $price_selected_is_percent,
2009
+			'disabled'                  => $disabled,
2010
+		);
2011
+		$template_args = apply_filters(
2012
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2013
+			$template_args,
2014
+			$ticket_row,
2015
+			$price_row,
2016
+			$price,
2017
+			$default,
2018
+			$disabled,
2019
+			$this->_is_creating_event
2020
+		);
2021
+		return EEH_Template::display_template(
2022
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2023
+			$template_args,
2024
+			true
2025
+		);
2026
+	}
2027 2027
 
2028 2028
 
2029
-    /**
2030
-     * @param int              $datetime_row
2031
-     * @param int              $ticket_row
2032
-     * @param EE_Datetime|null $datetime
2033
-     * @param EE_Ticket|null   $ticket
2034
-     * @param array            $ticket_datetimes
2035
-     * @param bool             $default
2036
-     * @return mixed
2037
-     * @throws DomainException
2038
-     * @throws EE_Error
2039
-     */
2040
-    protected function _get_ticket_datetime_list_item(
2041
-        $datetime_row,
2042
-        $ticket_row,
2043
-        $datetime,
2044
-        $ticket,
2045
-        $ticket_datetimes = array(),
2046
-        $default
2047
-    ) {
2048
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2049
-            ? $ticket_datetimes[ $ticket->ID() ]
2050
-            : array();
2051
-        $template_args = array(
2052
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2053
-                ? 'DTTNUM'
2054
-                : $datetime_row,
2055
-            'tkt_row'                  => $default
2056
-                ? 'TICKETNUM'
2057
-                : $ticket_row,
2058
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2059
-                ? ' ticket-selected'
2060
-                : '',
2061
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2062
-                ? ' checked="checked"'
2063
-                : '',
2064
-            'DTT_name'                 => $default && empty($datetime)
2065
-                ? 'DTTNAME'
2066
-                : $datetime->get_dtt_display_name(true),
2067
-            'tkt_status_class'         => '',
2068
-        );
2069
-        $template_args = apply_filters(
2070
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2071
-            $template_args,
2072
-            $datetime_row,
2073
-            $ticket_row,
2074
-            $datetime,
2075
-            $ticket,
2076
-            $ticket_datetimes,
2077
-            $default,
2078
-            $this->_is_creating_event
2079
-        );
2080
-        return EEH_Template::display_template(
2081
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2082
-            $template_args,
2083
-            true
2084
-        );
2085
-    }
2029
+	/**
2030
+	 * @param int              $datetime_row
2031
+	 * @param int              $ticket_row
2032
+	 * @param EE_Datetime|null $datetime
2033
+	 * @param EE_Ticket|null   $ticket
2034
+	 * @param array            $ticket_datetimes
2035
+	 * @param bool             $default
2036
+	 * @return mixed
2037
+	 * @throws DomainException
2038
+	 * @throws EE_Error
2039
+	 */
2040
+	protected function _get_ticket_datetime_list_item(
2041
+		$datetime_row,
2042
+		$ticket_row,
2043
+		$datetime,
2044
+		$ticket,
2045
+		$ticket_datetimes = array(),
2046
+		$default
2047
+	) {
2048
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2049
+			? $ticket_datetimes[ $ticket->ID() ]
2050
+			: array();
2051
+		$template_args = array(
2052
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2053
+				? 'DTTNUM'
2054
+				: $datetime_row,
2055
+			'tkt_row'                  => $default
2056
+				? 'TICKETNUM'
2057
+				: $ticket_row,
2058
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2059
+				? ' ticket-selected'
2060
+				: '',
2061
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2062
+				? ' checked="checked"'
2063
+				: '',
2064
+			'DTT_name'                 => $default && empty($datetime)
2065
+				? 'DTTNAME'
2066
+				: $datetime->get_dtt_display_name(true),
2067
+			'tkt_status_class'         => '',
2068
+		);
2069
+		$template_args = apply_filters(
2070
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2071
+			$template_args,
2072
+			$datetime_row,
2073
+			$ticket_row,
2074
+			$datetime,
2075
+			$ticket,
2076
+			$ticket_datetimes,
2077
+			$default,
2078
+			$this->_is_creating_event
2079
+		);
2080
+		return EEH_Template::display_template(
2081
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2082
+			$template_args,
2083
+			true
2084
+		);
2085
+	}
2086 2086
 
2087 2087
 
2088
-    /**
2089
-     * @param array $all_datetimes
2090
-     * @param array $all_tickets
2091
-     * @return mixed
2092
-     * @throws ReflectionException
2093
-     * @throws InvalidArgumentException
2094
-     * @throws InvalidInterfaceException
2095
-     * @throws InvalidDataTypeException
2096
-     * @throws DomainException
2097
-     * @throws EE_Error
2098
-     */
2099
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2100
-    {
2101
-        $template_args = array(
2102
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2103
-                'DTTNUM',
2104
-                null,
2105
-                true,
2106
-                $all_datetimes
2107
-            ),
2108
-            'default_ticket_row'                       => $this->_get_ticket_row(
2109
-                'TICKETNUM',
2110
-                null,
2111
-                array(),
2112
-                array(),
2113
-                true
2114
-            ),
2115
-            'default_price_row'                        => $this->_get_ticket_price_row(
2116
-                'TICKETNUM',
2117
-                'PRICENUM',
2118
-                null,
2119
-                true,
2120
-                null
2121
-            ),
2122
-            'default_price_rows'                       => '',
2123
-            'default_base_price_amount'                => 0,
2124
-            'default_base_price_name'                  => '',
2125
-            'default_base_price_description'           => '',
2126
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2127
-                'TICKETNUM',
2128
-                'PRICENUM',
2129
-                null,
2130
-                true
2131
-            ),
2132
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2133
-                'DTTNUM',
2134
-                null,
2135
-                array(),
2136
-                array(),
2137
-                true
2138
-            ),
2139
-            'existing_available_datetime_tickets_list' => '',
2140
-            'existing_available_ticket_datetimes_list' => '',
2141
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2142
-                'DTTNUM',
2143
-                'TICKETNUM',
2144
-                null,
2145
-                null,
2146
-                array(),
2147
-                true
2148
-            ),
2149
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2150
-                'DTTNUM',
2151
-                'TICKETNUM',
2152
-                null,
2153
-                null,
2154
-                array(),
2155
-                true
2156
-            ),
2157
-        );
2158
-        $ticket_row = 1;
2159
-        foreach ($all_tickets as $ticket) {
2160
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2161
-                'DTTNUM',
2162
-                $ticket_row,
2163
-                null,
2164
-                $ticket,
2165
-                array(),
2166
-                true
2167
-            );
2168
-            $ticket_row++;
2169
-        }
2170
-        $datetime_row = 1;
2171
-        foreach ($all_datetimes as $datetime) {
2172
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2173
-                $datetime_row,
2174
-                'TICKETNUM',
2175
-                $datetime,
2176
-                null,
2177
-                array(),
2178
-                true
2179
-            );
2180
-            $datetime_row++;
2181
-        }
2182
-        /** @var EEM_Price $price_model */
2183
-        $price_model = EE_Registry::instance()->load_model('Price');
2184
-        $default_prices = $price_model->get_all_default_prices();
2185
-        $price_row = 1;
2186
-        foreach ($default_prices as $price) {
2187
-            if (! $price instanceof EE_Price) {
2188
-                continue;
2189
-            }
2190
-            if ($price->is_base_price()) {
2191
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2192
-                    'PRC_amount',
2193
-                    'localized_float'
2194
-                );
2195
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2196
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2197
-                $price_row++;
2198
-                continue;
2199
-            }
2200
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2201
-                             || count($default_prices) === 1);
2202
-            $show_create = ! (count($default_prices) > 1
2203
-                              && count($default_prices)
2204
-                                 !== $price_row);
2205
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2206
-                'TICKETNUM',
2207
-                $price_row,
2208
-                $price,
2209
-                true,
2210
-                null,
2211
-                $show_trash,
2212
-                $show_create
2213
-            );
2214
-            $price_row++;
2215
-        }
2216
-        $template_args = apply_filters(
2217
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2218
-            $template_args,
2219
-            $all_datetimes,
2220
-            $all_tickets,
2221
-            $this->_is_creating_event
2222
-        );
2223
-        return EEH_Template::display_template(
2224
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2225
-            $template_args,
2226
-            true
2227
-        );
2228
-    }
2088
+	/**
2089
+	 * @param array $all_datetimes
2090
+	 * @param array $all_tickets
2091
+	 * @return mixed
2092
+	 * @throws ReflectionException
2093
+	 * @throws InvalidArgumentException
2094
+	 * @throws InvalidInterfaceException
2095
+	 * @throws InvalidDataTypeException
2096
+	 * @throws DomainException
2097
+	 * @throws EE_Error
2098
+	 */
2099
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2100
+	{
2101
+		$template_args = array(
2102
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2103
+				'DTTNUM',
2104
+				null,
2105
+				true,
2106
+				$all_datetimes
2107
+			),
2108
+			'default_ticket_row'                       => $this->_get_ticket_row(
2109
+				'TICKETNUM',
2110
+				null,
2111
+				array(),
2112
+				array(),
2113
+				true
2114
+			),
2115
+			'default_price_row'                        => $this->_get_ticket_price_row(
2116
+				'TICKETNUM',
2117
+				'PRICENUM',
2118
+				null,
2119
+				true,
2120
+				null
2121
+			),
2122
+			'default_price_rows'                       => '',
2123
+			'default_base_price_amount'                => 0,
2124
+			'default_base_price_name'                  => '',
2125
+			'default_base_price_description'           => '',
2126
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2127
+				'TICKETNUM',
2128
+				'PRICENUM',
2129
+				null,
2130
+				true
2131
+			),
2132
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2133
+				'DTTNUM',
2134
+				null,
2135
+				array(),
2136
+				array(),
2137
+				true
2138
+			),
2139
+			'existing_available_datetime_tickets_list' => '',
2140
+			'existing_available_ticket_datetimes_list' => '',
2141
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2142
+				'DTTNUM',
2143
+				'TICKETNUM',
2144
+				null,
2145
+				null,
2146
+				array(),
2147
+				true
2148
+			),
2149
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2150
+				'DTTNUM',
2151
+				'TICKETNUM',
2152
+				null,
2153
+				null,
2154
+				array(),
2155
+				true
2156
+			),
2157
+		);
2158
+		$ticket_row = 1;
2159
+		foreach ($all_tickets as $ticket) {
2160
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2161
+				'DTTNUM',
2162
+				$ticket_row,
2163
+				null,
2164
+				$ticket,
2165
+				array(),
2166
+				true
2167
+			);
2168
+			$ticket_row++;
2169
+		}
2170
+		$datetime_row = 1;
2171
+		foreach ($all_datetimes as $datetime) {
2172
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2173
+				$datetime_row,
2174
+				'TICKETNUM',
2175
+				$datetime,
2176
+				null,
2177
+				array(),
2178
+				true
2179
+			);
2180
+			$datetime_row++;
2181
+		}
2182
+		/** @var EEM_Price $price_model */
2183
+		$price_model = EE_Registry::instance()->load_model('Price');
2184
+		$default_prices = $price_model->get_all_default_prices();
2185
+		$price_row = 1;
2186
+		foreach ($default_prices as $price) {
2187
+			if (! $price instanceof EE_Price) {
2188
+				continue;
2189
+			}
2190
+			if ($price->is_base_price()) {
2191
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2192
+					'PRC_amount',
2193
+					'localized_float'
2194
+				);
2195
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2196
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2197
+				$price_row++;
2198
+				continue;
2199
+			}
2200
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2201
+							 || count($default_prices) === 1);
2202
+			$show_create = ! (count($default_prices) > 1
2203
+							  && count($default_prices)
2204
+								 !== $price_row);
2205
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2206
+				'TICKETNUM',
2207
+				$price_row,
2208
+				$price,
2209
+				true,
2210
+				null,
2211
+				$show_trash,
2212
+				$show_create
2213
+			);
2214
+			$price_row++;
2215
+		}
2216
+		$template_args = apply_filters(
2217
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2218
+			$template_args,
2219
+			$all_datetimes,
2220
+			$all_tickets,
2221
+			$this->_is_creating_event
2222
+		);
2223
+		return EEH_Template::display_template(
2224
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2225
+			$template_args,
2226
+			true
2227
+		);
2228
+	}
2229 2229
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             );
154 154
             $msg .= '</p><ul>';
155 155
             foreach ($format_validation as $error) {
156
-                $msg .= '<li>' . $error . '</li>';
156
+                $msg .= '<li>'.$error.'</li>';
157 157
             }
158 158
             $msg .= '</ul><p>';
159 159
             $msg .= sprintf(
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
         $this->_scripts_styles = array(
183 183
             'registers'   => array(
184 184
                 'ee-tickets-datetimes-css' => array(
185
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
185
+                    'url'  => PRICING_ASSETS_URL.'event-tickets-datetimes.css',
186 186
                     'type' => 'css',
187 187
                 ),
188 188
                 'ee-dtt-ticket-metabox'    => array(
189
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
189
+                    'url'     => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js',
190 190
                     'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
191 191
                 ),
192 192
             ),
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
                             'event_espresso'
211 211
                         ),
212 212
                         'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
213
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
213
+                                                     . esc_html__('Cancel', 'event_espresso').'</button>',
214 214
                         'close_button'            => '<button class="button-secondary ee-modal-cancel">'
215
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
215
+                                                     . esc_html__('Close', 'event_espresso').'</button>',
216 216
                         'single_warning_from_tkt' => esc_html__(
217 217
                             'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
218 218
                             'event_espresso'
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                             'event_espresso'
223 223
                         ),
224 224
                         'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
225
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
225
+                                                     . esc_html__('Dismiss', 'event_espresso').'</button>',
226 226
                     ),
227 227
                     'DTT_ERROR_MSG'         => array(
228 228
                         'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315 315
             // trim all values to ensure any excess whitespace is removed.
316 316
             $datetime_data = array_map(
317
-                function ($datetime_data) {
317
+                function($datetime_data) {
318 318
                     return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319 319
                 },
320 320
                 $datetime_data
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
             );
345 345
             // if we have an id then let's get existing object first and then set the new values.
346 346
             // Otherwise we instantiate a new object for save.
347
-            if (! empty($datetime_data['DTT_ID'])) {
347
+            if ( ! empty($datetime_data['DTT_ID'])) {
348 348
                 $datetime = EE_Registry::instance()
349 349
                                        ->load_model('Datetime', array($timezone))
350 350
                                        ->get_one_by_ID($datetime_data['DTT_ID']);
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
                 // after the add_relation_to() the autosave replaces it.
359 359
                 // We need to do this so we dont' TRASH the parent DTT.
360 360
                 // (save the ID for both key and value to avoid duplications)
361
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
+                $saved_dtt_ids[$datetime->ID()] = $datetime->ID();
362 362
             } else {
363 363
                 $datetime = EE_Registry::instance()->load_class(
364 364
                     'Datetime',
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
             // because it is possible there was a new one created for the autosave.
395 395
             // (save the ID for both key and value to avoid duplications)
396 396
             $DTT_ID = $datetime->ID();
397
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
-            $saved_dtt_objs[ $row ] = $datetime;
397
+            $saved_dtt_ids[$DTT_ID] = $DTT_ID;
398
+            $saved_dtt_objs[$row] = $datetime;
399 399
             // @todo if ANY of these updates fail then we want the appropriate global error message.
400 400
         }
401 401
         $event->save();
@@ -460,13 +460,13 @@  discard block
 block discarded – undo
460 460
             $update_prices = $create_new_TKT = false;
461 461
             // figure out what datetimes were added to the ticket
462 462
             // and what datetimes were removed from the ticket in the session.
463
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
464
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
463
+            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
464
+            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]);
465 465
             $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
466 466
             $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
467 467
             // trim inputs to ensure any excess whitespace is removed.
468 468
             $tkt = array_map(
469
-                function ($ticket_data) {
469
+                function($ticket_data) {
470 470
                     return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
471 471
                 },
472 472
                 $tkt
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
             $base_price_id = isset($tkt['TKT_base_price_ID'])
489 489
                 ? $tkt['TKT_base_price_ID']
490 490
                 : 0;
491
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
492
-                ? $data['edit_prices'][ $row ]
491
+            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row])
492
+                ? $data['edit_prices'][$row]
493 493
                 : array();
494 494
             $now = null;
495 495
             if (empty($tkt['TKT_start_date'])) {
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
                 /**
502 502
                  * set the TKT_end_date to the first datetime attached to the ticket.
503 503
                  */
504
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
504
+                $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)];
505 505
                 $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
506 506
             }
507 507
             $TKT_values = array(
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
             // need to make sue that the TKT_price is accurate after saving the prices.
637 637
             $ticket->ensure_TKT_Price_correct();
638 638
             // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
639
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
639
+            if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
640 640
                 $update_prices = true;
641 641
                 $new_default = clone $ticket;
642 642
                 $new_default->set('TKT_ID', 0);
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                 // save new TKT
682 682
                 $new_tkt->save();
683 683
                 // add new ticket to array
684
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
684
+                $saved_tickets[$new_tkt->ID()] = $new_tkt;
685 685
                 do_action(
686 686
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
687 687
                     $new_tkt,
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
                 );
692 692
             } else {
693 693
                 // add tkt to saved tkts
694
-                $saved_tickets[ $ticket->ID() ] = $ticket;
694
+                $saved_tickets[$ticket->ID()] = $ticket;
695 695
                 do_action(
696 696
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
697 697
                     $ticket,
@@ -758,31 +758,31 @@  discard block
 block discarded – undo
758 758
         // to start we have to add the ticket to all the datetimes its supposed to be with,
759 759
         // and removing the ticket from datetimes it got removed from.
760 760
         // first let's add datetimes
761
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
761
+        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
762 762
             foreach ($added_datetimes as $row_id) {
763 763
                 $row_id = (int) $row_id;
764
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
765
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
764
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
765
+                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
766 766
                     // Is this an existing ticket (has an ID) and does it have any sold?
767 767
                     // If so, then we need to add that to the DTT sold because this DTT is getting added.
768 768
                     if ($ticket->ID() && $ticket->sold() > 0) {
769
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
769
+                        $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false);
770 770
                     }
771 771
                 }
772 772
             }
773 773
         }
774 774
         // then remove datetimes
775
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
775
+        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
776 776
             foreach ($removed_datetimes as $row_id) {
777 777
                 $row_id = (int) $row_id;
778 778
                 // its entirely possible that a datetime got deleted (instead of just removed from relationship.
779 779
                 // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
780
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
781
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
780
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
781
+                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
782 782
                     // Is this an existing ticket (has an ID) and does it have any sold?
783 783
                     // If so, then we need to remove it's sold from the DTT_sold.
784 784
                     if ($ticket->ID() && $ticket->sold() > 0) {
785
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
785
+                        $saved_datetimes[$row_id]->decreaseSold($ticket->sold());
786 786
                     }
787 787
                 }
788 788
             }
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
             );
896 896
         }
897 897
         // possibly need to save tkt
898
-        if (! $ticket->ID()) {
898
+        if ( ! $ticket->ID()) {
899 899
             $ticket->save();
900 900
         }
901 901
         foreach ($prices as $row => $prc) {
@@ -929,17 +929,17 @@  discard block
 block discarded – undo
929 929
                 }
930 930
             }
931 931
             $price->save();
932
-            $updated_prices[ $price->ID() ] = $price;
932
+            $updated_prices[$price->ID()] = $price;
933 933
             $ticket->_add_relation_to($price, 'Price');
934 934
         }
935 935
         // now let's remove any prices that got removed from the ticket
936
-        if (! empty($current_prices_on_ticket)) {
936
+        if ( ! empty($current_prices_on_ticket)) {
937 937
             $current = array_keys($current_prices_on_ticket);
938 938
             $updated = array_keys($updated_prices);
939 939
             $prices_to_remove = array_diff($current, $updated);
940
-            if (! empty($prices_to_remove)) {
940
+            if ( ! empty($prices_to_remove)) {
941 941
                 foreach ($prices_to_remove as $prc_id) {
942
-                    $p = $current_prices_on_ticket[ $prc_id ];
942
+                    $p = $current_prices_on_ticket[$prc_id];
943 943
                     $ticket->_remove_relation_to($p, 'Price');
944 944
                     // delete permanently the price
945 945
                     $p->delete_permanently();
@@ -1090,18 +1090,18 @@  discard block
 block discarded – undo
1090 1090
                 $TKT_ID = $ticket->get('TKT_ID');
1091 1091
                 $ticket_row = $ticket->get('TKT_row');
1092 1092
                 // we only want unique tickets in our final display!!
1093
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1093
+                if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094 1094
                     $existing_ticket_ids[] = $TKT_ID;
1095 1095
                     $all_tickets[] = $ticket;
1096 1096
                 }
1097 1097
                 // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1098
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1098
+                $datetime_tickets[$DTT_ID][] = $ticket_row;
1099 1099
                 // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1100 1100
                 if (
1101
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1102
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1101
+                    ! isset($ticket_datetimes[$TKT_ID])
1102
+                    || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true)
1103 1103
                 ) {
1104
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1104
+                    $ticket_datetimes[$TKT_ID][] = $datetime_row;
1105 1105
                 }
1106 1106
             }
1107 1107
             $datetime_row++;
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
         // sort $all_tickets by order
1113 1113
         usort(
1114 1114
             $all_tickets,
1115
-            function (EE_Ticket $a, EE_Ticket $b) {
1115
+            function(EE_Ticket $a, EE_Ticket $b) {
1116 1116
                 $a_order = (int) $a->get('TKT_order');
1117 1117
                 $b_order = (int) $b->get('TKT_order');
1118 1118
                 if ($a_order === $b_order) {
@@ -1153,16 +1153,16 @@  discard block
 block discarded – undo
1153 1153
         $status_change_notice = EventEspresso\core\services\loaders\LoaderFactory::getLoader()->getShared(
1154 1154
             'EventEspresso\core\admin\StatusChangeNotice'
1155 1155
         );
1156
-        if (! $status_change_notice->isDismissed()) {
1156
+        if ( ! $status_change_notice->isDismissed()) {
1157 1157
             $main_template_args['status_change_notice'] = EEH_Template::display_template(
1158
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
1158
+                EE_ADMIN_TEMPLATE.'status_change_notice.template.php',
1159 1159
                 ['context' => '__event-editor', 'page_slug' => 'espresso-events'],
1160 1160
                 true
1161 1161
             );
1162 1162
         }
1163 1163
 
1164 1164
         EEH_Template::display_template(
1165
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1165
+            PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php',
1166 1166
             $main_template_args
1167 1167
         );
1168 1168
     }
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
             'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1205 1205
         );
1206 1206
         return EEH_Template::display_template(
1207
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1207
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php',
1208 1208
             $dtt_display_template_args,
1209 1209
             true
1210 1210
         );
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
             $this->_is_creating_event
1274 1274
         );
1275 1275
         return EEH_Template::display_template(
1276
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1276
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php',
1277 1277
             $template_args,
1278 1278
             true
1279 1279
         );
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
             'DTT_ID'                            => $default ? '' : $datetime->ID(),
1315 1315
         );
1316 1316
         // need to setup the list items (but only if this isn't a default skeleton setup)
1317
-        if (! $default) {
1317
+        if ( ! $default) {
1318 1318
             $ticket_row = 1;
1319 1319
             foreach ($all_tickets as $ticket) {
1320 1320
                 $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
             $this->_is_creating_event
1341 1341
         );
1342 1342
         return EEH_Template::display_template(
1343
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1343
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php',
1344 1344
             $template_args,
1345 1345
             true
1346 1346
         );
@@ -1366,8 +1366,8 @@  discard block
 block discarded – undo
1366 1366
         $datetime_tickets = array(),
1367 1367
         $default
1368 1368
     ) {
1369
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1370
-            ? $datetime_tickets[ $datetime->ID() ]
1369
+        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()])
1370
+            ? $datetime_tickets[$datetime->ID()]
1371 1371
             : array();
1372 1372
         $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1373 1373
         $no_ticket = $default && empty($ticket);
@@ -1388,8 +1388,8 @@  discard block
 block discarded – undo
1388 1388
                 ? 'TKTNAME'
1389 1389
                 : $ticket->get('TKT_name'),
1390 1390
             'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1391
-                ? ' tkt-status-' . EE_Ticket::onsale
1392
-                : ' tkt-status-' . $ticket->ticket_status(),
1391
+                ? ' tkt-status-'.EE_Ticket::onsale
1392
+                : ' tkt-status-'.$ticket->ticket_status(),
1393 1393
         );
1394 1394
         // filter template args
1395 1395
         $template_args = apply_filters(
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
             $this->_is_creating_event
1405 1405
         );
1406 1406
         return EEH_Template::display_template(
1407
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1407
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php',
1408 1408
             $template_args,
1409 1409
             true
1410 1410
         );
@@ -1460,19 +1460,19 @@  discard block
 block discarded – undo
1460 1460
         // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1461 1461
         // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1462 1462
         $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1463
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1464
-            ? $ticket_datetimes[ $ticket->ID() ]
1463
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
1464
+            ? $ticket_datetimes[$ticket->ID()]
1465 1465
             : array();
1466 1466
         $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1467 1467
         $base_price = $default ? null : $ticket->base_price();
1468 1468
         $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1469 1469
         // breaking out complicated condition for ticket_status
1470 1470
         if ($default) {
1471
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1471
+            $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale;
1472 1472
         } else {
1473 1473
             $ticket_status_class = $ticket->is_default()
1474
-                ? ' tkt-status-' . EE_Ticket::onsale
1475
-                : ' tkt-status-' . $ticket->ticket_status();
1474
+                ? ' tkt-status-'.EE_Ticket::onsale
1475
+                : ' tkt-status-'.$ticket->ticket_status();
1476 1476
         }
1477 1477
         // breaking out complicated condition for TKT_taxable
1478 1478
         if ($default) {
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
                 : ' style="display:none;"',
1565 1565
             'show_price_mod_button'         => count($prices) > 1
1566 1566
                                                || ($default && $count_price_mods > 0)
1567
-                                               || (! $default && $ticket->deleted())
1567
+                                               || ( ! $default && $ticket->deleted())
1568 1568
                 ? ' style="display:none;"'
1569 1569
                 : '',
1570 1570
             'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
                 $this->_date_time_format,
1609 1609
                 current_time('timestamp')
1610 1610
             );
1611
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1611
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1612 1612
         }
1613 1613
         if (empty($template_args['TKT_end_date'])) {
1614 1614
             // get the earliest datetime (if present);
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1619 1619
                 )
1620 1620
                 : null;
1621
-            if (! empty($earliest_dtt)) {
1621
+            if ( ! empty($earliest_dtt)) {
1622 1622
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1623 1623
                     'DTT_EVT_start',
1624 1624
                     $this->_date_time_format
@@ -1637,10 +1637,10 @@  discard block
 block discarded – undo
1637 1637
                     )
1638 1638
                 );
1639 1639
             }
1640
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1640
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1641 1641
         }
1642 1642
         // generate ticket_datetime items
1643
-        if (! $default) {
1643
+        if ( ! $default) {
1644 1644
             $datetime_row = 1;
1645 1645
             foreach ($all_datetimes as $datetime) {
1646 1646
                 $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
@@ -1656,7 +1656,7 @@  discard block
 block discarded – undo
1656 1656
         }
1657 1657
         $price_row = 1;
1658 1658
         foreach ($prices as $price) {
1659
-            if (! $price instanceof EE_Price) {
1659
+            if ( ! $price instanceof EE_Price) {
1660 1660
                 continue;
1661 1661
             }
1662 1662
             if ($price->is_base_price()) {
@@ -1689,7 +1689,7 @@  discard block
 block discarded – undo
1689 1689
             $this->_is_creating_event
1690 1690
         );
1691 1691
         return EEH_Template::display_template(
1692
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1692
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php',
1693 1693
             $template_args,
1694 1694
             true
1695 1695
         );
@@ -1729,7 +1729,7 @@  discard block
 block discarded – undo
1729 1729
                 $this->_is_creating_event
1730 1730
             );
1731 1731
             $tax_rows .= EEH_Template::display_template(
1732
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1732
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php',
1733 1733
                 $template_args,
1734 1734
                 true
1735 1735
             );
@@ -1848,7 +1848,7 @@  discard block
 block discarded – undo
1848 1848
             $this->_is_creating_event
1849 1849
         );
1850 1850
         return EEH_Template::display_template(
1851
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1851
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php',
1852 1852
             $template_args,
1853 1853
             true
1854 1854
         );
@@ -1918,7 +1918,7 @@  discard block
 block discarded – undo
1918 1918
             $this->_is_creating_event
1919 1919
         );
1920 1920
         return EEH_Template::display_template(
1921
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1921
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php',
1922 1922
             $template_args,
1923 1923
             true
1924 1924
         );
@@ -1948,7 +1948,7 @@  discard block
 block discarded – undo
1948 1948
     ) {
1949 1949
         $select_name = $default && ! $price instanceof EE_Price
1950 1950
             ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1951
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1951
+            : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]';
1952 1952
         /** @var EEM_Price_Type $price_type_model */
1953 1953
         $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1954 1954
         $price_types = $price_type_model->get_all(array(
@@ -1966,10 +1966,10 @@  discard block
 block discarded – undo
1966 1966
         $price_option_spans = '';
1967 1967
         // setup price types for selector
1968 1968
         foreach ($price_types as $price_type) {
1969
-            if (! $price_type instanceof EE_Price_Type) {
1969
+            if ( ! $price_type instanceof EE_Price_Type) {
1970 1970
                 continue;
1971 1971
             }
1972
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1972
+            $all_price_types[$price_type->ID()] = $price_type->get('PRT_name');
1973 1973
             // while we're in the loop let's setup the option spans used by js
1974 1974
             $span_args = array(
1975 1975
                 'PRT_ID'         => $price_type->ID(),
@@ -1977,12 +1977,12 @@  discard block
 block discarded – undo
1977 1977
                 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1978 1978
             );
1979 1979
             $price_option_spans .= EEH_Template::display_template(
1980
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1980
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php',
1981 1981
                 $span_args,
1982 1982
                 true
1983 1983
             );
1984 1984
         }
1985
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1985
+        $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]'
1986 1986
             : $select_name;
1987 1987
         $select_input = new EE_Select_Input(
1988 1988
             $all_price_types,
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
             $this->_is_creating_event
2020 2020
         );
2021 2021
         return EEH_Template::display_template(
2022
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2022
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php',
2023 2023
             $template_args,
2024 2024
             true
2025 2025
         );
@@ -2045,8 +2045,8 @@  discard block
 block discarded – undo
2045 2045
         $ticket_datetimes = array(),
2046 2046
         $default
2047 2047
     ) {
2048
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2049
-            ? $ticket_datetimes[ $ticket->ID() ]
2048
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
2049
+            ? $ticket_datetimes[$ticket->ID()]
2050 2050
             : array();
2051 2051
         $template_args = array(
2052 2052
             'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
@@ -2078,7 +2078,7 @@  discard block
 block discarded – undo
2078 2078
             $this->_is_creating_event
2079 2079
         );
2080 2080
         return EEH_Template::display_template(
2081
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2081
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2082 2082
             $template_args,
2083 2083
             true
2084 2084
         );
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
         $default_prices = $price_model->get_all_default_prices();
2185 2185
         $price_row = 1;
2186 2186
         foreach ($default_prices as $price) {
2187
-            if (! $price instanceof EE_Price) {
2187
+            if ( ! $price instanceof EE_Price) {
2188 2188
                 continue;
2189 2189
             }
2190 2190
             if ($price->is_base_price()) {
@@ -2221,7 +2221,7 @@  discard block
 block discarded – undo
2221 2221
             $this->_is_creating_event
2222 2222
         );
2223 2223
         return EEH_Template::display_template(
2224
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2224
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php',
2225 2225
             $template_args,
2226 2226
             true
2227 2227
         );
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks_Extend.class.php 1 patch
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -16,214 +16,214 @@
 block discarded – undo
16 16
 class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks
17 17
 {
18 18
 
19
-    /**
20
-     * extending the properties set in espresso_events_Registration_From_Hooks
21
-     *
22
-     * @access protected
23
-     * @return void
24
-     */
25
-    protected function _extend_properties()
26
-    {
27
-        if (
28
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
-            && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
-        ) {
31
-            return;
32
-        }
33
-        $this->_metaboxes = array_merge(
34
-            $this->_metaboxes,
35
-            array(
36
-                1 => array(
37
-                    'page_route' => array('create_new', 'edit'),
38
-                    'func'       => 'additional_questions',
39
-                    'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
40
-                    'priority'   => 'default',
41
-                    'context'    => 'side',
42
-                ),
43
-            )
44
-        );
45
-        $this->_scripts_styles = array(
46
-            'registers' => array(
47
-                'extended-event-editor' => array(
48
-                    'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
49
-                                 . 'registration_form/assets/event-editor-question-groups.js',
50
-                    'depends' => array('jquery'),
51
-                ),
52
-            ),
53
-            'enqueues'  => array(
54
-                'extended-event-editor' => array('edit', 'create_new'),
55
-            ),
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     * @param Callable[] $callbacks
62
-     * @return array
63
-     */
64
-    public function modify_callbacks($callbacks)
65
-    {
66
-        $callbacks = parent::modify_callbacks($callbacks);
67
-        $callbacks[] = array($this, 'additional_question_group_update');
68
-        return $callbacks;
69
-    }
70
-
71
-
72
-    /**
73
-     * Call back hooked into revision restores.
74
-     *
75
-     * @param $post_id
76
-     * @param $revision_id
77
-     * @return EE_Base_Class|void
78
-     * @throws EE_Error
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     * @throws ReflectionException
83
-     */
84
-    public function restore_revision($post_id, $revision_id)
85
-    {
86
-        $post_evt = parent::restore_revision($post_id, $revision_id);
87
-
88
-        // restore revision for additional questions
89
-        $post_evt->restore_revision(
90
-            $revision_id,
91
-            ['Question_Group'],
92
-            [
93
-                'Question_Group' => ['Event_Question_Group.EQG_additional' => true],
94
-            ]
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * @param $post_id
101
-     * @param $post
102
-     * @throws EE_Error
103
-     * @throws InvalidArgumentException
104
-     * @throws InvalidDataTypeException
105
-     * @throws InvalidInterfaceException
106
-     */
107
-    public function additional_questions($post_id, $post)
108
-    {
109
-        $this->_event = $this->_adminpage_obj->get_event_object();
110
-        $event_id = $this->_event->ID();
111
-        ?>
19
+	/**
20
+	 * extending the properties set in espresso_events_Registration_From_Hooks
21
+	 *
22
+	 * @access protected
23
+	 * @return void
24
+	 */
25
+	protected function _extend_properties()
26
+	{
27
+		if (
28
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
+			&& $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
+		) {
31
+			return;
32
+		}
33
+		$this->_metaboxes = array_merge(
34
+			$this->_metaboxes,
35
+			array(
36
+				1 => array(
37
+					'page_route' => array('create_new', 'edit'),
38
+					'func'       => 'additional_questions',
39
+					'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
40
+					'priority'   => 'default',
41
+					'context'    => 'side',
42
+				),
43
+			)
44
+		);
45
+		$this->_scripts_styles = array(
46
+			'registers' => array(
47
+				'extended-event-editor' => array(
48
+					'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
49
+								 . 'registration_form/assets/event-editor-question-groups.js',
50
+					'depends' => array('jquery'),
51
+				),
52
+			),
53
+			'enqueues'  => array(
54
+				'extended-event-editor' => array('edit', 'create_new'),
55
+			),
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @param Callable[] $callbacks
62
+	 * @return array
63
+	 */
64
+	public function modify_callbacks($callbacks)
65
+	{
66
+		$callbacks = parent::modify_callbacks($callbacks);
67
+		$callbacks[] = array($this, 'additional_question_group_update');
68
+		return $callbacks;
69
+	}
70
+
71
+
72
+	/**
73
+	 * Call back hooked into revision restores.
74
+	 *
75
+	 * @param $post_id
76
+	 * @param $revision_id
77
+	 * @return EE_Base_Class|void
78
+	 * @throws EE_Error
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function restore_revision($post_id, $revision_id)
85
+	{
86
+		$post_evt = parent::restore_revision($post_id, $revision_id);
87
+
88
+		// restore revision for additional questions
89
+		$post_evt->restore_revision(
90
+			$revision_id,
91
+			['Question_Group'],
92
+			[
93
+				'Question_Group' => ['Event_Question_Group.EQG_additional' => true],
94
+			]
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param $post_id
101
+	 * @param $post
102
+	 * @throws EE_Error
103
+	 * @throws InvalidArgumentException
104
+	 * @throws InvalidDataTypeException
105
+	 * @throws InvalidInterfaceException
106
+	 */
107
+	public function additional_questions($post_id, $post)
108
+	{
109
+		$this->_event = $this->_adminpage_obj->get_event_object();
110
+		$event_id = $this->_event->ID();
111
+		?>
112 112
         <div class="inside">
113 113
             <p><strong>
114 114
                     <?php _e('Question Groups', 'event_espresso'); ?>
115 115
                 </strong><br/>
116 116
                 <?php
117
-                printf(
118
-                    esc_html__(
119
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event.',
120
-                        'event_espresso'
121
-                    ),
122
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
123
-                    '</a>'
124
-                );
125
-                ?>
117
+				printf(
118
+					esc_html__(
119
+						'Add a pre-populated %1$sgroup of questions%2$s to your event.',
120
+						'event_espresso'
121
+					),
122
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
123
+					'</a>'
124
+				);
125
+				?>
126 126
             </p>
127 127
             <?php
128 128
 
129
-            $qsg_where['QSG_deleted'] = false;
130
-            $query_params = apply_filters(
131
-                'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
132
-                array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
133
-            );
134
-            $QSGs = EEM_Question_Group::instance()->get_all($query_params);
135
-            $EQGs = ! empty($event_id)
136
-                ? $this->_event->get_many_related(
137
-                    'Question_Group',
138
-                    [['Event_Question_Group.EQG_additional' => true]]
139
-                )
140
-                : [];
141
-            $EQGids = array_keys($EQGs);
142
-
143
-            if (! empty($QSGs)) {
144
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
145
-                foreach ($QSGs as $QSG) {
146
-                    $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : '';
147
-                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
148
-                        array(
149
-                            'action' => 'edit_question_group',
150
-                            'QSG_ID' => $QSG->ID(),
151
-                        ),
152
-                        EE_FORMS_ADMIN_URL
153
-                    );
154
-
155
-                    $html .= '
129
+			$qsg_where['QSG_deleted'] = false;
130
+			$query_params = apply_filters(
131
+				'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
132
+				array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
133
+			);
134
+			$QSGs = EEM_Question_Group::instance()->get_all($query_params);
135
+			$EQGs = ! empty($event_id)
136
+				? $this->_event->get_many_related(
137
+					'Question_Group',
138
+					[['Event_Question_Group.EQG_additional' => true]]
139
+				)
140
+				: [];
141
+			$EQGids = array_keys($EQGs);
142
+
143
+			if (! empty($QSGs)) {
144
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
145
+				foreach ($QSGs as $QSG) {
146
+					$checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : '';
147
+					$edit_link = EE_Admin_Page::add_query_args_and_nonce(
148
+						array(
149
+							'action' => 'edit_question_group',
150
+							'QSG_ID' => $QSG->ID(),
151
+						),
152
+						EE_FORMS_ADMIN_URL
153
+					);
154
+
155
+					$html .= '
156 156
 					<p id="event-question-group-' . $QSG->ID() . '">
157 157
 						<input value="' . $QSG->ID() . '"'
158
-                             . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
158
+							 . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
159 159
 						<a href="' . $edit_link . '" title="'
160
-                             . sprintf(
161
-                                 esc_attr__('Edit %s Group', 'event_espresso'),
162
-                                 $QSG->get('QSG_name')
163
-                             )
164
-                             . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
160
+							 . sprintf(
161
+								 esc_attr__('Edit %s Group', 'event_espresso'),
162
+								 $QSG->get('QSG_name')
163
+							 )
164
+							 . '" target="_blank">' . $QSG->get('QSG_name') . '</a>
165 165
 					</p>';
166
-                    if ($QSG->ID() === 2) {
167
-                        $html .= '
166
+					if ($QSG->ID() === 2) {
167
+						$html .= '
168 168
 					<p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">'
169
-                                 . esc_html__(
170
-                                     'The Personal Information question group is required whenever the Address Information question group is activated.',
171
-                                     'event_espresso'
172
-                                 )
173
-                                 . '</p>';
174
-                    }
175
-                }
176
-                $html .= count($QSGs) > 10 ? '</div>' : '';
177
-
178
-                echo $html;
179
-            } else {
180
-                esc_html_e(
181
-                    'There seems to be a problem with your questions. Please contact [email protected]',
182
-                    'event_espresso'
183
-                );
184
-            }
185
-            do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
186
-            ?>
169
+								 . esc_html__(
170
+									 'The Personal Information question group is required whenever the Address Information question group is activated.',
171
+									 'event_espresso'
172
+								 )
173
+								 . '</p>';
174
+					}
175
+				}
176
+				$html .= count($QSGs) > 10 ? '</div>' : '';
177
+
178
+				echo $html;
179
+			} else {
180
+				esc_html_e(
181
+					'There seems to be a problem with your questions. Please contact [email protected]',
182
+					'event_espresso'
183
+				);
184
+			}
185
+			do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
186
+			?>
187 187
         </div>
188 188
         <?php
189
-    }
190
-
191
-
192
-    public function additional_question_group_update($evtobj, $data)
193
-    {
194
-        $question_groups = ! empty($data['add_attendee_question_groups'])
195
-            ? (array) $data['add_attendee_question_groups']
196
-            : [];
197
-        $added_qgs = array_keys($question_groups);
198
-        $success = [];
199
-
200
-        // let's get all current question groups associated with this event.
201
-        $current_qgs = $evtobj->get_many_related(
202
-            'Question_Group',
203
-            [['Event_Question_Group.EQG_additional' => true]]
204
-        );
205
-        $current_qgs = array_keys($current_qgs); // we just want the ids
206
-
207
-        // now let's get the groups selected in the editor and update (IF we have data)
208
-        if (! empty($question_groups)) {
209
-            foreach ($question_groups as $qgid) {
210
-                // add to event
211
-                if ($qgid) {
212
-                    $qg = $evtobj->add_question_group($qgid, false);
213
-                }
214
-                $success[] = ! empty($qg) ? 1 : 0;
215
-            }
216
-        }
217
-
218
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
219
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
220
-
221
-        foreach ($removed_qgs as $qgid) {
222
-            $qg = $evtobj->remove_question_group($qgid, false);
223
-            $success[] = ! empty($qg) ? 1 : 0;
224
-        }
225
-
226
-
227
-        return in_array(0, $success, true) ? false : true;
228
-    }
189
+	}
190
+
191
+
192
+	public function additional_question_group_update($evtobj, $data)
193
+	{
194
+		$question_groups = ! empty($data['add_attendee_question_groups'])
195
+			? (array) $data['add_attendee_question_groups']
196
+			: [];
197
+		$added_qgs = array_keys($question_groups);
198
+		$success = [];
199
+
200
+		// let's get all current question groups associated with this event.
201
+		$current_qgs = $evtobj->get_many_related(
202
+			'Question_Group',
203
+			[['Event_Question_Group.EQG_additional' => true]]
204
+		);
205
+		$current_qgs = array_keys($current_qgs); // we just want the ids
206
+
207
+		// now let's get the groups selected in the editor and update (IF we have data)
208
+		if (! empty($question_groups)) {
209
+			foreach ($question_groups as $qgid) {
210
+				// add to event
211
+				if ($qgid) {
212
+					$qg = $evtobj->add_question_group($qgid, false);
213
+				}
214
+				$success[] = ! empty($qg) ? 1 : 0;
215
+			}
216
+		}
217
+
218
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
219
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
220
+
221
+		foreach ($removed_qgs as $qgid) {
222
+			$qg = $evtobj->remove_question_group($qgid, false);
223
+			$success[] = ! empty($qg) ? 1 : 0;
224
+		}
225
+
226
+
227
+		return in_array(0, $success, true) ? false : true;
228
+	}
229 229
 }
Please login to merge, or discard this patch.